Skip to content

refactor(native-chat): give each structured dispatch state exactly one meaning - #20133

Merged
brennanb2025 merged 12 commits into
mainfrom
brennanb2025/simplify-dispatch-doubt-states
Sep 13, 2026
Merged

brennanb2025 merged 12 commits into
mainfrom
brennanb2025/simplify-dispatch-doubt-states

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

When a message can't be sent, Orca now says which of two things happened — "it definitely didn't go" or "I genuinely can't tell" — instead of saying "I can't tell" for both. That matters because Retry is safe in the first case and dangerous in the second.

The critical change, in one sentence

Retry's safety stops depending on a list being correct, and starts depending on the state itself.

Before, every failed send landed in one state — unknown, "delivery in doubt" — and Retry consulted a lookup of reasons to decide whether re-delivering that particular unknown was safe:

dispatchState = 'unknown'
reason        = 'provider_write_failed: broken pipe'   <- allowlisted, re-delivery permitted
reason        = 'provider_exited_before_acknowledgement' <- not allowlisted, refused
reason        = 'host_restarted_before_acknowledgement'  <- not allowlisted, refused

That is a runtime judgement call standing in front of a duplicate-delivery hazard. It is only safe while the list is right, and nothing fails when somebody adds a new reason and forgets it.

After, the one case that was provably safe is not an unknown at all — a write the agent's input pump never took resolves rejected, because "provably did not happen" is what rejected already means. With that case gone, the allowlist has no entries left and is deleted. Retry's rule becomes unconditional:

Never re-deliver an unknown. No exceptions, nothing to look up.

Re-sending after a rejected is safe by construction rather than by permission: it goes out under a fresh client message id, so it is a new message and cannot duplicate an old one.

That is the whole change. A judgement call became a structural invariant. Everything below — the copy fixes, the mobile fixes — follows from the states now meaning one thing each.

What you see today vs after

Case A — the agent's input pipe breaks (agent crashed, was killed, restarted). The message provably never left your machine.

Today After
Banner "Message delivery is unconfirmed." "Message was not sent."
Second line provider_write_failed: broken pipe in red "Couldn't reach the agent. Your message was not sent — Retry to send it again."
Retry Refuses — nothing happens, forever Sends it as a genuinely new message

Today that red line is an internal identifier on your screen. There is nothing you can do with it, and the Retry button next to it is inert.

Case B — Orca genuinely can't tell (host restarted mid-send, ack lost). The agent may or may not have it.

Unchanged on purpose: still "Message delivery is unconfirmed.", still refuses to re-deliver. That refusal is the point — see Why.

On mobile. Today, a send whose outcome is unknown reports as sent: the composer clears your draft and the message looks delivered. After: it reports unknown, keeps your draft, and says "Delivery unconfirmed — check chat before retrying."

Why

Retry used to re-deliver messages that had already reached the model. In one measured session a single message reached the model five times. The root cause was fixed in #19863 (a 10-second timer that declared healthy sends "unconfirmed" — 25% of all sends tripped it). This PR fixes the state model underneath it.

unknown meant five different things, only one of which was real ambiguity. A one-entry allowlist then existed to teach Retry that one particular unknown was safe. That is a judgement call sitting in front of a duplicate-delivery hazard.

Moving the provable case to rejected deletes the allowlist and makes it an invariant: Retry never re-delivers an unknown, no exceptions to reason about. The asymmetry justifies being strict — refusing a legitimate retry costs you a retype; allowing a bad one silently puts a second copy of your message in the model's context, where you won't see it.

Four states, one meaning each:

state means
pending written, waiting for the agent to acknowledge
accepted the agent has it
rejected provably did not happen
unknown genuinely cannot tell

What changed in the code

  • A transport write the agent's input pump never took now resolves rejected instead of unknown.
  • The redelivery allowlist is deleted; performSend cannot re-deliver an unknown at all.
  • Rejection reasons split into the provider's own words (shown verbatim — "Claude does not support the image type .bmp" is the whole answer) and internal causes (never shown; replaced with copy you can act on).
  • Mobile reads the send's real state instead of treating any successful RPC as delivered, and keeps its operation id when delivery is unknown — reusing that id delivers if nothing landed and replays if something did, so it can't duplicate.
  • A refused worker-start preamble throws a typed code instead of prose a caller has to parse.

Review history worth knowing

A mid-review commit made mobile rotate its operation id on unknown, which host-side is a second dispatch — the exact defect this PR removes, reintroduced on another surface. It was caught, reverted, and the guard restored with a test that fails against the pre-fix code. The mobile send fixture was also replaced: it returned a shape that structurally could not express this bug, which is why the inversion passed review.

Testing

pnpm tc clean. Affected suites green; mobile src/session 160 files / 1511 tests. Every new test ablated — including an arm running the production file at the pre-fix commit with the new tests kept, which fails.

One pre-existing failure, claude-structured-real-cli.test.ts, verified to fail identically on plain main.

Visual proof

The only user-visible change is copy, tabulated above. Not run in the app — flagging that rather than claiming N/A.

Notes

Loading
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