Skip to content

fix(runtime): inject Grok orchestration prompts as plain text - #10034

Closed
innocarpe wants to merge 6 commits into
stablyai:mainfrom
innocarpe:fix/grok-dispatch-inject-empty
Closed

innocarpe wants to merge 6 commits into
stablyai:mainfrom
innocarpe:fix/grok-dispatch-inject-empty

Conversation

@innocarpe

@innocarpe innocarpe commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

Orca could send Grok a paste format its composer ignored. It could also choose the format from the agent that originally launched the terminal after a different agent took over. Prompt delivery now asks the execution host which process is consuming input before choosing the format.

What Changed

  • Await the current foreground-process probe when a queued prompt is ready, for PTY-backed and restored-leaf terminals. Current recognized processes take precedence over cached or original launch information. Inspection has a separate two-second budget with cancellation; every expired inspection rejects before writing, even if a cached identity exists. Unframed Grok input requires positive current-host recognition: a cached Grok hint with an unavailable, empty, failed, or generic-wrapper result cannot authorize text that could execute in a shell. Non-Grok wrapper hints retain existing receipt behavior; ordinary shells use the default format.
  • Send Grok sanitized plain text with CRLF/CR normalized to LF, followed by one scheduled Enter. Other and unknown agents retain bracketed paste.
  • Use that same consumer for rendering, submit policy, and receipt provider selection. Reject stale generations and replaced-controller results before writing.
  • Keep atomic prompt writes, host-aware ingest timing, permission checks, and queued prompt receipts.

Why

Refs #9838: the reported plain-send workaround reached Grok while bracketed injection did not. Probing the consumer at submission time handles terminal reuse and restore without relying on asynchronous snapshot refresh or changing stored agent status. Hosts without foreground inspection, and ready Grok sessions with an empty inspection, currently reject delivery: this is an intentional compatibility limitation. The reviewer withdrew the availability finding after reviewing the stale-Grok-to-shell security evidence. Re-enabling historical cache fallback would restore the reviewed shell-command execution risk; a safe fallback needs an authoritative live owner signal.

Linked Issue

Fixes #9838

Visual Proof

N/A — byte delivery changes. The reported welcome-screen failure is in #9838; automated before/after regressions cover the wire bytes and stale identity cases. A fresh live Grok TUI run was not performed.

Testing

  • Automated coverage for current Grok behind stale Claude information, restored terminals with pending and 500 ms probes, restored leaves, current Codex behind stale Grok information, ordinary unknown processes, non-Grok wrapper fallbacks, stale Grok wrapper rejection, timeout rejection for cached Grok and Claude identities, empty/failed Grok lookup rejection, unhinted timeout rejection, cancellation, generation changes, and replaced controllers.
  • CRLF/CR/LF and ESC byte tests; existing prompt, hook, liveness, and RPC prompt suites.
  • Latest-main focused verification: 131 runtime and formatting tests across six files.
  • Changed-code quality gate and Node TypeScript check on macOS.
  • Live Windows/Linux/SSH and Grok TUI verification; full build.

AI Disclosure

Implementation and verification assisted by OpenAI Codex.

Agent skill upstream boundary

  • Not applicable — product runtime and regression tests only.

Checklist

  • Focused prompt-delivery change with before/after, mechanism, and rationale.
  • Self-reviewed for permissions, platform timing, remote execution authority, and folder workspaces.
  • Cross-platform manual verification and full build.

Related: #10504 changes input serialization in the same runtime entry point. The remaining PR will need rebasing after either one merges.

@coderabbitai

coderabbitai Bot commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: c9e60d7e-61f8-4f58-805a-be7c32104b23

📥 Commits

Reviewing files that changed from the base of the PR and between ba13096ee51fabf6da60489a0dbab68baf9a2e97 and 62c89f31c5f23fa061a5268b287168e9b59133ed.

📒 Files selected for processing (2)
  • src/main/runtime/grok-agent-prompt-submission.test.ts
  • src/main/runtime/orca-runtime-controller-knows-pty-is-live.ts

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


📝 Walkthrough

Walkthrough

Grok prompts now use sanitized plain text with normalized line endings. Other and unidentified agents continue to use bracketed-paste framing. Runtime submission resolves the prompt consumer when the queued prompt is ready, checks lifecycle generation and controller ownership, and uses the selected agent to configure prompt writing.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 62c89

Prompt delivery uses the cached agent when foreground inspection is unavailable and the default format when another process is in the foreground. No identified issue remains to block merging after normal checks.

Security Architecture Review

Security architecture risk: 🟡 Moderate · up to 62c89

If the receiving program changes during delivery, text intended as a message could be interpreted as commands in the local workspace. Access checks limit which session can be reached, but do not establish that its receiving program remains the same.

Retained concerns

  • Medium · security · inferred: A foreground-process result selects unframed text, but the process is not checked again before delivery. If it exits or yields the terminal to a shell, embedded newlines could be interpreted as commands rather than message text; interruption between the body and Enter writes can also leave unframed input behind.
Security review details

Security Blast Radius

  • inferred — The plausible exposure is the selected local or restored terminal and its execution-host privileges if another foreground program consumes the bytes. The inspected flow does not show a new terminal target, tenant boundary, credential grant, or deployment change.

Security Findings and Attack Paths

  • inferred — Command-like prompt content could reach a shell as unframed, newline-containing input if the recognized consumer changes after inspection. This is a transition risk, not a verified exploit or an established path for an external attacker.

Trust Boundaries and Controls

  • observed — The foreground result changes formatting, not terminal authorization. Handle, generation, controller, request-activity, and permission checks constrain delivery, but no foreground-process check is shown immediately before either write.

Resilience and Maintainability Implications

  • inferred — A failure after the first write may leave unsubmitted text, while a failure after Enter may leave uncertainty about whether retrying would duplicate input. The inspected serializer supplies ordering, not a demonstrated retry or cleanup guarantee; separate writes themselves predate this change.

Hardening Proposals

  • proposed — Define how unframed input remains safe across foreground-process changes and how partial delivery is reconciled before a caller retries; a second process check alone would still leave a race before the write.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 6 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR addresses #9838. sendTerminalAgentPrompt probes the current foreground process before it builds and writes the prompt. grok receives sanitized plain text with CRLF and CR normalized to LF, …
Out of Scope Changes check ✅ Passed The changes remain within #9838. Agent-format helpers, foreground-process selection, shared prompt-consumer state, lifecycle checks, and related tests directly support reliable Grok prompt delivery an…
Title check ✅ Passed The title clearly and concisely describes the main change: sending Grok orchestration prompts as plain text.
Description check ✅ Passed The description explains the user impact, implementation, rationale, linked issue, testing, limitations, and checklist status. It omits the optional Review and Notes headings, but the required informa…
  • Fix all pre-merge checks with AI

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: 5


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 41c76c6e-6c7d-4b62-82cc-49358935c87e

📥 Commits

Reviewing files that changed from the base of the PR and between 7a42271 and 1792c5f5334e39ee617d356315e1387fffc820bb.

📒 Files selected for processing (7)
  • .grok/skills/oss-pr-mirror/SKILL.md
  • .grok/skills/oss-pr-mirror/scripts/mirror-upstream-pr.sh
  • .grok/skills/oss-pr-mirror/scripts/sync-contribution-push.sh
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/shared/agent-prompt-injection.test.ts
  • src/shared/agent-prompt-injection.ts

@innocarpe

Copy link
Copy Markdown
Contributor Author

Sync update (e80f954a0)

Remove accidental .grok/skills/oss-pr-mirror files from this PR (local tooling only).

@nwparker nwparker added the bug Something isn't working label Jul 27, 2026
@innocarpe
innocarpe force-pushed the fix/grok-dispatch-inject-empty branch from e80f954 to bda2d09 Compare September 28, 2026 22:57
@greptile-apps

greptile-apps Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 4/5

[Medium risk] Changes how agent prompts are formatted and delivered to different runtime agents.

The PR is not ready to merge while a live Grok session on a supported older daemon can lose its launch or dispatch prompt.

Findings

  1. P1 Grok prompts rejected without probe ▶

Summary

The PR probes the foreground process before queued terminal-prompt submission and sends Grok sanitized, newline-normalized plain text rather than bracketed paste.

  • It uses the selected agent for prompt framing, submit timing, render waiting, and receipts.
  • It adds regressions for terminal reuse, restoration, probe delays, and stale lifecycle results.
  • The latest rejection rule also prevents prompt delivery to Grok when a supported host cannot provide a foreground-process name.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Queued prompt] --> B[Probe execution host]
  B --> C{Recognized foreground agent?}
  C -->|Grok| D[Normalized plain text + Enter]
  C -->|Other agent| E[Bracketed paste + submit]
  C -->|No result with Grok launch| F[Reject without writing]
Loading

Reviews (6) · Last reviewed commit: "fix(runtime): require fresh process evid..."

Comment thread src/main/runtime/orca-runtime.ts Resolved
Comment thread src/main/runtime/orca-runtime.ts Resolved
Comment thread src/shared/agent-prompt-injection.ts Resolved
@innocarpe
innocarpe force-pushed the fix/grok-dispatch-inject-empty branch from bda2d09 to e88413d Compare September 29, 2026 07:47

@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: Advanced

Run ID: e8296b7b-8a26-451a-8ce9-fc0a0b184ac2

📥 Commits

Reviewing files that changed from the base of the PR and between bda2d09 and e88413da1fecc22d24893adb6b314926e14b694e.

📒 Files selected for processing (6)
  • src/main/runtime/grok-agent-prompt-submission.test.ts
  • src/main/runtime/orca-runtime-controller-knows-pty-is-live.ts
  • src/main/runtime/orca-runtime-create-agent-prompt-render-gate.ts
  • src/main/runtime/orca-runtime-write-terminal-agent-prompt.ts
  • src/shared/agent-prompt-injection.test.ts
  • src/shared/agent-prompt-injection.ts

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

@innocarpe
innocarpe force-pushed the fix/grok-dispatch-inject-empty branch from e88413d to ba13096 Compare September 29, 2026 08:18
@innocarpe
innocarpe force-pushed the fix/grok-dispatch-inject-empty branch from ba13096 to e4fcabc Compare September 29, 2026 08:52
@innocarpe

Copy link
Copy Markdown
Contributor Author

Updated this follow-up at 62c89f31c5: known review findings are addressed, with 128 focused runtime/formatting tests, the Node TypeScript check, and changed-code quality checks passing. The foreground budget preserves known-agent delivery on slow hosts while retaining the unhinted restore and stale-wrapper guards.

PR Checks, PR test LoC, and Bun profile persistence currently require maintainer approval. Please approve those workflow runs when reviewing this update. This PR and #10504 still touch the same runtime entry point, so the remaining branch will need rebasing after either one merges.

Grok Build can swallow bracketed-paste frames on the welcome composer while
still accepting plain terminal send --enter. dispatch --inject used the
Claude/Codex BP path, so injected:true could leave the TUI empty. Prefer
plain sanitized text for launchAgent/foregroundAgent=grok and only emit
the BP emergency closer when a BP frame was actually started.

Fixes stablyai#9838
@innocarpe
innocarpe force-pushed the fix/grok-dispatch-inject-empty branch from 62c89f3 to 445963a Compare September 29, 2026 09:33
@innocarpe

Copy link
Copy Markdown
Contributor Author

Updated at 445963acb4 after the follow-up security review. Foreground inspection remains bounded to two seconds, but its timeout now rejects before any write for all cached identities. Plain Grok text requires positive current-host recognition; missing, failed, empty, and generic-wrapper inspection cannot authorize it. This supersedes my earlier cached-identity availability fallback because a cached Grok session can have returned to a shell.

All 131 focused tests, the current-head Node TypeScript check, and changed-code quality pass. Individual review replies explain the tradeoff and the four before/after zero-byte regressions; both PR heads and descriptions match. Live cross-platform/Grok TUI verification and full build remain unperformed. General upstream CI still needs maintainer execution approval; please approve those runs when reviewing.

@nwparker

Copy link
Copy Markdown
Contributor

Thanks @innocarpe. Current Grok accepts Orca's bracketed paste (verified with real Grok across dispatch, worker-start and terminal send), and the welcome-screen symptom was Grok's folder-trust question, which dispatch now refuses cleanly. Closing as superseded; #33571 covers the remaining CLI-send path.

@nwparker nwparker closed this Oct 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: orchestration dispatch --inject reports success but leaves Grok TUI empty (v1.4.149)

3 participants