Skip to content

fix(agent-hooks): ignore status posts from an extension Orca did not launch - #17243

Closed
brennanb2025 wants to merge 5 commits into
mainfrom
fix/unmanaged-omp-status-extension
Closed

brennanb2025 wants to merge 5 commits into
mainfrom
fix/unmanaged-omp-status-extension

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Aug 29, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​453 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​453
Prod 11 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​443 $\color{#cf222e}{\Huge{\mathbf{−}}}$​27 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​416

ELI5

Orca's OMP/Pi status extension lives in the agent's own extensions folder, and OMP loads every file it finds there. If a copy of orca-agent-status.ts is already sitting in that folder that Orca didn't write, Orca deliberately refuses to overwrite it — it's the user's file — and side-loads its own managed copy with -e instead.

So both run. In the same process. Posting the same pane's status to the same endpoint.

That's fine while the two agree. It stops being fine the moment Orca ships a fix to the extension, because the old copy doesn't have it. The old copy posts agent_end unconditionally; a current one can withhold it (for example while OMP has an automatic continuation scheduled). The old copy's post lands first, the pane settles, and the user — who just installed the fix — watches their pane go quiet mid-turn and concludes the fix didn't work.

Orca can tell the two apart, because Orca stamps a launch token into every process it starts and the old copy predates that field. But "I once saw a post with a token" is not the same as "the copy with the token is still alive". So the discrimination is written as a delay, not a veto: a post without a token is held, and it is delivered anyway unless the copy with the token speaks up and contradicts it.

Before / after, for a user

Before this PR After
Stale extension settles a pane mid-turn Pane goes quiet while the agent is still working Stale post is held; the managed copy's own post wins
The managed copy stops posting (crash, exit) — Pane settles ~30s later instead of hanging
Orca's own Codex account-switch restart — Unchanged; it now carries a launch token
Warning toast — One toast per agent, only when two posters are actually proven

What was measured

Against the shipped omp 17.0.5 binary, in a temp PI_CODING_AGENT_DIR (nothing in ~ was read, written, moved, or removed):

  • Both copies load. One auto-discovered from <agentDir>/extensions/, one passed with -e. Load-time markers from both landed. omp --help documents --no-extensions as "Disable extension discovery (explicit -e paths still work)", which is the same statement from the other side.
  • Both reach the hook server on the same paneKey, through /hook/omp, in one turn: before_agent_start, agent_start, agent_end from each.
  • The unmanaged copy's agent_end lands first. It won the race in the captured ordering.
  • The launch token separates them. The managed copy sends launchToken; the unmanaged copy omits the field entirely.

Correction to an earlier claim in this description

An earlier revision said the discrimination turns on absent vs present-but-empty: with ORCA_AGENT_LAUNCH_TOKEN unset the managed copy still sends launchToken: '', while an unmanaged copy omits the key.

That is true on the wire and false at the gate. readEnvelopeString (src/shared/agent-hook-listener/hook-envelope.ts:89-96) trims the value and returns undefined for anything empty, so by the time the fence is called the two cases are already the same value. Nothing in this PR can rely on that distinction, and nothing in it does — the gate reads "non-empty token" vs "no usable token", which is the only fact that survives parsing. Recovering the distinction would need a wire/parse change, which is not in scope here.

What the review loops found, and how each is fixed

1. Armed, then died — the pane stranded on "working" forever

The original fence dropped tokenless posts permanently once a tokened poster had been seen on a pane. Measured with the identical post sequence (agent_start with a token, then a tokenless agent_end, then silence):

Build Outcome
main (a1f198be0d) pane settles to done — 1 check passed
this PR at 2c2415735d pane strands on working, no TTL at all — 1 check failed

So the first cut traded a pane that settles too early for one that never settles. That is not the better failure: a pane wrongly stuck on "working" is invisible, permanent, and has no user recovery. The claim in the earlier description that it "fails open in every other direction" was wrong, and this is the direction it was wrong about.

The fix: suppression is provisional. A tokenless post on an owned pane is held, not dropped.

  • A following tokened post discards the held post. That is also the only real proof that two posters share the pane — one process cannot both send and omit the token — so that is when the warning fires.
  • Silence past UNMANAGED_POST_CONFIRMATION_WINDOW_MS (30s) re-opens the gate, forgets the owner, and delivers the held post through the same gates it would have passed originally.

Every held post is therefore either superseded by the managed poster or delivered — but that only became true of every removal path in defect 3 below. This line, as originally written, asserted an invariant the PR did not hold; see there for what falsified it.

The shipped window had no committed reader

Every window test ran on the 40ms test seam, so UNMANAGED_POST_CONFIRMATION_WINDOW_MS had zero readers — the 30s that actually ships was untested, and an edit to the constant or to the constructor default that wires it would have left every test green.

Closed by exercising the real constant rather than only asserting the wiring, because fake timers make that free. unmanaged-status-extension-fence.test.ts (new) drives a default-constructed fence and advances to UNMANAGED_POST_CONFIRMATION_WINDOW_MS - 1 (no release), then +1 (release). That is a real reader of the shipped value and a wiring assertion, in ~150ms of wall clock rather than 30s. A second check pins the value between the two bounds that justify it — above the sub-second band in which the managed copy supersedes, below the real AGENT_STATUS_STALE_AFTER_MS rather than a copy of it.

The two are separately load-bearing, which the ablations show: unwiring the constructor default reddens only the first, changing the constant's value reddens only the second.

Why 30s: both copies run in one process off one hook event, so the managed copy's superseding post lands in the same millisecond band as the unmanaged one. Even the deliberately-withheld agent_end is re-checked every 25–250ms until idle, and an auto-continuation posts agent_start as soon as it is scheduled. 30s is orders of magnitude above that, and far below the 30-minute AGENT_STATUS_STALE_AFTER_MS at which Orca stops believing a "working" claim anyway — so a lapse means the managed poster is gone, not merely quiet. Verified end-to-end against the real constant with no test seam: the pane settles at 33s.

The property this PR exists for is kept: while the managed copy is alive and posting, every stale post is superseded, so a stale extension still cannot settle a pane that is genuinely still working.

2. Orca's own relaunch posted without a token, and got warned about

codex-detached-pane-restart.ts — Orca's driver for an accepted Codex account-switch restart on an unmounted pane — kill-and-respawns Codex into the same pane key via buildPaneIdentityEnv, which set ORCA_PANE_KEY / ORCA_TAB_ID / ORCA_WORKTREE_ID but not ORCA_AGENT_LAUNCH_TOKEN. Codex's hook script posts launchToken=${ORCA_AGENT_LAUNCH_TOKEN}, so the replacement posted tokenless into a pane the previous (tokened) Codex had already armed. Result: Orca suppressed its own replacement's status and toasted the user about "an extension Orca did not install" — for a process Orca launched. Unactionable, and worse than the bug it was guarding.

This is a gap in the token contract, not in the fence. The launch token is Orca's only in-band proof of authorship, and every gate keyed on it reads a tokenless post as foreign — the retired-pane fence (restartedStatusLaunchTokenHashByPaneKey) as much as this one. Teaching one fence to recognise one relaunch path would leave the other gates wrong and would need a new exemption for every future path. So the fix is at the source: that path now mints a launch token, like every other Orca agent spawn.

Surveyed all four renderer pty.spawn call sites; this was the only one that named a launchAgent and shipped no token. launch-worktree-background-terminals.ts also omits it but launches no agent, so it arms nothing.

Note that fix 1 independently removes the toast here (a relaunch never produces the interleaved tokened post that confirmation requires), but it would still have left ~30s of suppressed status on Orca's own process. Both halves are needed.

3. The owner cap destroyed a held post instead of releasing it

The fence tracks at most MAX_TRACKED_PANES (512) pane owners and evicts the least-recently-tokened one. That eviction called discardPaneHolds, which cleared the pane's hold timer and dropped the entry without calling its release — so the held post was destroyed with nothing left to resolve it, and the pane claimed working permanently.

Measured against a control: two arms, one variable, identical hold window and identical waits, with the filler loop asserted to finish inside the window so the lapse could not be the discriminator.

Arm Filler panes Outcome
A 512 (crosses the cap) strands on ['working']
B 10 (control) delivers ['working', 'done']

Swapping in a releasing variant flips arm A to ['working', 'done']. The shipped suite stayed 10/10 green either way — nothing pinned it.

The fix: eviction resolves the hold instead of destroying it. Eviction is not a delivery event, so it is treated exactly as the lapse is — the owner is forgotten, the gate re-opens, and the held post is released down the same re-entrant path. The releases run after the eviction loop, because a release re-enters classify and must not mutate the owner map mid-iteration.

Every path that can remove a held post, enumerated. This is the third mechanism to break one invariant, so the check is exhaustive rather than incremental:

Removal path Releases? Verdict
A tokened post supersedes it (classify) no correct — the managed post is delivered in its place
A newer tokenless post replaces it (holdPost, latest-only) no correct — the replacement still resolves, and carries the newer state. Now pinned (row P) — it reddened 0 before, and no test reached it at all
The confirmation window lapses (timer) yes correct
The pane is retired (forgetPane) no deliberate — the post describes the turn that just ended, and retirement closes the pane's row in the same step. Pinned; reddens if collapsed into a release
The owner LRU evicts the pane (rememberOwner) yes, now this defect
Server teardown (dispose) no app quit only — one production caller, index.ts. Nothing held here is what the next launch reads: what survives is the pane's persisted status row, and hydrate re-stamps every non-done row restoredUnconfirmed (server.ts:3321-3323), which isFreshNonDoneAgentStatus refuses to read as live work. See the correction below. Now pinned (rows N and O) — the reasoning was right and nothing tested it

So the invariant now holds on every path: no reachable sequence of posts can leave a pane permanently claiming work that has finished.

Correction to the explanation of the last row

The invariant is confirmed. The reason given for the teardown row was not, and this is the third revision of this description to assert something false about its own invariant while landing on the right conclusion — which is exactly how a wrong explanation survives review.

Two things were wrong. The sentence above it said the single path that ends a hold without delivering it retires the pane's row; there are two — pane retirement and server teardown. And teardown was said to be safe because what persists "is re-read on the next launch as a replay, which this fence does not gate at all". A replay is a different thing in this code (isReplay, fenced by hydratedLaunchTokenHashByPaneKey), and "the fence does not gate it" explains only why the fence is irrelevant — not why the pane is safe.

The mechanism that actually makes it safe is a restore path keyed on restoredUnconfirmed:

  • At quit the held post is dropped. The pane's persisted row is whatever the managed poster last said — typically working.
  • On the next launch, hydrate stamps that row: if (entry.payload.state !== 'done') entry.restoredUnconfirmed = true (src/main/agent-hooks/server.ts:3321-3323; the field is declared at :142-143 and is deliberately not persisted — it is stripped on write at :3449 so hydrate always re-stamps it).
  • Every freshness gate then discounts that row rather than treating it as live work: isFreshNonDoneAgentStatus (src/shared/agent-status-types.ts:252-263), isExplicitAgentStatusFresh (src/renderer/src/lib/pane-agent-evidence.ts:17-25), and the sidebar, tab-bar and palette readers that call them.
  • The flag clears only when a live event replaces the entry (server.ts:1641-1645), or the row is retired by the ended-process / hydrated-authority machinery.

So a hold lost at quit cannot produce a standing "working" claim, because the row that comes back is explicitly marked as not-live-truth until something live confirms it. The code comment asserted the old, wrong reason too; both it and the class doc's "only pane retirement" line are corrected in b1cd969660. No behaviour changed — comment text only, verified by stripping comments from both revisions of the file and diffing the remainder (identical), with src/main/agent-hooks + src/shared/agent-hook-listener at 952 checks, 0 red (6 skipped, 92 files), pnpm tc exit 0 / 0 error TS run cold after clearing the build cache, oxlint exit 0 with stdout retained and empty, and oxfmt --check reporting the file correctly formatted.

4. Three live paths that nothing protected — coverage, not behaviour

Three more pieces of this change reddened 0 of 775 in src/main/agent-hooks — the whole
suite passed with each of them removed:

  • dispose() clearing the held posts' timers,
  • that path's only call site, this.unmanagedExtensionFence.dispose() in stop(),
  • and holdPost's latest-only supersede, the discardHeldPost that drops an older hold
    before installing a newer one.

A 0-red is a question, not an answer, so each was classified against a whole-function
control before anything was written. Controls first, then the verdicts:

Control Red What it establishes
dispose() throws unconditionally 200/775 the function is reached, and often
dispose() throws only when a hold is outstanding 1/775 the state it protects is reached too — once
the stop() call removed and dispose() throws 1/775 (from 200) stop() is the route for 199 of those 200 reaches
holdPost returns immediately (never holds) 5/775 the hold machinery is exercised
holdPost throws on a second hold for the same pane and source 0/775 that path is never reached at all
Path Which kind of zero Fix
dispose() clears held timers unprotected. Reached by 200 tests, and once with a hold outstanding, yet no assertion depended on the timer being cleared pinned
stop() disposes the fence unprotected. Executed by 199 tests, and nothing asserted its effect pinned
holdPost latest-only supersede unreachable in this population — reachable in production. No test posts a second tokenless post inside the first one's window; one stale extension posting a whole turn tokenless does exactly that pinned by a test that reaches it

None of the three is unreachable code, so none warrants a tripwire or a deletion: the
remedy in every case is a test that reaches the path and fails if it changes.

The stop() pin needed the right observable. stop() sets this.onAgentStatus = null
before it reaches the fence, so a hold that outlives teardown never calls back — a
listener-based assertion would have passed either way and been vacuous. What it does instead
is re-enter the routing path and write a fresh row for a pane whose row stop() just
cleared, so the pin reads getStatusSnapshotForPane(PANE) and requires it to stay empty.

With the three pins in place the same three mutations redden 2 / 1 / 1 of 778. The
dispose mutation reddens two because both new teardown pins depend on that one clearTimeout.

Blast radius

Orca does still write to that directory today — installManagedExtensions writes <sourceAgentDir>/extensions/orca-agent-status.ts on every OMP/Pi launch, where sourceAgentDir defaults to ~/.omp/agent. But it writes only when the file already there carries the @orca-managed-pi-extension marker. An unmarked file is treated as user-owned, is never replaced, and Orca falls back to userData/omp-managed-status-extension/.

That means the condition is permanent once it exists. It does not heal on upgrade. Every subsequent Orca release side-loads a second extension alongside the stale one, and each release widens the behavioural gap between them.

How a marker-less copy gets there:

  • Not from a current Orca write — every managed write is marked.
  • Not from an older Orca write either. Before the managed-extension change, Orca wrote extensions into a per-source overlay under userData/…-agent-overlays/, not into ~/.<agent>/agent/extensions. The legacy overlay migration that copies that state home explicitly skips the three managed extension filenames.
  • So the realistic sources are hand-installed or hand-copied files: omp install / omp plugin link, a copy out of an overlay or another machine, or a user editing the managed file and dropping the marker line — that last one silently converts Orca's own extension into a permanently-stale one.

Verdict: not everyone who upgraded, but not a closed set either. This is pre-existing. It is not caused by the OMP settle work, but it can mask it.

What changed

  • src/main/agent-hooks/unmanaged-status-extension-fence.ts — the classifier. Holds instead of drops, discards a held post when a tokened post supersedes it, reports only on that confirmation, and releases the held post when the window lapses or when the owner LRU evicts its pane. MAX_TRACKED_PANES is exported so the eviction test names the boundary instead of hard-coding 512.
  • src/main/agent-hooks/server.ts — threads a re-delivery thunk into getAgentStatusDisposition, which is the single choke point both the local HTTP path and the relay ingestRemote path already funnel through. The local path is now a re-entrant routeLocalHookStatus, so a released hold re-runs every gate against the pane as it stands at release time rather than replaying a stale decision. stop() disposes held timers.
  • src/renderer/src/components/terminal-pane/codex-detached-pane-restart.ts — mints ORCA_AGENT_LAUNCH_TOKEN for the respawn.
  • src/main/agent-hooks/unmanaged-status-extension-fence.test.ts, server-unmanaged-status-extension.test.ts — tests only. Three pins for the teardown and supersede paths that reddened 0 of 775 (see finding 4).
  • src/main/agent-hooks/unmanaged-status-extension-fence.ts (b1cd969660) — comment only. The class doc named pane retirement as the only path that ends a hold without delivering it; server teardown does too, and dispose() now states the reason it is safe (the restoredUnconfirmed restore path) instead of the replay claim that was wrong.

Orca does not delete, move, rename, or rewrite the user's file, and this PR adds no code that could. Detection and discrimination only.

Surfacing

A quiet filter would leave someone staring at their own extension being ignored for no stated reason. So the drop is announced, once per pane and source, and only once two posters are actually proven:

  • console.warn in main naming the source and pane, plus agent_hook_unmanaged_extension telemetry carrying the source only — the pane key and the file's contents are user data.
  • A one-shot renderer toast, title "Ignoring status from an extension Orca did not install".

The one-shot property lives in the renderer's per-source dedupe, not in the fence: main reports per pane and source, so 13 affected panes produce 13 detections that the renderer collapses to 1 toast. Both halves are now pinned by tests (they previously had none), and both redden under ablation.

Verification

Every number below was observed in the foreground, on this head, after the branch was refreshed onto main. The rebase pulled in main's pnpm 12 and oxlint/oxfmt upgrades, so every gate was re-run from a clean install rather than carried over.

  • pnpm tc: exit 0, 0 error TS, run cold — node_modules/.tmp removed and every *.tsbuildinfo deleted first, because it is incremental and a warm cache has returned exit 0 on a tree that does not typecheck. Proven non-vacuous the same cold way: planting const orcaTcProbe2f45: number = 'not a number' in the fence gives exit 1 and 2 error TS naming that file at line 245.
  • oxlint 1.80.0 on the two changed test files: exit 0, stdout and stderr retained and both empty. Proven non-vacuous: planting a debugger gives exit 1 and eslint(no-debugger) naming line 54; removing it returns exit 0. (Run directly, retaining stdout — oxlint writes configuration failures there, and the changed-code quality gate brace-slices that stdout, which Node 26 pollutes with an engine warning.) Versions read from origin/main at the rebase target rather than a worktree: pnpm 12.0.0, oxlint ^1.80.0, oxfmt ^0.65.0; installed binaries report 12.0.0 / 1.80.0 / 0.65.0.
  • oxfmt on the two changed test files, plus the repo's own staged-file hook (oxlint, react-doctor, oxfmt --write) running clean at commit time.
  • All three defects proven failing-first against a control, not by reasoning about the failure direction:
    • Defect 1, identical probe: main 1 check, 0 red; the first cut 1 check, 1 red (['working'], no done).
    • Defect 2, relaunch env: at the first cut ORCA_AGENT_LAUNCH_TOKEN is undefined — 1 red. Relaunch toast probe: 1 red then, passes now.
    • Defect 3, two arms differing only in pane count: 512 filler panes 1 red (['working']), 10 filler panes 0 red (['working', 'done']), with the filler loop asserted to finish inside the hold window so the lapse was not the discriminator.
  • Suites: server-unmanaged-status-extension.test.ts 12 checks, 0 red; unmanaged-status-extension-fence.test.ts 4 checks, 0 red — 16 together in 1.7s.
  • Sweeps: src/main/agent-hooks → 778 checks, 0 red (6 skipped, 77 files). src/main/agent-hooks + src/shared/agent-hook-listener → 961 checks, 0 red (6 skipped, 92 files).
  • Branch currency measured with the compare API, not the mergeable label: before this round diverged, ahead 4 / behind 18, while GitHub reported MERGEABLE — the label is not a currency signal. After the refresh onto main (0a995cc30d): ahead, ahead 5, behind_by 0. CI re-earned on that base: 19 pass, 7 skipping, 0 failed — all eight test / tests node 24 shards, static analysis, package and package (windows) included.

Ablations

Gate level, one mutation at a time, each verified applied by diff before the run (an edit that silently misses reads as 0-red), tree restored and asserted clean between runs, run serially.

Rows J–M re-measured on this head. Rows A–I were measured at the previous head 574b7cbf97 and are reproduced here unchanged; they have not been re-run since the rebase.

# Mutation Red
A delete release() on lapse 1
B report on the first tokenless post instead of on confirmation 1
C keep the owner armed across the lapse 1
D drop the launch token from Orca's relaunch env 1
E positive control — delete the fence gate entirely 5
F a tokened post no longer supersedes the held post 2
G pane retirement no longer drops the held post 1
H remove the renderer per-source dedupe 2
I collapse main-side reporting from per-pane to per-source 1
J eviction destroys the held post instead of releasing it 1
K the constructor default stops reading the shipped constant 1
L the shipped constant's value is changed 1
M pane retirement releases instead of dropping 1
N dispose() stops clearing the held posts' timers 2
O stop() stops disposing the fence 1
P holdPost stops superseding the older hold 1

Rows N–P are new in this round, each measured on the rebased head against a 778-check population; all three reddened 0 of 775 before their pins existed. Each of J–M reddens exactly its own gate and nothing else, which is what separates them: J and M are the two halves of "which removal paths release"; K and L are the two halves of "which edits to the shipped window get caught". J also reddens only the new test — the ten shipped tests stayed green under it, which is why the defect survived two rounds.

G reddened 0 on its first run in the previous round: the retired-pane gate suppressed the released post anyway, so the test named a line it did not exercise. It was rewritten to revive the pane through omp's real new-turn boundary (before_agent_start) — a reused pane key settling on the previous turn's completion — and now reddens 1.

Outstanding

The toast's rendered appearance still has not been checked. This change alters only when it fires, not its copy, styling, or markup, so no rendered-UI claim is made here. The $electron skill is present and well-formed in this worktree (.claude/skills/electron/SKILL.md), unlike the lane that wrote the first revision, where it returned Unknown skill.

@greptile-apps

greptile-apps Bot commented Aug 29, 2026 •

Copy link
Copy Markdown

Greptile Summary

This PR adds a provisional fence that delays tokenless agent-status posts until a managed poster confirms or fails to supersede them. It also propagates unmanaged-extension detections through the preload boundary, adds a renderer warning, and supplies launch identity for detached Codex restarts.

  • Holds and conditionally releases status posts from unattributed OMP/Pi extensions.
  • Adds bounded pane ownership, retirement, eviction, and shutdown handling.
  • Sends one-shot unmanaged-extension notices to the renderer.
  • Adds launch tokens to detached Codex account-switch restarts.
  • Expands server, fence, renderer lifecycle, and restart coverage.

Confidence Score: 4/5

The PR is not yet safe to merge because unmanaged-extension detections can still be permanently lost while the main window is closed.

The app-scoped hook server continues classifying posts after the window detaches its listener, while reportOnce marks a pane/source reported before the optional callback runs; reopening the window installs a listener without replaying that consumed detection, leaving the user-facing warning permanently absent.

Files Needing Attention: src/main/agent-hooks/unmanaged-status-extension-fence.ts, src/main/index.ts

Important Files Changed

Filename Overview
src/main/agent-hooks/unmanaged-status-extension-fence.ts Introduces bounded ownership and provisional holding for tokenless status posts, including timeout, eviction, retirement, and detection bookkeeping.
src/main/agent-hooks/server.ts Integrates the fence into the shared local and remote status-disposition path and re-routes released posts through current gates.
src/main/index.ts Connects unmanaged-extension detections to telemetry and renderer IPC across the main-window lifecycle.
src/renderer/src/hooks/ipc-events/unmanaged-status-extension-notice.ts Adds a persistent, per-source warning toast for confirmed unmanaged status extensions.
src/renderer/src/components/terminal-pane/codex-detached-pane-restart.ts Adds an Orca launch token to detached Codex account-switch respawns.

Sequence Diagram

sequenceDiagram
  participant U as Unmanaged extension
  participant F as Status fence
  participant M as Managed extension
  participant R as Renderer
  U->>F: Tokenless status post
  F->>F: Hold post
  alt Managed poster responds
    M->>F: Tokened status post
    F->>F: Discard held post
    F-->>R: Unmanaged-extension notice
  else Confirmation window lapses
    F->>F: Forget owner
    F->>F: Re-deliver held post
  end
Loading

Reviews (6): Last reviewed commit: "test(agent-hooks): pin the fence's teard..." | Re-trigger Greptile

@coderabbitai

coderabbitai Bot commented Aug 29, 2026 •

Copy link
Copy Markdown
Contributor

Review 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

Adds token-based detection for unmanaged status extensions. The agent hook server holds eligible tokenless posts and releases them after the confirmation window. The main process records telemetry and forwards notifications through preload and web APIs. The renderer displays translated notices with dismissal support. Codex detached restarts now receive launch tokens. Tests cover ownership, source isolation, relaunch behavior, deferred posts, teardown, and notification deduplication.

Merge Risk: 🟡 Moderate · up to b1c73

This PR defers and filters agent-status updates and adds launch-token handling for restarted agents, but unresolved lifecycle and deferred-delivery paths can still leave panes stuck, lose valid completion updates, or apply stale status after teardown or pane transfer. The change is not merge-ready until these bounded correctness issues are fixed or explicitly accepted; the launch token also provides cooperative rather than independently verified provenance.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 12 functions across 15 files. (1 skipped:… Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The description is detailed and directly explains the problem, implementation, behavior, testing, and limitations. However, it omits the required Linked Issue, does not provide the required visual att… Add the required issue reference after “Fixes #”. Attach before-and-after screenshots or a video, or provide the exact required N/A statement if visual proof is not applicable. Complete the Testing, AI Disclosure, Review, Agent skill upstre…
✅ 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: ignoring status posts from extensions that Orca did not launch.
Full details: Docstring Coverage

Explanation

Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 12 functions across 15 files. (1 skipped: 1 unsupported.)

Full details: Description check

Explanation

The description is detailed and directly explains the problem, implementation, behavior, testing, and limitations. However, it omits the required Linked Issue, does not provide the required visual attachments for this behavior/UI change, and does not complete the template checklist and review sections.

Resolution

Add the required issue reference after “Fixes #”. Attach before-and-after screenshots or a video, or provide the exact required N/A statement if visual proof is not applicable. Complete the Testing, AI Disclosure, Review, Agent skill upstream boundary, Notes, and Checklist sections as 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

Caution

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

⚠️ Outside diff range comments (1)
src/main/agent-hooks/server.ts (1)

1904-1980: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Maintain fence state for every pane-key transition.

transferPaneAuthority moves the status and alias state but leaves the fence owner under previousOwnerPaneKey. Later posts are alias-normalized to toPaneKey, so a tokenless unmanaged post can bypass the old owner and update the transferred pane. clearPaneState also leaves the owner intact, so a reused tokenless launch is suppressed after ordinary PTY teardown.

  • src/main/agent-hooks/server.ts#L1904-L1980: move the fence entry from previousOwnerPaneKey to toPaneKey with the other pane-keyed state.
  • src/main/agent-hooks/server.ts#L3008-L3030: forget fence entries for every cleared physical and resolved pane key.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d4539707-8179-48eb-b711-541fa675ae18

📥 Commits

Reviewing files that changed from the base of the PR and between a1f198b and 2c24157.

📒 Files selected for processing (12)
  • src/main/agent-hooks/server-unmanaged-status-extension.test.ts
  • src/main/agent-hooks/server.ts
  • src/main/agent-hooks/unmanaged-status-extension-fence.ts
  • src/main/index.ts
  • src/preload/api/agent-status-api.ts
  • src/preload/index.ts
  • src/renderer/src/hooks/ipc-events/agent-status-listeners.ts
  • src/renderer/src/hooks/ipc-events/unmanaged-status-extension-notice.ts
  • src/renderer/src/hooks/useIpcEvents-lifecycle.test.ts
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/web/preload-api/web-agent-status-api.ts
  • src/shared/telemetry-events.ts

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

Comment thread src/main/index.ts
// Why: detach the hook listener on close so the server never fires into destroyed webContents before reopen, and replay runs only on deliberate recreations.
agentHookServer.setListener(null)
agentHookServer.setPaneStatusClearListener(null)
agentHookServer.setUnmanagedStatusExtensionListener(null)

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

Keep unmanaged-extension reports deliverable after window teardown.

Line 1700 removes the listener while the fence remains active. The fence marks a (paneKey, source) as reported before it invokes the optional listener. A post received while no window exists is therefore suppressed permanently without the warning, telemetry, or renderer notice. Reopening a window installs a new listener but does not replay the report.

Keep a main-process reporter active across window recreation, and retain pending source notices until a renderer can receive them.

@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/agent-hooks/server.ts (1)

3048-3084: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Cancel held posts when their pane authority is cleared.

A held tokenless post survives these teardown paths. When its timer expires, it re-enters disposition after the old process or connection is gone. The post can then recreate a stale working or terminal status.

  • src/main/agent-hooks/server.ts#L3048-L3084: call unmanagedExtensionFence.forgetPane for the resolved pane and every cleared alias before cache cleanup.
  • src/main/agent-hooks/server.ts#L2888-L2937: cancel holds for each pane whose connection is being cleared before removing its status state.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 7a3ec998-88e9-48f7-b030-2cac7f793ac9

📥 Commits

Reviewing files that changed from the base of the PR and between 2c24157 and 574b7cb.

📒 Files selected for processing (6)
  • src/main/agent-hooks/server-unmanaged-status-extension.test.ts
  • src/main/agent-hooks/server.ts
  • src/main/agent-hooks/unmanaged-status-extension-fence.ts
  • src/renderer/src/components/terminal-pane/codex-detached-pane-restart.test.ts
  • src/renderer/src/components/terminal-pane/codex-detached-pane-restart.ts
  • src/renderer/src/hooks/ipc-events/unmanaged-status-extension-notice.test.ts

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

@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

Caution

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

⚠️ Outside diff range comments (1)
src/main/agent-hooks/server.ts (1)

1954-1960: 🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

Migrate fence state when pane authority moves.

transferPaneAuthority moves token-related state from previousOwnerPaneKey to toPaneKey, but it leaves unmanagedExtensionFence state on the old key. Later posts are alias-resolved to toPaneKey, so a tokenless post from the unmanaged extension is treated as unattributed and can settle the moved pane.

Add a fence transfer operation that moves owner, held-post, and report state to toPaneKey.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 2e5f0650-40b7-4b81-a474-5930d98c879a

📥 Commits

Reviewing files that changed from the base of the PR and between 574b7cb and b1d4bf99f9dbb4969b69a28ad654dc8fb7de185e.

📒 Files selected for processing (4)
  • src/main/agent-hooks/server-unmanaged-status-extension.test.ts
  • src/main/agent-hooks/server.ts
  • src/main/agent-hooks/unmanaged-status-extension-fence.test.ts
  • src/main/agent-hooks/unmanaged-status-extension-fence.ts

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

Comment on lines +2467 to +2472
launchToken: envelope.launchToken,
// Why re-enter rather than replay the tail: every gate below this point must be re-checked
// against the pane as it stands when the hold lapses, not as it stood when it was taken.
releaseIfUnconfirmed: () => {
this.ingestRemote(envelope, connectionId)
}

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 | 🟠 Major | 🏗️ Heavy lift

Validate the remote post before it can replace a held post.

A valid tokenless completion can be held after a tokened owner posts. A later tokenless relay envelope with an invalid payload replaces that hold here. The delayed callback then re-enters ingestRemote, fails normalizeAgentStatusPayload, and loses the original valid completion. The pane can remain working.

Move fencing until after payload validation, or prevent an unvalidated envelope from replacing an existing hold.

@brennanb2025
brennanb2025 force-pushed the fix/unmanaged-omp-status-extension branch 2 times, most recently from 86447ac to a7010ed Compare August 29, 2026 21:44

@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: e2e71e2e-2c2c-40db-87b6-993601acff87

📥 Commits

Reviewing files that changed from the base of the PR and between b1d4bf99f9dbb4969b69a28ad654dc8fb7de185e and b1cd969.

📒 Files selected for processing (1)
  • src/main/agent-hooks/unmanaged-status-extension-fence.ts

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

Comment on lines +215 to +216
if (sources.size === 0) {
this.ownerHashByPaneKey.delete(paneKey)

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.

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Clear report state when the final owner expires.

When the confirmation timer calls forgetOwner, Line 216 removes the last owner but leaves reportedSourcesByPaneKey retained. These orphaned report sets are no longer bounded by MAX_TRACKED_PANES. Repeated panes that report once and later lapse can accumulate entries until pane retirement.

Proposed fix
     if (sources.size === 0) {
       this.ownerHashByPaneKey.delete(paneKey)
+      this.reportedSourcesByPaneKey.delete(paneKey)
     }
📝 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
if (sources.size === 0) {
this.ownerHashByPaneKey.delete(paneKey)
if (sources.size === 0) {
this.ownerHashByPaneKey.delete(paneKey)
this.reportedSourcesByPaneKey.delete(paneKey)

brennanb2025 and others added 5 commits August 29, 2026 18:39
…launch

Pi/OMP auto-discover every file in the agent's extensions dir. When a user-owned
`orca-agent-status.ts` already holds that name, `writeManagedExtension` refuses to
overwrite it (no `@orca-managed-pi-extension` marker) and Orca side-loads its managed
copy with `-e` instead. Both then run in the same process and post the same pane key
to `/hook/omp` — but the user-owned copy is frozen at whatever Orca version wrote it,
so it can post a completion the managed copy deliberately withheld and settle a pane
that is still working.

Measured against omp 17.0.5 with both copies live: the unmanaged copy is discovered
with no flag, its `agent_end` lands *before* the managed one, and only the managed
copy carries a `launchToken` in the post body.

Fence the pane on that token. A tokened post always wins and becomes the pane's owner;
a tokenless post is dropped only once the same pane and source have proven a tokened
poster is live. Fails open in every other direction — with no tokened post the gate
never arms, so a bare shell (where the managed copy itself posts `launchToken: ''`)
cannot be stranded on "working".

Orca does not touch the user's file. A one-shot toast names the agent so the user can
find and remove it themselves.
…a's relaunch a token

The fence dropped tokenless status posts permanently once a tokened poster
had been seen on a pane, so a managed poster that posted once and then died
left the pane claiming work forever. Measured against main with the same
post sequence: main settles to done, the fence stranded on working.

Suppression is now provisional. A tokenless post is held, not dropped: a
following tokened post discards it -- and is the only real proof that two
posters share one pane, so that is when the warning fires -- while silence
past the confirmation window re-opens the gate and delivers the held post.
Every held post is therefore superseded or delivered, so no sequence of
posts can strand a pane.

Orca's detached Codex account-switch restart respawned into the same pane
key without ORCA_AGENT_LAUNCH_TOKEN, so Orca's own replacement read as a
poster Orca did not launch. Mint the token there: it is the contract every
token-keyed gate depends on, not just this fence.
Eviction destroyed the held tokenless post instead of resolving it, so the
pane claimed 'working' forever. Measured against a control: 512 filler panes
stranded on ['working'] where 10 delivered ['working','done'].
…a pane at quit

The fence's own doc named pane retirement as the only path that ends a hold
without delivering it. Server teardown does too. It is safe for a different
reason than replay: hydrate re-stamps every non-done row restoredUnconfirmed,
and the freshness gates refuse to read that as live work.

Comment only; no behaviour change.
…h nothing caught

dispose(), its stop() call site, and holdPost's latest-only supersede each reddened 0 of 775 in src/main/agent-hooks. Controls: dispose() is reached by 200 tests and once with a hold outstanding, its stop() route by 199, and the hold machinery by 5 - but a throw on a second hold for the same pane and source reddened 0, so that path was never reached at all.
brennanb2025 added a commit that referenced this pull request Aug 30, 2026
…it spawns

The relay builds each PTY's env from its own process.env, and a relay is
routinely started *from* an Orca pane — so that pane's ORCA_PANE_KEY, TAB_ID,
WORKTREE_ID and ORCA_AGENT_LAUNCH_TOKEN rode into every pane the relay spawned,
fresh or revived. The launch token is the damaging member: it is Orca's only
in-band proof of authorship, and the retired-pane status fence is keyed on it,
so one leaked token let any pane on the relay satisfy a fence a different pane
had set.

The daemon already scrubbed exactly these four keys. Hoist that scrub into
src/shared/pane-identity-env.ts and give the relay the same call, so the two PTY
hosts cannot drift again.

Adds a spawn-site ratchet: 52 files name the launch token but nothing stated the
rule producing it, and two paths shipped without it (#17243's detached-pane
restart, and this one) — each found by accident. A new pane-identity env site now
has to be classified deliberately instead of silently joining the broken half.
@brennanb2025
brennanb2025 force-pushed the fix/unmanaged-omp-status-extension branch from b1cd969 to b1c73e9 Compare August 30, 2026 02:02

@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.

🧹 Nitpick comments (1)
src/main/agent-hooks/server-unmanaged-status-extension.test.ts (1)

345-356: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Guard the server shutdown with try/finally in this test.

This is the only test in the file that calls server.stop() outside a finally block. If the assertion at Line 352 fails, stop() never runs. The HTTP server then stays listening and the held-post timer stays armed for the remainder of the run, which can keep the Vitest worker alive after the failure.

♻️ Proposed cleanup guard
     server._setUnmanagedExtensionConfirmationWindowMsForTests(40)
-    const seen = await runOmpPosts(server, [
-      { hookEventName: 'agent_start', launchToken: LAUNCH_TOKEN },
-      { hookEventName: 'agent_end' }
-    ])
-    expect(states(seen)).toEqual(['working'])
-    server.stop()
-    await new Promise((resolve) => setTimeout(resolve, 120))
-    expect(server.getStatusSnapshotForPane(PANE)).toEqual([])
+    try {
+      const seen = await runOmpPosts(server, [
+        { hookEventName: 'agent_start', launchToken: LAUNCH_TOKEN },
+        { hookEventName: 'agent_end' }
+      ])
+      expect(states(seen)).toEqual(['working'])
+    } finally {
+      server.stop()
+    }
+    await new Promise((resolve) => setTimeout(resolve, 120))
+    expect(server.getStatusSnapshotForPane(PANE)).toEqual([])

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 99c8a0d9-7703-4a16-a4a3-d0dde254af1e

📥 Commits

Reviewing files that changed from the base of the PR and between b1cd969 and b1c73e9.

📒 Files selected for processing (4)
  • src/main/agent-hooks/server-unmanaged-status-extension.test.ts
  • src/main/agent-hooks/unmanaged-status-extension-fence.test.ts
  • src/preload/index.ts
  • src/renderer/src/i18n/locales/en.json
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/renderer/src/i18n/locales/en.json

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

brennanb2025 added a commit that referenced this pull request Aug 30, 2026
…it spawns

The relay builds each PTY's env from its own process.env, and a relay is
routinely started *from* an Orca pane — so that pane's ORCA_PANE_KEY, TAB_ID,
WORKTREE_ID and ORCA_AGENT_LAUNCH_TOKEN rode into every pane the relay spawned,
fresh or revived. The launch token is the damaging member: it is Orca's only
in-band proof of authorship, and the retired-pane status fence is keyed on it,
so one leaked token let any pane on the relay satisfy a fence a different pane
had set.

The daemon already scrubbed exactly these four keys. Hoist that scrub into
src/shared/pane-identity-env.ts and give the relay the same call, so the two PTY
hosts cannot drift again.

Adds a spawn-site ratchet: 52 files name the launch token but nothing stated the
rule producing it, and two paths shipped without it (#17243's detached-pane
restart, and this one) — each found by accident. A new pane-identity env site now
has to be classified deliberately instead of silently joining the broken half.
@brennanb2025

Copy link
Copy Markdown
Contributor Author

The older-copy status conflict needs a fresh issue and a current reproduction before this branch is closed. The current fix should establish which reporter owns the status rather than delay competing reports for thirty seconds.

The remaining problem is tracked in #27666.

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