Skip to content

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

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

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

Conversation

@artile

@artile artile commented Aug 11, 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.

artile added 3 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.
@coderabbitai

coderabbitai Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f89b5a9c-6a5e-4123-958b-ebc71162f175

📥 Commits

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

📒 Files selected for processing (9)
  • skill-guides/orchestration.md
  • src/cli/bundled-skill-guides.ts
  • src/cli/handlers/orchestration.ts
  • src/cli/handlers/terminal.ts
  • src/cli/specs/terminal.ts
  • src/cli/terminal-format.ts
  • src/cli/terminal-send-verdict.test.ts
  • src/shared/terminal-submit-verdict.test.ts
  • src/shared/terminal-submit-verdict.ts
🚧 Files skipped from review as they are similar to previous changes (5)
  • skill-guides/orchestration.md
  • src/cli/handlers/terminal.ts
  • src/cli/handlers/orchestration.ts
  • src/shared/terminal-submit-verdict.ts
  • src/cli/specs/terminal.ts

📝 Walkthrough

Walkthrough

Added terminal submission verdict contracts and harness-specific submit-signal classification. The runtime tracks agent hook events, reports submission status, and retries pending submissions with an Enter-only write. RPC orchestration confirms injection from the verdict and preserves unresolved dispatch contexts. CLI commands accept verdict options and display verdict details. Terminal command specifications moved into a dedicated module. Tests and guides cover confirmed, pending, queued, unknown, and missing verdict outcomes.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the failure, implementation, behavior, tests, compatibility, and scope, but omits the required AI Review Report and Security Audit sections. Add the required Screenshots, Testing checklist, AI Review Report with cross-platform checks, Security Audit, and Notes sections.
Docstring Coverage ⚠️ Warning Docstring coverage is 21.05% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the primary change: reporting reliable submit verdicts from terminal sends.
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.

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/main/runtime/orca-runtime.ts (1)

32455-32492: 🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift

Hold the delivery flight until the submit retry settles.

The timer's finally calls settlePendingMessageDelivery(deliveryPtyId, flight) while retryPendingMessageSubmit is still pending. settlePendingMessageDelivery immediately re-runs any parked redelivery for the same pty, which writes a new pointer and its own \r. The pending retry can then fire afterwards and write an extra bare \r into the same pane.

retryPendingMessageSubmit only re-checks controllerKnowsPtyIsLive(ptyId), so it cannot detect that a newer delivery already used the pane. The extra \r submits whatever the composer holds at that moment.

Keep the flight open until the retry resolves, so the single-flight guard covers the whole pointer-to-submit span.

🐛 Proposed fix: settle after the retry resolves
           submitRetryArmed = true
-          void this.retryPendingMessageSubmit(deliveryPtyId, submitWatch)
+          void this.retryPendingMessageSubmit(deliveryPtyId, submitWatch).finally(() => {
+            this.settlePendingMessageDelivery(deliveryPtyId, flight)
+          })
         } catch {
           // Terminal may have closed during the delay; mail remains queued for check.
         } finally {
           if (!submitRetryArmed) {
             submitWatch?.release()
+            // Why: with no retry in flight, this callback is the end of the span.
+            this.settlePendingMessageDelivery(deliveryPtyId, flight)
           }
-          // Why finally: every outcome — submit, refusal, throw — ends the flight,
-          // and settle re-runs any trigger parked during it so nothing strands.
-          this.settlePendingMessageDelivery(deliveryPtyId, flight)
         }

retirePendingMessageDeliveryForPty already clears the flight on exit, so a retired pty still settles correctly.

🧹 Nitpick comments (1)
src/main/runtime/terminal-send-submit-verdict.test.ts (1)

172-188: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Add coverage for the queued no-retry branch.

The tests verify that unknown does not retry. They do not verify that queued does not retry. The tracker can return queued when UserPromptSubmit occurs while the pane was working at send time.

Add a test that asserts a queued verdict writes only ['ship it', '\r']. A regression that retries both pending and queued would pass the current retry tests.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: caf1011b-1b3f-4265-93bf-d2805b635c73

📥 Commits

Reviewing files that changed from the base of the PR and between c578f4e and e3ffc72.

📒 Files selected for processing (21)
  • 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/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.ts

Comment thread src/cli/handlers/terminal.ts Resolved
Comment thread src/cli/specs/terminal.ts Resolved
Comment thread src/shared/terminal-submit-verdict.ts Resolved
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.
@Tauri-EPO

Copy link
Copy Markdown
Contributor

One scope question, because the answer decides whether something I just filed is a real gap or already solved here.

This PR derives a submit verdict from the pane's hook stream — the only thing in the repo that answers "did a turn actually begin" rather than "did the write return". My question is how far that verdict is meant to travel.

worker-start writes stage = 'input_accepted' the moment sendTerminalAgentPrompt returns:

await runtime.sendTerminalAgentPrompt(terminalHandle, preamble)
effects.push({ kind: 'dispatch_input', role: 'agent', id: terminalHandle, state: 'accepted' })
const worker = db.markWorkerDispatchReady(started.dispatch.id, effects)   // stage = 'input_accepted'

So a dispatch whose prompt is sitting unsubmitted in a composer reads as accepted afterwards — the same failure this PR describes for terminal send, one layer up. And a dispatch --inject lane has no worker row at all, so it has nothing to read either way.

The question: is the verdict scoped to the terminal send / dispatch --inject response, or is it intended to become durable state on the dispatch that a later reader can consult?

  • If durable is in scope here, then there is nothing to build — the dispatch path should consume what this PR already produces, and I would rather help get this landed than write a second path to the same fact.
  • If it is deliberately response-scoped, the remaining gap is one column on dispatch_contexts written from the same signal, and that is a separate change that should not ride on yours.

Context is in #15180 — that issue is a report about what stage means today, not a proposal that competes with this. I kept the question here rather than there because it is about your PR's scope, and you would not have seen it buried in an issue you are not subscribed to.

Unrelated, in case the notification did not reach you: this branch reads dirty against main right now. orchestration/db.ts was split into a barrel plus a db/ directory upstream, so that hunk needs re-homing rather than a plain rebase. Same for #13762. Happy to share what that port looked like on my own branches if it saves you the archaeology.

@artile

artile commented Aug 18, 2026

Copy link
Copy Markdown
Contributor Author

Straight answer: the verdict is response-scoped in this PR, deliberately, and your gap is real. Nothing here writes durable state. orchestration.dispatch reads the verdict and decides injected from it, then returns it:

const send = await runtime.sendTerminalAgentPrompt(to, preamble, { submitVerdict: {} })
submitVerdict = send.submitVerdict
injected = isTerminalSubmitDelivered(submitVerdict)

No column, no row, no dispatch mutation. A later reader has nothing to consult, which is precisely the case you describe.

Your read of worker-start is right, and it is worse than the terminal send version of the same bug. markWorkerDispatchReady writes stage = 'input_accepted' off the return of sendTerminalAgentPrompt, so a preamble parked unsubmitted in a composer is recorded as accepted, durably, and every later reader inherits that claim. The terminal send failure at least ends with the response.

So build it, and do not wait on me. One column on dispatch_contexts, written from this same signal, is the right shape and it should not ride on this PR:

  • This PR is already 23 files and touches the CLI surface, the RPC contract and the runtime tracker. A schema change would give reviewers a second reason to argue with it.
  • The column has decisions this PR does not have to make — what a queued or unknown verdict persists as, whether a later real turn upgrades it, and whether stage stops meaning "the write returned" or gains a sibling. Those are yours to settle in the change that owns them.
  • The producer is stable either way. TerminalSubmitVerdict and isTerminalSubmitDelivered in src/shared/terminal-submit-verdict.ts are the whole contract, and runtime.sendTerminalAgentPrompt(handle, text, { submitVerdict: {} }) is the only call you need. If you want a shape change to make it easier to persist, ask here and I will make it rather than have you adapt around it.

The dispatch --inject lane having no worker row is the same story from the other end — it is the one path where the response is currently the only place the fact exists, and a column would give it one too.

#15180 is not competing with this. It reports what stage means today; this reports what the pane actually did. They meet at the column.

On the conflict: confirmed, and thank you — this branch and #13762 both read dirty. The orchestration/db.ts split into a barrel plus db/ means re-homing rather than rebasing, and I would rather match your placement than invent a second one. Please do share what the port looked like; it saves the archaeology twice.

One piece of context for why these have been quiet: our fork is org-owned, and GitHub refuses maintainer pushes on org-owned forks even while maintainer_can_modify reports true. A maintainer who wants to adjust one of these branches cannot push to it — #13639 was closed and rewritten for that reason. Being fixed on our side.

@artile

artile commented Aug 18, 2026

Copy link
Copy Markdown
Contributor Author

Moved to #15274 and closing this one — same branch, same commits, same head SHA, opened from a personal fork instead of an organisation-owned one.

The reason is the one Jinwoo-H hit on #13639: GitHub does not grant maintainer push access on a fork owned by an organisation, even though the API reports maintainer_can_modify: true. A maintainer who wanted to push a fixup here could not, and had to either ask and wait or rewrite the change on main and close ours. That is a poor trade for a reviewer, and it is very likely why these sat.

Nothing about the change moved. This thread keeps the review history, and #15274 carries the code.

@Tauri-EPO — same here: the scope answer stays on this thread, the code is now #15274. The dispatch_contexts column we discussed should build against that one.

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.

4 participants