Skip to content

fix: preserve recognized terminal drafts during automated input - #32241

Open
nwparker wants to merge 2 commits into
mainfrom
nwparker/issue-human-draft-admission
Open

nwparker wants to merge 2 commits into
mainfrom
nwparker/issue-human-draft-admission

Conversation

@nwparker

@nwparker nwparker commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Automated agent prompts and orchestration mailbox pointers could paste into an existing composer draft and submit it. Reuse the existing attributed composer projection to refuse a positively recognized occupied draft before any automated bytes, regardless of age or focus.

Keep the exact PTY identity, incarnation, generation, input revision and admitted output sequence current through the actual initial write. Retain the input fence through paste-to-Enter and remote settlement; Codex retry Enter additionally requires the unchanged owned prompt and no observed turn. Park refused mail without an immediate retry loop, preserve unread mail and durable attempted phases, and prevent same-key RPC replay after partial delivery.

Validation: the expanded suite passes 1,816 tests across 21 files (3 skipped), including actual runtime with real HeadlessEmulator, real SQLite mailbox refusal/resume, production renderer/runtime input funnels, final-await draft arrival, provider snapshots ahead of the local stream, and durable RPC replay. Node typecheck, changed-code quality and reliability-gate validation are recorded in the implementation evidence.

Scope: positive recognized drafts only. Unsupported, hidden, unavailable, whitespace-only and otherwise unrecognized composers retain legacy admission; input whose echo has not arrived before admission can remain unrecognized. A takeover error after paste can represent partial delivery; durable keyed receipts remain conservative. No native provider or visible Electron journey was exercised. This does not address external-input authorization, attribution or browser confinement in #19546.

Related: #11242, #18478.

Reliability contract: terminal-input.automated-draft-admission is experimental/partial. The manifest records the before/after oracle, provider matrix, failure modes, diagnostics and cost. O(1) input/lifecycle revisions reuse existing write funnels and visible-screen acquisition/cache; no polling, process spawn, focus check or duplicate parser. No draft text is added to logs.

Independent review exercised 21 cases, including real IPC/controller takeover and durable no-replay behavior. It found and red/green verified two freshness races; both are fixed. Node typecheck checks 17,631 files; changed-code quality has zero findings and all 151 gate definitions validate. The original implementation passed 248 tests /17 files after the file-length cleanup. A second independent review at bb77876 passes 58 targeted tests /4 files, confirms the actual input funnels and provider-snapshot-ahead control, and finds a clean three-way manifest merge with Pi #32197. Combined runtime execution was not performed.

Cross-platform/remote scope: shared host-side logic, no wire change, no path/shortcut changes, Git and folder workspaces use the same PTY contract. Deterministic macOS runtime/SQLite tests cover delayed remote-style settlement and existing Windows scheduling contracts; physical native agents, daemon/SSH, Windows/Linux and mobile caller journeys remain gaps. Parked mail resumes on an existing notification/idle edge or explicit check; no new polling watches draft edits. A prewrite occupied refusal can conservatively keep a durable request pending; a takeover error after paste must not be treated as a zero-byte receipt by unkeyed callers.

Visual proof: no rendered app proof captured. Before/after behavioral evidence uses actual runtime ingestion and real HeadlessEmulator cursor attributes with real SQLite; no live native provider or visible window was launched. This is not a rendered app or physical input acceptance claim.

Initial CI found 23 broader compatibility assertions that assumed synchronous pointer writes or a second Enter after a turn had started. A test/manifest-only correction now awaits actual admission, stages the pointer before lifecycle interruption, and strengthens permission/unverified-readiness checks to require zero bytes plus eventual delivery after readiness returns. Production safeguards are unchanged. Independent review found no blockers and independently passed 1,538 tests /3 entrypoints (3 skipped). The expanded 21-file gate passes 1,816 tests (3 skipped); these counts overlap. Fresh CI passed at 13a4889774f3: all five unit shards, static analysis/typecheck, mobile verification, Linux/Windows packaging, Linux persistence, relay integration and Ubuntu/Debian/Fedora WSL checks. These checks do not establish native-provider draft acceptance.

@coderabbitai

coderabbitai Bot commented Oct 23, 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: 0e4e2518-23aa-4017-a815-39b7ec7c0b37
📥 Commits

Reviewing files that changed from the base of the PR and between bb77876 and 13a4889.

📒 Files selected for processing: 7
  • config/reliability-gates.jsonc
  • src/main/runtime/orca-runtime-tests/agent-launch-prompt-submit.spec.ts
  • src/main/runtime/orca-runtime-tests/mobile-creation-and-orchestration-part-02.spec.ts
  • src/main/runtime/orca-runtime-tests/mobile-creation-and-orchestration-part-03.spec.ts
  • src/main/runtime/orca-runtime-tests/terminal-output-and-worker-recovery.spec.ts
  • src/main/runtime/orchestration-codex-completion-title.spec.ts
  • src/main/runtime/terminal-send-stale-leaf-liveness.test.ts

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

📝 Walkthrough

The change adds per-PTY input revisions and guarded admission for automated terminal prompts and mailbox pointer writes. Prompt submission and retries check the input guard and current terminal state. Mailbox delivery checks flight and target ownership, and parks redelivery for specified input refusals. The change also adds tests for revision updates, draft preservation, competing input, delayed submission, and retries, plus a reliability-gate declaration.

Priority: ➖ Normal

Merge Risk: 🟡 Moderate · up to 13a48

Automated prompts can fail when an agent produces output during admission, even without competing input. Address that failure before merging unless it is explicitly accepted.

Pre-merge checks: Passed 3 · Failed 2

Failed Failed checks: 2 warnings

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 30 files. (1 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check Warning The PR description is detailed and covers most required template sections. It explains the problem and the mechanism (reusing the attributed composer projection to refuse positively recognized occupie… Add an ELI5 section in plain language. Add a 'Fixes #' reference to an actual linked issue, since the template requires one for outside contributors. Complete the Visual Proof section with a before/after capture or a short N/A reason…
Passed Passed checks: 3 passed
Check name Status Explanation
Title check Passed The title "fix: preserve recognized terminal drafts during automated input" matches the main change. The PR makes automated prompts and mailbox pointer writes refuse to paste into a positively recogni…
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.
Full details: Title check

Explanation

The title "fix: preserve recognized terminal drafts during automated input" matches the main change. The PR makes automated prompts and mailbox pointer writes refuse to paste into a positively recognized occupied composer draft, which the title describes. It uses a conventional fix: prefix and is 8 words, so it is concise and specific.

Full details: Docstring Coverage

Explanation

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

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Full details: Description check

Explanation

The PR description is detailed and covers most required template sections. It explains the problem and the mechanism (reusing the attributed composer projection to refuse positively recognized occupied drafts before automated bytes, fencing PTY identity and input revisions, retaining the input fence through paste-to-Enter, and parking refused mail). It gives validation details (1,816 tests across 21 files, independent review, CI status) and scope limits. Several template sections are missing or incomplete. The 'ELI5' section is absent. The 'Linked Issue' section has no 'Fixes #' reference; the description cites #11242, #18478, and #19546 only as 'Related', and the author did not link an issue that the PR closes. The 'Visual Proof' section does not have a before/after capture or an 'N/A' with reason; it says no rendered app proof was captured, which is a gap for a behavior change. The 'Testing' checklist items are not ticked, and the 'Agent skill upstream boundary' checkbox is not addressed. The 'Review' and 'AI Disclosure' sections are absent or unaddressed, and the 'Checklist' is not marked. The description is also long and uses many internal references (for example, 'reliability contract' manifest details and commit hashes) that are hard for a reviewer to follow.

Resolution

Add an ELI5 section in plain language. Add a 'Fixes #<issue>' reference to an actual linked issue, since the template requires one for outside contributors. Complete the Visual Proof section with a before/after capture or a short N/A reason that explains why the behavior is only covered by runtime tests. Tick the Testing checkboxes that apply, and state which platforms were actually tested (the description says macOS-only runtime and SQLite tests, with no Linux, Windows, SSH, or mobile manual runs). Address the Agent skill upstream boundary checkbox. Complete the AI Disclosure section if any AI model was used, or confirm the author is a StablyAI team member. Tick or address the Checklist items, including the lint, typecheck, test, and build commands. Shorten the Why section so it states the alternatives considered and the reason the chosen approach is better.

✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1


ℹ️ 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: a8229beb-0fea-45cc-96a5-318b29954341
📥 Commits

Reviewing files that changed from the base of the PR and between fd18750 and bb77876.

📒 Files selected for processing: 25
  • config/reliability-gates.jsonc
  • src/main/ipc/pty/ipc/write-input-user-input.test.ts
  • src/main/runtime/agent-prompt-submission-runtime.test.ts
  • src/main/runtime/construction/runtime-construction-services.ts
  • src/main/runtime/construction/runtime-service-state.ts
  • src/main/runtime/orchestration-mailbox-notification-consistency.test.ts
  • src/main/runtime/orchestration-mailbox-notification-test-harness.ts
  • src/main/runtime/orchestration/mailbox-pointer-delivery-contract.ts
  • src/main/runtime/orchestration/mailbox-pointer-delivery.ts
  • src/main/runtime/orchestration/mailbox-pointer-pty-write.ts
  • src/main/runtime/orchestration/mailbox-pointer-stage.ts
  • src/main/runtime/orchestration/mailbox-pointer-state.ts
  • src/main/runtime/orchestration/mailbox-pointer-submit.test.ts
  • src/main/runtime/orchestration/mailbox-pointer-submit.ts
  • src/main/runtime/orchestration/terminal-authority/write-orchestration-pointer-pty.ts
  • src/main/runtime/rpc/terminal-prompt-delivery-receipt.test.ts
  • src/main/runtime/runtime-terminal-contracts.ts
  • src/main/runtime/terminal-automated-input-guard.ts
  • src/main/runtime/terminal-human-draft-admission.test.ts
  • src/main/runtime/terminal-run-facts-input.test.ts
  • src/main/runtime/terminal-run-facts.test.ts
  • src/main/runtime/terminal-run-facts.ts
  • src/main/runtime/terminal/input/terminal-agent-prompt.ts
  • src/main/runtime/terminal/output/terminal-visible-state.ts
  • src/shared/pty-write-settlement.ts

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

Comment on lines +68 to +78
const sequence = this.getPtyOutputSequence(ptyId)
const screen = await this.readVisibleTerminalState(ptyId)
guard.assertCurrent()
if (
screen
? screen.generation !== this.getPtyLifecycleGeneration(ptyId) ||
screen.sequence < this.getPtyOutputSequence(ptyId)
: sequence !== this.getPtyOutputSequence(ptyId)
) {
throw new Error('terminal_input_changed')
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

🔎 Supported by static analysis

🏁 Script executed:

set -u
printf '%s\n' '--- changed file ---'
nl -ba src/main/runtime/terminal/output/terminal-visible-state.ts | sed -n '1,240p'
printf '%s\n' '--- related symbols ---'
rg -n -F --glob '*.ts' -e 'readVisibleTerminalState' -e 'readHeadlessVisibleTerminalState' -e 'loadVisibleTerminalState' -e 'getPtyOutputSequence' -e 'outputSequence' -e 'admitTerminalAutomatedInput' -e 'captureTerminalAutomatedInputGuard' src/main src/shared tests || test "$?" -eq 1
printf '%s\n' '--- directly relevant definitions/callers ---'
rg -n -F --glob '*.ts' -e 'class TerminalAutomatedInputGuard' -e 'interface RuntimeVisibleTerminalState' -e 'type RuntimeVisibleTerminalState' -e 'class Headless' -e 'writeChain' src/main src/shared tests || test "$?" -eq 1
printf '%s\n' '--- changed-file diff against requested base ---'
git diff --no-ext-diff --unified=35 22a95c4efe7ecf5bf619c4259950a28d8b86a5bc bb7787666a5f79fabcde63c0875d83c7eda8a6ac -- src/main/runtime/terminal/output/terminal-visible-state.ts

Repository: stablyai/orca

Length of output: 42440


🏁 Script executed:

git status --short

Repository: stablyai/orca

Length of output: 151


🏁 Script executed:

printf '%s\n' 'awaiting prior inspection'

Repository: stablyai/orca

Length of output: 177


🏁 Script executed:

set -u
printf '%s\n' '--- headless sequence ownership and ingestion ---'
nl -ba src/main/runtime/terminal/output/headless-terminal-state.ts | sed -n '90,190p'
nl -ba src/main/runtime/terminal/output/terminal-output-generation.ts | sed -n '150,215p'
nl -ba src/main/runtime/terminal/output/pty-output-ingestion.ts | sed -n '80,155p'
printf '%s\n' '--- provider snapshot publication ---'
nl -ba src/main/runtime/rpc/methods/terminal/terminal-snapshot-publication.ts | sed -n '260,305p'
printf '%s\n' '--- admission tests and callers ---'
nl -ba src/main/runtime/terminal-human-draft-admission.test.ts | sed -n '1,430p'
nl -ba src/main/runtime/orchestration/terminal-authority/write-orchestration-pointer-pty.ts | sed -n '1,100p'
rg -n -F --glob '*.test.ts' -e 'terminal_input_changed' -e 'terminal_composer_occupied' -e 'admitTerminalAutomatedInput' src/main/runtime tests || test "$?" -eq 1

Repository: stablyai/orca

Length of output: 40934


🏁 Script executed:

printf '%s\n' 'pending source inspection'

Repository: stablyai/orca

Length of output: 177


🏁 Script executed:

rg -n -F -- 'state.outputSequence' src/main/runtime/terminal/output src/main/runtime
nl -ba src/main/runtime/terminal/output/headless-terminal-state.ts | sed -n '180,245p'
nl -ba src/main/runtime/terminal/output/terminal-output-generation.ts | sed -n '1,155p'

Repository: stablyai/orca

Length of output: 11646


Retry output-only stale reads.

admitTerminalAutomatedInput can reject valid automated input when output advances while readVisibleTerminalState is pending. Retry only for output-sequence staleness. Keep immediate rejection for input-revision changes, lifecycle changes, and recognized screen.draft values.

For provider snapshots, perform the retry after the existing snapshot backoff. Do not immediately repeat a null result while providerVisibleRetryAt still blocks another snapshot.

This branch has not been deployed

No deployments
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