Skip to content

feat(tui): read a background subagent's own session - #692

Merged
mohitranka merged 1 commit into
mainfrom
feat/child-session-view-tui
Sep 15, 2026
Merged

mohitranka merged 1 commit into
mainfrom
feat/child-session-view-tui

Conversation

@mohitranka

Copy link
Copy Markdown
Contributor

→ on a background task row now shows that subagent's own session — what it actually did, rather than an inference from a label — and ← returns. This is P5a; the smaller half of P5.

Read-only by construction

The child owns that session and may still be writing to it, so this replays its journal instead of opening a second runtime. The open_session route — which an earlier version of this plan called for — constructs a runtime, which would make this TUI a second owner of a session a subagent is writing to. Replaying is a second reader, which is what the durable store's WAL mode (SqliteJournalMode::Wal, forge-durable/src/lib.rs:292) permits.

The TUI therefore never holds a second AgentSession: no ownership question, no second writer, and nothing to unwind on the way out.

The chain

Journal::open(dir, id).await? | journal.replay(id).await?   // forge-durable
  -> forge_core::session_messages(dir, id)                  // same shape as the existing session_title_hint
  -> forge_session::replayed_transcript(dir, id, revision)
  -> the pane's existing TranscriptSnapshot

Each step is a thin pass-through, so the projection rule lives in one place. session_title_hint was the precedent — same Journal::open + replay, "independent of any live AgentSession (no tools/model/governance needed)" — so this adds a sibling rather than a new mechanism.

Details that are load-bearing

  • The child's revision must differ from the one it replaces. ConversationRenderKey keys on session_id and revision; reusing the parent's would put the parent's rendered lines behind the child's transcript.
  • Leaving restores the parent's TranscriptSnapshot rather than re-capturing it, so the return trip is a restore and the parent's revision stays intact.
  • The composer refuses input while the view is open. The hint alone would be a promise the TUI cannot keep.

Notes for the reviewer

  • events is empty in the child view. TurnEvents are not replayed, so it shows the conversation without the live activity rows the owning session carries. Documented on from_messages.
  • Not yet done, deliberately: the breadcrumb is the composer hint (read-only · viewing explore · ← to return) rather than chrome above the transcript, and the view does not refresh as a live child writes. Both are worth doing; neither is needed for the view to be correct rather than stale-by-design.
  • The header still describes the parent session (workspace, branch). The child runs in its own worktree, so those do not match while the view is open. The hint names the child that is on screen. Worth fixing with the breadcrumb.
  • A promoted row in the navigator's Sessions list (the other half of the "navigator promotion" idea) is not in this PR: → from the strip reaches the same view without inventing rows for sessions the TUI does not own.

Verification

  • cargo fmt --all -- --check clean; cargo clippy --package forge-core --package forge-session --package forge-tui --all-targets --locked -- -D warnings clean.
  • New tests: opening shows the child's own conversation with a distinct revision and the read-only hint, and ← restores the parent's snapshot exactly; a shell task is refused with a reason rather than opening an empty view; the composer does not take a character while the view is open.
  • The three local app::tests::tasks sandbox failures are unchanged and pass on CI.

`→` on a background task row now shows that subagent's session — what it
actually did, rather than an inference from a label — and `←` returns.

Read-only by construction. The child owns that session and may still be writing
to it, so this replays its journal instead of opening a second runtime: the
`open_session` route builds a runtime, which would make this TUI a second
*owner* of a session a subagent is writing to. Replaying is a second *reader*,
which is what the durable store's WAL mode permits. The TUI never holds a second
`AgentSession`, so there is no ownership question, no second writer, and nothing
to unwind on the way out.

The chain is `Journal::open` + `replay` (already used by `session_title_hint`,
which is the same read-only shape) -> `forge_core::session_messages` ->
`forge_session::replayed_transcript` -> the pane's existing `TranscriptSnapshot`.
Each step is a thin pass-through, so the projection rule lives in one place.

Details that are load-bearing:

- The child's revision must differ from the one it replaces. The conversation
  render cache keys on `session_id` *and* revision, and unsticking either would
  put the parent's rendered lines behind the child's transcript.
- Leaving restores the parent's `TranscriptSnapshot` rather than re-capturing
  it, so the return trip is a restore and the parent's revision stays intact.
- The composer hint carries the read-only notice, and the composer refuses
  input while the view is open — the hint alone would be a promise the TUI
  cannot keep.

Tests: opening shows the child's own conversation with a distinct revision and
the read-only hint, and `←` restores the parent's snapshot exactly; a shell task
is refused with a reason rather than opening an empty view; and the composer
does not take a character while the view is open.
@mohitranka
mohitranka merged commit 14bdfd0 into main Sep 15, 2026
3 checks passed
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.

1 participant