Skip to content

fix(agent-hooks): revive a retired pane on each provider's own new-turn event - #15344

Merged
brennanb2025 merged 4 commits into
mainfrom
brennanb2025/agent-status-retired-pane-gate
Aug 23, 2026
Merged

brennanb2025 merged 4 commits into
mainfrom
brennanb2025/agent-status-retired-pane-gate

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​141 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​140
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​31 $\color{#cf222e}{\Huge{\mathbf{−}}}$​6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​25

ELI5

When an agent finishes, Orca "retires" its sidebar row but leaves the pane reusable. Starting a new turn is supposed to bring the row back. That check only recognised two event names — and only 5 of our 18 agent integrations use them. For the other 10, the row never came back at all: you start working and the sidebar stays empty.

What Changed

src/main/agent-hooks/server.ts — the un-retirement gate now asks the per-provider classifier isNewTurnEvent instead of comparing against two raw literals.

Why

server.ts:1143 gated on hookEventName === 'UserPromptSubmit' || hookEventName === 'SessionStart'. Those are Claude-shaped names. Measured against the new test, 10 providers fail on main:

Provider Its actual new-turn event
gemini BeforeAgent
antigravity PreInvocation
amp agent.start
cursor beforeSubmitPrompt
pi / omp / prime-agent before_agent_start
grok user_prompt_submit
copilot sessionStart (the gate sees the raw name)
hermes pre_llm_call

And the gate was wrong in the other direction too. opencode, mimo-code and command-code have no turn boundary at all — isNewTurnEvent returns false outright for them — yet a literal SessionStart revived their panes. Both directions are now covered by tests.

The correct classifier was already imported into this file and already used 160 lines below at :1305. #14706 added that call specifically so no consumer would re-derive boundaries from raw literals, with a comment saying a second literal list "would strand the providers whose boundary event is named anything else" — and left this one in place. This is that consumer.

Linked Issue

Refs #14626, which reported this defect. That PR is still open; this is the one-line form of its fix.

Visual Proof

N/A — the visible effect is a sidebar row appearing where none did. A before/after screenshot would be an empty sidebar next to a populated one, which carries less information than the per-provider test matrix above.

Testing

New file server-retired-pane-new-turn.test.ts — parametrised over every hook source, driving the real ingest path (ingestRemote → the disposition), asserting the pane revives.

Proven red, not assumed. Reverting server.ts to main and rerunning: 11 failures — the 10 providers above, plus the negative case where opencode incorrectly revived. Restoring the fix: 17 pass.

Exhaustiveness is enforced by the type, not by a hand-maintained list: the event map is a Record<AgentHookSource, string | null>, so a new source fails typecheck here rather than silently skipping coverage.

Two negative controls, both of which would catch an over-broad gate:

  • a source with no turn boundary (opencode) must stay retired;
  • a non-boundary event on a revivable source (gemini + AfterAgent) must stay retired.

One existing test changed, and the reason matters. server-closed-tab-suppression.test.ts asserted that a pane whose tab was closed stays fenced after the tab-id LRU evicts. It posted pi's before_agent_start and passed — but only because that event was not recognised. I measured the same scenario on main with a recognised boundary:

MAIN  claude + UserPromptSubmit  ->  1 row   (pane revives)
MAIN  pi     + before_agent_start ->  0 rows  (pane stays fenced)

So the property it protected already did not hold on main for the most common boundary event; it passed for a reason unrelated to its stated intent. I switched it to a non-boundary event so it tests the property it describes, and added a control asserting the same event does produce a row on an unfenced pane — otherwise the empty snapshot could pass vacuously. The original comment now records the measurement so the next reader is not misled.

Whether a genuine new turn should lift the pane fence for a closed tab is a real question, but it is pre-existing behaviour for Claude and Codex today and is not something this PR decides.

Gates, run locally: pnpm typecheck exit 0; vitest over src/main/agent-hooks, src/shared/agent-hook-listener, src/main/runtime — 441 files, 5408 passed, 14 skipped; oxfmt --check clean on all 3 changed files; oxlint clean.

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

Review

Agent skill upstream boundary

  • Not applicable.

Notes

  • Remote wire compatibility: source is optional on the remote envelope, and an older relay does not send it. Requiring it would have left every source-less remote pane retired forever — a silent regression for mixed-version pairs. The gate keeps the literal check on that path, so an old relay behaves exactly as it does today. This was caught by an existing test failing, not by inspection.
  • Cross-platform / SSH: no platform-conditional code; the change is in the shared ingest path used by local, SSH and relay legs alike.
  • Performance: one function call replacing two string comparisons.
  • Backwards compatibility: no wire, schema, or persisted-state change.

Checklist

  • This PR is small and focused
  • I explained what changed and why (including ELI5)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

Author

  • X / Twitter: @BrennanKB5

@coderabbitai

coderabbitai Bot commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The server now uses hook sources to classify provider-specific new-turn events when determining retired pane status. Source-less remote events retain the existing UserPromptSubmit and SessionStart fallback behavior. Tests cover revival across providers, suppression for non-boundary events, and status creation when no pane fence exists.

Merge Risk: ⚪ Minimal · up to 4ca1d

The change restores retired sidebar rows on each provider's recognized new-turn event while preserving legacy source-less relay behavior; no actionable merge-blocking risk remains.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: reviving retired panes on provider-specific new-turn events.
Description check ✅ Passed The description follows the template, explains the change and rationale, links the issue, documents testing, and addresses compatibility and scope.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
📝 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

🧹 Nitpick comments (1)
src/main/agent-hooks/server.ts (1)

1140-1145: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Reduce historical comments to brief invariant comments.

  • src/main/agent-hooks/server.ts#L1140-L1145: Keep one short comment that explains the provider classifier and the source-less compatibility fallback.
  • src/main/agent-hooks/server-retired-pane-new-turn.test.ts#L63-L66: Keep one short comment that explains exhaustive provider coverage.
  • src/main/agent-hooks/server-closed-tab-suppression.test.ts#L518-L523: Keep one short comment that explains why the test uses a non-boundary event.

As per coding guidelines, comments must be concise, non-obvious, and brief.

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: fd543f6b-56c4-42d1-9e33-bff65c5edcf9

📥 Commits

Reviewing files that changed from the base of the PR and between 2a760e3 and fe04134.

📒 Files selected for processing (3)
  • src/main/agent-hooks/server-closed-tab-suppression.test.ts
  • src/main/agent-hooks/server-retired-pane-new-turn.test.ts
  • src/main/agent-hooks/server.ts

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

Comment thread src/main/agent-hooks/server.ts Resolved

@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: Pro Plus

Run ID: a5f8064c-aefe-48e3-bbc1-1b113f939ce4

📥 Commits

Reviewing files that changed from the base of the PR and between fe04134 and 7df06d6.

📒 Files selected for processing (2)
  • src/main/agent-hooks/server-retired-pane-new-turn.test.ts
  • src/main/agent-hooks/server.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/agent-hooks/server.ts

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

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Behavioural validation — real grok hook events through the real hook server

Unit tests already covered all 18 sources. This closes the remaining gap: a real agent CLI's own captured bytes, driven through the real AgentHookServer over real HTTP to /hook/grok — not ingestRemote, and not assumed event names.

Subject: grok 1.0.5, one grok -p turn in a scratch GROK_HOME with capture-only hooks.

The finding that explains the whole bug

Grok registers its hooks under PascalCase keys (UserPromptSubmit, SessionStart) in ~/.grok/hooks/orca-status.json — but emits hookEventName in snake_case.

The registration name is not the emitted name. origin/main's gate compares the emitted name against the two raw literals, so it never matches, and the pane stays retired forever. This PR routes through normalizeHookEventName, which lowercases and snake-cases, so it matches.

That mismatch is a good illustration of why a hand-maintained literal list rots: the name Orca writes into the vendor's config looks correct, and the name the vendor sends back is different.

Verbatim captured vocabulary (one turn, in order):

session_start → user_prompt_submit → pre_tool_use → post_tool_use → stop → session_end → stop

hook_event_name was absent on every event; the field is hookEventName.

The classifier is correct for grok, and this PR's test-map row grok: 'user_prompt_submit' is correct. No discrepancy between the real emitted name and what isGrokEvent expects — which was the specific thing I asked to be checked rather than assumed.

Arms

Both builds ran in one process with origin/main's server.ts copied in as the control, so each saw byte-identical input.

Arm Build Event Result
1 this branch user_prompt_submit revived ✅
2 origin/main same bytes stayed retired ✅
3 this branch stop, pre_tool_use, post_tool_use stayed retired ✅

Arm 2 is what makes arm 1 meaningful — it proves the capture genuinely reproduces the defect. Arm 3 is the over-broad check: a non-boundary event must not resurrect a finished agent's row.

Honest limits

  • One provider. grok is one of the ten stranded by the old gate; the other nine are covered by unit tests only. An earlier attempt at gemini and omp was auth-blocked (gemini demanded an interactive browser login, omp had no models or API key) and was correctly abandoned rather than worked around — no result was inferred from the unit tests for those.
  • The vocabulary rows for the other nine providers remain unverified against real CLIs on this machine. That is a gap, not a confirmation.

…rn event

The un-retirement gate matched two raw event-name literals, UserPromptSubmit and
SessionStart. Only 5 of 18 hook sources name their turn boundary that way, so for
the rest a reused pane stayed rowless forever: the user starts a new turn and no
row ever appears in the sidebar or dashboard.

Measured, not estimated — 10 providers fail the new test on main: gemini
(BeforeAgent), antigravity (PreInvocation), amp (agent.start), cursor
(beforeSubmitPrompt), pi/omp/prime-agent (before_agent_start), grok
(user_prompt_submit), copilot (sessionStart, seen raw), hermes (pre_llm_call).

The gate was also wrong in the other direction: opencode has no turn boundary at
all, yet a literal SessionStart revived its pane. Both directions are covered.

The correct per-provider classifier, isNewTurnEvent, was already imported into
this file and already used 160 lines below — #14706 added that call specifically
so consumers would stop re-deriving boundaries from literals, and left this one.

Keeps the literal check when the remote envelope omits source: that field is
optional, an older relay does not send it, and requiring it would have left every
source-less remote pane retired forever.
Review of the first commit found that `isAgentHookSource(envelope.source) ?
envelope.source : undefined` collapses two different wire conditions into one:
an older relay that omits `source`, and a NEWER host relaying a provider this
build does not know. They need opposite answers.

Case two is the normal upgrade order — hosts and clients update independently —
and its boundary event will not be UserPromptSubmit/SessionStart, because 13 of
the 18 providers we already ship are named something else. So the legacy-literal
fallback stranded that provider's panes permanently: the exact defect this branch
fixes, silently reintroduced for traffic our own wire doctrine calls normal.

Pass the raw wire value so the gate can distinguish them, and fail OPEN on an
unrecognized provider. The costs are asymmetric: a stranded pane is invisible,
permanent, and has no user-facing recovery, while a spurious revive produces a
row that decays after AGENT_STATUS_STALE_AFTER_MS.

Also from review:
- Cover the source-less branches, which had no coverage at all — including a test
  pinning what the legacy shim CANNOT do, so nobody later widens the literal list
  to "fix" it.
- Use the source as agentType rather than always 'claude'; 15 of 16 rows were
  describing a state that cannot occur.
- Reword the opencode comment: no plugin in that family emits these literals, so
  this closes a hole rather than removing behavior.

Checked and not changed: the local HTTP path 404s an unresolvable source, so the
fallback is unreachable there and masks nothing.
…tic event

The negative case asserted that an opencode pane stays retired after a literal
SessionStart. That rests on a false premise: origin/main's opencode plugin never
emits SessionStart at all — zero occurrences in opencode/hook-service.ts, and the
shared family source is what mimo-code uses too. So the assertion pinned an event
no plugin sends, and it would have become actively wrong the moment a pending
change gives opencode a real SessionStart, silently re-breaking the rowless
reused-pane case that change exists to fix.

Assert against mimo-code and command-code instead. Both genuinely have no
boundary event in any planned state, so the case tests what it claims to.
@brennanb2025
brennanb2025 force-pushed the brennanb2025/agent-status-retired-pane-gate branch from 5898e93 to 2af1226 Compare August 19, 2026 23:17
Only a non-empty unknown string can identify a future provider. Keep null, blank, numeric, and object source values behind the retired-pane fence instead of treating malformed wire data as a new turn.
@coderabbitai

coderabbitai Bot commented Aug 19, 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.

@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

🧹 Nitpick comments (1)
src/main/agent-hooks/server-retired-pane-new-turn.test.ts (1)

69-72: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Shorten the test rationale comments.

These comments contain multi-line implementation history and repeat behavior expressed by the test names and assertions. Keep only the constraint that is necessary to understand an unusual test case.

As per coding guidelines: “Comments must be concise, non-obvious, and brief—prefer one line; do not explain obvious behavior or walk through code.”

Also applies to: 83-84, 90-91, 96-98, 114-117

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 1052da41-1952-4345-b80e-ded6ecbb97b3

📥 Commits

Reviewing files that changed from the base of the PR and between fcdbcf8 and 4ca1dc3.

📒 Files selected for processing (3)
  • src/main/agent-hooks/server-closed-tab-suppression.test.ts
  • src/main/agent-hooks/server-retired-pane-new-turn.test.ts
  • src/main/agent-hooks/server.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/main/agent-hooks/server.ts
  • src/main/agent-hooks/server-closed-tab-suppression.test.ts

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

Comment on lines +85 to +87
it('revives on a literal boundary when an older relay omits source', () => {
expect(reviveRetiredPane(undefined, 'UserPromptSubmit')).toBe(true)
})

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Cover the source-less SessionStart fallback.

Lines 85-87 test only UserPromptSubmit. The parameterized provider cases always set source, so they do not execute the legacy fallback branch. Add a source-less SessionStart assertion. A regression that removes only this fallback literal will otherwise pass.

Proposed test update
-  it('revives on a literal boundary when an older relay omits source', () => {
-    expect(reviveRetiredPane(undefined, 'UserPromptSubmit')).toBe(true)
-  })
+  it.each(['UserPromptSubmit', 'SessionStart'])(
+    'revives on %s when an older relay omits source',
+    (hookEventName) => {
+      expect(reviveRetiredPane(undefined, hookEventName)).toBe(true)
+    }
+  )
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
it('revives on a literal boundary when an older relay omits source', () => {
expect(reviveRetiredPane(undefined, 'UserPromptSubmit')).toBe(true)
})
it.each(['UserPromptSubmit', 'SessionStart'])(
'revives on %s when an older relay omits source',
(hookEventName) => {
expect(reviveRetiredPane(undefined, hookEventName)).toBe(true)
}
)

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Rendered sidebar proof (visual arm only)

Closes the remaining user-visible gap for this PR: a retired pane’s sidebar agent row stays gone until that provider’s own new-turn event, then comes back in the full Orca window.

Instance. Dev build of this worktree at 4ca1dc3620, identity window.api.app.getIdentity() = Orca: brennanb2025/task-984f0aea-pr15344-review (devRepoRoot /Users/brennanbenson/orca/workspaces/orca/task-984f0aea-pr15344-review). Unique ORCA_DEV_USER_DATA_PATH, CDP 9335, renderer 5176. Fresh profile; added a small git workspace named sidebar-proof; Terminal 1 is the reused pane.

Setup. Seeded a live Gemini row via authenticated POST to this instance’s /hook/gemini, then retired the pane through retireAgentPaneAuthority (main-process fence). Later events are more synthetic /hook/gemini envelopes on that same pane — not a live Gemini CLI, and not a rerun of the grok /hook/grok classifier arm.

Visible observations (uncropped full window, sidebar on the left):

  1. Retired / fenced. The sidebar-proof card shows only main / primary. There is no Agents list and no Gemini row. Terminal 1 has no working sparkle.

retired-no-sidebar-row.png

  1. Non-boundary AfterAgent. Same window after posting Gemini AfterAgent to the fenced pane: still no sidebar agent row. The main fence held.

afteragent-still-absent.png

  1. Provider-specific new-turn BeforeAgent. After posting Gemini BeforeAgent (prompt: gemini new-turn after retire): the sidebar-proof card shows a Gemini row with that prompt and just now, and Terminal 1 shows the working sparkle.

beforeagent-row-revived.png

Live row immediately before retirement, for contrast:

live-gemini-row-before-retire.png

Limits. Visual proof only — Gemini is the on-screen representative of a provider whose boundary is not UserPromptSubmit/SessionStart. Did not rerun real grok hook bytes. Did not screenshot every other source in the live window. The small chevron at the bottom center is a collapsed capture overlay, not product UI.

@msokh

msokh commented Aug 20, 2026

Copy link
Copy Markdown

Confirming this from the OMP side. Orca 1.4.182, OMP 17.3.4.

The solid part first. I added a sidecar pi extension that logs every hook and retries the completion post until the server answers 2xx. Three panes have agent_end recorded as delivered with a 2xx and their terminal titles were still showing the working spinner when I checked minutes afterward. One comparison pane reached done normally in the same window. The hook server answers 204 before the suppression runs, so the retry chain changed nothing. That is what pointed me at getAgentStatusDisposition instead of at delivery.

In last-status.json I also have 12 persisted pane rows whose last recorded hook is mid-turn (message_end or tool_call, state working), while other rows show agent_end and done.

Now something I cannot pin on this gate, offered only as a possible downstream effect. I have 47 automation runs stuck in dispatched across 8 automations. The three lanes I checked had all finished their work and written their output on schedule. AutomationsPage only marks a run completed once the pane row reaches state === 'done' (automation-run-completion-evidence.ts), so a lost completion would strand a run permanently.

One run argues against it being the same bug. Its agent_end was delivered with a 2xx, and no row was present in last-status.json after the pane closed. Pane level retirement does not explain that on its own, and I have not identified what suppressed it, so treat the automation side as unverified.

Separate scope question: does this lift the tab level fence at server.ts:1006 too? That branch returns suppress with no revive path.

@brennanb2025
brennanb2025 merged commit d1127b9 into main Aug 23, 2026
89 of 91 checks passed
paidaxingyo666 pushed a commit to paidaxingyo666/Manta that referenced this pull request Aug 25, 2026
…rn event (stablyai#15344)

* fix(agent-hooks): revive a retired pane on each provider's own new-turn event

The un-retirement gate matched two raw event-name literals, UserPromptSubmit and
SessionStart. Only 5 of 18 hook sources name their turn boundary that way, so for
the rest a reused pane stayed rowless forever: the user starts a new turn and no
row ever appears in the sidebar or dashboard.

Measured, not estimated — 10 providers fail the new test on main: gemini
(BeforeAgent), antigravity (PreInvocation), amp (agent.start), cursor
(beforeSubmitPrompt), pi/omp/prime-agent (before_agent_start), grok
(user_prompt_submit), copilot (sessionStart, seen raw), hermes (pre_llm_call).

The gate was also wrong in the other direction: opencode has no turn boundary at
all, yet a literal SessionStart revived its pane. Both directions are covered.

The correct per-provider classifier, isNewTurnEvent, was already imported into
this file and already used 160 lines below — stablyai#14706 added that call specifically
so consumers would stop re-deriving boundaries from literals, and left this one.

Keeps the literal check when the remote envelope omits source: that field is
optional, an older relay does not send it, and requiring it would have left every
source-less remote pane retired forever.

* fix(agent-hooks): tell an absent source apart from an unrecognized one

Review of the first commit found that `isAgentHookSource(envelope.source) ?
envelope.source : undefined` collapses two different wire conditions into one:
an older relay that omits `source`, and a NEWER host relaying a provider this
build does not know. They need opposite answers.

Case two is the normal upgrade order — hosts and clients update independently —
and its boundary event will not be UserPromptSubmit/SessionStart, because 13 of
the 18 providers we already ship are named something else. So the legacy-literal
fallback stranded that provider's panes permanently: the exact defect this branch
fixes, silently reintroduced for traffic our own wire doctrine calls normal.

Pass the raw wire value so the gate can distinguish them, and fail OPEN on an
unrecognized provider. The costs are asymmetric: a stranded pane is invisible,
permanent, and has no user-facing recovery, while a spurious revive produces a
row that decays after AGENT_STATUS_STALE_AFTER_MS.

Also from review:
- Cover the source-less branches, which had no coverage at all — including a test
  pinning what the legacy shim CANNOT do, so nobody later widens the literal list
  to "fix" it.
- Use the source as agentType rather than always 'claude'; 15 of 16 rows were
  describing a state that cannot occur.
- Reword the opencode comment: no plugin in that family emits these literals, so
  this closes a hole rather than removing behavior.

Checked and not changed: the local HTTP path 404s an unresolvable source, so the
fallback is unreachable there and masks nothing.

* test(agent-hooks): stop pinning opencode's fence behavior on a synthetic event

The negative case asserted that an opencode pane stays retired after a literal
SessionStart. That rests on a false premise: origin/main's opencode plugin never
emits SessionStart at all — zero occurrences in opencode/hook-service.ts, and the
shared family source is what mimo-code uses too. So the assertion pinned an event
no plugin sends, and it would have become actively wrong the moment a pending
change gives opencode a real SessionStart, silently re-breaking the rowless
reused-pane case that change exists to fix.

Assert against mimo-code and command-code instead. Both genuinely have no
boundary event in any planned state, so the case tests what it claims to.

* fix(agent-hooks): reject malformed relay sources at retired fence

Only a non-empty unknown string can identify a future provider. Keep null, blank, numeric, and object source values behind the retired-pane fence instead of treating malformed wire data as a new turn.

(cherry picked from commit d1127b9)
dallascrilley pushed a commit to dallascrilley/orca that referenced this pull request Aug 27, 2026
…rn event (stablyai#15344)

* fix(agent-hooks): revive a retired pane on each provider's own new-turn event

The un-retirement gate matched two raw event-name literals, UserPromptSubmit and
SessionStart. Only 5 of 18 hook sources name their turn boundary that way, so for
the rest a reused pane stayed rowless forever: the user starts a new turn and no
row ever appears in the sidebar or dashboard.

Measured, not estimated — 10 providers fail the new test on main: gemini
(BeforeAgent), antigravity (PreInvocation), amp (agent.start), cursor
(beforeSubmitPrompt), pi/omp/prime-agent (before_agent_start), grok
(user_prompt_submit), copilot (sessionStart, seen raw), hermes (pre_llm_call).

The gate was also wrong in the other direction: opencode has no turn boundary at
all, yet a literal SessionStart revived its pane. Both directions are covered.

The correct per-provider classifier, isNewTurnEvent, was already imported into
this file and already used 160 lines below — stablyai#14706 added that call specifically
so consumers would stop re-deriving boundaries from literals, and left this one.

Keeps the literal check when the remote envelope omits source: that field is
optional, an older relay does not send it, and requiring it would have left every
source-less remote pane retired forever.

* fix(agent-hooks): tell an absent source apart from an unrecognized one

Review of the first commit found that `isAgentHookSource(envelope.source) ?
envelope.source : undefined` collapses two different wire conditions into one:
an older relay that omits `source`, and a NEWER host relaying a provider this
build does not know. They need opposite answers.

Case two is the normal upgrade order — hosts and clients update independently —
and its boundary event will not be UserPromptSubmit/SessionStart, because 13 of
the 18 providers we already ship are named something else. So the legacy-literal
fallback stranded that provider's panes permanently: the exact defect this branch
fixes, silently reintroduced for traffic our own wire doctrine calls normal.

Pass the raw wire value so the gate can distinguish them, and fail OPEN on an
unrecognized provider. The costs are asymmetric: a stranded pane is invisible,
permanent, and has no user-facing recovery, while a spurious revive produces a
row that decays after AGENT_STATUS_STALE_AFTER_MS.

Also from review:
- Cover the source-less branches, which had no coverage at all — including a test
  pinning what the legacy shim CANNOT do, so nobody later widens the literal list
  to "fix" it.
- Use the source as agentType rather than always 'claude'; 15 of 16 rows were
  describing a state that cannot occur.
- Reword the opencode comment: no plugin in that family emits these literals, so
  this closes a hole rather than removing behavior.

Checked and not changed: the local HTTP path 404s an unresolvable source, so the
fallback is unreachable there and masks nothing.

* test(agent-hooks): stop pinning opencode's fence behavior on a synthetic event

The negative case asserted that an opencode pane stays retired after a literal
SessionStart. That rests on a false premise: origin/main's opencode plugin never
emits SessionStart at all — zero occurrences in opencode/hook-service.ts, and the
shared family source is what mimo-code uses too. So the assertion pinned an event
no plugin sends, and it would have become actively wrong the moment a pending
change gives opencode a real SessionStart, silently re-breaking the rowless
reused-pane case that change exists to fix.

Assert against mimo-code and command-code instead. Both genuinely have no
boundary event in any planned state, so the case tests what it claims to.

* fix(agent-hooks): reject malformed relay sources at retired fence

Only a non-empty unknown string can identify a future provider. Keep null, blank, numeric, and object source values behind the retired-pane fence instead of treating malformed wire data as a new turn.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…rn event (stablyai#15344)

* fix(agent-hooks): revive a retired pane on each provider's own new-turn event

The un-retirement gate matched two raw event-name literals, UserPromptSubmit and
SessionStart. Only 5 of 18 hook sources name their turn boundary that way, so for
the rest a reused pane stayed rowless forever: the user starts a new turn and no
row ever appears in the sidebar or dashboard.

Measured, not estimated — 10 providers fail the new test on main: gemini
(BeforeAgent), antigravity (PreInvocation), amp (agent.start), cursor
(beforeSubmitPrompt), pi/omp/prime-agent (before_agent_start), grok
(user_prompt_submit), copilot (sessionStart, seen raw), hermes (pre_llm_call).

The gate was also wrong in the other direction: opencode has no turn boundary at
all, yet a literal SessionStart revived its pane. Both directions are covered.

The correct per-provider classifier, isNewTurnEvent, was already imported into
this file and already used 160 lines below — stablyai#14706 added that call specifically
so consumers would stop re-deriving boundaries from literals, and left this one.

Keeps the literal check when the remote envelope omits source: that field is
optional, an older relay does not send it, and requiring it would have left every
source-less remote pane retired forever.

* fix(agent-hooks): tell an absent source apart from an unrecognized one

Review of the first commit found that `isAgentHookSource(envelope.source) ?
envelope.source : undefined` collapses two different wire conditions into one:
an older relay that omits `source`, and a NEWER host relaying a provider this
build does not know. They need opposite answers.

Case two is the normal upgrade order — hosts and clients update independently —
and its boundary event will not be UserPromptSubmit/SessionStart, because 13 of
the 18 providers we already ship are named something else. So the legacy-literal
fallback stranded that provider's panes permanently: the exact defect this branch
fixes, silently reintroduced for traffic our own wire doctrine calls normal.

Pass the raw wire value so the gate can distinguish them, and fail OPEN on an
unrecognized provider. The costs are asymmetric: a stranded pane is invisible,
permanent, and has no user-facing recovery, while a spurious revive produces a
row that decays after AGENT_STATUS_STALE_AFTER_MS.

Also from review:
- Cover the source-less branches, which had no coverage at all — including a test
  pinning what the legacy shim CANNOT do, so nobody later widens the literal list
  to "fix" it.
- Use the source as agentType rather than always 'claude'; 15 of 16 rows were
  describing a state that cannot occur.
- Reword the opencode comment: no plugin in that family emits these literals, so
  this closes a hole rather than removing behavior.

Checked and not changed: the local HTTP path 404s an unresolvable source, so the
fallback is unreachable there and masks nothing.

* test(agent-hooks): stop pinning opencode's fence behavior on a synthetic event

The negative case asserted that an opencode pane stays retired after a literal
SessionStart. That rests on a false premise: origin/main's opencode plugin never
emits SessionStart at all — zero occurrences in opencode/hook-service.ts, and the
shared family source is what mimo-code uses too. So the assertion pinned an event
no plugin sends, and it would have become actively wrong the moment a pending
change gives opencode a real SessionStart, silently re-breaking the rowless
reused-pane case that change exists to fix.

Assert against mimo-code and command-code instead. Both genuinely have no
boundary event in any planned state, so the case tests what it claims to.

* fix(agent-hooks): reject malformed relay sources at retired fence

Only a non-empty unknown string can identify a future provider. Keep null, blank, numeric, and object source values behind the retired-pane fence instead of treating malformed wire data as a new turn.
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.

2 participants