Repository navigation
fix(mobile): serialize native chat PTY writes and fence superseded ask keystrokes (STA-3333) - #12502
Conversation
Two composed native-chat write sequences into one PTY interleaved their bytes: the per-terminal send-in-flight guard lived inside the image attachments hook, so ask answers, permission choices, and question answers wrote straight past it. Move the guard to a shared module-scope write lock (the terminal outlives any one screen) and take it on all four paths. Ask answers additionally queue behind the prior chain's RPC rather than racing it, and a superseding answer is fenced once a key has actually landed: an accepted or ambiguously-delivered keystroke already moved the remote selector, so a replacement's from-scratch key plan would answer the wrong question. A superseding answer inherits the cancelled chain's hold (refcounted, last chain out releases) so changing your mind mid-answer still works, and Stop/cancel stay unguarded so an interrupt can never deadlock against the send it cancels. Refs STA-3333.
📝 WalkthroughWalkthroughThe change adds a shared per-terminal write lock for native chat operations. Permission responses, question answers, and image attachment sends now reject concurrent writes and release the lock after completion. Answer sending coordinates superseding turns, tracks predecessor delivery safety, fences unsafe successors, and preserves the lock during queued writes. Tests cover contention, recovery, fencing, delivery outcomes, accepted-action callbacks, and lock cleanup. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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. Comment |
The fence added for superseding Ask answers returned false with no onSendError, and the card re-enables on a false result — so a queued answer vanished with no banner and no toast, looking exactly like a dead button. Every other bail in answerAsk reports. Keep the generation- mismatch branch silent: a newer answer owns the error surface. Also covers the hold-count release, which had no test at all: replacing it with an unconditional release left all 58 tests green while silently reopening the terminal mid-sequence — the exact interleave this PR fixes.
A chain that finished its key plan reported `true` even after a newer answer superseded it. The route sends through useNativeChatAcceptedAction, whose accepted callback retires the send-error banner — and that callback runs after the successor's fence report, because finishTurn() fires in `finally`, before the chain's own promise settles. So the successful predecessor deterministically wiped the fence message the successor had just raised: every healthy write took that branch, which made the previous commit's report vacuous exactly where it mattered. A superseded chain now reports no success, matching every other supersession checkpoint in this hook.
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: cf352c4a-e9c2-41f7-9dd2-6407a3adaa71
📒 Files selected for processing (9)
mobile/src/session/mobile-native-chat-permission-send.test.tsmobile/src/session/mobile-native-chat-permission-send.tsmobile/src/session/mobile-native-chat-terminal-write-lock.tsmobile/src/session/use-mobile-native-chat-answer-send.test.tsmobile/src/session/use-mobile-native-chat-answer-send.tsmobile/src/session/use-mobile-native-chat-image-attachments.test.tsmobile/src/session/use-mobile-native-chat-image-attachments.tsmobile/src/session/use-mobile-native-chat-message-send.test.tsmobile/src/session/use-mobile-native-chat-message-send.ts
| // A question answer is not composer text, so it never syncs the draft. It | ||
| // reaches this send directly (not through the image hook's locked path), so | ||
| // it takes the per-terminal write lock itself: an answer landing mid-flight | ||
| // in an image paste sequence would interleave bytes into the PTY. | ||
| const answerQuestion = useCallback( | ||
| async (text: string): Promise<boolean> => | ||
| (await sendMessage(text, undefined, false)) !== 'rejected', | ||
| [sendMessage] | ||
| async (text: string): Promise<boolean> => { | ||
| const terminal = handleRef.current | ||
| if (terminal && !acquireMobileNativeChatTerminalWrite(terminal)) { | ||
| onSendError('Answer not sent') | ||
| return false | ||
| } | ||
| try { | ||
| return (await sendMessage(text, undefined, false)) !== 'rejected' | ||
| } finally { | ||
| if (terminal) { | ||
| releaseMobileNativeChatTerminalWrite(terminal) | ||
| } | ||
| } | ||
| }, | ||
| [handleRef, onSendError, sendMessage] | ||
| ) |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Find who consumes the message-send surface and whether those paths hold the lock.
set -euo pipefail
echo '--- consumers of the hook ---'
rg -nP --type=ts -C4 '\buseMobileNativeChatMessageSend\s*\(' mobile
echo '--- direct send / sendWithOutcome call sites ---'
rg -nP --type=ts -C4 '\.(send|sendWithOutcome)\s*\(' mobile/src mobile/app
echo '--- baseSend wiring (locked image path) ---'
rg -nP --type=ts -C4 '\bbaseSend\b' mobile/src mobile/app
echo '--- all lock acquisition sites ---'
rg -nP --type=ts -C3 'acquireMobileNativeChatTerminalWrite' mobileRepository: stablyai/orca
Length of output: 50369
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo '--- relevant hook implementation lines ---'
sed -n '180,250p' 'mobile/src/session/use-mobile-native-chat-message-send.ts'
echo '--- relevant controller wiring lines ---'
sed -n '230,265p' 'mobile/src/session/use-mobile-native-chat-controller.ts'
echo '--- image hook relevant lines ---'
sed -n '250,325p' 'mobile/src/session/use-mobile-native-chat-image-attachments.ts'
echo '--- controller exports and consumers ---'
rg -NP --type=ts -C3 '\b(handleNativeChatSend|handleNativeChatSendWithOutcome|baseSend|sendNativeChat)\b' mobile/src/session/mobile src 2>/dev/null || true
echo '--- sendWithOutcome definitions in message-send file ---'
rg -NP --type=ts -C3 'sendWithOutcome|send:' 'mobile/src/session/use-mobile-native-chat-message-send.ts'Repository: stablyai/orca
Length of output: 8296
Lock the unlocked sender surface.
sendNativeChat in use-mobile-native-chat-image-attachments.ts reaches baseSend without acquiring acquireMobileNativeChatTerminalWrite, while answerQuestion acquires the same per-terminal write lock. This leaves normal composer sends and image sends interleaved with question answers through sendMessage/terminal.send; make sendNativeChat take the lock too rather than documenting send as unlocked.
Mobile emulator QA — both ask-answer send paths exercised liveRun against this branch at 1. Stepping path (Claude/Codex) — paced keystroke groupsAsk card rendered, both questions answered, "Send answer" tapped. Mock server observed exactly three writes, correctly paced ~1016 ms apart: Card dismissed with no error banner — i.e. 2. Paste path (Grok) — single composed writeSame fixture with Mock server observed exactly one write: Card dismissed with no error banner — the paste branch's Desktop regression smoke (Electron, CDP-attached)This is a mobile-only change under What remains unverified on-deviceThe superseded-answer case itself (a second answer landing while the first chain is mid-flight) is covered by unit tests, not by the emulator run — driving two answers inside one ~1 s pacing step is not reliably reproducible through tap automation. The four added tests cover superseded-lands on both the step and paste paths, triple-fence-reports-once, and late-third-queues-behind. The QA-only mock fixture edit was reverted; the branch contains no test-harness or screenshot changes. |
The supersession guards added in c36f2ce read `generationRef`, but `cancelPending()` bumps that counter from three callers with no successor chain: Stop, ask-cancel, and the lease effect that fires on every disconnect. An answer whose key had already landed then reported false — `fail()` never runs on an accepted write, so the card stayed up silent with Submit re-enabled, and the retry wrote the same key into a selector that key had already advanced. Test the turn slot instead: a successor takes it synchronously before its first await and cannot resolve ahead of this chain, so it means "a successor took over" exactly, without catching bare cancellations.
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
mobile/src/session/use-mobile-native-chat-answer-send.ts (1)
153-158: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winCondense the new protocol comments.
Keep the selector-safety rationale. Replace these multi-line implementation walkthroughs with concise comments. The control flow already shows the implementation details.
As per coding guidelines, comments must be concise, limited to non-obvious information, and preferably one line.
Also applies to: 264-268, 293-293
Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 2ad98dd2-f69e-4d63-8ac1-479ef543733a
📥 Commits
Reviewing files that changed from the base of the PR and between c36f2ce and d101086731c373964696374ccaf11ab4c65ea905.
📒 Files selected for processing (2)
mobile/src/session/use-mobile-native-chat-answer-send.test.tsmobile/src/session/use-mobile-native-chat-answer-send.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- mobile/src/session/use-mobile-native-chat-answer-send.test.ts
| // eslint-disable-next-line no-console | ||
| console.log('[PROBE] chain start gen=', generation) | ||
| let sawUnknownOutcome = false | ||
| let sawAcceptedGroup = false | ||
| // One budget for the whole answer instead of a fresh timeout per keystroke | ||
| // group, which let an N-group selector hold the card for N × the send timeout. | ||
| // It bounds transport time only: each deliberate pacing wait is credited back | ||
| // below, so a long multi-question answer still gets a full budget to write in. | ||
| let deadline = openMobileNativeChatSendBudget() | ||
| const sendTerminal = async (body: string, enter: boolean): Promise<boolean> => { | ||
| const activeRoute = activeRouteRef.current | ||
| if ( | ||
| !activeRoute.enabled || | ||
| activeRoute.client !== client || | ||
| activeRoute.sessionId !== sessionId || | ||
| activeRoute.streamIdentity !== streamIdentity || | ||
| handleRef.current !== handle | ||
| ) { | ||
| let predecessorSafe = true | ||
| try { | ||
| predecessorSafe = await previousTurn | ||
| // eslint-disable-next-line no-console | ||
| console.log( | ||
| '[PROBE] chain gen=', | ||
| generation, | ||
| 'resumed predecessorSafe=', | ||
| predecessorSafe, | ||
| 'current=', | ||
| generationRef.current | ||
| ) |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Remove the probe logging.
These console.log calls run for every answer chain. They add production log noise and require no-console suppression. Remove them before release.
…neration The fence-report guard tested generationRef, which answers "was I cancelled", not "did a successor replace me". Stop and ask-cancel both write an Escape that clears the ask card, so their silence is harmless. A dropped input lease bumps the same counter and writes nothing: the card stays up with Submit re-enabled while the predecessor's option key has already advanced the live selector, so the retry double-steps it. Gate on the turn slot, matching the two success returns.
d101086 to
b277516
Compare
Review rounds 3 & 4 — two more blockers found and fixedFollow-up to the QA comment above. Review continued past that comment and found two further defects, both in the same class as rounds 1–2 (a write that actually landed reported as a plain Correction to the QA comment aboveThat comment quotes the guard expression as it stood at
Both now read Round 3 —
|
| Caller | Bumps generation | Writes an Escape (clears the ask card) |
|---|---|---|
use-mobile-native-chat-stop.ts:49 (Stop) |
✅ | ✅ |
use-mobile-native-chat-cancel-ask.ts:24 (cancel ask) |
✅ | ✅ |
the hook's own effect, deps [client, enabled, sessionId, streamIdentity] |
✅ | ❌ nothing |
So an answer that was fully accepted and then hit Stop returned false — a landed write reported as a failure, with no banner, because fail() only runs when the send itself failed.
The correct discriminator is the turn slot: writeTurnsRef.current.get(handle) === turn. A successor claims that slot synchronously, before its first await (:132), and can never resolve ahead of this chain — it awaits this chain's turn, which resolves in this chain's finally. The test is exact where the counter is only correlated.
Round 4 — b277516d — the same confusion one branch up, on the fence-report path
The !predecessorSafe branch guarded its onSendError('Answer not sent — check chat before retrying') with the same generation test. I initially cleared this as a non-defect by reasoning "Stop writes an Escape, which clears the ask card, so suppressing the banner is correct." That is true for Stop and for cancel-ask. It is false for the third caller — the lease-drop effect writes nothing.
Concretely: a transport blip drops enabled, the generation bumps, the ask card stays up with Submit re-enabled, and a queued answer whose predecessor's option key already landed goes completely silent. The re-tap writes the same option digit into a selector that key already advanced.
Same one-line cure, same discriminator:
if (writeTurnsRef.current.get(handle) === turn) {
onSendError('Answer not sent — check chat before retrying')
}Known tradeoff, stated deliberately: the fix cannot separate Stop from a lease drop (both are non-successor bumps with the slot intact), so Stop now also shows the banner. The message is literally true in that case — the predecessor's keys may well have landed — so it is the right side to err on.
Evidence
Both fixes are proven non-vacuous by mutation, each mutation applied on a scratch copy and reverted:
| Mutation | Tests killed |
|---|---|
M1 — :259+:283 back to the generation guard |
exactly the 2 Stop-with-no-successor tests (28 pass) |
M2 — :259+:283 guards deleted |
exactly the 4 fence tests (26 pass) |
M3 — :148 back to the generation guard |
exactly the new lease-drop test (30 pass) |
M4 — :148 → true |
exactly fences a third answer behind an already-fenced successor, reporting once (30 pass) |
Disjoint kill sets, each matching the defect its guard addresses.
Gates at b277516d: use-mobile-native-chat-answer-send 31/31; full mobile session suite 920/920 across 114 files; tsc, oxlint, code-quality native plugins, React Doctor changed-lines, oxfmt all exit 0; CI green (42 pass, 1 skipping).
Lock-hold audit (no perf regression): all four acquire sites — mobile-native-chat-permission-send.ts:45, use-mobile-native-chat-image-attachments.ts:228, use-mobile-native-chat-message-send.ts:224, use-mobile-native-chat-answer-send.ts:122 — acquire immediately before a try/finally release and bail before acquiring, so the hold count balances. One chain's worst-case hold is bounded at the 15s shared transport budget (MIN_WRITE_TIMEOUT_MS returns 'rejected' rather than restarting the clock on an exhausted budget) plus 1s per inter-group pacing gap. A chain that accepted any group fences its successor, so queued chains add ~0 to the hold.
QA staleness — please read before merging
The screenshots and QA notes in the comment above were captured at c36f2ce14e (mobile) and 54ed019570 (desktop). Neither includes rounds 3 or 4. Those two commits are covered by unit tests plus the mutation matrix above, not by re-run device QA — both fixes are one-line guard swaps on paths that need a queued-answer race against a dropped input lease, which is not reliably reachable by hand on a device. I'd rather say that plainly than imply the screenshots cover the current head.
Residual, not fixed here (follow-up)
The send-error banner is scoped per tab (mobileNativeChatScopeKey(hostId, worktreeId, tabId) — no handle component), while the fence is scoped per terminal handle. A fenced answer's banner can therefore be attributed to the wrong scope if the handle changes under a stable tab.
Deliberately left alone: pre-PR there is no fence on that path at all, so this is not a regression this PR introduces. The obvious fix — adding the handle to the scope key — churns the scope null → handle on tab open and blanks pending-handle banners, trading a narrow race for a broader one in the same silent-loss class, and it edits the session route (scope creep against this PR's stated bounds). The in-file alternative (testing handleRef.current === handle in the success returns) reintroduces a silent false on the handle-change path that two existing tests specifically protect.
Scope note: this PR remains limited to (a) native-chat PTY write serialization/ordering and (b) fencing unsafe queued/superseding ask keystrokes. Partial-answer abort UX is #12503 and ask-dismissal state is #12497; neither is touched here.
The slot delete in the finally was the one line in this hook no test killed: without it a landed answer's resolved-false turn stays parked, so every later answer on that handle reads a fenced predecessor and the ask card dies after its first use.
Round 5 —
|
Review closed — final stateHead
The fence is one-shot — worth stating explicitly"Reports exactly once" was verified at 2-deep, 3-deep simultaneous, 4-deep, and late-third. But the simultaneous and late-third cases get there by different mechanisms, and the distinction matters for anyone reading this code later:
That is by design. The fence is scoped to chains already queued behind the unsafe write — those composed their key plan against pre-supersession state. A later tap is a deliberate re-answer after the banner said "check chat," and the card intentionally re-enables on a false result. It is also exactly what So: the fence does not persist across later taps, and nothing in this PR claims it does. Areas checked with nothing found
One real issue found here, correctly belonging to #12503Tracing the reconnect path surfaced a genuine silent-loss hole, and it is not this PR's to fix: In the stepping loop, a dropped lease mid-sequence makes Same class as round 4, different line. Two reasons it is not fixed here:
Flagging for #12503 rather than fixing. QA coverage — more precise than my earlier noteI understated this above. Correcting:
Follow-ups recorded, deliberately not fixed here
Scope is unchanged and intact: (a) native-chat PTY write serialization/ordering, (b) fencing unsafe queued/superseding ask keystrokes. Nothing here touches partial-answer abort UX (#12503) or ask-dismissal state (#12497). |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 5b2f9c3b-1b5b-4892-bfa7-99085fa940bc
📒 Files selected for processing (2)
mobile/src/session/mobile-native-chat-terminal-write-lock.test.tsmobile/src/session/use-mobile-native-chat-answer-send.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- mobile/src/session/use-mobile-native-chat-answer-send.test.ts
| } from './mobile-native-chat-terminal-write-lock' | ||
|
|
||
| describe('mobile-native-chat-terminal-write-lock', () => { | ||
| afterEach(resetMobileNativeChatTerminalWritesForTests) |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Assert that released terminals can be acquired again.
The test calls releaseMobileNativeChatTerminalWrite but does not check its effect. The afterEach reset clears the state after the test, so a broken release implementation can pass. Add an acquisition assertion after each release, then release the new holds.
Proposed test adjustment
releaseMobileNativeChatTerminalWrite('terminal-a')
releaseMobileNativeChatTerminalWrite('terminal-b')
+ expect(acquireMobileNativeChatTerminalWrite('terminal-a')).toBe(true)
+ expect(acquireMobileNativeChatTerminalWrite('terminal-b')).toBe(true)
+ releaseMobileNativeChatTerminalWrite('terminal-a')
+ releaseMobileNativeChatTerminalWrite('terminal-b')Also applies to: 17-18
Final clean review + current-head QAReviewed and validated at
Electron regression smokeValidated through Electron CDP at the current head. iOS current-head QAThe ask card rendered, accepted both selections, and dismissed without an error/redbox after Send. The mock observed the exact paced writes |
Takes main's side across the whole tree. The PR's FIFO stop lease, writer gate, controller-writer plumbing and module-level cleanup-retry map are obsolete: #12502 landed mobile-native-chat-terminal-write-lock.ts, which already serializes writer-vs-writer per terminal. Only the Codex /stop leg survives, and it is written fresh on main's structure in the next commit.
…k keystrokes (STA-3333) (stablyai#12502) * fix(mobile): serialize native chat PTY writes Two composed native-chat write sequences into one PTY interleaved their bytes: the per-terminal send-in-flight guard lived inside the image attachments hook, so ask answers, permission choices, and question answers wrote straight past it. Move the guard to a shared module-scope write lock (the terminal outlives any one screen) and take it on all four paths. Ask answers additionally queue behind the prior chain's RPC rather than racing it, and a superseding answer is fenced once a key has actually landed: an accepted or ambiguously-delivered keystroke already moved the remote selector, so a replacement's from-scratch key plan would answer the wrong question. A superseding answer inherits the cancelled chain's hold (refcounted, last chain out releases) so changing your mind mid-answer still works, and Stop/cancel stay unguarded so an interrupt can never deadlock against the send it cancels. Refs STA-3333. * fix(mobile): report a fenced native-chat answer instead of dropping it The fence added for superseding Ask answers returned false with no onSendError, and the card re-enables on a false result — so a queued answer vanished with no banner and no toast, looking exactly like a dead button. Every other bail in answerAsk reports. Keep the generation- mismatch branch silent: a newer answer owns the error surface. Also covers the hold-count release, which had no test at all: replacing it with an unconditional release left all 58 tests green while silently reopening the terminal mid-sequence — the exact interleave this PR fixes. * fix(mobile): stop a superseded answer from clearing the fence banner A chain that finished its key plan reported `true` even after a newer answer superseded it. The route sends through useNativeChatAcceptedAction, whose accepted callback retires the send-error banner — and that callback runs after the successor's fence report, because finishTurn() fires in `finally`, before the chain's own promise settles. So the successful predecessor deterministically wiped the fence message the successor had just raised: every healthy write took that branch, which made the previous commit's report vacuous exactly where it mattered. A superseded chain now reports no success, matching every other supersession checkpoint in this hook. * fix(mobile): fence on the turn slot, not the generation counter The supersession guards added in c36f2ce read `generationRef`, but `cancelPending()` bumps that counter from three callers with no successor chain: Stop, ask-cancel, and the lease effect that fires on every disconnect. An answer whose key had already landed then reported false — `fail()` never runs on an accepted write, so the card stayed up silent with Submit re-enabled, and the retry wrote the same key into a selector that key had already advanced. Test the turn slot instead: a successor takes it synchronously before its first await and cannot resolve ahead of this chain, so it means "a successor took over" exactly, without catching bare cancellations. * fix(mobile): report a fenced answer when a dropped lease bumps the generation The fence-report guard tested generationRef, which answers "was I cancelled", not "did a successor replace me". Stop and ask-cancel both write an Escape that clears the ask card, so their silence is harmless. A dropped input lease bumps the same counter and writes nothing: the card stays up with Submit re-enabled while the predecessor's option key has already advanced the live selector, so the retry double-steps it. Gate on the turn slot, matching the two success returns. * test(mobile): cover the turn-slot release after a landed answer The slot delete in the finally was the one line in this hook no test killed: without it a landed answer's resolved-false turn stays parked, so every later answer on that handle reads a fenced predecessor and the ask card dies after its first use. * test(mobile): keep PTY write locks terminal-scoped












Summary
Split from #12373 (item 8 of the STA-3333 native-chat QA sweep) as an independent PR against
main. It carries only the PTY write-serialization fix and its regression tests — no answer-UX or dismissal-state changes from that sweep.Two composed native-chat write sequences into one PTY could interleave their bytes. The per-terminal send-in-flight guard lived in a
useRefinside the image-attachments hook, so it only ever covered the composer's own clear/paste/settle/submit sequence — ask answers, permission choices, and question answers wrote straight past it. Tapping a prompt card while an image paste was mid-flight wove a keystroke into the middle of that sequence.mobile-native-chat-terminal-write-lock.ts), now also taken by ask answers, permission responses, and question answers. Module scope for the same reason as the existing stale-input marker: the terminal outlives any one screen, and independent hooks share the same PTY. A second sender is rejected up front rather than woven in.User-visible effect: a card tap during a mid-flight send now reports "Answer not sent" / "Response not sent" and can simply be retried, instead of silently corrupting the agent's input line or double-stepping its selector.
Screenshots
No visual change — this is transport-ordering logic behind the existing inline send-error banner.
Testing
pnpm lint(oxlint root + mobile clean; changed-code quality gate: 0 new native / 0 type-aware / 0 React Doctor findings across the 9 changed files; max-lines ratchet OK, nomax-linesdisables added)pnpm typecheck(mobiletsc --noEmit, exit 0)pnpm test(mobilesrc/sessionsuite: 114 files, 911 passed)pnpm build— not run; no build-affecting changes (CI covers it)Tests added — all at the concurrency/selector-movement seams:
rejects an answer while another composed write holds the terminalrejects a choice while another composed write holds the terminal, then recoversrejects a question answer while another composed write holds the terminalfences a superseding answer after the cancelled chain moved the selectordoes not write a successor after the prior in-flight key is accepteddoes not write a successor after the prior delivery becomes ambiguouslets a queued successor continue after the prior key is definitely rejectedVerified non-vacuous: with the source changes reverted (tests kept), 6 of the 7 fail. The 7th is the deliberate negative control, which passes before and after.
AI Review Report
Self-reviewed with focus on:
finally, so a throwing send cannot strand the lock. The ask path is the only refcounted holder: a superseding answer re-enters before the cancelled chain unwinds, inherits the hold, and only the last chain out releases — verified by the two tests that assert the terminal is re-acquirable after both chains settle. Stop/cancel intentionally bypass the lock so an interrupt cannot deadlock against the send it cancels.fail()and the supersede checkpoints are left exactly as they are onmain, so the two splits stay independent.Security Audit
No new input parsing from untrusted sources, no command execution, no path handling, no auth or secret handling, and no dependency changes. The new module holds only in-memory terminal-handle strings in a module-scope
Set— no persistence and no cross-user surface. The IPC/RPC surface is unchanged: no new methods, and the fix only withholds writes that would previously have been sent. Rejection messages are fixed literals, not server-echoed content. If anything the change is a net reduction in risk, since it removes a path where two senders could compose an unintended byte sequence on a PTY.Notes
maindirectly and is independent of the other STA-3333 splits; it is an Orca child only for lineage.Refs STA-3333.