Repository navigation
Conversation
Parse the body of one Program Status report (protocol rev 0.4) into a report or a discard. Malformed pairs are skipped and counted; every well-formed occurrence is checked against the per-pair limits (key length, msg and title encoded and decoded size, strict base64 that decodes as UTF-8, control characters, app size, id size and grammar) before duplicates resolve, so an invalid earlier duplicate discards the report. A missing or unrecognized state discards it; an unrecognized kind, app or progress is treated as absent. Decoded msg and title are validated and not retained. Pure and not yet wired to any terminal.
Scan a PTY stream for OSC 7501 reports, OSC 133;A prompt starts and RIS, each with its source offsets, whatever the chunk boundaries. A report ends at BEL or ST, and a bare ESC also terminates it, as in Ghostty: the report is parsed up to that ESC and scanning resumes at the ESC, so it can begin the next sequence. The scanner carries at most a partial prefix or one open frame; a frame over 4096 UTF-8 bytes (skipped pairs and a BEL or ST terminator included) is discarded whole and skipped to its terminator without being buffered. The probe body is ignored. RIS and prompt starts are only scanned while the caller says they matter, re-read after every event so a report can arm the rest of the same chunk; DECSTR, alternate screen switches and erase display are not resets. Searches only move forward, and a chunk with nothing to report costs one indexOf per active pattern with no copy of the chunk.
Keep the per-terminal records the Program Status protocol describes: a report replaces its record completely, clear removes the addressed record and its subtree (no id is the root, so it empties the store), and past 256 records the least recently updated one is evicted. A prompt start drops working and blocked records and keeps idle, done and error; RIS drops everything. Summarize the records into the aggregate state a status dot shows (blocked and question above working above error above done above idle, ties to the most recent update), the root record's own state, and whether a child failed. A child error never becomes the aggregate error. The projection carries the current summary and the one that remains once the attached process exits (done and error only), computed without changing the store. Pure and not yet wired to any terminal.
…ations and budget Run the scanner and the record store for one PTY incarnation and number what they produce. After every applied event, in byte order and before any throttling, the tracker recomputes the projection and gives each of its two views (now, and what remains on exit) a new generation when that view's summary changed, drawn from one counter that clear, RIS and prompt starts never reset, so a generation is never reused. A changed view also records, on the owner's wall clock passed in by the caller, when its aggregate and its root last changed. Any change of either view takes the next reportSeq, so an equal reportSeq always means an identical observation, and a repeated state takes no number. Emission is throttled per PTY (a burst of 8, 20 per second) and the latest observation is always delivered, at worst by one 100 ms trailing timer. The budget and its timer read an injectable monotonic clock, never the wall clock, so a step of the owner's clock, backward or forward, neither credits time that did not pass nor delays delivery. An emission carries the reportSeq and the views recorded with it, so a coalesced done, working, done still shows a newer generation than the first done. snapshot() returns the current state without incrementing anything, and discarded reports are counted by reason. Pure and not yet wired to any terminal.
…mposition Define the program-status slot a pane will hold beside its hook row: the PTY and incarnation it belongs to, the tracker's reportSeq, a liveness (live, unverifiable, exited) with the instant it began, and the shown view (now, or what remains on exit) with its generation. A dismissal is an acknowledgement of one incarnation, view and generation. A strict codec parses the fact a PTY owner sends and the acknowledgement argument, rejecting an unknown state, a non-positive or fractional generation and a non-finite time. applyProgramStatusWrite is the pure acceptance rule: reports are ordered by reportSeq inside an incarnation and another incarnation replaces the slot; lifecycle writes are fenced by identity, exited is absorbing, and an empty view removes the slot. The liveness time is copied from the write and never stamped, so a re-created slot keeps the instant its producer was last verified. carryAckAcrossExit keeps a dismissal across the process exit only when it names exactly the pre-exit view and the remaining view shows the same summary; it reads the acknowledgement and the exit write alone, so it holds with no pane record. composeAgentStatusEntry applies the precedence setting as a pure input and reads no clock or timestamp: without a slot the hook entry is returned as is; by default a hook row wins unless it is absent, a seed Orca planted at launch or from process output, or restored and not yet confirmed. The display entry built from a slot maps the aggregate to the existing states, takes the main agent verdict from the root alone, and marks the idle state as resting. Tests run the existing sidebar row, dashboard, worktree card and worktree ps readers on that entry and on a hook entry of the same state and verdict, and expect the same result for every summary but idle. Pure and not yet wired to any reader.
Six transcripts of the agent CLI version 2.1.295 on macOS, captured with config/scripts/capture-agent-pty-transcript.mjs: idle at startup, one turn, a Bash permission dialog answered allow once, an AskUserQuestion answered with its first option, an Escape interrupt, and one subagent followed by /exit. The agent reports only once its OSC 7501 probe is answered ahead of DA1, so the capture script ran inside a test terminal that answers the probe the way the PTY owner's startup ingress does and the other startup queries the way the renderer's xterm.js does. Orca's own reply ordering is covered by the startup ingress tests. A run whose terminal leaves the probe unanswered carries the probe and no report. Each sidecar records the commit the capture ran on, the route and the scenario. Session link ids, the home path, the plan tier, the usage notice and the resume id are scrubbed at the same length, so the captured screens keep their wrapping. The replay reads the real bytes through the pure core: the scanner yields the same events at every read size and at every cut in and around each sequence, the parser accepts every report, the tracker yields each scenario's transitions with the descriptive second done folded into the first, and the subagent run drives a child record, its clear by id and the exit-time root clears.
Record the problem, the protocol and capture constraints, the architecture, compatibility, scope, rejected alternatives and known limits of OSC 7501 program status support.
A secret found inside the decoded msg or title of an OSC 7501 report was redacted by filling the encoded span with X. That fill is not valid base64 of UTF-8 text, so the parser discards the whole report and a scrubbed fixture silently stops carrying it on replay. Redact the decoded text instead and encode it again, keeping the original padding style. The placeholders are ASCII, so the encoding keeps its length whenever the secret was ASCII. The new test parses the scrubbed report, not only rescans it.
A lifecycle write that omits `shown` keeps the slot's view. On the move into `exited` that kept the pre-exit `now` view while the slot was relabelled `onExit`, so the pane went on showing working or blocked state after the exit, and an `onExit` dismissal was compared against a `now` generation. Refuse a lifecycle write that omits `shown` when it would change the view name. Only the move into `exited` does that, since `exited` is absorbing; an `exited` to `exited` write without `shown` is still a no-op. The ledger's exit write already carries the `onExit` view.
The parser checked the id grammar on every occurrence of `id`, so `state=done:id=a//b:id=a` was discarded although the spec says the last value of a repeated key wins and ignores only a report whose id does not match the grammar. Keep the id size limits (128 bytes, 32 per segment, 8 levels) on every occurrence, as the spec asks of every limit before any record is touched, and check the segment grammar once, on the value that wins. The msg and title checks are unchanged.
The scanner reported OSC 133;A as a prompt start as soon as a `;` followed the `A`, so a truncated `ESC]133;A;` dropped every working and blocked record although no complete prompt sequence arrived. A bare ESC right after the `A` counted too. Scan a prompt start like a report frame: through its parameters, across chunks, under the same 4096 byte bound, and report it only once BEL or ST ends it, which is how the shell lifecycle scanner reads OSC 133. A bare ESC ends the candidate without a prompt start and is scanned as the next sequence; an unterminated or oversized body reports nothing. The event's end now points past the terminator, like a report's.
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Priority: ⬇️ Low Merge Risk: ⚪ Minimal · up to
|
|
Adding my support for this foundation: accurate agent status is important when managing multiple sessions. In my current workflow, a Codex CLI session waiting for verification results from another session appears completed as soon as its response turn ends. I shared the concrete use case on the integration PR: #30145 (comment). I have not verified whether OSC 7501 covers that specific Codex case, but support for explicit program-reported status is valuable for making these workflows clearer. |
|
Closing this as superseded by #30260, #30261 and #30262, merged on 2026-10-19. I compared the two stacks against main at Two differences remain, and neither justifies a follow-up today. This stack had a setting that let OSC 7501 outrank hooks. #30261 keeps hooks first and hands the row to OSC 7501 after 2 minutes of hook silence, which covers the crashed-hook case without a setting. Our daemon also tracked reports before keep-tail thinning, so a hidden, backlogged daemon pane could not lose one. Main degrades that case to "ended", not to a wrong state, and I have no live repro of it. I will open an issue only if I get one. Thanks @nwparker for the implementation. The Codex question from @innocarpe is answered on #30145. |
ELI5
Some coding agents can now tell the terminal what they are doing (working, waiting for an answer, done) with a standard escape sequence, OSC 7501. Orca does not listen for it yet. This PR adds the parts that read and remember those reports, plus real recordings of an agent sending them. Nothing in the app uses these parts yet, so nothing changes for users. Part 2 plugs them in.
What Changed
Before and after, as a user sees it: no change. The new OSC 7501 core has no production callers in this part. The three refactors preserve existing runtime behavior.
The mechanism, commit by commit:
src/shared/program-status/program-status-report.ts): reads one report body by the spec (rev 0.4) and validates its fields. Malformed pairs are skipped, unknown keys ignored, the last duplicate wins (theidgrammar is checked on that last value, its size on every occurrence), and a report that breaks a field limit (field sizes, strict base64 that decodes as UTF-8, control characters) is discarded whole.program-status-stream-scanner.ts): finds reports, prompt starts (OSC 133;A) and RIS in a PTY stream whatever the chunk boundaries, and enforces the 4096-byte whole-sequence limit before a report reaches the parser. A prompt start drops records, so it counts only once BEL or ST ends it, as Orca's existing OSC 133 reader (terminal-shell-lifecycle-scanner.ts) requires; a bare ESC, a missing terminator or a body over 4096 bytes is not one. It carries at most one partial frame, never buffers an oversized one, and costs oneindexOfper active pattern on a chunk with nothing to report.program-status-record-store.ts,program-status-projection.ts): the spec's records (a report replaces its record,clearremoves a subtree, 256 records max, prompt start dropsworkingandblocked, RIS drops everything), summarized into what a status dot shows, plus what remains once the process exits.program-status-tracker.ts): runs the above for one PTY, numbers each change it would publish (reportSeq), gives each view a generation that is never reused, and throttles emission (burst of 8, then 20 per second) while always delivering the latest state.program-status-slot.ts,program-status-slot-transition.ts,compose-agent-status-entry.ts): the data a pane will hold beside its hook row, the pure rule that accepts or refuses a write (an exit write must carry the view it shows), the dismissal rule, and the pure function readers will use to choose between the hook row and the program's own report.pty-startup-ingress.ts, the daemon session's startup ingress wiring is extracted fromsession.ts(both files sat at the line cap), and the PTY-to-pane attribution rule is exported asruntime-pty-pane-attribution.ts.src/main/runtime/__fixtures__/claude-program-status-2-1-295-*): six recordings of Claude Code 2.1.295 on macOS (startup, one turn, a permission prompt, a question, an interrupt, a subagent then/exit), captured withconfig/scripts/capture-agent-pty-transcript.mjsand scrubbed at the same length. A replay test runs the real bytes through the core; it covers seven read sizes and every cut in and immediately around each detected sequence.docs/design/osc7501-program-status.md): the problem, constraints, choices, rejected alternatives and limits. It says which part lands what and describes the state once both parts are merged.docs/**is ignored by default, so the commit adds two allow-list lines to.gitignore, the way other tracked docs are listed.idgrammar on the last duplicate, the exit write that must carry its view, and the secret scanner's redaction (below). The other three update the note: two follow part 2's own fixes (a retired pane reopens only once its restore binds; a report taken before its pane exists is written once the pane binds), and one says which part lands what.Two existing CI checks needed a change because of the new transcripts:
config/scripts/pty-transcript-secret-scan.mjsflagged the base64msg=values of the reports as opaque tokens. The scanner now decodes OSC 7501msgandtitlevalues strictly (as the parser does) and scans the decoded text with the same rules, so a secret inside a message is still caught and reported at its encoded position. Redacting such a secret re-encodes the scrubbed text at the same length, so the report still decodes. A value that does not decode is left to the existing rules.src/main/daemon/serialize-grid-transcript-replay.test.tsreplays every committed transcript through the snapshot serializer. Five of the new ones show divergences that already exist in the serializer (a true-colour background left on restored cells, and in the subagent run a cursor one column short after a shrink). The serializer is not touched; they are added toKNOWN_PREEXISTING_I2_FAILURESin the file's existing style. The unscrubbed captures diverge identically. I can drop these entries if you would rather track them elsewhere.Why
OSC 7501 lets agents report their state directly instead of Orca inferring it from titles and per-agent hooks (#26809). Splitting the work keeps each review tractable: this part is the pure core plus three behavior-preserving refactors, which you can read and test on their own, and part 2 is the integration that changes behavior. Real transcripts come first because the protocol leaves room for behaviors that matter here (see the design memo below), and
AGENTS.mdasks for rules about agent screens to be written against captured transcripts.Design memo
The full note is
docs/design/osc7501-program-status.md. It can be dropped from this PR if you prefer not to keep design docs in the repo (as with the cleanup in #26328); this section carries the same content in short.Problem. Agents without hooks or a recognizable title show no status in Orca, and title parsers break when titles change. Agents that wait for feature detection, including the captured Claude Code version, report only after the terminal answers the
OSC 7501 ; ?probe, which Orca never does.Constraints from the spec (rev 0.4). Strict limits and a discard-whole rule; records with a subtree
clear; prompt start and RIS rules; on process exitdoneanderrorsurvive; no heartbeat, so a record must not expire only because the program is quiet; reports are untrusted input; the probe reply may spell out the default states and kinds.What the capture showed. The agent writes XTVERSION, the Kitty keyboard query, the 7501 probe and DA1 in one write. If the DA1 reply arrives before the 7501 reply, it decides support is absent and never probes again.
donearrives twice (bare, then with a message about two seconds later). An interrupt reportsidle. Exit sends three rootclearreports. Subagent ids are flat hex ids, and a child ends withclear:id=..., neverdone.Choices.
AGENTS.mdrule that new producers write into that one store.Rejected alternatives.
Compatibility, scope and limits. The new OSC 7501 core has no production callers in this part, and the three refactors preserve existing runtime behavior, so nothing changes for any client. Part 2 adds daemon protocol 50, optional fields, and a new
program-statuskind within the existingtransientFactevent, with no new opcode; old clients and mobile stay on hooks. Supported scope will be the macOS desktop app (local and daemon PTYs); SSH, Linux, Windows andorca serveare not yet covered. Known limits are listed in the note.Linked Issue
Refs #26809 (part 1 of 2; part 2 carries
Fixes #26809).Visual Proof
N/A, no visual change. The new OSC 7501 core has no production callers in this part, and the three refactors preserve existing runtime behavior.
Testing
Every commit passes
pnpm tcon its own, andoxlint(default andconfig/oxlint-react-doctor.json) on the files it touches,oxfmt --check,pnpm run check:code-quality:changedandcheck:max-lines-ratchet; the four note commits have no code to lint.Every test file this part adds or changes (15 files): 660 tests pass at its last commit.
Transcript replay (
src/main/runtime/program-status-claude-transcripts.test.ts): 26 tests, checked to fail against deliberately broken implementations (the scanner's carry, the tracker's fold of the seconddone, the parser'stitlehandling, the store's childclear).Refactors shown neutral by comparing per-test results before and after each one: the 12 test files around the startup ingress (176 tests, identical), all of
src/main/daemon(identical, including 18 real-shell timeout tests that fail the same way before the change on this machine), and all ofsrc/main/runtime(identical apart from the 6 added tests; 3 existing tests fail the same way before the change).config/scripts/pty-transcript-secret-scan.test.mjs: 145 tests, including new ones for a secret hidden in a decodedmsgortitleand for a scrubbed report that still parses.serialize-grid-transcript-replay.test.ts: 127 tests.Not run:
pnpm build, e2e, and the fullpnpm teston this part alone (the full suite was run on the stacked branch, see part 2). macOS only, under Node 26 (the repo pins 24, which I don't have on this machine).I manually tested these changes locally
Automated tests added/updated, or explained why not below
AI Disclosure
Assisted by Claude (Anthropic).
Review
Agent skill upstream boundary
Notes
indexOfper active pattern on a chunk with nothing to report and copies nothing.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)