Skip to content

fix(runtime): keep launch authority when a resident TUI repaints mid-turn - #24732

Closed
ggbdpq wants to merge 3 commits into
stablyai:mainfrom
ggbdpq:fix/omp-repaint-agent-status
Closed

ggbdpq wants to merge 3 commits into
stablyai:mainfrom
ggbdpq:fix/omp-repaint-agent-status

Conversation

@ggbdpq

@ggbdpq ggbdpq commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

ELI5

Orca watches agent terminals for the shell's "command finished" signal (OSC 133;D). But agent TUIs like OMP also emit that same signal when they merely redraw their transcript — resizing the window, splitting a pane, or switching the sidebar all trigger a redraw. Orca mistook those redraw marks for "the agent's command ended", tore down the pane's agent-status authority, and then silently discarded (HTTP 204) every status update the agent sent for the rest of its turn. The agent kept working; Orca just showed it as idle/gone until the next prompt. This PR ignores the "command finished" signal from a redraw while the agent's own status row still shows a live turn.

What Changed

Both command-finished trigger sites — the byte-path title tracker (orca-runtime-get-unpersisted-tracked-title-for-pty.ts) and the daemon transient-fact path (orca-runtime-emit-daemon-pty-transient-fact.ts) — previously called retirePtyAgentLaunchAuthority(ptyId) unconditionally. They now call a new retirePtyAgentLaunchAuthorityOnCommandFinished(ptyId), which skips retirement only when the PTY has a fresh explicit agent status row (via the existing selectFreshExplicitAgentStatusRow, same freshness window as everywhere else) whose agent is a resident turn source (pi, omp, prime-agent — the Pi family whose turn boundaries are their own before_agent_start hooks, not the shell command a 133;D would close) and whose mapped state is not idle.

Everything else is unchanged: non-resident agents, ended (done) rows, rows outside the freshness window, and the real onPtyExit path all keep retiring today. The user-visible before/after: an OMP turn no longer goes grey/idle mid-turn after a resize, split, or sidebar change — orca worktree ps keeps showing the row, and mid-turn hooks are applied instead of 204'd.

Why

The bug is not in the closed-pane suppression gate itself (that gate is intentional and #14236 kept it deliberately) — it is that a redraw mark was misread as authority-retirement evidence. Fixing at the shared judgment point (the two trigger sites' retirement call) heals every dispatch surface that funnels through managed worktrees, instead of teaching the downstream disposition to second-guess retirement. Scoping the skip to the Pi family preserves the STA-4557 semantics pinned in opencode-finished-session-authority (opencode's 133;D is a real session boundary and must retire), and the freshness window bounds the skip so a stale or crashed row can never pin authority forever.

Alternatives considered and rejected: foreground-process/presence gates (OMP hooks carry no process identity and WSL foreground reads are unavailable — the gate would silently no-op exactly in the reported environment); ignoring 133;D whenever a launch agent is set (would break real exit detection for shell-wrapped panes); accepting non-new-turn events downstream when the launch token still matches (a downstream patch over a misjudgment upstream).

Linked Issue

Fixes #24436

Visual Proof

N/A — no UI surface change; the fix is main-process authority bookkeeping observable through orca worktree ps --json rows and hook acceptance. The regression test asserts the before/after at those seams (attest stays non-null, snapshot row stays working across a mid-turn repaint; later hooks still land).

Testing

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

New omp-repaint-launch-authority.test.ts drives a real AgentHookServer + OrcaRuntimeService through the public seams (real HTTP hook endpoint, onPtyData byte injection, emitDaemonPtyTransientFact, onPtyExit): mid-turn repaint keeps authority and the working row on both trigger paths and later hooks still apply; a genuinely ended turn and a real PTY exit still retire. Local matrix: aggregate orca-runtime.test.ts 1341 passed / 1 skipped (pre-existing skip, covers all specs feeding 133;D); STA-4557 opencode authority and adjacent authority/lifetime suites 49/49; pnpm tc clean; oxlint clean on changed files. Manual end-to-end against a real OMP/WSL2 setup was not run in this environment. Known residual, disclosed: the renderer-side pane-agent-identity row drop on command-finished is untouched (a transient drop that the next accepted hook rebuilds); a mid-turn repaint during an interactive-shell-wrapped crash inside the freshness window defers retirement until the 30-minute staleness clock or PTY exit.

AI Disclosure

Implemented by GLM-5.3-Flash (ZCode agent) under direction of ggbdpq, who reviewed the diff and re-ran the new and protected test suites.

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

Cross-platform: the gate reads only in-process hook state, no platform APIs; SSH/daemon paths go through the same two trigger sites. No persistence, protocol, or backwards-compatibility impact — retirement behavior for every pre-existing case is byte-identical, and the new skip is bounded by the existing freshness window (also the fallback cleanup clock).

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)

@coderabbitai

coderabbitai Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e298a174-49e5-46dc-8c87-923491c308ba
Commits

Reviewing files that changed from the base of the PR and between 50965775861c05fb895ac8587f84f20eecc04cbf and f62baf4.

Files selected for processing: 4
  • src/main/runtime/omp-repaint-launch-authority.test.ts
  • src/main/runtime/terminal/output/terminal-orchestration-authority.ts
  • src/main/runtime/terminal/output/terminal-title-tracker.ts
  • src/main/runtime/terminal/output/terminal-transient-facts.ts

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

Walkthrough

Command-finished handling now preserves PTY launch authority when a fresh status row belongs to a Pi-compatible agent with a non-idle runtime status. Otherwise, it retires that authority. Tests cover OSC 133;D repaint and daemon transient facts during a working turn, later hook completion, authority retirement after agent_end, and status removal after a real PTY exit.

Priority: Normal

Severity of issue fixed: Medium

Merge Risk: Minimal · up to f62ba

The reviewed change is mergeable after normal checks; no actionable risk remains established.

Security architecture risk: Low · up to e23d5

The change preserves existing launch permissions during active work while retaining normal exit cleanup. No new permission bypass was established, but terminal reuse needs further verification to ensure status from an earlier launch cannot delay revocation.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The changed decision operates on one PTY and its associated pane identities. Preserved authority still requires existing caller checks involving a launch secret, live terminal identity, and host scope; the complete downstream action and data-store exposure was not established.

Trust Boundaries and Controls

  • observed — Compatibility verification checks the supplied launch-token hash and host scope. Its attested path additionally requires token-hash and connection equality with a unique current pane observation. These checks are separate from status-row selection; a matching status row alone does not authenticate a caller.
  • observed — Existing pane retirement fences aliases and clears status rows and current authority observations. Restart disposition can fence subsequent status by launch-token hash. These controls counter the prior-generation-row hypothesis, but do not prove every production reuse path removes old evidence before the new preservation decision.

Resilience and Maintainability Implications

  • observed — PTY exit rejects mismatched exit incarnations and ordinarily invokes retirement independently of status preservation. Certified process death also reconciles status rows. The existing unconfirmed abnormal SSH-exit branch follows a separate recovery policy, so exit cleanup is not universally unconditional.

Hardening Proposals

  • proposed — Make the launch-generation binding of preservation evidence explicit, either through a documented upstream invariant with reuse and recovery coverage or through generation-aware selection. This would close the remaining identity proof gap without treating it as a verified bypass.
Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 7 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: preserving launch authority when a resident TUI repaints during an active turn.
Description check Passed The description is complete and directly addresses the required sections. It explains the user impact, implementation, rationale, linked issue, testing, AI disclosure, compatibility considerations, an…
Linked Issues check Passed The PR satisfies the coding requirements in [#24436]. Both command-finished paths now use retirePtyAgentLaunchAuthorityOnCommandFinished. The guard preserves authority only for a fresh explicit st…
Out of Scope Changes check Passed The changes remain within [#24436]. The implementation changes authority retirement for command-finished events. The added tests cover the reported repaint behavior and required retirement boundaries.…
Full details: Description check

Explanation

The description is complete and directly addresses the required sections. It explains the user impact, implementation, rationale, linked issue, testing, AI disclosure, compatibility considerations, and visual-proof exception. The unchecked aggregate command checklist is offset by the detailed reported test results and is not critical.

Full details: Linked Issues check

Explanation

The PR satisfies the coding requirements in [#24436]. Both command-finished paths now use retirePtyAgentLaunchAuthorityOnCommandFinished. The guard preserves authority only for a fresh explicit status row from a resident Pi-family agent with a non-idle state. Other command-finished cases and real PTY exit still retire authority. The regression tests cover both trigger paths, later hook delivery, ended turns, and PTY exit.

Full details: Out of Scope Changes check

Explanation

The changes remain within [#24436]. The implementation changes authority retirement for command-finished events. The added tests cover the reported repaint behavior and required retirement boundaries. No unrelated implementation or test changes are shown.

  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.

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.

@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 critical issues — one maintainability suggestion inline.

Reviewed changes

  • Mid-turn repaint no longer retires launch authority: both command-finished trigger sites now call a new retirePtyAgentLaunchAuthorityOnCommandFinished, which skips retirement only while a fresh, live hook row for a resident Pi-family agent shows a non-idle state; everything else falls through to unconditional retirement.
  • Regression coverage: omp-repaint-launch-authority.test.ts drives a real hook server + runtime through both trigger paths (byte 133;D and daemon transient fact) and asserts authority and the working row survive a mid-turn repaint, later hooks still apply, and a real turn end / PTY exit still retire. Verified passing locally alongside the STA-4557 opencode-finished-session-authority suite.

I checked the two design questions this PR turns on and both hold: the class-mixin chain makes the new protected method reachable at both call sites (the fresh test exercises it), and a fresh done row really is terminal for Pi-family agents — OMP suppresses willContinue === true and Pi/prime gate on ctx.isIdle() (src/main/pi/agent-status-handler-source.ts:277), so !== idle is consistent with the STA-4557 behavior the PR preserves. onPtyExit correctly stays unconditional. The one thing worth tightening is the hand-rolled resident set.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@euclodius

Copy link
Copy Markdown

Released-build evidence relevant to the two retirement sites changed by this PR: Windows paired client 1.4.224 + Linux headless server 1.4.224 + fresh OMP 18.10.4. The WSL host is reached directly over loopback WebSocket, so this reproduction does not require SSH.

An isolated sleep 45 turn first produced an accepted tool_execution_start/working entry. Splitting its pane removed that entry before completion. Later tool_execution_end, message_end, and agent_end posts all received HTTP 204, but the accepted hook cache stayed empty. Inspection of the installed runtime confirms unconditional retirement in both the title-tracker and daemon command-finished paths.

This is evidence for the bug and the relevance of your changed call sites, not validation of this PR; I have not run its branch. The visible row sometimes survived through terminal-output-derived status, so UI appearance alone can mask the lost hook state.

For a live paired-headless check, please verify accepted hook state across both a mounted resize/split and a parked daemon scan, including completion after the repaint. Real PTY exit must still clear authority. Could you clarify whether the disclosed renderer-side identity drop requires a separate fix/release for paired clients, and which released server/client versions will contain the complete behavior?

Detailed isolated reproduction: comment on #24436.


AI assistance disclosure: prepared with an OpenAI coding assistant via OMP, using my reported behavior and local runtime diagnostics/source inspection. Reproduction and validation limits are stated above.

…turn

A resident Pi-family TUI (omp, pi, prime-agent) repaints its transcript on
resize, split, or sidebar switches, re-emitting the rendered user message's
OSC 133;A..D marks while the turn is still running. Every `command-finished`
fact unconditionally retired the pane's launch authority, and the closed-pane
gate then 204-suppressed every later mid-turn hook (tool_execution_start/end,
message_end, agent_end), so the status row vanished until the next prompt
(stablyai#24436). Even without a resize, the hook/post-paint race dropped status on 4
of 24 real-prompt trials.

Both command-finished trigger sites (byte-path title tracker and daemon
transient fact) now skip retirement when the PTY has a fresh explicit agent
status row from a resident turn source whose state is not idle: while that
row is live, the 133;D mark cannot be the launched command ending. Everything
else keeps today's unconditional retirement — non-resident agents, ended
(done) rows, rows outside the freshness window, and the real `onPtyExit` path
— preserving the STA-4557 opencode semantics where 133;D is a session
boundary.

Fixes stablyai#24436

Generated-by: GLM-5.3-Flash (ZCode)
…entType

RESIDENT_AGENT_TURN_SOURCES re-stated the PiAgentKind union that
isPiCompatibleAgentType already owns, so a future Pi-family kind could be
silently omitted from the command-finished retirement gate. Import the
helper instead; the set of gated agent types is unchanged.

Generated-by: GLM-5.3-Flash (ZCode)
…-id spawn contract

The launch path now hands spawn pane ids (worktree/tab/leaf) instead of a raw
env blob, and pane binding is committed by the committingSpawn fixture. Use
spawnedPtyEnv + committingSpawn like the sibling
opencode-finished-session-authority harness so the four repaint/retire
assertions exercise the same wiring on the current base.

Generated-by: GLM-5.3-Flash (ZCode)
@ggbdpq

ggbdpq commented Oct 25, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @euclodius for the released-build evidence and the cross-references — the accepted-hook-cache-empty observation and the unconditional retirement in both the title-tracker and daemon command-finished paths match exactly the two call sites this PR changes.

On your verification ask: the rebased head now pins all four behaviors you named in src/main/runtime/omp-repaint-launch-authority.test.ts (green on the new base):

  1. mid-turn OSC 133;D repaint (the resize/split trigger) keeps launch authority and the working row, and later message_end/agent_end hooks are applied — not 204'd — with the row ending at done;
  2. the same repaint arriving as a daemon transient fact (your parked-daemon-scan path) also keeps authority;
  3. a genuinely ended turn (done row) still retires authority on a repaint;
  4. a real PTY exit clears authority even while a fresh working row exists.
    These are unit-level pins on the runtime wiring, not validation on released paired builds — I have no paired Windows/headless environment here, so your released-build reproduction remains the only end-to-end evidence on record.

On the renderer-side identity drop and versions: this PR only changes runtime launch-authority retirement; the renderer-side identity behavior you saw is a separate surface it does not touch. Note the paired/mobile projection side independently changed on main via #32195 (an idle-title repaint no longer retires a fresh working hook in the projection). Whether a paired-client release needs to bundle both, and which versions carry them, is @nwparker's call — I can't speak to release planning.

Status: rebased onto a886dcd today. The October runtime reorganization had moved both call sites into terminal/output/, and the launch harness now uses the pane-id spawn contract — both resolved (head f62baf4, conflicts resolved, harness adapted, typecheck:node clean, PR suite 4/4 + STA-4557 sibling suite 5/5). No absorption: upstream still calls retirePtyAgentLaunchAuthority unconditionally at both sites, and #24436/#26933 remain open.

@nwparker gentle ping — happy to adjust anything.

@euclodius

Copy link
Copy Markdown

@ggbdpq Thanks for the detailed follow-up and for adding the four lifecycle cases. Those line up with the runtime guards raised in my earlier comment. I also appreciate the explicit distinction between launch-authority retirement and the separate renderer/projection behavior.

Our current released-build update is Orca 1.4.240 across the paired Windows client and both Linux Electron servers, with OMP 18.12.6. Agent status seems to be working normally on that setup at the moment.

@ggbdpq

ggbdpq commented Oct 25, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @euclodius — the 1.4.240 data point settles it. Your report led me back to what actually landed: #30273 (merged Oct 18, first shipped in v1.4.230) fixes this at the OSC 133 scanner layer — OMP's back-to-back bubble markers (133;B C D;0) are now recognized as a zone close rather than command-finished, so retirePtyAgentLaunchAuthority no longer fires mid-turn from either terminal-title-tracker.ts or terminal-transient-facts.ts, and the real-exit semantics (D from the shell itself, PTY exit) are preserved.

That covers both call sites this PR conditionalyzed, from one level closer to the root cause, and your released-build confirmation plus #24436's closure is the end-to-end evidence this branch could not produce locally. Closing this in favor of #30273 — the call-site guards it added are no longer needed with the misfire eliminated upstream. Should a hook-state loss ever reappear through a path the scanner doesn't cover, the four pinned lifecycle behaviors in this branch's history (repaint, daemon transient fact, done-row retirement, real PTY exit) document the expected semantics to reopen against.

@ggbdpq ggbdpq closed this Oct 25, 2026
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.

[Bug]: OMP agent status vanishes mid-turn after any repaint of a user message (OSC 133;D retires launch authority; later hooks silently 204'd)

2 participants