Skip to content

Fix orchestration agent prompt injection - #7758

Merged
Jinwoo-H merged 1 commit into
mainfrom
Jinwoo-H/bug-orchestration-claude-codex-cannot-send-long
Jul 8, 2026
Merged

Jinwoo-H merged 1 commit into
mainfrom
Jinwoo-H/bug-orchestration-claude-codex-cannot-send-long

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • add a dedicated agent prompt injection path that bracket-pastes orchestration prompts and submits separately
  • route orchestration dispatch and coordinator worker prompts through that path instead of raw terminal.send
  • add a long-prompt repro harness and register the terminal-input.agent-prompt-injection reliability gate

Closes #7226

Validation

  • pnpm exec vitest run --config config/vitest.config.ts src/shared/agent-prompt-injection.test.ts src/main/runtime/orca-runtime.test.ts src/main/runtime/rpc/methods/orchestration.test.ts src/main/runtime/orchestration/coordinator.test.ts
  • node tools/repro-orchestration-long-prompt.mjs --cli out/bin/orca-dev --mode codex-like --size-kb 32 --timeout-ms 20000
  • node tools/repro-orchestration-long-prompt.mjs --cli out/bin/orca-dev --mode wire --size-kb 32 --timeout-ms 20000
  • node tools/repro-orchestration-long-prompt.mjs --cli out/bin/orca-dev --mode codex-like --size-kb 80 --timeout-ms 20000
  • pnpm run typecheck:node
  • pnpm exec oxlint tools/repro-orchestration-long-prompt.mjs src/shared/agent-prompt-injection.ts src/shared/agent-prompt-injection.test.ts src/main/runtime/rpc/methods/orchestration.ts src/main/runtime/rpc/methods/orchestration.test.ts src/main/runtime/orchestration/coordinator.ts src/main/runtime/orchestration/coordinator.test.ts src/main/runtime/orca-runtime.ts src/main/runtime/orca-runtime.test.ts
  • pnpm run check:reliability-gates
  • pnpm check:max-lines-ratchet
  • node --check tools/repro-orchestration-long-prompt.mjs

Reliability

  • Class: terminal-input.agent-prompt-injection
  • Invariant: injected orchestration task prompts for recognized agent CLIs arrive as one bracketed paste frame, with Enter sent only after the frame completes
  • Oracle: runtime write-sequence tests plus live dev-runtime fake Codex-like 32KB dispatch harness
  • Coverage: local macOS covered; daemon, SSH, remote-runtime, Linux, and Windows remain registered gaps
  • Performance: O(prompt bytes) work using existing 16KB terminal input chunking and the existing 500ms submit gap; no polling, provider listing, subprocess churn, hidden-pane wakeups, or renderer work added

Made with Orca 🐋

Co-authored-by: Orca <help@stably.ai>
@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Changes

This PR adds bracketed-paste framing for terminal agent-prompt injection. Shared helpers in agent-prompt-injection.ts sanitize prompt text, wrap it with bracketed-paste markers, and support chunked iteration. OrcaRuntimeService.sendTerminalAgentPrompt now builds and chunk-writes these framed payloads to the pty, closing the paste frame on failure before rejecting. CoordinatorRuntime and the orchestration.dispatch RPC handler now call sendTerminalAgentPrompt instead of raw sendTerminal. A new reliability gate (terminal-input.agent-prompt-injection) documents the invariant and oracle. A new script, tools/repro-orchestration-long-prompt.mjs, provides a live CLI reproduction harness. Tests were updated/added across affected modules.

Sequence Diagram(s)

Included above within the hidden review stack artifact.

Related Issues: Not specified in provided information.

Related PRs: Not specified in provided information.

Suggested labels: area/runtime, area/orchestration, testing

Suggested reviewers: Not specified in provided information.

🐰 A prompt slips in, paste-frame tight,
Escape bytes tamed, chunks sent just right,
The coordinator hums a bracketed tune,
Enter arrives not a beat too soon,
Hop, hop — the terminal's safe tonight.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers summary and validation, but it omits required template sections like screenshots, AI review report, security audit, and notes. Add the missing template sections, including screenshots or no visual change, AI review report, security audit, and notes.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: fixing orchestration agent prompt injection.
Linked Issues check ✅ Passed The PR addresses #7226 by routing long orchestration prompts through bracketed paste and separate submit handling, which matches the reported bug.
Out of Scope Changes check ✅ Passed The added helper, tests, reliability gate, and repro harness are all directly related to the prompt-injection fix and validation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 5c3ba0b5-f116-4a80-acf5-8834095a154c

📥 Commits

Reviewing files that changed from the base of the PR and between 37ba94a and 1787f41.

📒 Files selected for processing (10)
  • config/reliability-gates.jsonc
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/runtime/orchestration/coordinator.test.ts
  • src/main/runtime/orchestration/coordinator.ts
  • src/main/runtime/rpc/methods/orchestration.test.ts
  • src/main/runtime/rpc/methods/orchestration.ts
  • src/shared/agent-prompt-injection.test.ts
  • src/shared/agent-prompt-injection.ts
  • tools/repro-orchestration-long-prompt.mjs

Comment on lines +9222 to +9269
private async writeTerminalAgentPrompt(
ptyId: string,
pastePayload: string,
options: {
beforeWrite?: (ptyId: string) => void | Promise<void>
suffixFailureError?: string
} = {}
): Promise<void> {
let wrotePasteBytes = false
let completedPaste = false
try {
const chunks = iterateTerminalInputChunks(pastePayload)
let chunk = chunks.next()
while (!chunk.done) {
await options.beforeWrite?.(ptyId)
const wrote = this.ptyController?.write(ptyId, chunk.value) ?? false
if (!wrote) {
throw new Error('terminal_not_writable')
}
wrotePasteBytes = true
chunk = chunks.next()
if (!chunk.done) {
await new Promise((resolve) => setTimeout(resolve, 0))
}
}
completedPaste = true
} catch (error) {
if (wrotePasteBytes && !completedPaste) {
this.ptyController?.write(ptyId, AGENT_PROMPT_BRACKETED_PASTE_END)
}
throw error
}

await new Promise((resolve) => setTimeout(resolve, AGENT_PROMPT_SUBMIT_DELAY_MS))
try {
await options.beforeWrite?.(ptyId)
} catch (error) {
if (options.suffixFailureError) {
throw new Error(options.suffixFailureError)
}
throw error
}
const suffixWrote = this.ptyController?.write(ptyId, AGENT_PROMPT_SUBMIT) ?? false
if (!suffixWrote) {
throw new Error(options.suffixFailureError ?? 'terminal_not_writable')
}
}

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.

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Find other call sites that write to a ptyId that could race
# with an in-flight sendTerminalAgentPrompt/writeTerminalAgentPrompt.
rg -nP --type=ts '\bptyController\??\.write\(' src/main/runtime | grep -v '\.test\.ts'

Repository: stablyai/orca

Length of output: 1242


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Map the relevant areas before reading them.
ast-grep outline src/main/runtime/orca-runtime.ts --view expanded > /tmp/orca-outline.txt || true

# Inspect the surrounding write paths.
sed -n '9160,9275p' src/main/runtime/orca-runtime.ts
printf '\n====\n'
sed -n '12740,12805p' src/main/runtime/orca-runtime.ts
printf '\n====\n'
sed -n '20160,20245p' src/main/runtime/orca-runtime.ts
printf '\n====\n'

# Search for serialization/queue/lock mechanisms keyed by ptyId in runtime.
rg -n "queue|lock|serialize|serialized|in-flight|inflight|mutex|semaphore|ptyId" src/main/runtime/orca-runtime.ts

Repository: stablyai/orca

Length of output: 50369


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Find the PTY controller implementation and any write serialization.
rg -n "writeChain|class .*Pty|implements PtyController|write\(ptyId: string" src/main/runtime src/main -g '!**/*.test.ts' | head -n 200

printf '\n====\n'

# Inspect the nearby code around any writeChain references.
rg -n -C 4 "writeChain" src/main/runtime/orca-runtime.ts src/main -g '!**/*.test.ts'

printf '\n====\n'

# Find the concrete PTY controller file(s) if present.
fd -a -t f "pty" src/main 2>/dev/null | head -n 100

Repository: stablyai/orca

Length of output: 30285


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the PTY write implementations and any serialization around them.
sed -n '300,420p' src/main/providers/local-pty-provider.ts
printf '\n====\n'
sed -n '1,220p' src/main/providers/ssh-pty-provider.ts
printf '\n====\n'
sed -n '1,220p' src/main/daemon/daemon-pty-router.ts
printf '\n====\n'
sed -n '1,220p' src/main/daemon/daemon-pty-adapter.ts
printf '\n====\n'
sed -n '1,220p' src/main/daemon/degraded-daemon-pty-provider.ts

Repository: stablyai/orca

Length of output: 38576


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the concrete write implementations for the PTY providers.
rg -n -C 6 "^\s*write\(id: string, data: string\): void|^\s*write\(ptyId: string, data: string\): void|\.write\(.*data" \
  src/main/providers/local-pty-provider.ts \
  src/main/providers/ssh-pty-provider.ts \
  src/main/daemon/daemon-pty-adapter.ts \
  src/main/daemon/daemon-pty-router.ts \
  src/main/daemon/degraded-daemon-pty-provider.ts \
  | head -n 220

Repository: stablyai/orca

Length of output: 5092


Serialize agent prompt writes per PTY
writeTerminalAgentPrompt yields between chunks and before the final \r, while ptyController.write(...) is a direct write path with no per-ptyId queue. A concurrent input on the same PTY can splice into the bracketed-paste sequence and break unattended prompt delivery.

@Jinwoo-H
Jinwoo-H merged commit 8368e94 into main Jul 8, 2026
2 checks passed
@Jinwoo-H
Jinwoo-H deleted the Jinwoo-H/bug-orchestration-claude-codex-cannot-send-long branch July 8, 2026 02:50
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 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] Orchestration claude -> codex cannot send long prompts

1 participant