Skip to content

Fix negotiated Pi CLI prompt framing - #32197

Open
nwparker wants to merge 4 commits into
mainfrom
nwparker/issue-20695-prompt-framing
Open

nwparker wants to merge 4 commits into
mainfrom
nwparker/issue-20695-prompt-framing

Conversation

@nwparker

@nwparker nwparker commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​316 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​316
Prod 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​144 $\color{#cf222e}{\Huge{\mathbf{−}}}$​23 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​121

A desktop CLI prompt such as check issue #12 please。 can open Pi's asynchronous file completion. The delayed Enter then inserts .agents/ instead of submitting the prompt. Eligible Pi sends now reuse the existing atomic bracketed-paste writer and one separate Enter.

This is a partial repair for #20695. It requires a Pi launch target, fresh foreground Pi confirmation, authoritative negotiated paste mode, and a durable request. The exact PTY/process binding, foreground and mode are checked again before frame and Enter. A failed recheck or cancellation stops delivery without a raw fallback or rescue Enter. The receipt truthfully remains observation: unsupported.

Validation:

  • Official @earendil-works/[email protected] Editor/StdinBuffer/CombinedAutocompleteProvider consumed captured production RPC writes: disabling only the Pi route produces .agents/ completion with zero submissions; the candidate submits the exact prompt once. The same check preserves and includes an ordinary existing draft.
  • 67 focused tests pass, including 23 new Pi framing and fault-injection cases. Independent native review reran those 67 tests and the official recipient oracle with no blocking findings. Node typecheck, changed-code quality, and reliability manifest validation pass. All CI checks pass at a1749505ff60; that follow-up changes only the manifest confirmation-budget wording.
  • Combined terminal prompt reliability suites: 1,673 pass, 3 skipped, 2 existing macOS folder-import path failures. Both failures reproduce on unchanged base production code (/var versus /private/var).

Reliability contract: terminal-input.cli-agent-prompt-submit remains experimental/partial and now records the Pi-specific oracle and limits. The Pi route adds at most three targeted process confirmations beyond existing classification (up to four for the full operation) and existing output-chain awaits, with no polling, inventories, snapshots or new timers. Local runtime/RPC and the official recipient are covered on macOS. Live daemon, SSH/remote, WSL and native Linux/Windows Pi journeys remain gaps. Mobile/relay keeps its existing direct route; no git-worktree-only assumptions were added.

Cursor, worker-start readiness and generic Pi draft detection remain follow-ups. Control input and leading /, ., ~ stay raw because Pi paste normalization can change those draft semantics. Missing provider confirmation, partially restored mode state, non-durable calls, and Pi manually started in a pane launched for another provider also retain raw delivery. This does not claim a model turn started or close all of #20695.

@coderabbitai

coderabbitai Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 7 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

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: 124d17f0-2666-4678-8d34-46e1bdcce013
Commits

Reviewing files that changed from the base of the PR and between cbaa24b and ee8d16e.

Files selected for processing: 1
  • config/reliability-gates.jsonc

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: 1300401c-1059-4784-9c94-3235e158c7bd
Commits

Reviewing files that changed from the base of the PR and between a174950 and cbaa24b.

Files selected for processing: 2
  • config/reliability-gates.jsonc
  • src/main/runtime/orchestration/pi-terminal-prompt-framing.ts
Files with no reviewable changes: 1
  • config/reliability-gates.jsonc

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

Walkthrough

The change adds Pi prompt preparation for eligible durable desktop terminal sends. It checks request text, terminal binding, foreground process, pending output, and bracketed-paste mode before writing. The send path uses the prepared options to select agent-prompt sending. New tests cover framing, excluded requests, and terminal-state changes. The reliability gate records the test coverage and Pi-related limitations.

Priority: Pending latest changes

Merge Risk: Low · up to cbaa2

A prompt could be pasted into another foreground program during a narrow transition. The change is otherwise mergeable with owner awareness of this remaining risk.

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 6 files. (1 skipped: 1 … 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 is concise, specific, and accurately describes the main change: fixing negotiated Pi CLI prompt framing.
Description check Passed The description clearly explains the user impact, implementation, rationale, linked issue reference, testing, limitations, compatibility scope, and known failures. It does not reproduce the template h…
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: Description check

Explanation

The description clearly explains the user impact, implementation, rationale, linked issue reference, testing, limitations, compatibility scope, and known failures. It does not reproduce the template headings or explicitly state visual proof as N/A, but the required information is mostly present.

Full details: Docstring Coverage

Explanation

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 6 files. (1 skipped: 1 unsupported.)

Resolution

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

Finishing Touches: 💡 2
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🛠️ Fix failing CI checks: 💡
  • 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: 40a95da6-eea6-4d82-b16d-5b46e25b3dc1
📥 Commits

Reviewing files that changed from the base of the PR and between 54e8ee5 and 250d1d8.

📒 Files selected for processing: 7
  • config/reliability-gates.jsonc
  • src/main/daemon/headless-emulator.ts
  • src/main/runtime/orchestration/pi-terminal-prompt-framing.ts
  • src/main/runtime/orchestration/terminal-pane-mail-routing.ts
  • src/main/runtime/rpc/methods/terminal/terminal-prompt-routing.ts
  • src/main/runtime/rpc/methods/terminal/terminal-send-method.ts
  • src/main/runtime/rpc/pi-terminal-prompt-framing.test.ts

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

Comment on lines +24 to +46
const canPaste = async (): Promise<boolean> => {
this.assertAgentPromptExpectedBinding(handle, binding)
const state = this.headlessTerminals.get(binding.ptyId)
// A partial suffix of a restored provider stream cannot certify negotiated modes.
if (!state || this.providerSnapshotPreferredPtys.has(binding.ptyId)) {
return false
}
if (recognizeAgentProcess(await confirm(binding.ptyId))?.agent !== 'pi') {
return false
}
const pendingOutput = state.writeChain
await pendingOutput
this.assertAgentPromptExpectedBinding(handle, binding)
const supported =
state.writeChain === pendingOutput &&
this.headlessTerminals.get(binding.ptyId) === state &&
!this.providerSnapshotPreferredPtys.has(binding.ptyId) &&
state.emulator.getModes().bracketedPaste
const pty = this.ptysById.get(binding.ptyId)
if (supported && pty) {
pty.foregroundAgent = 'pi'
}
return supported

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 | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

sed -n '1,85p' src/main/runtime/orchestration/pi-terminal-prompt-framing.ts
rg -n 'confirmForeground|foregroundProcess|pendingOutput|writeChain' src/main/runtime/orchestration/pi-terminal-prompt-framing.ts src/main/runtime/terminal/input/terminal-agent-prompt.ts

Repository: stablyai/orca

Length of output: 3095


🏁 Script executed:

set -eu
printf '%s\n' '--- confirmForegroundProcess bindings ---'
rg -n -F --glob '*.ts' -e 'confirmForegroundProcess' -e 'foregroundAgent' -e 'writeChain' src/main src/shared tests 2>/dev/null || true
printf '%s\n' '--- framing references and tests ---'
rg -n -F --glob '*.{ts,tsx}' -e 'preparePiTerminalPrompt' -e 'agent_not_in_foreground' -e 'OrcaRuntimeWithPreparePiTerminalPrompt' src tests 2>/dev/null || true
printf '%s\n' '--- candidate declarations ---'
rg -n -F --glob '*.ts' -e 'class .*Pty' -e 'confirmForeground' src/main/runtime src/main 2>/dev/null || true

Repository: stablyai/orca

Length of output: 41511


🏁 Script executed:

set -eu
printf '%s\n' '--- confirmForegroundProcess and state bindings ---'
rg -n -F --glob '*.ts' -e 'confirmForegroundProcess' -e 'foregroundAgent' -e 'writeChain' src/main src/shared || true
printf '%s\n' '--- framing references and tests ---'
rg -n -F --glob '*.{ts,tsx}' -e 'preparePiTerminalPrompt' -e 'agent_not_in_foreground' -e 'OrcaRuntimeWithPreparePiTerminalPrompt' src tests 2>/dev/null || true

Repository: stablyai/orca

Length of output: 30627


🏁 Script executed:

set -eu
printf '%s\n' '--- foreground inspection ---'
sed -n '245,290p' src/main/daemon/pty-subprocess/foreground-process-tracker.ts
sed -n '245,265p' src/main/daemon/session.ts
sed -n '185,202p' src/main/providers/local-pty-provider.ts
printf '%s\n' '--- headless state and output-chain mutation ---'
sed -n '90,180p' src/main/runtime/terminal/output/headless-terminal-state.ts
sed -n '170,198p' src/main/runtime/terminal/output/terminal-output-generation.ts
printf '%s\n' '--- cached foreground-agent updates ---'
sed -n '110,145p' src/main/runtime/runtime-pty-foreground-agent.ts
printf '%s\n' '--- focused framing tests ---'
sed -n '1,275p' src/main/runtime/rpc/pi-terminal-prompt-framing.test.ts

Repository: stablyai/orca

Length of output: 17462


🏁 Script executed:

set -eu
printf '%s\n' '--- complete foreground confirmation tail ---'
sed -n '260,340p' src/main/daemon/pty-subprocess/foreground-process-tracker.ts
printf '%s\n' '--- remaining framing tests ---'
sed -n '220,380p' src/main/runtime/rpc/pi-terminal-prompt-framing.test.ts
printf '%s\n' '--- output ingestion and write-chain ownership ---'
sed -n '90,145p' src/main/runtime/terminal/output/pty-output-ingestion.ts
sed -n '175,235p' src/main/runtime/terminal/output/headless-terminal-state.ts

Repository: stablyai/orca

Length of output: 10772


Reconfirm the foreground process after pendingOutput.

confirmForegroundProcess performs a fresh process scan before await pendingOutput. A foreground transition during that wait does not change the headless state or write-chain identity. The current checks can therefore still pass, and the writer can send the Pi paste and Enter to the new foreground program.

Suggested fix
       const pendingOutput = state.writeChain
       await pendingOutput
       this.assertAgentPromptExpectedBinding(handle, binding)
+      if (recognizeAgentProcess(await confirm(binding.ptyId))?.agent !== 'pi') {
+        return false
+      }
       const supported =
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const canPaste = async (): Promise<boolean> => {
this.assertAgentPromptExpectedBinding(handle, binding)
const state = this.headlessTerminals.get(binding.ptyId)
// A partial suffix of a restored provider stream cannot certify negotiated modes.
if (!state || this.providerSnapshotPreferredPtys.has(binding.ptyId)) {
return false
}
if (recognizeAgentProcess(await confirm(binding.ptyId))?.agent !== 'pi') {
return false
}
const pendingOutput = state.writeChain
await pendingOutput
this.assertAgentPromptExpectedBinding(handle, binding)
const supported =
state.writeChain === pendingOutput &&
this.headlessTerminals.get(binding.ptyId) === state &&
!this.providerSnapshotPreferredPtys.has(binding.ptyId) &&
state.emulator.getModes().bracketedPaste
const pty = this.ptysById.get(binding.ptyId)
if (supported && pty) {
pty.foregroundAgent = 'pi'
}
return supported
const canPaste = async (): Promise<boolean> => {
this.assertAgentPromptExpectedBinding(handle, binding)
const state = this.headlessTerminals.get(binding.ptyId)
// A partial suffix of a restored provider stream cannot certify negotiated modes.
if (!state || this.providerSnapshotPreferredPtys.has(binding.ptyId)) {
return false
}
if (recognizeAgentProcess(await confirm(binding.ptyId))?.agent !== 'pi') {
return false
}
const pendingOutput = state.writeChain
await pendingOutput
this.assertAgentPromptExpectedBinding(handle, binding)
if (recognizeAgentProcess(await confirm(binding.ptyId))?.agent !== 'pi') {
return false
}
const supported =
state.writeChain === pendingOutput &&
this.headlessTerminals.get(binding.ptyId) === state &&
!this.providerSnapshotPreferredPtys.has(binding.ptyId) &&
state.emulator.getModes().bracketedPaste
const pty = this.ptysById.get(binding.ptyId)
if (supported && pty) {
pty.foregroundAgent = 'pi'
}
return supported

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