Skip to content

fix: history open session as tab for cross-project and Codex#730

Open
pedramamini wants to merge 3 commits intomainfrom
251-fix-history-open-session-as-tab
Open

fix: history open session as tab for cross-project and Codex#730
pedramamini wants to merge 3 commits intomainfrom
251-fix-history-open-session-as-tab

Conversation

@pedramamini
Copy link
Copy Markdown
Collaborator

@pedramamini pedramamini commented Apr 5, 2026

Summary

Closes #251

  • Bug A fix: Thread projectPath from history entries through HistoryEntryItemRightPanelhandleResumeSession, so sessions from different projects resolve correctly instead of always using activeSession.projectRoot. This fixes the AgentSessions read error when opening sessions from a different project.
  • Bug B fix: Update Codex findSessionFile() and findSessionFileRemote() to also match metadata.payload?.id in addition to metadata.id, consistent with how parseSessionFile() already handles the newer Codex session format. This fixes empty tabs when resuming Codex sessions.

Test plan

  • TypeScript type checking passes (npm run lint)
  • ESLint passes (npm run lint:eslint)
  • All 22,445 tests pass (npm run test)
  • Manual: Open History, click "Open session as new tab" for a Claude Code session from a different project — should open correctly
  • Manual: Open History, click "Open session as new tab" for a Codex session — should load messages

Summary by CodeRabbit

  • New Features

    • Session opening functionality now passes project path context through the callback chain.
  • Bug Fixes

    • Enhanced session file lookup to recognize sessions using alternate ID field locations.
  • Documentation

    • Updated guidance on auto-run document placement to enforce flat directory structure.
  • Chores

    • Normalized line ending formatting in release notes.

- Standardized multi-phase auto-run docs into one flat, dated subdirectory 📁
- Explicitly banned nested project/feature folder structures for phase outputs 🚫
- Improved guidance for clean lexicographic sorting with zero-padded phases 🔢
- Made it easier to add entire effort folders to auto-run at once ➕
- Clarified organization rules so related phase documents stay tightly grouped 🧭
…x session lookup (#251)

Two fixes for "Open session as new tab" in History:

1. Thread projectPath from history entries through to handleResumeSession so
   sessions from different projects resolve correctly instead of always using
   activeSession.projectRoot.

2. Update Codex findSessionFile/findSessionFileRemote to also check
   metadata.payload.id, matching the newer Codex session format where the
   session ID lives in payload.id rather than the top-level id field.
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 5, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: efa8e56a-ba76-4404-9f29-af8d703ee99b

📥 Commits

Reviewing files that changed from the base of the PR and between 3e0e338 and 1a74dbb.

📒 Files selected for processing (11)
  • docs/releases.md
  • src/__tests__/renderer/components/History/HistoryEntryItem.test.tsx
  • src/__tests__/renderer/components/HistoryPanel.test.tsx
  • src/main/storage/codex-session-storage.ts
  • src/prompts/maestro-system-prompt.md
  • src/renderer/components/DirectorNotes/UnifiedHistoryTab.tsx
  • src/renderer/components/History/HistoryEntryItem.tsx
  • src/renderer/components/HistoryPanel.tsx
  • src/renderer/components/RightPanel.tsx
  • src/renderer/hooks/agent/useAgentSessionManagement.ts
  • src/renderer/hooks/props/useRightPanelProps.ts

📝 Walkthrough

Walkthrough

This PR addresses session-opening failures by threading project path context through history callbacks. Components now pass projectPath when resuming sessions, allowing resume logic to use the correct project root instead of always defaulting to the active session's root. Session storage also checks payload.id for Codex sessions.

Changes

Cohort / File(s) Summary
Documentation Formatting
docs/releases.md, src/prompts/maestro-system-prompt.md
Line-ending normalization and prompt clarification for multi-phase document placement; no functional changes.
Component Prop Signatures
src/renderer/components/History/HistoryEntryItem.tsx, src/renderer/components/HistoryPanel.tsx, src/renderer/components/RightPanel.tsx, src/renderer/components/DirectorNotes/UnifiedHistoryTab.tsx
Updated callback signatures to accept optional projectPath?: string parameter and pass it through the component hierarchy when opening sessions.
Hook Updates
src/renderer/hooks/agent/useAgentSessionManagement.ts, src/renderer/hooks/props/useRightPanelProps.ts
Extended handleResumeSession to accept optional projectPath parameter and derive resolvedProjectRoot from provided path or active session; updated prop wiring to thread projectPath through resume flow.
Session Storage
src/main/storage/codex-session-storage.ts
Updated session file lookup to check both metadata.id and metadata.payload?.id for Codex session matching.
Test Updates
src/__tests__/renderer/components/History/HistoryEntryItem.test.tsx, src/__tests__/renderer/components/HistoryPanel.test.tsx
Updated callback expectations to verify onOpenSessionAsTab is called with both session ID and project path arguments.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 A tale of tabs that find their way,
With project paths now passed to play,
Sessions open where they're meant,
No more errors—intent is sent! 🎩✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: history open session as tab for cross-project and Codex' directly summarizes the main change: fixing the 'Open session as tab' feature for cross-project and Codex sessions.
Linked Issues check ✅ Passed All code requirements from issue #251 are met: projectPath is threaded through components [HistoryEntryItem, HistoryPanel, RightPanel, useAgentSessionManagement], and codex-session-storage now checks both metadata.id and metadata.payload?.id.
Out of Scope Changes check ✅ Passed Changes are focused and in-scope: test updates align with signature changes, docs/releases.md is a documentation-only normalization, maestro-system-prompt.md clarifies rules, and all other changes directly support the two bugs from issue #251.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 251-fix-history-open-session-as-tab

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@greptile-apps
Copy link
Copy Markdown

greptile-apps bot commented Apr 5, 2026

Greptile Summary

This PR fixes two independent bugs in the History panel's "open session as new tab" feature.

Bug A threads projectPath from HistoryEntry down the HistoryEntryItem → HistoryPanel → RightPanel → useRightPanelProps → handleResumeSession prop chain, so that sessions from a different project use the correct project root when reading session files — instead of always falling back to activeSession.projectRoot, which caused an AgentSessions read error for cross-project sessions.

Bug B updates findSessionFile() and findSessionFileRemote() in CodexSessionStorage to also match metadata.payload?.id, consistent with how parseSessionFile() already handled the newer Codex session format. This fixes empty tabs when resuming Codex sessions whose session ID is stored in the payload wrapper rather than at the top level.

Key changes:

  • HistoryEntryItem now passes entry.projectPath when invoking onOpenSessionAsTab
  • handleResumeSession in useAgentSessionManagement accepts an optional projectPath and uses projectPath || activeSession.projectRoot for resolution
  • useRightPanelProps forwards projectPath from the onOpenSessionAsTab wrapper to handleResumeSession
  • Codex findSessionFile/findSessionFileRemote now check metadata.payload?.id in addition to metadata.id
  • Tests updated to verify the projectPath is forwarded correctly

Confidence Score: 4/5

Safe to merge - both fixes are narrowly scoped, additive, and follow existing patterns without touching risky infrastructure.

Both bug fixes are correct and well-tested. The only caveat is that the cross-project projectPath fix is partial: the session-pill button is fixed, but the HistoryDetailModal resume button still omits projectPath. This is a pre-existing gap rather than a regression introduced by this PR.

src/renderer/components/HistoryPanel.tsx - the HistoryDetailModal onResumeSession callback does not forward projectPath, leaving the detail-modal cross-project resume path still broken.

Important Files Changed

Filename Overview
src/main/storage/codex-session-storage.ts Adds metadata.payload?.id check in findSessionFile and findSessionFileRemote, consistent with how parseSessionFile already handles the newer Codex session format; fixes empty tabs when resuming Codex sessions with the newer payload-wrapped ID
src/renderer/components/History/HistoryEntryItem.tsx Passes entry.projectPath as second argument to onOpenSessionAsTab; prop interface correctly updated with optional projectPath parameter
src/renderer/components/HistoryPanel.tsx Propagates the updated onOpenSessionAsTab signature with optional projectPath; the HistoryDetailModal onResumeSession callback still omits projectPath (see inline comment)
src/renderer/components/RightPanel.tsx Forwards the updated onOpenSessionAsTab prop signature with optional projectPath; no logic change beyond prop threading
src/renderer/hooks/agent/useAgentSessionManagement.ts handleResumeSession now accepts optional projectPath and uses projectPath
src/renderer/hooks/props/useRightPanelProps.ts onOpenSessionAsTab wrapper correctly forwards projectPath to handleResumeSession; onResumeSession still maps directly to handleResumeSession without projectPath, leaving the detail-modal resume path as a pre-existing gap
src/renderer/components/DirectorNotes/UnifiedHistoryTab.tsx Correctly ignores _projectPath in handleOpenSessionAsTab since the unified view routes via entry.sourceSessionId; intentional and correct
src/tests/renderer/components/History/HistoryEntryItem.test.tsx New test verifies onOpenSessionAsTab is called with both the session ID and entry.projectPath, directly covering the Bug A fix
src/tests/renderer/components/HistoryPanel.test.tsx Test suite updated to reflect component changes; good coverage of filter, navigation, and history-loading behaviour
docs/releases.md Whitespace and blank-line formatting changes only; no content modifications

Sequence Diagram

sequenceDiagram
    participant H as HistoryEntryItem
    participant HP as HistoryPanel
    participant RP as RightPanel
    participant URPP as useRightPanelProps
    participant UASM as useAgentSessionManagement
    participant IPC as window.maestro.agentSessions

    H->>HP: onOpenSessionAsTab(agentSessionId, entry.projectPath)
    HP->>RP: onOpenSessionAsTab(agentSessionId, projectPath)
    RP->>URPP: onOpenSessionAsTab(agentSessionId, projectPath)
    URPP->>UASM: handleResumeSession(agentSessionId, ..., projectPath)
    UASM->>UASM: resolvedProjectRoot = projectPath or activeSession.projectRoot
    UASM->>IPC: agentSessions.read(agentId, resolvedProjectRoot, agentSessionId, ...)
    IPC-->>UASM: messages
    UASM->>UASM: createTab with messages

    Note over HP,RP: onResumeSession (detail modal path) still passes only agentSessionId
Loading

Comments Outside Diff (1)

  1. src/renderer/components/HistoryPanel.tsx, line 596-602 (link)

    P2 Cross-project resume via detail modal still broken

    The projectPath fix only covers the session-pill "Open as tab" button (onOpenSessionAsTab). When a user opens the detail modal for a cross-project history entry and clicks the Resume button inside it, HistoryDetailModal calls onResumeSession(entry.agentSessionId) with only the session ID and no projectPath. Because onResumeSession in useRightPanelProps (line 143) is mapped directly to handleResumeSession without forwarding a projectPath, the cross-project lookup falls back to activeSession.projectRoot and will still produce the same AgentSessions read error on that code path.

    To complete the fix, extend HistoryDetailModal's onResumeSession prop signature to also accept an optional projectPath (passing entry.projectPath at the call site), and thread that through HistoryPanel → RightPanel → useRightPanelProps the same way onOpenSessionAsTab was updated in this PR.

Reviews (1): Last reviewed commit: "style: format docs/releases.md with pret..." | Re-trigger Greptile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

History “Open session … as new tab” fails for local Claude Code (AgentSessions read error) and opens empty tab for local Codex

1 participant