Skip to content

fix(orchestration): unify structured-session status across worktree ps and sidebar - #19217

Merged
brennanb2025 merged 8 commits into
mainfrom
brennanb2025/structured-worktree-ps
Sep 9, 2026
Merged

brennanb2025 merged 8 commits into
mainfrom
brennanb2025/structured-worktree-ps

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 8 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​711 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​709
Prod 26 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​421 $\color{#cf222e}{\Huge{\mathbf{−}}}$​170 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​251

Structured Claude and Codex chats have no PTY or hook snapshots, so worktree ps could report no agent activity while the sidebar showed a running chat.

The runtime now reads the execution host's currently held sessions through source adapters and uses the shared working/blocked/done mapping. PTY admission and expiry stay unchanged, and structured chats are not added to terminal inventory.

Live execution ownership is distinct from retained conversation history. An optional ownership marker keeps genuinely running or approval-waiting sessions active beyond the hook timeout, without changing journal timestamps. Completion does not become a permission wait. Provider exit, handoff, rewind, closure, and status-feed teardown revoke ownership; reconnects cannot restore it from stale callbacks or cached history. Older hosts without the marker retain the freshness fallback.

Validation: focused host, renderer, lifecycle, and runtime regression tests; the installed-host worktree ps call-site tests; typechecking and changed-code quality checks. Final Electron evidence and review status are recorded in the review comment.

Follow-up to #18827.

…ion as idle

A worktree running a structured Claude or Codex chat read as idle to `orca
worktree ps`, while the desktop sidebar showed the same session working. The
sidebar was right: the host already projects a status summary for every
structured session and publishes it, and the renderer maps it into an agent
row. `worktree ps` simply never consumed it, so the agent-facing surface was
the blind one.

Structured sessions have no PTY, so they reach neither the hook snapshots nor
the retained ones that every other row is built from. This reads the summaries
the host has already published and applies the same projection the sidebar
does — working, attention as blocked, otherwise done — so the CLI and the GUI
cannot disagree about one session.

Two things worth knowing:

The connected-PTY evidence gate had to be skipped for these rows. It exists to
drop a row whose PTY is gone, which is the wrong question for a session that
never had one; a structured row's liveness evidence is the status feed that
produced it. The exemption is keyed on the row being structured, so every
PTY-backed row keeps today's behaviour.

`RuntimeWorktreeAgentRow` needed no change. It was already a non-PTY shape —
paneKey, state, agentType, and no ptyId, connected or writable — so a
structured row fits without inventing a fake terminal coordinate.

The pane key is the DERIVED one the renderer already publishes, never the
orchestration bearer handle or the minted worker pane key: both are
credentials, since `orchestration check` is identity-gated and accepts a
caller-supplied pane key.

`orca terminal list` is deliberately untouched, and a test pins that. Adding
rows there breaks real consumers: mobile mounts a terminal WebView per row that
can never receive a frame, a `connected`-keyed refresh check goes permanently
true and pins shipped clients to a fast cadence with no exit, and the plugin
projection has no field that can carry `writable: false`. Every safe consumer
of a terminal summary checks `ptyId`; the breaking ones key off `connected` or
mere row presence, which no added field can qualify. An honest partial-listing
count there is a separate change.
@coderabbitai

coderabbitai Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The status feed now exposes summaries only for sessions still held in its live session map. worktree ps consumes these summaries through unified agent-source collection and projects structured sessions into non-PTY agent rows. Shared status mapping is used by worktree reporting and the renderer bridge. Tests cover status mapping, pane keys, null statuses, terminal-listing isolation, source admission, host access, and session eviction.

Priority: ➖ Normal

Merge Risk: 🟡 Moderate · up to e370a

Idle structured sessions may be reported as requiring permission rather than inactive, producing incorrect worktree status until done rows are excluded from activity aggregation.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 44.44% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 18 functions across 17 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The description explains the problem, implementation, issue follow-up, and validation, but it omits required template sections and checklist details. It does not provide visual proof or an explicit `N… Complete the required template sections. Add visual proof for the behavior change, or write N/A with a reason if no visual or interaction change exists. Add explicit testing details, including platforms and manual-test status. Complete th…
✅ Passed checks (3 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely describes the main change: unified structured-session status handling between worktree ps and the sidebar.
Full details: Description check

Explanation

The description explains the problem, implementation, issue follow-up, and validation, but it omits required template sections and checklist details. It does not provide visual proof or an explicit N/A explanation, manual-testing and platform status, AI disclosure, review notes, or the required checklist confirmations.

Resolution

Complete the required template sections. Add visual proof for the behavior change, or write N/A with a reason if no visual or interaction change exists. Add explicit testing details, including platforms and manual-test status. Complete the AI Disclosure, Review, Agent skill upstream boundary, Notes, and Checklist sections. Record the linked issue in the required Fixes #... format if applicable.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: 36f38468-3d9e-4839-923f-2d4457186a82

📥 Commits

Reviewing files that changed from the base of the PR and between fa5ef99 and a2f4bd9.

📒 Files selected for processing (5)
  • src/main/native-chat/agent-session-wire/structured-agent-session-host.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-status-feed.ts
  • src/main/runtime/orca-runtime-get-worktree-ps.ts
  • src/main/runtime/runtime-worktree-agent-rows-structured.test.ts
  • src/main/runtime/runtime-worktree-agent-rows.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

The enumerator reads every summary the host has ever projected, including sessions whose tabs have since been closed, so worktree ps will report closed structured chats as phantom rows.

Reviewed changes

  • Host exposes its projected summaries — StructuredAgentSessionHost.publishedStatusSummaries() and StructuredAgentSessionStatusFeed.publishedSummaries() expose the last projected status per session for polling readers.
  • worktree ps enumerates structured sessions — attachRuntimeWorktreeAgentRows accepts a structuredSummaries source and projects each into a row using the same working/blocked/done mapping the sidebar applies, skipping null-status sessions and exempting them from the connected-PTY gate.
  • Tests — five new cases in runtime-worktree-agent-rows-structured.test.ts plus a source ratchet pinning that terminal list stays untouched.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@coderabbitai

coderabbitai Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

The status feed's `published` map is a broadcast cache, not a roster. It
deliberately never retracts — an evicted idle session is still idle, and a
reloading renderer must not lose every settled row — so enumerating it lists
every session the host has ever opened, and eviction's `forget-session` step
deletes the session from the live map while touching nothing else.

Reading it as a roster made `worktree ps` report a closed chat forever. The
sharp edge is a chat closed while an approval was pending: a deliberate close
does not settle a pending prompt, so the retained summary stays `attention`,
maps to a `blocked` row, and merges the worktree to `permission` for the whole
30-minute freshness window — on the CLI and on the mobile sidebar it backs.

The poller now answers from the sessions the host still holds, intersecting the
live map with the retained projections. `subscribe()` and its snapshot are
untouched: retention there is the point. Gating on the live session set rather
than the visible tabs keeps a headless orchestration worker listed, which is
what the agent-facing surface is for.

Also folds out two things the enumerator left behind: the working/attention/idle
to working/blocked/done mapping now lives once in the shared projection module
instead of once per process, which is what actually enforces "the CLI and the
GUI cannot disagree"; and the structured row source no longer builds a
write-only `payload` behind an `as` cast that compensated for nothing. The
structured source construction moves to its own module to keep
runtime-worktree-agent-rows.ts clear of the 300-line cap.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

What changed since the prior review (a2f4bd9):

  • Phantom rows fixed via a live-session intersection — publishedSummaries() became liveSessionSummaries(), which third-party the retained broadcast cache against this.deps.sessions (the map eviction's forget-session step deletes), so worktree ps no longer lists closed structured chats as phantom rows.
  • Source projection extracted — the inline structured-summary loop moved into structuredRuntimeWorktreeAgentSources() in its own module, emitting a structured: true source with the derived pane key and no fake hook payload.
  • payload made optional with a guard — RuntimeWorktreeAgentSource.payload is now optional; retained/hook sources populate flattened top-level fields, and the monitoring hook-match branch gained an existing.payload !== undefined guard.
  • Status-state mapping shared across the wire — structuredAgentSessionStatusState() in structured-agent-session-projection.ts replaces the inline ternary in both the CLI rows and the StructuredAgentSessionStatusBridge, so the two surfaces cannot disagree.
  • Tests — a feed unit test for the liveness intersection plus an end-to-end runtime-worktree-structured-agent-rows-liveness.test.ts covering the closed-chat-parked-on-approval sharp edge (blocked while held, gone once evicted).

The prior findings are addressed and no new issues surfaced. Affected suites pass locally (22 tests).

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

Merge Sim added 2 commits September 7, 2026 13:31
# Conflicts:
#	src/main/native-chat/agent-session-wire/structured-agent-session-host.ts
Both structured-row suites called attachRuntimeWorktreeAgentRows directly
with summaries they built themselves, so nothing ever ran getWorktreePs's
own `getStructuredAgentSessionHost()?.liveSessionStatusSummaries()`. That
file carries `@ts-nocheck`, so renaming the accessor was green in typecheck
and in the suite, while `orca worktree ps` and mobile's 3s poll would throw
a TypeError for every user — the `?.` optional-chains the host, not the
method. Swapping the call back to a whole-cache read was equally invisible:
the liveness suite injects feed.liveSessionSummaries() itself, and the
string-match guard only needs the identifier to appear somewhere in the file.

Drives the real runtime with a stub host over a real status feed that has
published two sessions and forgotten one, asserting the live session's row
reaches ps output, that the live accessor is the one called, and that the
`?? []` fallback still returns a page with no host installed. The stub is
typed against the real host, so a class-side rename reddens tc here.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

  • Exercised the production worktree ps call site end to end — a new worktree-ps-structured-host.spec.ts drives OrcaRuntimeService(store).getWorktreePs() through the real attachRuntimeWorktreeAgentRows path, whereas both prior structured-row suites called attachRuntimeWorktreeAgentRows directly with hand-built summaries. This closes the /@ts-nocheck/ gap on orca-runtime-get-worktree-ps.ts: renaming liveSessionStatusSummaries (or reverting the call site to a whole-cache read) now reddens the suite, since the test pins both the accessor name via expect(liveSessionStatusSummaries).toHaveBeenCalledTimes(1) and the live-only behavior via the toHaveLength(1) assertion on a feed that still retains a forgotten session.

The change is test-only; the production wiring and projection are unchanged from the prior reviewed state.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review status: ready to merge — with one follow-up I'd file before someone trips over it

Reviewed across four loops (independent review, precedent review, two fix rounds, plus opening and closing readiness audits). One blocker was found and fixed, three smaller items were folded in, and the branch was brought up to date with main. Judgments are separated below.

1. Functional correctness

A blocker was found and fixed. The original revision enumerated StructuredAgentSessionStatusFeed.published as if it were a roster of live sessions. It is a broadcast cache that deliberately never retracts, and the contract saying so is written on the type this PR consumes — src/shared/agent-session-wire.ts:209-210:

"A summary outlives its provider child … the host keeps the last projection and never retracts one. Tabs, not this feed, decide what is listed."

published has no delete path; eviction's forget-session step removes the session from the live map (structured-agent-session-host-lifetime.ts:53-56) and touches nothing else. Because this PR also exempted structured rows from the connected-PTY gate, nothing else dropped them either. Two certain consequences:

  • Ghost rows. Every structured chat opened during an app generation stayed in worktree ps until restart. mobile/src/worktree/host-worktree-refresh.ts:5 polls worktree.ps every 3s and WorktreeListRow.tsx:198 renders every row unfiltered — agent-row-display.ts decays the dot at 30 min but never drops the row.
  • A closed chat pinning a worktree to permission for 30 minutes. A deliberate close does not settle a pending approval — settleUnexpectedStructuredAgentSessionExit returns null unless cause === 'unexpected-exit' (structured-agent-session-unexpected-exit.ts:45-47) — so a chat closed on a pending prompt keeps status: 'attention', maps to blocked, stays fresh for the full window, and merges the worktree to permission.

The fix replaces publishedSummaries() with liveSessionSummaries(), intersecting retained projections with the host's live session map. subscribe() and its snapshot are untouched — retention there is the point, and a test pins that a late subscriber still sees an evicted session's summary while the poller does not.

Also folded in: the working/attention/idle → working/blocked/done mapping now lives once in src/shared/structured-agent-session-projection.ts and is called by both the renderer bridge and the main-process row builder (it was duplicated across the process boundary, which is what the PR's own invariant was asserting in prose); a write-only payload behind an as cast was dropped; and structured row-source construction moved to runtime-worktree-structured-agent-rows.ts.

2. Architectural fit

Honest read: the bug class is removed, but one part of the expression is a bolt-on.

The mechanism was twofold — structured sessions reached no row source, and the connected-PTY evidence gate would have dropped them anyway. The first half is genuinely removed: they now have a source, and its liveness is established at the source rather than assumed. The second half is expressed as source.structured !== true && prepended to a five-clause PTY-specific condition. The idea behind it is right — liveness is per source kind, and this kind proves its own — but a negative boolean opt-out on a shared struct is a guard around the gate rather than a model of it.

The greenfield shape would make row sources a discriminated union ({kind:'pty', ptyId, connectionId…} vs {kind:'structured', sessionId…}) with liveness as a per-kind predicate, so the question "what proves this row is live?" is answered exhaustively per kind instead of one kind opting out of another's test. That also keeps the two PTY sources' merge logic off the structured path, and stops a future fourth source adding another boolean.

I did not do that here: it touches the whole row builder and its existing tests for what is otherwise a contained bug fix. Recommended as an actionable follow-up, not a merge gate.

3. Precedent, and where it deviates

Comparing mechanisms rather than surface behaviour:

  • Matches. Deriving a synchronous reader's answer at read time from the live owning collection — rather than from a cached broadcast mirror — is the established shape for exactly this problem, and it is also what this repo already does elsewhere: src/main/runtime/orchestration/structured-session-pointer-delivery.ts:63-76 re-projects from live items precisely so the gate and the visible state cannot disagree.
  • Deviates. The common reference pattern keeps such a mirror truthful with an explicit retraction (a removal message on close/terminate). Orca's feed deliberately does not retract, so this fix works around non-retraction at the read instead of fixing the cache. That deviation is justified here, not accidental: the retention serves a real requirement — a reloading renderer must not lose every settled row — that the reference cases don't have. Two readers genuinely want different answers, so the read-time split is the right resolution.

I am naming the matching part specifically rather than claiming the design "follows precedent" wholesale.

4. Validation performed, and remaining gaps

  • Full sweep of the affected trees: 772 test files / 7768 tests pass. pnpm tc exit 0. oxlint clean.
  • Ablations run against the committed tree, not just asserted. Removing the liveness gate turns exactly two tests red for the right reason. Removing the production call site's accessor turns the new runtime test red with the expected TypeError.
  • A gap in the original test coverage was found and closed. The single line wiring this into production sits in a // @ts-nocheck file, so neither typecheck nor the suite executed it; the only thing touching it was a source-text string match. Under an ablation that renamed the accessor, that string-match test stayed green 5/5 while worktree ps would have thrown for every user — the ?. guards the host, not the method. orca-runtime-tests/worktree-ps-structured-host.spec.ts now drives the real getWorktreePs() with a stub host installed through the registry, and is typed so a class-side rename also reddens tc.
  • Electron: validated in a dev instance at this commit (instance ownership confirmed by binary path). worktree.ps executes end-to-end with a non-null structured host, which is what proves the renamed accessor resolves at runtime given the @ts-nocheck call site.
  • Gap, stated plainly: the working→appears / closed→disappears transitions were not exercised through a real provider session in-app — that needs provider auth on a fresh profile. Those semantics are covered by the integration test that runs the real journal → status feed → row builder chain, which I ablated to confirm it catches a revert.
  • CI on this head: 28 checks, 0 failures, 0 pending.

Known and accepted

  • Orchestration attribution is null on structured rows (taskTitle/displayName/parentPaneKey). The derived pane key cannot match the randomly-minted worker key, and that randomness is deliberate — orchestration.check is identity-gated and matches by leaf suffix (structured-worker-identity.ts:53-67). Emitting the derived key leaks nothing; it was always derivable from the session id the tab id carries in plaintext. Not a regression: no row existed before.
  • 30-minute staleness. summariesEqual ignores updatedAt for non-idle statuses, so a session in one long silent tool call can freeze the published stamp and decay out of the worktree-status merge. Both surfaces decay identically — the renderer early-returns on an unchanged updatedAt and so never restamps either. The row keeps reading working; only the status merge stops. Same behaviour as a hook agent silent for 30 minutes. Pre-existing, out of scope.

Follow-up worth filing now

structured-agent-session-host.ts sits at exactly 300 effective lines against the 300-line cap. main brought it there; this PR needed one line and bought it by deleting a redundant explicit return type on getPersistedVisibleSessionTabIndex (the store declares the identical shape at agent-session-record-store.ts:123, so inference is exact and tc agrees). That dedup removes no information — but it was the last line available. Since CI lints the merge ref, the next PR to touch this file goes red without changing a line of it, and main has already produced one conflict there. It should be split, as its own change rather than inside a bug fix.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Electron validation — screenshots

Captured from a dev instance launched off this branch at ce1024096b, on a fresh profile, with instance ownership confirmed by the running binary's path (pr19217-claude-review/out/electron-dev/.../Orca: 5c83abfe2e.app) rather than by the CDP response alone — an earlier attach landed on a different worktree's app that had taken the port first.

What these show: the app boots and runs at this commit, and the workspace is live. What they do not show: any visual delta — this change is main-process only, and the desktop sidebar reads the store rather than worktree ps, so there is nothing here a screenshot can prove. They are included as run evidence, not as verification of the fix.

The load-bearing Electron evidence is not visual: with a non-null structured host installed, worktree.ps executes end-to-end and returns ok: true. That is what proves the renamed liveSessionStatusSummaries() accessor resolves at runtime, which matters because its only production call site lives in a // @ts-nocheck file that pnpm tc cannot cover, and getStructuredAgentSessionHost()?. optional-chains the host, not the method — so a bad name would surface as a TypeError breaking worktree ps and mobile's 3s poll for every user, structured chat or not. Before the host was installed, that call was short-circuiting and proving nothing; the host-null vs host-present states were distinguished by agentSession.history returning structured_agent_session_unsupported vs agent_session_ownership_unknown.

01-app-running-at-fix-commit.png

02-workspace-active-at-fix-commit.png

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Reviewed and refactored in 0adaea521337cdfa8438bca6c35017fdf727f14d. Independent review and readiness checks ran at the start and end; final independent code review found no proven issues. The PR remains unmerged.

Functional correctness: A real Codex structured session appeared in orca worktree ps as working while the desktop sidebar showed working. Closing its chat tab removed that exact row and returned the worktree to active; a separate completed chat remained present. The executable runtime call-site test was ablated by substituting retained-cache enumeration: it failed with two rows instead of one, then passed after restoring the live-roster accessor.

Architecture: Replaced the third-input/boolean-bypass shape with one admitted source collection. PTY hook/retained reconciliation, connected-process evidence and mirrored workspace resolution now belong to a PTY source adapter. Structured rows come from the installed host's held-session projections; row assembly no longer assumes PTYs or makes structured exceptions. The broadcast cache remains history rather than lifecycle authority. Hold-resume wiring moved into the existing lifetime module, taking the host below its line cap without a lint suppression.

Mechanism boundaries: PTY reports still arrive through independent hook and retained-status channels, so precedence and conservative remote evidence rules remain necessary. A held structured session is not a claim that its provider child is running; successful eviction removes it, while failed cleanup deliberately keeps it available for retry. The existing 30-minute freshness rule and differing CLI/sidebar activity timestamps are preserved; complete timing parity is not claimed.

Validation: On the committed candidate, 1,342 tests passed and one was skipped across eight runtime, source-admission, host, handoff, hold and feed suites. Full pnpm tc passed, as did commit-hook lint/format checks. The independent reviewer separately ran 1,344 tests with one skipped, including restore, eviction and host-scope cases. Electron identity confirmed the target checkout, and all UI actions and full-window captures used background CDP. The launched validation app and both review workers were cleaned up.

Remaining gaps: live Claude approval/input journeys, Windows/Linux/WSL/SSH/relay/mobile runs, and release-scale latency/heap measurements. No provider subprocess, journal replay, new subscription or polling interval was added to the status read. Existing runtime row shape and vocabulary are retained for mobile clients.

The screenshots show actual CLI JSON reduced to status, provider and pane identity beside the sidebar:

Working structured session:

Working CLI and sidebar

After closing that chat:

Closed CLI and sidebar

Validation notes

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/main/native-chat/agent-session-wire/structured-agent-session-status-feed.ts (1)

51-51: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Refresh cached timestamps for active summaries.

working and attention summaries compare equal when only updatedAt changes. publish() then keeps the old cached timestamp. An active structured row can exceed the preserved 30-minute freshness window during a long unchanged turn.

Update published with the new summary before the equal-projection return. Keep event suppression separate from cache freshness.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: f2714108-752b-4d2b-939c-85b4e0c129ff

📥 Commits

Reviewing files that changed from the base of the PR and between 5c83abf and 0adaea5.

⛔ Files ignored due to path filters (2)
  • docs/review-evidence/pr-19217/closed.png is excluded by !**/*.png
  • docs/review-evidence/pr-19217/working.png is excluded by !**/*.png
📒 Files selected for processing (15)
  • docs/review-evidence/pr-19217/README.md
  • src/main/native-chat/agent-session-wire/structured-agent-session-host-lifetime.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-host.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-status-feed.ts
  • src/main/runtime/orca-runtime-get-worktree-ps.ts
  • src/main/runtime/orca-runtime-tests/worktree-ps-structured-host.spec.ts
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/runtime-worktree-agent-rows-structured.test.ts
  • src/main/runtime/runtime-worktree-agent-rows.ts
  • src/main/runtime/runtime-worktree-agent-source.ts
  • src/main/runtime/runtime-worktree-agent-sources.test.ts
  • src/main/runtime/runtime-worktree-agent-sources.ts
  • src/main/runtime/runtime-worktree-pty-agent-sources.ts
  • src/main/runtime/runtime-worktree-structured-agent-rows-liveness.test.ts
  • src/main/runtime/runtime-worktree-structured-agent-rows.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 4 remain after this review.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

Since the prior review (ce10240), commit 0adaea5 refactors the source admission ahead of row projection without changing behavior:

  • Source admission extracted from row shaping — attachRuntimeWorktreeAgentRows now receives a pre-collected rowSources: ReadonlyMap<string, RuntimeWorktreeAgentSource> instead of the raw snapshots. The retained/hook reconciliation (including the monitoring-enrichment branch) and the connected-PTY gate moved verbatim into collectRuntimeWorktreePtyAgentSources in runtime-worktree-pty-agent-sources.ts.
  • structured bypass flag eliminated — RuntimeWorktreeAgentSource moved to its own module and dropped the optional payload and structured fields. Structured (non-PTY) sources are now admitted as a separate collection merged after the PTY sources in collectRuntimeWorktreeAgentSources, so the connected-evidence gate applies to PTY-backed rows by construction rather than via a flag exemption; a PTY-backed row still wins on a pane-key collision.
  • Hold factory consolidated — createStructuredAgentSessionHolds now takes reconcileLeases/attach/close and builds resume/evict internally, removing the resumeStructuredAgentSessionForHold import from structured-agent-session-host.ts. The resume path is equivalent: lifetimeContext() returns stable deps/sessions/runtimeState/now references, so capturing it once at construction matches the prior per-resume call.
  • Tests + evidence — a new runtime-worktree-agent-sources.test.ts pins admission precedence (disconnected-local rejection, remote evidence, mirror ownership, monitoring enrichment); the structured-row suites were migrated to the new API, and docs/review-evidence/pr-19217 records the manual worktree ps validation.

Verified locally: pnpm tc:node clean, the four changed/adjacent test suites pass (25 tests), the full orca-runtime.test.ts passes (1261/1262, 1 skipped), and the changed-code quality gate reports 0 new findings.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@brennanb2025 brennanb2025 changed the title fix(orchestration): stop worktree ps reporting a busy structured session as idle fix(orchestration): unify structured-session status across worktree ps and sidebar Sep 8, 2026
@brennanb2025

brennanb2025 commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor Author

Review resumed on September 8, 2026. The earlier Codex launch failure was caused by an incorrect model ID (gpt-6 instead of gpt-6-astra), not an established account restriction.

The checkout has been safely fast-forwarded to PR head 0adaea521337cdfa8438bca6c35017fdf727f14d; pre-existing edits were preserved separately. The initial Codex readiness scan completed with zero proven defect candidates. Codex review/test loops and OpenCode Muse Spark 1.3 Free manual validation are in progress, with a final status comment to follow.

Grok validation was replaced at the author’s request after Grok Build reported its weekly usage limit. No merge-readiness verdict is claimed yet.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 632d8141-501b-483f-af0d-b05c964d6185

📥 Commits

Reviewing files that changed from the base of the PR and between 0adaea5 and e370aeb.

📒 Files selected for processing (4)
  • src/main/runtime/runtime-worktree-agent-rows.ts
  • src/main/runtime/runtime-worktree-agent-source.ts
  • src/main/runtime/runtime-worktree-structured-agent-rows-liveness.test.ts
  • src/main/runtime/runtime-worktree-structured-agent-rows.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/runtime/runtime-worktree-agent-source.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 6 remain after this review.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

The new structured-host authority bypass overreaches: it drops the state !== 'done' exclusion together with the staleness window, so an idle structured session (a completed turn the host still holds) now marks its worktree permission — the CLI/GUI drift this PR aims to eliminate, in the opposite direction.

Reviewed changes

  • Made structured-host statuses authoritative past the freshness window — RuntimeWorktreeAgentSource gained authority?: 'structured-host' (set on structured sources), and the row loop now skips isFreshNonDoneAgentStatus for them so an aged host-held working/attention summary no longer decays to inactive.
  • Tests — two liveness cases assert an aged host-held working / approval state stays authoritative, matching the sidebar.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

Since the prior review (e370aeb), commit f7330f9 replaces the static structured-host authority flag with a host-owned execution lifecycle, which also fixes the done→permission regression from the last review:

  • hostExecutionOwned lifecycle — AgentSessionStatusSummary gains hostExecutionOwned: true, published only while session.hasProviderChild is set, and re-published (clearing the flag) on every child-exit path: handoff, unexpected exit, and Claude rewind. close revokes it out-of-band via statusFeed.revokeLive.
  • done exclusion restored — the structured-host freshness waiver is now source?.authority === 'structured-host' && row.state !== 'done', so an idle held session can no longer bump its worktree to permission.
  • Renderer mirrors the waiver — structuredHostOwned on AgentStatusEntry keeps a host-owned row fresh past the staleness window, and the status feed strips it on disconnect (revokeSnapshotOwnership) so a lost host degrades cleanly instead of leaving a phantom working row.
  • Tests — a feed ownership-transition test, a renderer feed lifecycle suite, host-held freshness/disconnect cases, and a "completed host-held session stays inactive" assertion.

Verified locally: the affected suites pass (feed 16, liveness 4, structured rows 6, bridge 16, feed lifecycle 3).

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review complete for f7330f99f1e969400bf19024e1db993d91a9bbb2. Independent Codex review loops and START/END readiness checks found no unresolved in-scope defects in the final code.

The fixes make structured activity follow provider ownership, preserve journal timestamps and completed history, and revoke live authority on exit, handoff, rewind, closure, or feed loss. Completed sessions no longer turn the worktree into a permission wait. PTY admission and expiry remain unchanged.

Validation passed: focused host/renderer/runtime tests, completion and reconnect regressions, installed-host call-site tests, typechecking, and changed-code quality checks. All code CI checks are green, including all eight test shards, wire compatibility, and packaging including Windows. The automated review is still pending.

Final macOS Electron validation used a real structured Codex turn: working → done (worktree active, not permission) → closed (agent row removed), with the unrelated shell still usable. Screenshots below are from the final commit. Live approval/attention, Claude, Windows/Linux/SSH/relay/mobile flows, and a 30-minute live soak were not exercised; no broader live-validation claim is made. The PR has not been merged.

Final Electron screenshots: working, done, closed

Working:

Working structured chat

Done, with matching worktree ps aggregate active:

Completed structured chat

Closed; unrelated shell remains usable:

Closed chat and live shell

@brennanb2025
brennanb2025 merged commit 1c1cb71 into main Sep 9, 2026
28 checks passed
brennanb2025 pushed a commit that referenced this pull request Sep 9, 2026
…ver store

Structured (native chat) sessions have no PTY and no hook script, so their
status never reached the hook server's store; #19217 gave `worktree ps` its
own adapter over the structured feed instead. The feed now writes every
projection into that store through a status sink the runtime wires, drops
the row when the host closes the session, and `worktree ps` reads the one
snapshot like every other agent.

Rows carry a `structuredHost` marker and the journal clock; they are never
persisted to last-status.json, and the main process does not forward them
to the renderer yet, whose feed bridge still owns them until it is retired.

Design and the two follow-ups: docs/reference/agent-status-store.md.
brennanb2025 added a commit that referenced this pull request Sep 10, 2026
…ver store (#19683)

* refactor(agent-status): publish structured sessions into the hook server store

Structured (native chat) sessions have no PTY and no hook script, so their
status never reached the hook server's store; #19217 gave `worktree ps` its
own adapter over the structured feed instead. The feed now writes every
projection into that store through a status sink the runtime wires, drops
the row when the host closes the session, and `worktree ps` reads the one
snapshot like every other agent.

Rows carry a `structuredHost` marker and the journal clock; they are never
persisted to last-status.json, and the main process does not forward them
to the renderer yet, whose feed bridge still owns them until it is retired.

Design and the two follow-ups: docs/reference/agent-status-store.md.

* chore: drop stray @pnpm/exe lockfile entry

An unrelated local pnpm run added @pnpm/exe as a packageManagerDependency
with no package.json change, so CI's --frozen-lockfile install failed
before any job ran.

* docs(agent-status): describe the step that actually landed

The design record claimed PR 1 deletes RuntimeAgentRowStore, drops the
retained-versus-hook reconciliation, stamps terminalHandle on OSC rows, and
tags rows with a source field of 'structured-host'. None of that is true of
the shipped code: the retained store and its reconciliation are still in
place, and the row field is structuredHost: 'held' | 'owned'.

AGENTS.md points every future contributor here before they touch agent
status, so split the roadmap into the 1a that landed and the 1b that has not,
and name the fields the code actually writes.

* fix(agent-status): pair session removal with the status-row forget

A session dropped from the host's map without an explicit forget left its row
in the store forever: `structuredHostOwned` bypasses the staleness check, so a
failed re-attach (the Claude rewind path reaches one) stranded a permanently
working agent in `worktree ps` and on mobile with no UI able to clear it.
Deletion and forget are now one operation both callers route through.

* fix(agent-status): give orcad the store worktree ps reads from

`orcad` constructed its runtime with neither `getAgentStatusSnapshot` nor
`structuredAgentStatusSink`, so once `worktree ps` sourced rows only from that
snapshot the headless host published nowhere and listed nothing. The hook
server's store is a module singleton whose import tree never reaches Electron,
and its file paths come from `start()`, which orcad never calls.

* fix(agent-status): drop a structured row without a renderer clear

`dropStructuredStatus` went through `clearPaneState`, which fans a pane clear
out to the renderer for a pane key the renderer's own feed bridge still writes
- so 'exactly one writer per pane key' held for writes and not for deletes.
`dropStatusEntry` routes through the status-drop tap instead, and skips the
resume-identity remnant: a structured session has no pane to resume into, and
every null-status publish would otherwise re-mint one.

* test(agent-status): pin both half-migration structured-row filters

Neither the `agentStatus:getSnapshot` filter nor the main-window listener's had
a single assertion, so deleting either — the first step of PR 2 — was green
everywhere. Also covers the perf skip and the drop's lack of a renderer clear.

* docs(agent-status): correct three statements this PR made false

The sink JSDoc claimed only tests construct a host without one; `orcad` did.
The doc argued a structured row needs no tab mirror 'because headless serve has
no renderer', reasoning about exactly the topology the wiring had not reached.
The deleted runtime adapter's warning that the pane key must be the DERIVED one
- never a bearer handle or minted worker key - was lost with it.

* test(agent-status): declare orcad in the hook-row producer census

Wiring the hook store into the orcad runtime added a production site that
hands hook rows to a consumer, which the census ratchet pins deliberately.

---------

Co-authored-by: Merge Sim <sim@local>
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