Skip to content

fix(codex): turning Codex off per agent keeps its hook entry off - #23667

Merged
brennanb2025 merged 8 commits into
mainfrom
brennanb2025/codex-per-agent-optout-launch
Sep 29, 2026
Merged

brennanb2025 merged 8 commits into
mainfrom
brennanb2025/codex-per-agent-optout-launch

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​323 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​321
Prod 18 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​80 $\color{#cf222e}{\Huge{\mathbf{−}}}$​71 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​9

ELI5

In Settings > Agents you can set an agent to Disabled. Disabling Codex is supposed to take Orca's status hook out of Codex's config, but the next time you opened a terminal or resumed a Codex session, Orca quietly put the hook back. Now a disabled Codex stays unhooked.

What Changed

Before: with the main "agent status hooks" switch on, setting Codex to Disabled in Settings > Agents did not stick. Opening a new terminal (Orca prepares Codex's home before every local terminal, because codex can be typed into any of them), or resuming a Codex session, re-added Orca's hook entry to the real ~/.codex/hooks.json (or to the selected account's Codex home), so Codex kept running Orca's status hook. On the real ~/.codex lane the Settings toggle itself also left the entry in place.

After: with Codex disabled, opening a terminal or resuming a Codex session leaves the hook out, exactly as it already does when the main switch is off: the real ~/.codex entry is swept and the account home only has the user's own hooks refreshed. On the real ~/.codex lane, disabling Codex also clears the entry straight away; an account home drops it on the next terminal open. With Codex enabled, or with a different agent disabled, Codex installs its hook as before.

Mechanism: the question "is this agent's status hook on?" (main switch on AND this agent not turned off) now lives in one small function, isAgentStatusHooksEnabledForAgent, and the places that spelled it out by hand now call that function. The terminal spawn env, which is handed the switch and the opt-out list rather than the settings, combines the same two values inline, and the SSH and WSL installs keep dropping disabled agents from their detection list.

  • Codex launch prep and Codex session resume read only the main switch, so they re-installed the hook for a Codex the user had turned off. They now call the shared function. This is the fix.
  • The gate that tells the legacy ~/.codex cleanup to stand down while the real-home lane owns that file also read only the main switch, so turning Codex off never let the cleanup run. It is now a small function beside that cleanup, shouldSuppressSystemCodexHomeHookSweep, which calls the shared function, so turning Codex off lets the cleanup run the same as turning every hook off.
  • The startup controls, the Settings reconcile, the retained-pane reconcile, the WSL preflight RPC, the CLI's agent hooks prepare-codex and the OpenCode plugin selection each spelled out the same check by hand. They now call the shared function too; their behaviour does not change.
  • The terminal spawn env was handed a separate precomputed Codex flag next to the switch and opt-out list it already receives. It now works the Codex flag out from those two values, the same way it already does for OpenCode and Pi, and the extra field is gone.

Do other agents already turn off like this? Was this only a Codex bug?

On this machine, yes, the other agents already did this, and Codex was the only one that broke:

  • Claude and the other agents whose hooks Orca installs into their own settings (Gemini, Cursor, Copilot, Grok and the rest) are installed once at startup and whenever you change the setting. Both already skip an agent you turned off, and turning one off removes Orca's entry from that agent's settings. Nothing re-adds it when a terminal opens, because Orca never writes their settings on launch.
  • Codex was different because Orca also writes Codex's settings every time a terminal opens and every time a session resumes, and those launch paths checked only the global switch. That is the bug this PR fixes, together with the cleanup of your real ~/.codex, which had the same global-only check.

Gaps that remain for other agents. None is caused or fixed by this PR, and they are tracked as one follow-up:

  • SSH, Pi / OMP / Prime: the remote helper checks only the global switch, so with Pi turned off, connecting to an SSH host still writes Orca's extension into the remote ~/.pi. A live connection also keeps writing it after the global switch goes off. Fixing it needs a change to the remote helper, handled for older remote versions.
  • WSL, Pi / OMP: the same global-only check inside the distro.
  • OpenCode, Pi, OMP, Prime and Mimo Code: turning them off never removes the plugin files Orca wrote (for example ~/.config/opencode/plugins/orca-opencode-status.js), so a hand-typed opencode in an Orca terminal may still report status. The same is true for the global switch.
  • SSH and WSL, all agents: nothing removes Orca's hook entries from the remote machine or distro when an agent (or all hooks) is turned off; a later connect only stops re-adding them.
  • Minor: local Mimo Code launches check only the global switch (the write lands in Orca's own data folder).

Why

This bug was already on main and behaves the same there. I found it while reviewing #23552, but it does not depend on that PR, so this PR is based on main and not stacked on it.

The launch path had two answers to one question: the terminal spawn env and startup honoured the per-agent opt-out, while launch prep and resume, which run just before the same spawn, did not. Adding the per-agent check at the two broken call sites would fix today's symptom but leave the other hand-written copies of the same check waiting to drift again. One function, reused everywhere, removes the way this happened.

The function lives in src/shared/agent-status-hooks-setting.ts rather than in managed-agent-hook-controls.ts, because the CLI runs prepare-codex before every Codex launch in a shell pane. It reads only settings, so it should not load every agent's hook installer, and in src/shared the CLI compiles it itself instead of needing another build entry under out/main. managed-agent-hook-controls.ts re-exports it, so existing importers are unchanged.

"Off" keeps its existing meaning at launch: the same sweep-and-refresh path the main switch already takes. No new removal behaviour was invented for the per-agent case.

Linked Issue

None. Found while reviewing #23552.

Visual Proof

N/A. Nothing on screen changes: the fix is about what Orca writes to Codex's config files on launch, resume and the Settings toggle.

Testing

  • New src/main/startup/codex-launch-per-agent-hook-opt-out.test.ts covers launch prep and session resume on both the real ~/.codex lane and a managed account home, for four settings: Codex turned off, every agent on, another agent turned off, and the main switch off. Each test seeds the hook settings explicitly and uses the real predicate.

  • Red on main: with the two call sites put back to main's code, the four "Codex turned off" cases fail and the other twelve pass. With the fix, all sixteen pass.

  • New src/main/codex/codex-hook-sweep-per-agent-opt-out.test.ts covers the legacy-cleanup gate: a table of the four settings on the real-home lane, the gate off that lane, and remove() against a seeded ~/.codex/hooks.json. With Codex turned off, Orca's entry is removed and the user's hook stays; with Codex on, the entry stays.

  • Red without the fix: with the gate put back to the main switch only, the "Codex turned off" table case and the remove() case fail and the other five pass.

  • pnpm tc:node and pnpm tc:cli pass. oxlint is clean on the changed files, and pnpm run check:code-quality:changed -- origin/main passes.

  • 38 related vitest suites pass (462 tests), including the CLI bundle-parity test, which fails if the CLI imports a src/main module the build does not emit: launch prep, session resume, managed hook controls, the Settings and runtime-settings reconcile, the CLI and RPC Codex preflights, the terminal spawn env, retained Codex homes, and OpenCode plugin selection over WSL and SSH.

  • Not tested by hand in the running app.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

AI Disclosure

Review

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Ensure no issues in: Security, Cross-platoform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

  • SSH and WSL: remote hook installs already filter out turned-off agents before installing, and the WSL preflight RPC already checked the opt-out. Both keep that behaviour; only how they spell the check changes.
  • Mixed client and host versions: no RPC parameter, stream frame or published content changes. The removed spawn-env field was in-process only.
  • Multiple Orca profiles: "Codex off" now does what "main switch off" already did. The cleanup matches Orca's entry by its script file name, so turning Codex off in one profile also removes the entry another profile put in the shared ~/.codex; that profile writes it back the next time it opens a terminal or resumes a Codex session. The main switch already behaves this way; no new removal path is added.
  • Folder workspaces: not affected; the decision reads only settings.
  • Not changed here: the Codex hook code still receives a yes/no worked out by its caller, and a launch that is already queued keeps the answer it read before queueing. If Codex is disabled during that short window, the queued launch can write the entry back until the next terminal opens. The main switch behaves the same way today.
  • Not changed here: over SSH, the Pi, OMP and Prime Agent status extensions are still sent based on the main switch only. That is a separate, older gap for those agents.

Author X: @BrennanKB5

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • 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)

…oks are on

"Global switch on and this agent not turned off" was spelled out separately
in the startup controls, the settings reconcile, the retained-home
reconcile, the WSL preflight RPC, the CLI preflight and the OpenCode plugin
selection. They now share one function, in a module light enough for the
CLI's per-launch Codex preflight to load. The PTY spawn env derives the
Codex flag from the switch and opt-out list it already carries, the same way
it does for OpenCode and Pi, instead of receiving a second copy.
Turning Codex off in the per-agent hook settings removes Orca's Codex hook
entry, but launch prep and session resume read only the global hooks switch,
so the next Codex launch or resume wrote the entry straight back into the
real ~/.codex or the account's home. Both now read the per-agent predicate,
which the PTY spawn env and startup already honoured.
While the real-home lane owns ~/.codex/hooks.json, the legacy system-home
sweep stands down. That gate read only the global switch, so turning Codex
off per agent ran remove() with the sweep still suppressed and left Orca's
entry in the real ~/.codex. The gate now reads the per-agent predicate, the
same as turning every hook off.
The gate that lets the legacy system-home sweep run was an inline closure in
startup, so reverting it to the global switch left CI green. It is now a
pure function beside the gate it feeds, with a table test and a remove()
test on a seeded ~/.codex: turning Codex off strips Orca's entry and keeps
user hooks; with Codex on the entry stays.
…r-agent-optout-launch

# Conflicts:
#	src/main/agent-hooks/managed-agent-hook-controls.ts
…ged CLI

The CLI's prepare-codex handler imported the predicate from src/main, but
the Electron build rebuilds out/main from its declared entries only, so the
packaged `orca agent hooks` commands could not load it (package jobs and the
CLI bundle-parity test were red). The predicate reads only settings, so it
now lives in src/shared, which the CLI compiles itself.
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Status: ready for review

Head: 91954190d03. CI green: 26 passed, 15 skipped. Review loops ended clean.

Live QA (macOS, background Orca rigs driven over CDP)

Setup

  • BEFORE build: origin/main at 409462a3190. AFTER build: this PR's head.
  • Each launch rebuilt out/main. The two function names only this PR adds (shouldSuppressSystemCodexHomeHookSweep, isAgentStatusHooksEnabledForAgent) were found in every AFTER build and in no BEFORE build.
  • Each rig had its own CODEX_HOME, so every write landed in the rig's hooks.json, never the real one.
  • In the terminal screenshots, the number under the paths is the count of Orca's entries in that rig hooks.json, read from inside the terminal. Orca installs 8 (one per Codex hook event). The pane's HOME shows the real user directory because macOS login shells reset it. Nothing agent-related ran in those panes.
Case BEFORE (main) AFTER (this PR)
1. Startup installs Orca's Codex entry 8 entries, 8 trusted 8 entries, 8 trusted
2. Turn Codex off in Settings entry stays entry and its trust removed; only the user's own Stop hook is left
3. Open a new plain terminal with Codex off entry written back within the same second stays removed, file untouched
4. Restart Orca, then open a terminal (not reached: the entry was never removed) stays removed through restart
5. Turn Codex back on, open a terminal n/a the toggle alone writes nothing; the next terminal restores 8 entries, 8 trusted
6. Control: turn Claude off instead Codex entry byte-identical Codex entry byte-identical

Extra run: a stale entry added while the app was closed is not removed at startup, since startup only installs or skips. The first terminal opened after that removes it.

Case 1, AFTER. Codex enabled; the first terminal shows 8 entries:

Codex enabled in Settings
Terminal 1: 8 Orca entries

Cases 2–4, AFTER. Codex disabled; terminals opened afterwards, and after a restart, show 0:

Codex disabled in Settings
Terminal 2: 0 Orca entries
Terminal 3 after restart: 0 Orca entries

Case 3, BEFORE, for contrast. With Codex disabled, a new terminal writes all 8 back:

BEFORE: Terminal 5 with Codex disabled shows 8 entries written back

Case 5, AFTER. Codex re-enabled; the next terminal restores 8:

Codex re-enabled in Settings
Terminal 5: 8 Orca entries restored

Case 6, AFTER. Claude disabled; the Codex entry is untouched:

Claude disabled, Codex enabled
Terminal 6: 8 Orca entries, unchanged

Not covered here

  • Windows and Linux were not run live for this PR. The change is a shared settings predicate plus a main-process gate, with no platform branch.
  • SSH: the per-agent opt-out does not yet reach every remote agent's hook installer. That's a separate follow-up and not changed by this PR.

@brennanb2025
brennanb2025 marked this pull request as ready for review September 29, 2026 04:09
@greptile-apps

greptile-apps Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 4/5

[Medium risk] Refactors agent hook enable logic to respect per-agent opt-out.

The PR does not yet appear safe to merge because disabling Codex in one profile can still repeatedly remove another profile’s shared real-home hook entry.

Findings

  1. P1 Shared Codex hook gets removed ▶

Summary

This PR centralizes the per-agent status-hook setting and applies it to Codex launch preparation, session resume, cleanup gating, and terminal preflight.

  • Adds tests for disabled Codex hooks in real and managed homes.
  • Keeps the existing shared-home cleanup behavior, which remains the subject of an unresolved review thread.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
  Settings[Global switch and per-agent opt-out] --> Gate[Codex hook predicate]
  Gate --> Launch[Launch and resume preparation]
  Gate --> Sweep[Real-home sweep gate]
  Launch --> Home[Codex hook configuration]
  Sweep --> Home
Loading

Reviews (2) · Last reviewed commit: "Merge origin/main into #23667"

Comment on lines +55 to +57
return (
args.isHostSystemDefaultRealHome && isAgentStatusHooksEnabledForAgent(args.settings, 'codex')
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Shared Codex hook gets removed

If one Orca profile has Codex disabled while another has it enabled, this gate allows the legacy sweep to run during every managed-home hook refresh in the disabled profile. Opening a terminal in that profile can remove the enabled profile’s entry from their shared ~/.codex/hooks.json. Its running Codex sessions then stop reporting status until that profile installs the entry again. An explicit opt-out can remove the entry, but routine launch preparation should not repeatedly undo another profile’s install.

Knowledge Base Used: Agent integrations and hooks

@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

This PR makes the per-agent Codex opt-out stick across launch prep, session resume, and the real-home hook sweep by routing every "is this agent's status hook on?" check through one shared predicate.

  • Shared predicate — isAgentStatusHooksEnabledForAgent(settings, agent) (main switch on AND agent not disabled) added to src/shared/agent-status-hooks-setting.ts; managed-agent-hook-controls.ts re-exports it so existing importers are unchanged, and the shared location lets the packaged CLI compile it without an out/main entry.
  • The fix — codex-launch-preparation.ts and codex-session-resume-launch.ts now read the per-agent opt-out instead of only the main switch, so a disabled Codex no longer re-installs Orca's hook on the next launch or resume.
  • Sweep gate — new shouldSuppressSystemCodexHomeHookSweep({ isHostSystemDefaultRealHome, settings }) in codex-hook-legacy-cleanup.ts (wired in main-process-account-services.ts) re-arms the legacy real-~/.codex sweep when Codex is turned off, so the Settings toggle actually clears a real-home entry.
  • Hand-rolled copies unified — ipc/settings.ts, runtime-client-settings.ts, runtime/rpc/methods/agent-hooks.ts, main-process-pty-startup.ts, cli/handlers/agent-hooks.ts, and opencode-plugin-settings.ts now call the shared predicate; behavior is unchanged there.
  • Spawn env cleanup — BuildPtyHostEnvOptions.codexStatusHooksEnabled is gone; host-env/assembly.ts recomputes agentStatusHooksEnabled && isTuiAgentEnabled('codex', disabledTuiAgents), matching the existing OpenCode/Pi/OMP pattern. isCodexStatusHooksEnabled in codex-home.ts is removed with no remaining references.

I verified the behavior on this branch: the two new suites pass (16 + 7), the affected suites (managed-agent-hook-controls, hook-service-legacy-cleanup, codex-launch-trust-write-deadline, headless-pty-hydration-ordering, main-process-ready-identity-write) pass, and the CLI build-entry parity guard (config/scripts/cli-main-module-bundle-parity.test.ts) passes, confirming the new src/shared import stays loadable by the packaged CLI. The assertions are exact (hooksEnabled: codexHooksOn, seeded real-home hooks.json), so the tests fail if the regression returns rather than absorbing either outcome.

The multi-profile note in the PR body holds up: Codex-off removes Orca's entry from the shared real ~/.codex exactly as the main switch already did, and another profile rewrites it on its next launch. That is existing semantics, not a new removal path, so it does not block.

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

@coderabbitai

coderabbitai Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 124be9f4-374d-49a8-a556-f38bc1f97434

📥 Commits

Reviewing files that changed from the base of the PR and between 9195419 and bbeb4bf.

📒 Files selected for processing (4)
  • src/main/ipc/pty/host-env/assembly.ts
  • src/main/runtime/runtime-client-settings.ts
  • src/main/startup/codex-session-resume-daemon-guard.test.ts
  • src/main/startup/codex-session-resume-launch.ts

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


📝 Walkthrough

Walkthrough

The change adds shared global and per-agent status-hook checks and applies them to hook preparation and reconciliation paths. Codex launch and resume paths use Codex-specific enablement. PTY environment assembly no longer accepts a separate Codex status-hook option. A new predicate gates system Codex home hook-sweep suppression, with tests covering enablement combinations and hook removal.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to bbeb4

Codex’s per-agent opt-out is honored by the reviewed launch, reconciliation, cleanup, and WSL preparation paths. No concrete merge-blocking behavior was established.

Security Architecture Review

Security architecture risk: 🔵 Low · up to bbeb4

The change reduces the chance that a disabled Codex hook is restored. No new hook-writing authority was identified, but removal can still be delayed or fail, so disabling the agent is not an instantaneous guarantee across every home.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The affected sink is Codex hook configuration in the selected real or managed home, not a newly introduced service or credential authority. A stale managed entry can continue to run wherever its home remains in use until successful cleanup.

Trust Boundaries and Controls

  • observed — Resume preparation distinguishes the verified session home from the system home before selecting the real-home installer or managed-home hook service; it does not substitute the currently selected account for the session origin.

Resilience and Maintainability Implications

  • inferred — Serialized reconciliation and guarded real-home writes limit conflicting mutations, but they do not make an opt-out immediately effective against an already queued launch or a failed sweep. The inspected change does not establish that this timing window was introduced by the PR.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 20 functions across 17 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 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 primary fix: keeping Codex hooks disabled when Codex is turned off per agent.
Description check ✅ Passed The description is detailed and covers the user impact, implementation, rationale, testing, scope, known limitations, and checklist. It states that no linked issue exists and leaves some template chec…
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

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.

Kept main's daemon socket guard on resume (#23724) beside the per-agent hooks
check; its new test mocks the per-agent predicate.

@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

Re-reviewed the single commit added since the prior pullfrog review — a merge of origin/main into the PR branch. The per-agent hook fix is intact and merges cleanly with main's new resume guard.

  • Main's Codex resume daemon guard retained — codex-session-resume-launch.ts now also runs ensureCodexDaemonSocketGuard(resumeHome) for non-system homes (main #23724), beside the PR's per-agent isAgentStatusHooksEnabledForAgent(..., 'codex') check; the guard is orthogonal to hook enablement and still skipped on the real ~/.codex lane.
  • Merge-resolution test mock updated — codex-session-resume-daemon-guard.test.ts mocks isAgentStatusHooksEnabledForAgent instead of isAgentStatusHooksEnabled, matching the launch file's import; without that the resumed-home tests would have hit the real predicate.

Verified locally: the 3 daemon-guard tests, 16 launch-opt-out tests, and 7 sweep tests all pass (26).

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

brennanb2025 added a commit that referenced this pull request Sep 29, 2026
Conflicts: #23552 deletes the system-home sweep latch that #23667 made
per-agent, so the latch and its per-agent gate stay deleted. #23667's sweep
test keeps only its case that still applies: Codex turned off per agent
reaches the explicit opt-out, which strips the real-home entry.
brennanb2025 added a commit that referenced this pull request Sep 29, 2026
#23667 moved the agent-status hooks predicate to src/shared and merged main.
Both conflicts were that import move landing in code this PR deleted: the
CLI's in-pane Codex preparation and the system-home sweep switch. Both
imports are dropped; every remaining import already uses the shared path.
brennanb2025 added a commit that referenced this pull request Sep 29, 2026
One conflict, in managed-hook-command-contract.test.ts: main added CodeBuddy
beside Qoder to the PowerShell variable scan. Codex keeps this branch's form
marker prefix. #23667's predicate in src/shared/agent-status-hooks-setting.ts
is unchanged. pnpm-lock.yaml is main's.
brennanb2025 added a commit that referenced this pull request Sep 29, 2026
Kept #23724's daemon socket guard on resume beside the real-home wait; took
#23815's deletion of the main-thread boundary source test and its rewrite of the
trust parity test, whose export-list check this branch had edited.
@brennanb2025
brennanb2025 merged commit 62e3a5a into main Sep 29, 2026
49 checks passed
brennanb2025 added a commit that referenced this pull request Sep 29, 2026
#23667 landed as a squash of the branch this PR was built on, identical in
content (22 files, +403/-73). Merged with #23667's branch tip as the base, so
only main's other changes since then come in and nothing of #23667 is
duplicated or reverted.
brennanb2025 added a commit that referenced this pull request Sep 29, 2026
Fixes the Orca part of #23289. A Codex worker could sit forever at
Codex's hooks screen: Orca's own hook entry had the right trusted_hash
but `enabled = false`, so the SessionStart event Orca waits for never
fired. Orca only ever granted the hash and never re-checked `enabled`
(the ledger fast path compared hashes only, the text fallback kept an
existing `enabled = false`, and the SSH installer passed no value), so a
stale `enabled = false` at the position Orca's entry occupies stuck.

Now every launch prep that installs Orca's hook re-derives it: the Codex
app-server grant writes `{ trusted_hash, enabled = true }` for Orca's
exact managed keys and verify fails if one is still disabled; the ledger
fast path misses when the entry is disabled; the local, WSL and SSH
fallbacks write `enabled = true` for Orca's entries. Project and user
hooks are never touched, so their review stays the user's decision.

Orca's own settings stay the only off switch: all of these writes run
only on the install path, which launch prep, session resume, startup and
the SSH/WSL installs take only when status hooks are on for Codex
(#23667's per-agent check). With Codex turned off, launch prep takes the
refresh-user-hooks path, which never writes Orca's hook state, so a
disabled entry stays off; turning Codex back on re-enables it on the next
launch. Supersedes #23292, which enabled the hook once at account creation
with nothing to re-derive it later.
brennanb2025 added a commit that referenced this pull request Sep 30, 2026
…ned off

The run producer ignored the status-hooks switch, so a user who turned
status off globally or for OpenCode (#23667) still got a run's Working and
Done. It now checks isAgentStatusHooksEnabledForAgent for the run's agent
(opencode or opencode2), the same predicate the plugin install honours,
before reading argv or posting anything.
brennanb2025 added a commit that referenced this pull request Sep 30, 2026
)

* fix(opencode): report OpenCode 2 status from each pane's TUI

OpenCode 2 serves every pane from one shared server whose env names only
the pane that started it, so every same-folder pane's work showed on that
pane, and the plugin's single aggregate swallowed the Idle of a pane whose
turn ended while another pane was busy.

Install the status plugin a second time as an OpenCode 2 TUI plugin
(plugins/<name>-tui/tui.js, written only when its bytes differ, locally,
in overlays and in the SSH/WSL relay installs). In a TUI process setup()
runs the same engine, fed through the same event translation as the
server, but only for root sessions this pane owns: the route's session
from when it starts (or when the route reaches it while running, hydrated
from the TUI's session status) until it settles, is deleted, or the TUI
exits. The server plugin stands down in any serve process when the TUI
copy is installed beside it; a relay that predates the TUI copy keeps the
old behavior. OpenCode 1 loads no plugin directories and is unchanged.

Delete the session-to-pane binder, registry, client sweep and ingest
reattribution: with every post stamped by its own pane nothing is left
for them to correct.

Known gap: OpenCode 2 `opencode run` in a pane has no TUI, so it reports
no pane status.

* fix(opencode): settle missed OpenCode 2 turn ends and order TUI installs

- The TUI copy now settles an owned root whose run the TUI's session data
  reports ended, with no pending permission or form, when the engine still
  holds it busy. An execution end missed across a service restart or
  reconnect no longer leaves the pane Working until the TUI exits.
- The TUI copy stays idle without ORCA_PANE_KEY. post() cannot report without
  it, so OpenCode 2 TUIs outside Orca no longer run the route poll and engine.
- Installers write the TUI copy before the server plugin file. The server
  decides at load whether to stand down, so a reload between the two writes
  now finds the TUI copy.

* fix(opencode): reconcile OpenCode 2 TUI status only once queued events drain

The TUI's session data applies each event before this plugin's queued handling
reaches it, so settling against it mid-backlog published a false Done before a
fast turn's later steps (Working, Done, Working, Done). Reconcile only when no
event is queued; a mismatch then is a start or end missed across a reconnect,
and both directions are now re-derived (a missed start left the pane on Done).

Also install the TUI copy beside the server plugin in the retired shared hooks
dir, so a TUI or service still loading that dir reports per pane instead of
leaving the service reporting under its starter pane.

* fix(opencode): keep OpenCode 2 TUI panes silent on plugin dispose

A TUI plugin hot reload disposes the plugin while the pane's turn keeps
running. The server path already passes sessionsOutliveDispose so dispose
publishes nothing; the TUI adapter now does the same, or every TUI reload
would still show a false Done. Also refreshes the generated-bytes digest
after rebasing onto the write-if-changed installers.

* fix(opencode): refresh installed OpenCode status plugins at app start

After an Orca upgrade, an OpenCode 2 service that was already running kept
the previous plugin, and with it the old wrong-pane status, until any new
terminal pane rewrote the file. OpenCode 2 reloads a plugin whose file
changes, so Orca now refreshes its existing installs once after the first
window shows: the global config dir, source overlays and the retired shared
dir, TUI copy first. It reuses the per-pane writers, which skip unchanged
files, never creates an install the user did not have, and honours the
status-hook and per-agent switches. An SSH relay does the same for its
canonical install when Orca connects and ships the plugin sources.

The plugin source assembly moves to its own module (re-exported unchanged)
to keep hook-service.ts under the line limit.

* fix(opencode): derive each OpenCode 2 pane's status from its TUI session data

The TUI copy of the status plugin translated OpenCode events into the
server-side engine and then patched the engine's latches back toward the
TUI's own session data: a settle on every tick, a queued-event counter, a
re-assert, synthetic Busy and Idle. Each review found another place where
the two copies disagreed: a missed end left the pane Working, a backlog of
slow posts flickered Done, a missed start showed Done mid-turn, a turn held
only by a subagent never settled, and a request answered while disconnected
pinned Needs input.

The TUI reporter now reads the pane's level straight from the session data
OpenCode keeps current (and re-hydrates on reconnect) on every event and on
a 100 ms tick: for each root session this pane owns, Needs input (an open
permission, else form, anywhere in its family while it runs) outranks
Working (any family member running) outranks Done. It posts one status per
level change through the plugin's existing delivery functions (retry,
dedupe, message-part throttle, ordering), so the wire and Orca's ingest are
unchanged. Ownership is kept in OpenCode's storage.memory, which survives a
plugin hot reload, so a turn that ends during a reload still shows Done;
dispose publishes nothing, and a level the old generation could not deliver
is re-posted by the next. On reconnect it re-syncs blockers for the owned
sessions OpenCode would not re-sync itself, ignoring requests already
answered. Events are handled synchronously, so a slow post can no longer
hold up event processing. The server path, OpenCode 1 and mimo are
unchanged.

* fix(opencode): keep an OpenCode 2 pane on Needs input while its root streams text

Orca treats every OpenCode MessagePart as Working. While a background
subagent waits on a permission or form, the root session can keep streaming
reply text, and the TUI reporter forwarded that text as a MessagePart. The
pane then flipped from Needs input to Working, and nothing restored it until
the level changed, so the user could miss the open request.

Skip reply text while the pane's level is Needs input, as the reporter
already does for queued prompts.

* fix(opencode): leave OpenCode 2 step events to the server path's own change

The shared-server translation re-derived Working from session.step.started.
The pane reporter no longer uses it, so it only changed the server path and
duplicated a separate open change. Drop it; server behaviour matches main.

* fix(opencode): reset an OpenCode 2 pane to idle when its TUI starts

Before this change, a pane could keep a status an earlier process left on
it. The case that matters is an upgrade mid-turn: the old shared-service
plugin posted pane B's turn under pane A's key, then stood down, and pane
A's TUI loaded the new reporter owning nothing, so it never posted and A
showed a wrong Working until its own next turn.

A freshly started reporter that owns no running turn now posts the host's
existing session-start boundary once, which the host shows as connected
idle: no completion, no notification, and an unseen Done it lands on stays
unread. A plugin hot reload keeps its memory and skips it, and where
OpenCode keeps no plugin memory it is never sent.

* fix(opencode): keep OpenCode 1 serve + attach sessions on the attaching pane

OpenCode 1 `opencode serve` in one pane plus `opencode attach` in others
reports every session from the serve process, whose environment names only
the serve pane. Before this branch the session-to-pane binder moved those
posts to the attaching pane; deleting it for OpenCode 2 put them back on the
serve pane.

Restore the binder, registry, correlation and client sweep for OpenCode 1
(and mimo-code, which it also served), gated so OpenCode 2 never uses it:

- The status plugin now sends `opencodeMajor: 2` on every post from a process
  whose loader called setup(), which only OpenCode 2 does. The host skips the
  binder (no rewrite, no kicked round) for any post that carries it. OpenCode 1
  and older plugins send nothing and keep the previous behaviour.
- The binder reads only OpenCode 1's `session` table. OpenCode 2 writes
  `session_v2`, so its sessions never bind; on a database both versions wrote,
  OpenCode 1 sessions are no longer hidden behind the v2 table.

OpenCode-1-only; it goes when OpenCode 1 support is removed.

* fix(opencode): show OpenCode 2 `opencode run` as Working, then Done, on its own pane

OpenCode 2's `opencode run` loads no plugin, and the shared service that
runs its session cannot tell which pane it belongs to, so a pane running it
showed nothing.

The runtime now reports it from the pane's own process lifetime. On the
pane's OSC 133 command start (main already parses 133 for every local PTY;
the start callback was never wired), after the pane tracker's 350 ms settle
it reads the foreground process name through the existing foreground
reader, and only when that name is OpenCode, the foreground command line
from one fresh shell-foreground process-table capture. An `opencode run`
posts Working through the existing terminal-status path into the hook
server's store; the pane's 133;D (or the daemon's background fact) posts
Done, marked interrupted on Ctrl-C. No polling.

Exclusive with plugin reporting: each write carries the command's start
time, and the store drops it once a hook has written the pane since then,
so an OpenCode 1 `run` (in-process plugin) or a server plugin without the
TUI copy owns its command alone and there is never a second Done.

Local macOS and Linux panes only; SSH, WSL and Windows panes stay silent
because their foreground cannot be read on this host.

* fixup! fix(opencode): show OpenCode 2 `opencode run` as Working, then Done, on its own pane

Type the selected descendants as process-table rows; ReturnType of the generic collector widened them to bare identity rows.

* fix(opencode): keep an `opencode run` pane's Done after the command exits

The run's Done was published inside the chunk that carried its OSC 133;D,
before the chunk's command-finished fact. The renderer drops an exited
agent's row on command-finished when the row has not changed since that
fact arrived, so it took the Done as the stale row and dropped it, in the
renderer and in main.

Publish the run's Done after the chunk's side-effect facts are emitted (and
after the daemon's background fact). The renderer then sees command-finished
while the row is still Working, and the Done that follows counts as a change,
so it stays, the same way a hook Done that lands after exit already does.

* fix(opencode): let an `opencode run` revive a pane Orca retired

When an agent Orca launched exits, command completion retires the pane, and
only a hook new-turn event revived it. A later `opencode run` in that pane
posts no hook, so its process-lifetime Working was refused and the pane
stayed silent.

A process-lifetime Working is posted only after a fresh OSC 133;C and the
pane's own foreground argv prove a new OpenCode run, which is at least as
strong as a hook new turn. The store now revives the retired pane on it the
same way: it clears the retirement, drops the launch-token fence, and rebinds
the observation. OSC status and a lone process Done still cannot write a
retired pane, and a closed tab stays closed.

* fix(opencode): report `opencode run` on local Windows panes too

The run producer skipped every Windows pane, although Orca already resolves
a Windows pane's foreground agent from the native process table. On main an
OpenCode 2 `run` showed there (on the service's pane); on this branch it was
silent.

The argv read now has a Windows branch: one fresh native table read
(windows-process-table, no interpreter spawn), the same foreground identity
the Windows resolver already computes, and the command line of the process
that identity names. It runs only after the name read says OpenCode. Local
Windows panes whose shell prints OSC 133 C/D (PowerShell with PSReadLine,
Git Bash with Orca's wrapper) now go Working, then Done; cmd.exe prints no
markers and stays silent. SSH and WSL panes stay silent.

* fix(opencode): re-read an `opencode run` foreground on the pane tracker's ladder

The producer read the pane's foreground once, 350 ms after the command
started. A wrapper, a shim or `sleep 1; opencode run` execs OpenCode later,
so those runs stayed silent. The renderer's pane tracker already re-reads a
command's foreground at 350, then 1200, then 6000 ms for exactly this.

Move those delays to one shared module and use it from both. The producer
re-reads only while the foreground is a non-shell process that is not
OpenCode, and at most on those three rungs; no new polling.

* fix(opencode): end an armed `opencode run` when the next command starts

A new OSC 133;C in a pane whose `opencode run` was still armed dropped the
armed state without a Done, so a run whose 133;D never arrived left the pane
on Working. A new command start proves the previous command ended, so it now
posts that run's Done (not marked interrupted: no exit code is known) before
the new command is inspected.

* fix(opencode): skip the session-start row inside an OpenCode 1 `run` process

OpenCode 1 `run` loads the status plugin in its own process, and the plugin
posts SessionStart when the run's session is created. The host lands that as
an idle session boundary, so a pane the run producer had already shown as
Working blinked idle before the plugin's Busy.

The plugin now skips SessionStart when its own process is a `run`, read from
its argv the same way isOpenCodeRunCommand reads a pane's foreground (first
positional after global options, past the compiled binary's entry path). A
`run` session goes Busy at once, and its first prompt part still revives a
retired pane and resets the turn caches. The TUI and `serve` still post it,
and OpenCode 2's `run` loads no plugin.

* chore(opencode): say where the plugin's opencodeMajor comes from

The field is set when OpenCode's loader calls setup(), which only OpenCode 2
does; the plugin never reads OpenCode's version. Say so at the field. Comment
only; the generated plugin is unchanged.

* test(opencode): type the late-Done pane fixture without bare casts

The new renderer test passed its fixtures with `as never`; use the checked
fixture-tuple cast with a SAFETY note, like the sibling pty-connection tests.

* fix(opencode): keep `opencode run` silent when OpenCode status is turned off

The run producer ignored the status-hooks switch, so a user who turned
status off globally or for OpenCode (#23667) still got a run's Working and
Done. It now checks isAgentStatusHooksEnabledForAgent for the run's agent
(opencode or opencode2), the same predicate the plugin install honours,
before reading argv or posting anything.

* test(opencode): read the late-Done row without an untyped property access

The mock store types agentStatusByPaneKey values as unknown, so reading
`.state` failed tc:web. Assert the row with toMatchObject instead.

* perf(opencode): read a command's foreground only while it could become `opencode run`

Two costs the run producer paid on every command in every local pane:

- The retry ladder re-read the foreground (a process-table capture on the
  local provider) for any non-shell program still running, including other
  agents, editors and dev servers, up to three times. It now re-reads only
  while the foreground is still the shell (the command has not exec'd yet)
  or an unrecognised launcher that may still exec OpenCode (node, bun, bunx,
  npx, npm, pnpm, pnpx, yarn). Any other program is read once.
- With OpenCode status turned off for both opencode and opencode2, it still
  set the timer and read the foreground only to discard the result. It now
  returns before any timer or read. The per-agent check after the name read
  stays for the case where only one of them is off.

* fix(opencode): let a new hook turn end a pane's process-exit completion

A confirmed agent process exit records a pane-wide completion identity that
names only the agent. Hook Dones are matched against it by agent alone, and
only a working title cleared it, so in a pane whose agent paints no working
title (OpenCode) every later hook-reported Done was treated as already
notified: no notification and no unread mark. An unreported exit (a status-off
`opencode run`, or quitting an idle client) was enough to set it.

A fresh hook Working now clears a process-exit identity, since a new turn
cannot be a duplicate of an earlier exit. Hook identities stay, so
same-turn and replay dedupe is unchanged.

* refactor(opencode): share the foreground read schedule as one value

The pane tracker's import of the two shared foreground-read delays took
four lines where its old local constants took three, which put the file
one line over max-lines once merged with main. Export the settle delay
and retry ladder as one object so each consumer imports a single name.
No behaviour change: same 350 ms settle and 1200/6000 ms retries.
OmarHung pushed a commit to OmarHung/orca that referenced this pull request Oct 3, 2026
…blyai#23722)

* fix(opencode): report OpenCode 2 status from each pane's TUI

OpenCode 2 serves every pane from one shared server whose env names only
the pane that started it, so every same-folder pane's work showed on that
pane, and the plugin's single aggregate swallowed the Idle of a pane whose
turn ended while another pane was busy.

Install the status plugin a second time as an OpenCode 2 TUI plugin
(plugins/<name>-tui/tui.js, written only when its bytes differ, locally,
in overlays and in the SSH/WSL relay installs). In a TUI process setup()
runs the same engine, fed through the same event translation as the
server, but only for root sessions this pane owns: the route's session
from when it starts (or when the route reaches it while running, hydrated
from the TUI's session status) until it settles, is deleted, or the TUI
exits. The server plugin stands down in any serve process when the TUI
copy is installed beside it; a relay that predates the TUI copy keeps the
old behavior. OpenCode 1 loads no plugin directories and is unchanged.

Delete the session-to-pane binder, registry, client sweep and ingest
reattribution: with every post stamped by its own pane nothing is left
for them to correct.

Known gap: OpenCode 2 `opencode run` in a pane has no TUI, so it reports
no pane status.

* fix(opencode): settle missed OpenCode 2 turn ends and order TUI installs

- The TUI copy now settles an owned root whose run the TUI's session data
  reports ended, with no pending permission or form, when the engine still
  holds it busy. An execution end missed across a service restart or
  reconnect no longer leaves the pane Working until the TUI exits.
- The TUI copy stays idle without ORCA_PANE_KEY. post() cannot report without
  it, so OpenCode 2 TUIs outside Orca no longer run the route poll and engine.
- Installers write the TUI copy before the server plugin file. The server
  decides at load whether to stand down, so a reload between the two writes
  now finds the TUI copy.

* fix(opencode): reconcile OpenCode 2 TUI status only once queued events drain

The TUI's session data applies each event before this plugin's queued handling
reaches it, so settling against it mid-backlog published a false Done before a
fast turn's later steps (Working, Done, Working, Done). Reconcile only when no
event is queued; a mismatch then is a start or end missed across a reconnect,
and both directions are now re-derived (a missed start left the pane on Done).

Also install the TUI copy beside the server plugin in the retired shared hooks
dir, so a TUI or service still loading that dir reports per pane instead of
leaving the service reporting under its starter pane.

* fix(opencode): keep OpenCode 2 TUI panes silent on plugin dispose

A TUI plugin hot reload disposes the plugin while the pane's turn keeps
running. The server path already passes sessionsOutliveDispose so dispose
publishes nothing; the TUI adapter now does the same, or every TUI reload
would still show a false Done. Also refreshes the generated-bytes digest
after rebasing onto the write-if-changed installers.

* fix(opencode): refresh installed OpenCode status plugins at app start

After an Orca upgrade, an OpenCode 2 service that was already running kept
the previous plugin, and with it the old wrong-pane status, until any new
terminal pane rewrote the file. OpenCode 2 reloads a plugin whose file
changes, so Orca now refreshes its existing installs once after the first
window shows: the global config dir, source overlays and the retired shared
dir, TUI copy first. It reuses the per-pane writers, which skip unchanged
files, never creates an install the user did not have, and honours the
status-hook and per-agent switches. An SSH relay does the same for its
canonical install when Orca connects and ships the plugin sources.

The plugin source assembly moves to its own module (re-exported unchanged)
to keep hook-service.ts under the line limit.

* fix(opencode): derive each OpenCode 2 pane's status from its TUI session data

The TUI copy of the status plugin translated OpenCode events into the
server-side engine and then patched the engine's latches back toward the
TUI's own session data: a settle on every tick, a queued-event counter, a
re-assert, synthetic Busy and Idle. Each review found another place where
the two copies disagreed: a missed end left the pane Working, a backlog of
slow posts flickered Done, a missed start showed Done mid-turn, a turn held
only by a subagent never settled, and a request answered while disconnected
pinned Needs input.

The TUI reporter now reads the pane's level straight from the session data
OpenCode keeps current (and re-hydrates on reconnect) on every event and on
a 100 ms tick: for each root session this pane owns, Needs input (an open
permission, else form, anywhere in its family while it runs) outranks
Working (any family member running) outranks Done. It posts one status per
level change through the plugin's existing delivery functions (retry,
dedupe, message-part throttle, ordering), so the wire and Orca's ingest are
unchanged. Ownership is kept in OpenCode's storage.memory, which survives a
plugin hot reload, so a turn that ends during a reload still shows Done;
dispose publishes nothing, and a level the old generation could not deliver
is re-posted by the next. On reconnect it re-syncs blockers for the owned
sessions OpenCode would not re-sync itself, ignoring requests already
answered. Events are handled synchronously, so a slow post can no longer
hold up event processing. The server path, OpenCode 1 and mimo are
unchanged.

* fix(opencode): keep an OpenCode 2 pane on Needs input while its root streams text

Orca treats every OpenCode MessagePart as Working. While a background
subagent waits on a permission or form, the root session can keep streaming
reply text, and the TUI reporter forwarded that text as a MessagePart. The
pane then flipped from Needs input to Working, and nothing restored it until
the level changed, so the user could miss the open request.

Skip reply text while the pane's level is Needs input, as the reporter
already does for queued prompts.

* fix(opencode): leave OpenCode 2 step events to the server path's own change

The shared-server translation re-derived Working from session.step.started.
The pane reporter no longer uses it, so it only changed the server path and
duplicated a separate open change. Drop it; server behaviour matches main.

* fix(opencode): reset an OpenCode 2 pane to idle when its TUI starts

Before this change, a pane could keep a status an earlier process left on
it. The case that matters is an upgrade mid-turn: the old shared-service
plugin posted pane B's turn under pane A's key, then stood down, and pane
A's TUI loaded the new reporter owning nothing, so it never posted and A
showed a wrong Working until its own next turn.

A freshly started reporter that owns no running turn now posts the host's
existing session-start boundary once, which the host shows as connected
idle: no completion, no notification, and an unseen Done it lands on stays
unread. A plugin hot reload keeps its memory and skips it, and where
OpenCode keeps no plugin memory it is never sent.

* fix(opencode): keep OpenCode 1 serve + attach sessions on the attaching pane

OpenCode 1 `opencode serve` in one pane plus `opencode attach` in others
reports every session from the serve process, whose environment names only
the serve pane. Before this branch the session-to-pane binder moved those
posts to the attaching pane; deleting it for OpenCode 2 put them back on the
serve pane.

Restore the binder, registry, correlation and client sweep for OpenCode 1
(and mimo-code, which it also served), gated so OpenCode 2 never uses it:

- The status plugin now sends `opencodeMajor: 2` on every post from a process
  whose loader called setup(), which only OpenCode 2 does. The host skips the
  binder (no rewrite, no kicked round) for any post that carries it. OpenCode 1
  and older plugins send nothing and keep the previous behaviour.
- The binder reads only OpenCode 1's `session` table. OpenCode 2 writes
  `session_v2`, so its sessions never bind; on a database both versions wrote,
  OpenCode 1 sessions are no longer hidden behind the v2 table.

OpenCode-1-only; it goes when OpenCode 1 support is removed.

* fix(opencode): show OpenCode 2 `opencode run` as Working, then Done, on its own pane

OpenCode 2's `opencode run` loads no plugin, and the shared service that
runs its session cannot tell which pane it belongs to, so a pane running it
showed nothing.

The runtime now reports it from the pane's own process lifetime. On the
pane's OSC 133 command start (main already parses 133 for every local PTY;
the start callback was never wired), after the pane tracker's 350 ms settle
it reads the foreground process name through the existing foreground
reader, and only when that name is OpenCode, the foreground command line
from one fresh shell-foreground process-table capture. An `opencode run`
posts Working through the existing terminal-status path into the hook
server's store; the pane's 133;D (or the daemon's background fact) posts
Done, marked interrupted on Ctrl-C. No polling.

Exclusive with plugin reporting: each write carries the command's start
time, and the store drops it once a hook has written the pane since then,
so an OpenCode 1 `run` (in-process plugin) or a server plugin without the
TUI copy owns its command alone and there is never a second Done.

Local macOS and Linux panes only; SSH, WSL and Windows panes stay silent
because their foreground cannot be read on this host.

* fixup! fix(opencode): show OpenCode 2 `opencode run` as Working, then Done, on its own pane

Type the selected descendants as process-table rows; ReturnType of the generic collector widened them to bare identity rows.

* fix(opencode): keep an `opencode run` pane's Done after the command exits

The run's Done was published inside the chunk that carried its OSC 133;D,
before the chunk's command-finished fact. The renderer drops an exited
agent's row on command-finished when the row has not changed since that
fact arrived, so it took the Done as the stale row and dropped it, in the
renderer and in main.

Publish the run's Done after the chunk's side-effect facts are emitted (and
after the daemon's background fact). The renderer then sees command-finished
while the row is still Working, and the Done that follows counts as a change,
so it stays, the same way a hook Done that lands after exit already does.

* fix(opencode): let an `opencode run` revive a pane Orca retired

When an agent Orca launched exits, command completion retires the pane, and
only a hook new-turn event revived it. A later `opencode run` in that pane
posts no hook, so its process-lifetime Working was refused and the pane
stayed silent.

A process-lifetime Working is posted only after a fresh OSC 133;C and the
pane's own foreground argv prove a new OpenCode run, which is at least as
strong as a hook new turn. The store now revives the retired pane on it the
same way: it clears the retirement, drops the launch-token fence, and rebinds
the observation. OSC status and a lone process Done still cannot write a
retired pane, and a closed tab stays closed.

* fix(opencode): report `opencode run` on local Windows panes too

The run producer skipped every Windows pane, although Orca already resolves
a Windows pane's foreground agent from the native process table. On main an
OpenCode 2 `run` showed there (on the service's pane); on this branch it was
silent.

The argv read now has a Windows branch: one fresh native table read
(windows-process-table, no interpreter spawn), the same foreground identity
the Windows resolver already computes, and the command line of the process
that identity names. It runs only after the name read says OpenCode. Local
Windows panes whose shell prints OSC 133 C/D (PowerShell with PSReadLine,
Git Bash with Orca's wrapper) now go Working, then Done; cmd.exe prints no
markers and stays silent. SSH and WSL panes stay silent.

* fix(opencode): re-read an `opencode run` foreground on the pane tracker's ladder

The producer read the pane's foreground once, 350 ms after the command
started. A wrapper, a shim or `sleep 1; opencode run` execs OpenCode later,
so those runs stayed silent. The renderer's pane tracker already re-reads a
command's foreground at 350, then 1200, then 6000 ms for exactly this.

Move those delays to one shared module and use it from both. The producer
re-reads only while the foreground is a non-shell process that is not
OpenCode, and at most on those three rungs; no new polling.

* fix(opencode): end an armed `opencode run` when the next command starts

A new OSC 133;C in a pane whose `opencode run` was still armed dropped the
armed state without a Done, so a run whose 133;D never arrived left the pane
on Working. A new command start proves the previous command ended, so it now
posts that run's Done (not marked interrupted: no exit code is known) before
the new command is inspected.

* fix(opencode): skip the session-start row inside an OpenCode 1 `run` process

OpenCode 1 `run` loads the status plugin in its own process, and the plugin
posts SessionStart when the run's session is created. The host lands that as
an idle session boundary, so a pane the run producer had already shown as
Working blinked idle before the plugin's Busy.

The plugin now skips SessionStart when its own process is a `run`, read from
its argv the same way isOpenCodeRunCommand reads a pane's foreground (first
positional after global options, past the compiled binary's entry path). A
`run` session goes Busy at once, and its first prompt part still revives a
retired pane and resets the turn caches. The TUI and `serve` still post it,
and OpenCode 2's `run` loads no plugin.

* chore(opencode): say where the plugin's opencodeMajor comes from

The field is set when OpenCode's loader calls setup(), which only OpenCode 2
does; the plugin never reads OpenCode's version. Say so at the field. Comment
only; the generated plugin is unchanged.

* test(opencode): type the late-Done pane fixture without bare casts

The new renderer test passed its fixtures with `as never`; use the checked
fixture-tuple cast with a SAFETY note, like the sibling pty-connection tests.

* fix(opencode): keep `opencode run` silent when OpenCode status is turned off

The run producer ignored the status-hooks switch, so a user who turned
status off globally or for OpenCode (stablyai#23667) still got a run's Working and
Done. It now checks isAgentStatusHooksEnabledForAgent for the run's agent
(opencode or opencode2), the same predicate the plugin install honours,
before reading argv or posting anything.

* test(opencode): read the late-Done row without an untyped property access

The mock store types agentStatusByPaneKey values as unknown, so reading
`.state` failed tc:web. Assert the row with toMatchObject instead.

* perf(opencode): read a command's foreground only while it could become `opencode run`

Two costs the run producer paid on every command in every local pane:

- The retry ladder re-read the foreground (a process-table capture on the
  local provider) for any non-shell program still running, including other
  agents, editors and dev servers, up to three times. It now re-reads only
  while the foreground is still the shell (the command has not exec'd yet)
  or an unrecognised launcher that may still exec OpenCode (node, bun, bunx,
  npx, npm, pnpm, pnpx, yarn). Any other program is read once.
- With OpenCode status turned off for both opencode and opencode2, it still
  set the timer and read the foreground only to discard the result. It now
  returns before any timer or read. The per-agent check after the name read
  stays for the case where only one of them is off.

* fix(opencode): let a new hook turn end a pane's process-exit completion

A confirmed agent process exit records a pane-wide completion identity that
names only the agent. Hook Dones are matched against it by agent alone, and
only a working title cleared it, so in a pane whose agent paints no working
title (OpenCode) every later hook-reported Done was treated as already
notified: no notification and no unread mark. An unreported exit (a status-off
`opencode run`, or quitting an idle client) was enough to set it.

A fresh hook Working now clears a process-exit identity, since a new turn
cannot be a duplicate of an earlier exit. Hook identities stay, so
same-turn and replay dedupe is unchanged.

* refactor(opencode): share the foreground read schedule as one value

The pane tracker's import of the two shared foreground-read delays took
four lines where its old local constants took three, which put the file
one line over max-lines once merged with main. Export the settle delay
and retry ladder as one object so each consumer imports a single name.
No behaviour change: same 350 ms settle and 1200/6000 ms retries.

(cherry picked from commit 3727100)
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