Files
orca/config/scripts
Brennan Benson 04ac6d6cb2 Hold messages in the host until a chat's agent has finished starting (#26416)
* feat(native-chat): host-owned startup attempt and hold-and-deliver barrier

The host now mints one startup attempt before any adapter acquires (lease
identity, spawn token, pinned launch context, cancellation, a 60 s deadline
from the mint that activity never renews, option intent, and the event and
child-work sinks), and the shared delivery loop hands nothing to a child
still proving its start. A send is still accepted and journaled at once;
readiness (the normalized `started` settlement) wakes delivery, which
re-checks the child, fence, close and Stop before handover. A start that
fails, crashes, or misses its deadline leaves held messages definitely
unsent; a dispatch that throws after handover is `unknown`, never inferred
unsent from the child's phase.

* fix(native-chat): time agent starts from spawn by progress, and release Claude on initialize

Review round 1 on the host-owned startup attempt.

- The startup clock now starts when the process exists and fails a start
  only after 60 s with no stdout frame or stderr line, or 10 minutes after
  spawn however chatty it is. Every agent's child reports output through
  the one managed-process spawn, so a slow migration or history replay is
  no longer killed mid-way. Each start's spawn-to-outcome time is recorded
  as an `agentSession.startup` span for tuning.
- Claude reports `started` on its initialize answer; the settings read
  follows and is applied and persisted as a later `options-reported`
  update, so messages no longer wait on it.
- A started child's reported options are persisted in their own step after
  the held messages are handed over, and only if no pick changed the
  record's options since.
- An attempt now ends whenever its child ends or an expiry stopped it.
- Removed `optionsAsOf`, which was not an option revision, and comments
  that described the old publish-and-write-at-once behaviour.

* fix(native-chat): keep the startup attempt's contract free of host and process code

The adapter contract imported the attempt type from the module that also runs
its clock and imports the host types, which pulled the model catalog and
process-scan code into the mobile test typecheck. The attempt's shape and limits
now live in a dependency-free contract module.

* fix(native-chat): never let a stale option report undo a later pick

A report of the child's options is now persisted only if no pick, no
model-not-found heal and no newer report reached the chat since its read
began. The host keeps one option revision per chat; the startup attempt
hands the adapter a reader for it, and each report carries the revision
it was read at. This replaces the record-snapshot check `started` had and
covers the settings report, which had none, so a settings read answered
just after a pick can no longer write the older model back.

Also: the option read a ready child does inside its start now ends with
the start (limit, Stop or close); a start that turns ready as the limit
fires is recorded as ready; the startup-attempt host tests run under the
Node SQLite runtime; and the retired-model test follows the new startup
order.

* fix(native-chat): require the option revision and order reports by arrival

The host can no longer mint a startup attempt without the conversation's
option revision, so no host path can stamp a report at a stale zero and
drop every report after the first pick. Adapter tests may still omit it.

A report is now dropped only when a pick or a value the child showed it
cannot run came after its read. Reports are ordered among themselves by
when the host takes them, and only the newest admitted one is persisted.
The settings read's stamp therefore holds however late the host takes
the start's report, instead of relying on that report being handled
synchronously before the read begins.

Tests: a settings read stamped before the host took the start's report is
kept; a report read after a failed pick is persisted; the minted attempt's
revision reader answers the host's current revision.
2026-10-08 11:57:51 -07:00
..
2026-05-15 05:44:25 -04:00