Repository navigation
Commit 23b2587
authored
* ✨ Make a fresh <Session> a pending placement (#648)
A `<Session>` used to establish. It took ownership, published `acp-first`,
built a runtime, created a backend session and asserted an identity for it —
all before anything had asked for a conversation. That is why a
`<Session.Launch>` nested inside a `<Session>` could not work: the enclosing
element had already settled how the session was constructed, so the launch
inside it was refused for naming a session that had just been created out from
under it. It is also why a run could retain a conversation nothing ever had:
`ensureSession()` returning is not a backend accepting a turn.
A fresh `<Session>` now places. It validates the agent and where the session
will live, pins the exact `Session` value, and does nothing else — no route, no
runtime, no ensure, no record, no turn. The first consuming operation chooses
the immutable construction route: a first subscribed `<Prompt>` publishes
`acp-first` and constructs through ACP, and a first `<Session.Launch>`
constructs client-native. An established placement keeps its eager validation
exactly as before.
An ACP-first session becomes a conversation when the backend accepts its first
turn, and only the adapter can say when that happened. Both embedded adapters
now report it on one exact versioned key,
`executablemd.session-materialization/v1`, as `{"state":"accepted"}` in the
update metadata of a standard ACP `session_info_update` — Codex when
`turn/start` returns a turn, Claude when the SDK reports that exact queued
command dispatched. Nothing else promotes a session: not a returning ensure,
a first text delta, a synthesized `started`, a terminal result, a checkpoint
token, an error code or a diagnostic.
The vendored ACPX runtime gains a third behavioral patch to carry it. An ensure
asking for deferred materialization persists a provisional record — the key is
occupied, the serialized `agentSessionId` is absent — and holds the identity
`session/new` returned privately, so the record is occupancy rather than an
assertion. The acceptance marker is consumed rather than published: it reaches
no event stream, no conversation and no checkpoint. On acceptance the runtime
promotes a copy of the record, saves it through the store's own atomic
operation, adopts it in memory only after that save returns, and then resolves
`AcpRuntimeTurn.materialized`. Promotion is serialized against live-checkpoint
writes, so a promotion that failed is not later overwritten by finalization as
though it had succeeded.
The durable order is therefore route, provisional non-asserting record, backend
acceptance, asserting record, host mapping, and only then the events the turn
produced. A first turn nobody accepted leaves the route standing, the record
non-asserting, no workflow row, no identity on the value the document holds, and
that same pending value ready to retry — which creates fresh backend state
rather than resuming the arrangement no backend took. Acceptance, not successful
terminal text, is the boundary: a turn that failed after being accepted leaves
the session established.
The pre-commit window is unchanged and now sits one step later: the provider's
assertion is saved before the host is asked to retain anything, so an
interruption between them leaves exactly one canonical assertion for the next
attachment to reconcile and commit.
Provider provenance is now the exact object rather than the key inside it. A
structural copy, a value from another provider copy or a torn-down scope, and a
value used with a different resolved agent are each refused before any provider
work — and the value a `<Session>` pinned is the one every nested `<Prompt>`
receives.
A first prompt enters its session's FIFO before any route, ensure or runtime for
that placement, and re-reads the placement once the queue grants, so two
concurrent first prompts perform one backend creation and the waiter continues
what its predecessor established.
Both adapter snapshots are rebuilt from new commits on their existing upstream
pull request branches, and the test agent reports acceptance too — an agent that
never sent the marker would leave every session it serves unestablished.
* 🐛 Serialize concurrent prompts, and report acceptance from every turn
Two settled contracts the previous commit broke.
**Concurrent prompts on one advertised session.** Ownership was acquired before
the session's queue, and the coordinator refuses contention rather than queueing
it. That is right for a native UI holding the session for hours and wrong for
the next turn of a conversation this provider is already having: a second
subscription got `AgentSessionBusy` instead of running as the second turn. The
queue comes first now, and each prompt takes and gives back ownership in its
turn.
What still refuses is what genuinely competes. Another provider state, another
process and another kind of operation share no queue with this one, so they all
still meet the coordinator. A launch no longer takes the queue at all: a launch
is only ever performed for an advertised agent, so its acquisition is already
that session's exclusion, and holding the queue as well is what would have put a
prompt behind a native UI — the thing NL12 exists to prevent. It refuses
instead, and the coordinator is what refuses it.
`NO12` is the regression: an advertised adapter and a real coordinator, the
first turn held open while the second subscribes, proving two sequential grants
both granted, one materializing ensure, two turns in submission order, and one
retained identity in the provider's own store. It fails on the previous
ordering.
**Codex commands that start a turn.** The marker was published where a prompt
reaches the App Server through `turn/start` and nowhere else, so `/review`,
`/goal <objective>` and `/goal resume` accepted turns and reported nothing. All
three funnel through the adapter's command turn-started callback, which now
reports it and awaits publication; a command that starts no turn never reaches
it and still reports none. The upstream commit is
`fadc0a690e96c276629be8a34be980d35e821637` on the same pull-request branch, with
its own regressions, and the tarball, generated snapshot, manifest and
provenance are refreshed from it.
`EA8` proves it against the real embedded adapter: the fake App Server answers
`review/start` on a review thread of its own, and the adapter reports exactly one
acceptance for the session the command was sent on. It fails on the previous
tarball.
Neither fix adds an inference anywhere. Acceptance is still one exact marker
from the adapter, and the provider still waits for it.
* ✅ Order NO12 on barriers rather than on durations
Two of NO12's claims were timed rather than observed. It polled the fake until a
turn appeared, and then waited a fixed five milliseconds before asserting that
the second subscription had not run — which is a claim about what has *not*
happened, and a duration can only ever make that likely.
Three signals replace them. The fake runtime says when a turn has actually
started, which is what "the first turn is in flight" means. The second task says
when it is about to subscribe, immediately after constructing the stream, which
chose nothing and started nothing. And the provider's own agent resolution says
when that subscription is running — the point after which the only thing ahead
of it is the session's queue.
Only then does it assert the held state, and it asserts one more thing than
before: one ensure. A second subscription past the queue would have ensured, so
counting them is what makes "waiting" different from "not started yet".
`startedTurns(count)` on the fake runtime is the first of those signals, built
the way the workflow fake's already is. Nothing else changes; the released
sequence is asserted exactly as it was.
* ✅ Signal NO12 from the placement the provider is about to queue behind
The "this subscription is running" barrier was the provider's agent resolution,
which is several suspensions short of the queue: between it and `turns.slot`
lies the whole outer placement. So the held-state assertions were made while the
second subscription might still have been resolving where its session lives, and
what they observed was as much "not there yet" as "waiting".
The signal is the completion of that placement now, which is the step
immediately before the provider enters the queue. It comes from
`withSessionRoute` — the provider's own dependency, supplied the way a host
supplies it — rather than from anything added to production for a test to hold
on to.
`withSessionRoute` wraps two things per subscription, and only placements
*complete* while the first turn is held: the first subscription's second call
encloses its whole turn, which is still open. So the second completion is the
second subscription's placement, and the test asserts that identification rather
than leaving it to be inferred.
The wrapper suspends once before it signals, so nothing here rests on placement
being synchronous — a scheduler that hands control back at a yield has already
done so by the time the waiting task is released, and the signalling task runs
on into the queue before that task resumes.
Restoring ownership-before-queue fails this in both shapes, with the forced
suspension and without it, and fails it on the claim that matters: the second
subscription comes back `AgentSessionBusy` instead of `undefined`.
---------
Co-authored-by: Taras Mankovski <[email protected]>
1 parent a6e8bb7 commit 23b2587
36 files changed
Lines changed: 7130 additions & 5048 deletions
File tree
- packages
- acp
- src
- tests
- fixtures
- vendor
- acpx
- generated
- adapters
- claude
- codex
- generated
- cli
- src
- tests
- support
- core/tests
- test-agent/src
- worker
- scripts/tests
- specs
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
| 70 | + | |
70 | 71 | | |
71 | 72 | | |
72 | 73 | | |
| |||
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
34 | 47 | | |
35 | 48 | | |
36 | 49 | | |
| |||
82 | 95 | | |
83 | 96 | | |
84 | 97 | | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
85 | 102 | | |
86 | 103 | | |
87 | 104 | | |
88 | 105 | | |
89 | 106 | | |
90 | 107 | | |
91 | | - | |
| 108 | + | |
92 | 109 | | |
93 | 110 | | |
94 | 111 | | |
| |||
97 | 114 | | |
98 | 115 | | |
99 | 116 | | |
100 | | - | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
101 | 121 | | |
102 | 122 | | |
103 | | - | |
| 123 | + | |
104 | 124 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
135 | 135 | | |
136 | 136 | | |
137 | 137 | | |
| 138 | + | |
138 | 139 | | |
139 | 140 | | |
140 | 141 | | |
| |||
221 | 222 | | |
222 | 223 | | |
223 | 224 | | |
| 225 | + | |
224 | 226 | | |
225 | 227 | | |
226 | 228 | | |
| |||
0 commit comments