Skip to content

feat(terminal): report an honest submit verdict from terminal send - #15274

Open
artile wants to merge 4 commits into
stablyai:mainfrom
artile:artile/terminal-send-submit-verdict
Open

artile wants to merge 4 commits into
stablyai:mainfrom
artile:artile/terminal-send-submit-verdict

Conversation

@artile

@artile artile commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

The failure this closes

orca terminal send --enter returned success as soon as the bytes reached the PTY.
When the Enter was swallowed — a completion popup ate it, or the TUI was mid-turn —
the text sat unsubmitted in the composer and the caller could not tell that apart
from an agent that received the prompt and started work. dispatch --inject had the
same hole: it marked injected = true on a bare resolve, so a coordinator waited on
a worker whose preamble was still sitting in its composer.

What this does

Orca owns the PTY and already receives each harness's own turn-lifecycle hook, so it
answers the question from that signal rather than from rendered text. A send that
carries a submit arms a watch on the pane's hook stream before writing and reports:

verdict meaning
submitted the harness announced a turn start after the write
queued the harness recorded the text as a user message during a running turn (OpenCode family)
pending the harness reports turn starts, the pane was idle, and it said nothing inside the bound
unknown no live hook evidence for the pane, a harness with no turn-start signal, or a send into a running turn

Missing or stale evidence is unknown and is never promoted to submitted, matching
the convention already used for explicit agent status and the lastAgentStatusObservedLive
gate on push-on-idle delivery.

Retry rule

On pending — and only pending — the submit key is re-sent once. The text is never
re-typed: pending means the payload is already in the composer, so a second copy
would become a doubled message. queued and unknown are never retried. Push-on-idle
mail delivery uses the same rule.

Surfaces

  • terminal.send takes an optional submitVerdict request and returns an optional
    submitVerdict result. Old host → no verdict → callers read it as unknown;
    old client → ignores the field. Rule 1 of docs/reference/remote-wire-compatibility.md;
    the cross-version wire harness stays green.
  • orca terminal send --text ... --enter requests it by default. --submit-timeout-ms
    sets the bound, --no-submit-retry disables the re-send, --no-verdict skips the wait.
  • dispatch --inject reports injected: true only for submitted. The dispatch context
    stays open on an unproven submit — the bytes are in the pane and may still become a
    turn — but it is not reported as delivered work.

The hook tap is wired once in src/main/index.ts from agentHookServer.subscribeEnrichedStatus,
which is where local, WSL relay, and SSH relay events all land, so the verdict works on
all three transports and for folder workspaces as well as git worktrees.

Tests

src/shared/agent-submit-signal.test.ts,
src/main/runtime/terminal-submit-verdict-tracker.test.ts,
src/main/runtime/terminal-send-submit-verdict.test.ts,
src/main/runtime/rpc/methods/orchestration-dispatch-submit-verdict.test.ts —
submitted, pending, queued, unknown, mid-turn, replayed/restored rows, stale evidence,
the no-retype rule, and the dispatch guard.

tests/e2e/cross-version-wire/cross-version-terminal-wire.unit.test.ts, oxlint, both
code-quality audits, the max-lines ratchet, and all three tsconfigs are clean. The
terminal command specs move to their own file because the new flags pushed core.ts
past the max-lines limit; splitting is the fix rather than a suppression.

Not in scope

The autonomous coordinator loop (orchestration/coordinator.ts) still injects without
a verdict. Wiring it means changing failDispatch circuit-breaker accounting, which
belongs in its own change.


Moved from #13763, same commits, same head SHA. That pull request was opened from an organisation-owned fork, and GitHub refuses maintainer pushes on org-owned forks even when maintainer_can_modify reports true — so a maintainer could not push a fixup to it, only ask or rewrite. This one is on a personal fork, where a maintainer push works.

The review history stays readable on #13763: #13763

artile added 4 commits August 11, 2026 10:18
A send that wrote bytes into the PTY reported success even when the Enter was
swallowed — by a completion popup, or by a TUI that was mid-turn — and the text
was left sitting unsubmitted in the composer. Callers could not tell that apart
from an agent that received the prompt and started work.

Orca owns the PTY and already receives each harness's own turn-lifecycle hook,
so it can answer the question directly. A send that carries a submit now arms a
watch on the pane's hook stream before writing, and classifies the outcome:

- submitted — the harness announced a turn start after the write;
- queued — the harness recorded the text as a user message during a running
  turn, so it acts on it when that turn ends (OpenCode family);
- pending — the harness reports turn starts, the pane was idle, and it said
  nothing inside the bound;
- unknown — no trustworthy evidence: no live hook event for the pane, a harness
  with no turn-start signal at all, or a send into a running turn.

Missing or stale evidence is unknown and is never promoted to submitted, which
follows the convention already used for explicit agent status. On a pending
verdict the submit key is re-sent once, never the text, so a partly accepted
line cannot become a doubled message.

The verdict rides an optional field on the terminal.send result and an optional
request param, so an older host answers without one and an older client ignores
it (docs/reference/remote-wire-compatibility.md, Rule 1). Callers must read a
missing verdict as unknown.
… was submitted

`dispatch --inject` set `injected = true` as soon as the agent-prompt send
resolved, which only proves the bytes reached the PTY. When the Enter was
swallowed the preamble sat in the worker's composer while the coordinator was
told the task had been handed off, and it then waited on work that never
started.

The inject path now asks for a submit verdict and reports `injected` only for
`submitted`. Every other outcome returns the verdict alongside `injected:
false`, including the case where an older host answers with no verdict at all.

The dispatch context is deliberately left open on an unproven submit: the bytes
are in the pane and a queued or unknown send may still become a real turn, so
failing it here would discard work that is about to run.
`orca terminal send --text ... --enter` now asks the host for a submit verdict
and prints it in both output modes; `--json` carries the whole
`send.submitVerdict` object. `--submit-timeout-ms` sets the bound,
`--no-submit-retry` turns off the single submit re-send, and `--no-verdict`
skips the wait. The client RPC timeout is widened to clear the bound so the
transport cap does not fail a call the host is still answering.

`orchestration dispatch --inject` prints a warning when the preamble was not
confirmed submitted, so a coordinator does not read the dispatch as delivered.

The terminal command specs move to their own file; adding the new flags and
notes pushed core.ts past the max-lines limit, and splitting is the fix rather
than a suppression.
A host older than submit verdicts answers `terminal.send` with no `submitVerdict`
field at all. The CLI printed only the byte count in that case, and
`dispatch --inject` printed no warning, so an unproven submission read exactly
like a completed one — the failure the verdict exists to close.

Human output now reports `unknown` whenever this invocation asked for a verdict
and the response carries none, and the dispatch warning is gated on `--inject`
rather than on the presence of the field. Whether a verdict was requested is a
property of the invocation, not of the response, so it is passed to the
formatter and the JSON output stays exactly what the host sent.

Also from review:

- the `terminal send` usage string now advertises `--submit-timeout-ms`,
  `--no-submit-retry`, and `--no-verdict`, which `allowedFlags` already accepted;
- a positive fractional timeout is clamped to at least 1ms. Truncating 0.5 to 0
  skipped the evidence wait entirely and answered from the pre-write snapshot,
  which reads as a real verdict from a wait that never happened.
@coderabbitai

coderabbitai Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@artile, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 23 minutes

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

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

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 353ac5f9-fcc8-44fc-897c-35a63ec2b31f

📥 Commits

Reviewing files that changed from the base of the PR and between 545b3fb and dea344f.

📒 Files selected for processing (23)
  • skill-guides/orca-cli.md
  • skill-guides/orchestration.md
  • src/cli/bundled-skill-guides.ts
  • src/cli/handlers/orchestration.ts
  • src/cli/handlers/terminal.ts
  • src/cli/specs/core.ts
  • src/cli/specs/terminal.ts
  • src/cli/terminal-format.ts
  • src/cli/terminal-send-verdict.test.ts
  • src/main/index.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/runtime/rpc/methods/orchestration-dispatch-submit-verdict.test.ts
  • src/main/runtime/rpc/methods/orchestration.test.ts
  • src/main/runtime/rpc/methods/orchestration.ts
  • src/main/runtime/rpc/methods/terminal.ts
  • src/main/runtime/terminal-send-submit-verdict.test.ts
  • src/main/runtime/terminal-submit-verdict-tracker.test.ts
  • src/main/runtime/terminal-submit-verdict-tracker.ts
  • src/shared/agent-submit-signal.test.ts
  • src/shared/agent-submit-signal.ts
  • src/shared/runtime-types.ts
  • src/shared/terminal-submit-verdict.test.ts
  • src/shared/terminal-submit-verdict.ts

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.

@AmethystLiang

Copy link
Copy Markdown
Contributor

thanks for reporting. looking into it

@artile

artile commented Aug 19, 2026

Copy link
Copy Markdown
Contributor Author

A scope question for the maintainers, found while rebasing this branch — please read before reviewing the diff.

main now carries #14962 fix(terminal): verify agent prompt submission, and it answers part of the same question this PR was opened for. The two meet head-on in rpc/methods/terminal.ts, which is where the rebase conflicts:

#14962 (on main) this PR
What it watches agent activity sequences (workingSequence, permissionSequence, generation) the pane's hook stream (agent_turn_boundary, submit signal)
How it answers throws agent_prompt_stalled / terminal_handle_stale / blocked-on-permission returns a structured submitVerdict — delivered, pending, queued, unknown
Where it applies inside sendTerminalAgentPrompt, when useSettledAgentPrompt terminal send and orchestration dispatch --inject, both surfaced on the CLI
On a lost Enter fails the call after 5 s reports pending, re-sends the submit key exactly once, then answers honestly

So there is real overlap and a real remainder. I do not think either half is redundant, but which one should own the fact is not my call, and resolving the conflict silently would be me deciding it in a merge editor. Three ways to go:

  1. Rebuild this PR on fix(terminal): verify agent prompt submission #14962's verification — keep the verdict vocabulary and the CLI surface, drop my activity watching, and derive delivered / pending from verifyAgentPromptSubmission rather than the hook stream. Smallest surface, one mechanism.
  2. Keep both, drawn at the boundary — fix(terminal): verify agent prompt submission #14962 stays the agent-prompt guard that throws; this PR stays the reporter for terminal send and dispatch --inject, which fix(terminal): verify agent prompt submission #14962 does not cover and where a throw is the wrong shape because the caller needs a value.
  3. Close this if fix(terminal): verify agent prompt submission #14962 plus a follow-up is the intended direction, and I will say so on the issue rather than leave a competing PR open.

I would pick 2 — a dispatch caller needs a value it can branch on, not an exception — but I am not the one who should be picking. Tell me which, and I will do the rebase that matches it in the same day.

Related, from @Tauri-EPO on #15273: worker-start writes stage = 'input_accepted' straight off the send's return, so an unsubmitted preamble is recorded as accepted durably. Whichever of the three above is chosen, that gap stays open and is worth a column of its own.

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.

3 participants