Repository navigation
Think on the harness: stop means stop, several approvals in one reply, the tab's window, and more - #3562
Conversation
…at its deadline for a chat that was stable. Its waiters were woken at a run's end and on a transcript change. A run's end is told before its operation has settled, so a waiter that looked then still saw the operation open and waited again, and nothing woke it afterwards. Each round now also ends when the oldest open operation settles. Test: client-tools "reports stable only after the continuation the batch's last result armed has run". It timed out on the harness config and passes on both configs. Unit: slim/harness-stable-settled @30378fd72 (base bd29299a4)
…n a stop drops a continuation a tab's answer asked for. `ThinkHarness` withdrew the queued continuation on a stop and published nothing, so an app that stops every chat with `cancelAllChats()` never heard of it. The stop now publishes the event through the chat host, both for a queued continuation it withdraws and for one still only asked for while its reply streams. ## Test client-tools "cancelAllChats also drops the continuation of a result answered while the reply streamed", in its public form (the wait on a class private replaced by the server having handled the result). That form is finish's and is carried with this unit. Unit: slim/harness-stop-dropped @f363bf66a (base 30378fd72)
…id not hold. - **A stop of every turn with nothing running.** A reply holds two client calls. The first answer asks to continue and waits for its sibling. `cancelAllChats()` left that request in place, because the stop returned before it dropped it, so the sibling's later answer continued the reply though it asked for nothing. - **A tab's stop of a running continuation.** An answer that arrived while the continuation ran had queued another continuation behind it. That one ran after the stop. Every tool answer's continuation queued behind a running turn that is stopped is now withdrawn and published as dropped. ## Tests client-tools, harness config: - "a stop of everything drops a continuation waiting on a sibling: the sibling's answer alone does not continue" - "a tab's stop of a running continuation drops the answer that arrived while it ran" Both read green before only because the file's `settled()` returned before a continuation that was still to start. finish's fix to `settled()` (it also waits through `waitUntilStable`) is carried as the first commit; with it both failed on the harness config, and pass on both configs now. Unit: slim/harness-stop-requests @c83651139 (base f363bf66a)
…run of think@0.24.0: a reply that parked two calls continues after each approval. An approval that arrives while another one's continuation still waits to start joins it. The reply never waits for every pause: with one approved and one left undecided it goes on, and the other stays approvable and continues again when approved. However many continuations, the reply is one assistant message. On the harness-backed Think two things differed. - A decision's outcome held its continuation back when the reply "already ended in an answer". With calls parked in separate steps, a later step had parked another call and said so, so the first approval made no model call and only the last one continued. That gate is removed. - Each decision started its own continuation. One is no longer started while another decision's continuation of the session is still queued; that one reads both outcomes. ## Test actions-public "continues after each approval, with the outcomes so far", on the harness config. Two calls are parked in two steps. The first approval gives one more model call with the other call still pending, the second gives one more, and the conversation holds one assistant message. Before the change the first approval made no call. The class Think waits for every pause and takes the rule with the flip, so the case is skipped on the class config. The fixture's model gains a "pause in two steps" script and an answer to a continue prompt. verify gates the three cells on a deployment: back to back, 2 s apart, and one approved with one left undecided. ## Not covered by a test The join of an approval to a continuation that has not started. No public gate holds a continuation between queued and started without another turn in front of it, which moves the chat on. It rests on verify's back-to-back cell. Unit: slim/harness-coalesce-approvals @b2e1b08d2 (rv-1; base 8226866)
… test. A row think@0.24.0 left `running` and unmarked, with the first of its two messages already in the conversation, ends in error "Submission was interrupted after messages were partially applied." after the upgrade. It is not answered again and its second message is not stored. Test only: submissions "fails a running row with only some of its messages stored as partially applied, without answering it again". It passes on both configs. Unit: slim/harness-carry-partial @3d5569973 (rv-1; base b2e1b08)
…fig rows. When they are over the row budget together, Think does not store them, but the isolate that read them still runs with them: a turn the server starts there is offered the release's client tools. After the next restart they are gone. The harness-backed Think stored nothing and kept nothing, so that first turn ran without the tools. `ThinkHarness` now keeps such a context for the isolate through an internal method, `keepRequestContext`. Its client tools and body serve the turns placed there. They are not written, so a restart runs without them, as it runs without the context. A newer declaration or a clear ends it. ## Tests land's, in think-session, both configs: - "offers the release's client tools to a server turn in the isolate that read them, though they are over the row budget" failed on the harness config and passes now. - "deletes the release's request context when it is over the row budget, and nothing brings it back" still holds. ## Not in this PR A live request whose context is over the row budget. The class keeps that in memory for the isolate too; the shared chat turn drops it. That is the chat module's. Unit: slim/harness-context-in-memory @58771a430 (rv-1; base 3d55699)
…en a tab stops a turn that is waiting to be retried, for example during a rate limit's `retry-after`, and it keeps what the turn had streamed. The harness-backed Think took every stop of an open turn to the harness, which ended the run and reported no recovery outcome. A turn waiting out a retry is now left to the shared chat dispatch, which ends it as it ends the other hosts'. Test (land's): think-session "reports a retry a tab stopped while it waited as skipped by the user, not given up". It failed on the harness config and passes on both configs. Unit: slim/harness-stop-in-backoff @7eacddbc6 (rv-1; base 58771a4)
…fit and sends its tabs those. The harness-backed Think sent a tab the whole chat: at connect, when a message was placed, and at a turn's end. Verify measured about 350 KB a frame at about 1,700 stored messages, several times a turn (P14-4). Two changes: - `ThinkChat` takes the host's view of the transcript through a plumbing option, `transcript(reread)`. It is the messages the agent holds in memory, read again first only when something other than a turn wrote. Every list `ThinkChat` sends, and `/get-messages`, is that view. - `ThinkHarness` passes the host's `hydrationByteBudget` to the chat turn. A turn then reads, and sends with its own lists, the newest messages that fit, as the class's turn reads its window. The second change also bounds what the model is sent on a chat over the budget, as on the class. The default budget is 32 MiB, so a chat under it is unchanged. ## Test `window-frames.test.ts` "sends the window at connect and with a turn's lists": ten stored messages of about 30 KB under a 64 KB budget. On the harness config the connect's list held all ten. It passes on both Thinks. Cost: a connect and a turn's own lists no longer read the stored transcript. A turn under a budget reads the newest messages that fit instead of the whole path. Not covered here: the read counts of the rest of a turn (the run-record and config reads in verify's `flipcost-diff.md`), and the shared chat dispatch's own whole-history reads. ## Warm objects and list frames (verify's FIX) verify measured two differences from think@0.24.0 in an object that had not restarted, and extra list frames. - A connect re-windowed the view first, so a view that held what this lifetime appended was cut to the window. Think sends `this.messages` as it stands. A connect no longer re-windows. - A tab was sent four lists during one turn where Think sends one. The question's placement reached the tab that asked, because ThinkChat did not know the origin of a turn the shared dispatch started. The chat turn's own writes, its question and its reply, also came back through the session's change feed as messages written outside a turn. The tab that asked is now left out of the placement's list, and the running turn's own question and reply are not told a second time. Tests, both configs, both failing first on the harness config: "sends a connecting tab the agent's view as it stands, with what this lifetime appended" (new), and "sends the window at connect and with a turn's lists", which now expects exactly two lists: the connect's and the turn's end. - A view grown past its budget re-windowed at a turn's end. Think re-windows after it stores the turn's question, so after the turn its view is that window with the reply. The harness-backed Think now re-windows at the same moment. New test, both configs: "holds the same view as Think after twenty turns in one lifetime" (budget 2,000: the view's size after each of twenty turns; the harness config held 14 where Think holds 16, then 15). Unit: slim/harness-window-frames @3e9ffdfd2 (rv-1; base 7eacddb)
… `hydrationByteBudget` (WF-5): in a warm object the harness-backed Think asked the model with one message more than its view holds.
## Cause
The shell stamped `channel: "web"` on a browser's new user message when the turn's first model call was prepared. That was a read and a second write of the message every turn, and it landed after the turn had read its window. The stamp grows the row (74 to 103 bytes in the test), so the window the turn had read could be one message longer than a read made afterwards. Think stores the message with its channel when it takes the request.
## Fix
`ThinkHarness` takes the host's stamp for an operation's user messages through an internal plumbing option, `questionMetadata`, and writes it with them when they are placed. The shell gives `{ channel: "web" }` for a browser's request and no longer stamps afterwards.
## Test
window-frames "holds the same view as Think after twenty turns in one lifetime", both configs. It now also compares what the model is asked with, turn by turn. The windowed fixture records each request's size. It failed on the harness config.
## Cost
One read and one write fewer per browser turn.
Unit: slim/harness-window-request @b29f1c3b9 (rv-1; base 3e9ffdf)
…ide the connection of the tab the turn runs for. It asked the harness for that tab every time, and each ask read the run's record. A run's origin does not change, so it is now kept with the operation while it runs here. ## Cost One read of the run's record per operation for its origin, where there was one per tool call and hook. verify's table had the run record read 7 times by the class and 40 times by the harness-backed Think in a twenty-tool turn; verify re-measures. No behaviour change. harness-think 225, and client-tools, hooks and tab-closes-mid-tool on the harness config are unchanged. Unit: slim/harness-origin-once @e6dbdd947 (rv-1; base b29f1c3)
…er started stays `approval-responded`, as on Think. Only a reset reports a call as interrupted. The harness-backed Think failed such a call when it kept the stopped turn's reply: as interrupted, or as "no longer available" for a tool the build lacks. A tab's later result for it then had nothing to settle, and nothing continued. The calls an attempt starts are now noted. The reply a stop keeps leaves an approved call that was never started untouched. ## Test client-tools "an answer that arrives after a tab stopped a running continuation still continues", finish's public form of row 21, carried here. Its helper now reads the reply's calls only, since a Think that stores one message keeps the stopped continuation's step start in the same reply. It timed out on the harness config and passes on both configs. Unit: slim/harness-stop-keeps-approved @2337bcfdb (rv-1; base e6dbdd9)
…Harness` took them only before the question the list ends in. A list with a reply after its question, such as a tab echoing a paused call under a message id of its own, was turned away whole as `client_role`. The question was not stored and nothing answered it. Think stores the question and that reply and answers from there. The harness now does the same for a reconciled list. Input that is not a reconciled list may still only add user messages. ## Test parity's #1992 case, both configs: actions-public "does not resolve a later identical paused call a tab echoes under its own message". On the harness config neither the question nor the echoed reply was stored. It now passes on both: the first call keeps its outcome, the echoed one stays paused, and the action ran once. Unit: slim/harness-echoed-row @5b7f4160b (rv-1; base 2337bcf)
…the same moment join one continuation, as on think@0.24.0. On the release the continuation after an approval is a queue item with one id. An approval that arrives before the item has run replaces it, and one model call reads both outcomes. One that arrives while its continuation runs queues the next. The harness-backed Think started the continuation at once, so two approvals fired together made two model calls (verify: 8 of 8 runs; the release makes one in 10 of 14). The shell now starts a decision's continuation through a queue item too. The item and its callback carry the names the release queued its own under, so an item a release left queued is run after an upgrade. A stop of every turn dequeues it, and `waitUntilStable` counts it as work to come. Lands with `slim/harness-coalesce-approvals` and land's `slim/land-coalesce-tests`. ## Test actions-public "joins approvals that arrive before the continuation has started", on the harness config. Two calls are parked in two steps and both are approved at once: one more model call, both outcomes stored, one assistant message. It made two calls before; 5 of 5 runs pass. The class Think takes the rule with the flip, so the case is skipped there. verify re-runs its three cells. Unit: slim/harness-coalesce-queued @e75fe3408 (rv-1; base 5b7f416)
…pproved pause's reply is continued once, and a restart after it continues nothing more; its 'answered' seam is gone with the gate Unit: slim/land-coalesce-tests @ce92ed64a (rv-2; tests for the shell stack)
…t the whole path (hydration-budget's long path) A tab's resent transcript on a chat too long to read root-first (200,005 messages) failed its turn: preparing the model call read the whole path to find the system prompt the chat had been sent (Context.freezeSystemPrompt with no history), and Sessions refuses a root-first read that long. The shell now passes the window it holds, which Context is written to take. Unit: slim/land-hb-long-path @cb2da004d (rv approved)
…so a returning tab is offered it as on Think Unit: slim/switch-shell-stream-open @cb2ccf4f4 (rv-1 approved 787c5bbb6; rebase; verify PASS d0c32a2fb by diff)
|
agents
@cloudflare/ai-chat
@cloudflare/codemode
hono-agents
@cloudflare/shell
@cloudflare/think
@cloudflare/voice
@cloudflare/worker-bundler
commit: |
🟡 agents import sizes: 1 entry point grew
Changed exports (1)
How this worksEach runtime export is bundled on its own, minified, and gzipped. Changes smaller than 100 B, or smaller than 1% and 1 KiB, are ignored. Growth over 10% or 5 KiB is marked 🔴. This report is informational and does not fail CI. The workflow artifact contains every measurement. Compared |
The harness-backed Think only (the shell; the exported
Thinkclass is not changed by this PR): stop means stop, several approvals in one reply, a carried partial reply, context kept in memory, a stop during a backoff, the tab's window of the chat, one origin per turn, an echoed row, a stream left open, and a long path at hydration. Each unit below was reviewed on its own; the suites' proof is this PR's CI (locally: build, check and the changed test files, 405 passed).waitUntilStable()on the harness-backed Think could reportfalseat its deadline for a chat that was stable.chat:continuation:droppedwith reasonstoppedwhen a stop drops a continuation a tab's answer asked for.ThinkHarnesswithdrew the queued continuation on a stop and published nothing, so an app that stops every chat withcancelAllChats()never heard of it.slim/harness-carry-applied's test.chat:recovery:skippedwith reasonuser_cancelledwhen a tab stops a turn that is waiting to be retried, for example during a rate limit'sretry-after, and it keeps what the turn had streamed.hydrationByteBudgetset, Think holds the newest messages that fit and sends its tabs those. The harness-backed Think sent a tab the whole chat: at connect, when a message was placed, and at a turn's end. Verify measured about 350 KB a frame at about 1,700 stored messages, several times a turn (P14-4).hydrationByteBudget(WF-5): in a warm object the harness-backed Think asked the model with one message more than its view holds.executeand each hook inside the connection of the tab the turn runs for. It asked the harness for that tab every time, and each ask read the run's record.approval-responded, as on Think. Only a reset reports a call as interrupted.ThinkHarnesstook them only before the question the list ends in. A list with a reply after its question, such as a tab echoing a paused call under a message id of its own, was turned away whole asclient_role. The question was not stored and nothing answered it.1.
waitUntilStable()on the harness-backed Think could reportfalseat its deadline for a chat that was stable.Its waiters were woken at a run's end and on a transcript change. A run's end is told before its operation has settled, so a waiter that looked then still saw the operation open and waited again, and nothing woke it afterwards. Each round now also ends when the oldest open operation settles.
Test: client-tools "reports stable only after the continuation the batch's last result armed has run". It timed out on the harness config and passes on both configs.
2. Think publishes
chat:continuation:droppedwith reasonstoppedwhen a stop drops a continuation a tab's answer asked for.ThinkHarnesswithdrew the queued continuation on a stop and published nothing, so an app that stops every chat withcancelAllChats()never heard of it.The stop now publishes the event through the chat host, both for a queued continuation it withdraws and for one still only asked for while its reply streams.
Test
client-tools "cancelAllChats also drops the continuation of a result answered while the reply streamed", in its public form (the wait on a class private replaced by the server having handled the result). That form is finish's and is carried with this unit.
3. Stop means stop, as on Think. Two cases on the harness-backed Think did not hold.
cancelAllChats()left that request in place, because the stop returned before it dropped it, so the sibling's later answer continued the reply though it asked for nothing.Tests
client-tools, harness config:
Both read green before only because the file's
settled()returned before a continuation that was still to start. finish's fix tosettled()(it also waits throughwaitUntilStable) is carried as the first commit; with it both failed on the harness config, and pass on both configs now.4. The lead's rule for approvals of durable pauses, taken from verify's run of think@0.24.0: a reply that parked two calls continues after each approval. An approval that arrives while another one's continuation still waits to start joins it. The reply never waits for every pause: with one approved and one left undecided it goes on, and the other stays approvable and continues again when approved. However many continuations, the reply is one assistant message.
On the harness-backed Think two things differed.
Test
actions-public "continues after each approval, with the outcomes so far", on the harness config. Two calls are parked in two steps. The first approval gives one more model call with the other call still pending, the second gives one more, and the conversation holds one assistant message. Before the change the first approval made no call.
The class Think waits for every pause and takes the rule with the flip, so the case is skipped on the class config. The fixture's model gains a "pause in two steps" script and an answer to a continue prompt.
verify gates the three cells on a deployment: back to back, 2 s apart, and one approved with one left undecided.
Not covered by a test
The join of an approval to a continuation that has not started. No public gate holds a continuation between queued and started without another turn in front of it, which moves the chat on. It rests on verify's back-to-back cell.
5. The upgrade case rv-1 asked for beside
slim/harness-carry-applied's test.A row think@0.24.0 left
runningand unmarked, with the first of its two messages already in the conversation, ends in error "Submission was interrupted after messages were partially applied." after the upgrade. It is not answered again and its second message is not stored.Test only: submissions "fails a running row with only some of its messages stored as partially applied, without answering it again". It passes on both configs.
6. think@0.24.0 kept the last request's client tools and body in two config rows. When they are over the row budget together, Think does not store them, but the isolate that read them still runs with them: a turn the server starts there is offered the release's client tools. After the next restart they are gone.
The harness-backed Think stored nothing and kept nothing, so that first turn ran without the tools.
ThinkHarnessnow keeps such a context for the isolate through an internal method,keepRequestContext. Its client tools and body serve the turns placed there. They are not written, so a restart runs without them, as it runs without the context. A newer declaration or a clear ends it.Tests
land's, in think-session, both configs:
Not in this PR
A live request whose context is over the row budget. The class keeps that in memory for the isolate too; the shared chat turn drops it. That is the chat module's.
7. Think reports
chat:recovery:skippedwith reasonuser_cancelledwhen a tab stops a turn that is waiting to be retried, for example during a rate limit'sretry-after, and it keeps what the turn had streamed.The harness-backed Think took every stop of an open turn to the harness, which ended the run and reported no recovery outcome. A turn waiting out a retry is now left to the shared chat dispatch, which ends it as it ends the other hosts'.
Test (land's): think-session "reports a retry a tab stopped while it waited as skipped by the user, not given up". It failed on the harness config and passes on both configs.
8. With
hydrationByteBudgetset, Think holds the newest messages that fit and sends its tabs those. The harness-backed Think sent a tab the whole chat: at connect, when a message was placed, and at a turn's end. Verify measured about 350 KB a frame at about 1,700 stored messages, several times a turn (P14-4).Two changes:
ThinkChattakes the host's view of the transcript through a plumbing option,transcript(reread). It is the messages the agent holds in memory, read again first only when something other than a turn wrote. Every listThinkChatsends, and/get-messages, is that view.ThinkHarnesspasses the host'shydrationByteBudgetto the chat turn. A turn then reads, and sends with its own lists, the newest messages that fit, as the class's turn reads its window.The second change also bounds what the model is sent on a chat over the budget, as on the class. The default budget is 32 MiB, so a chat under it is unchanged.
Test
window-frames.test.ts"sends the window at connect and with a turn's lists": ten stored messages of about 30 KB under a 64 KB budget. On the harness config the connect's list held all ten. It passes on both Thinks.Cost: a connect and a turn's own lists no longer read the stored transcript. A turn under a budget reads the newest messages that fit instead of the whole path.
Not covered here: the read counts of the rest of a turn (the run-record and config reads in verify's
flipcost-diff.md), and the shared chat dispatch's own whole-history reads.Warm objects and list frames (verify's FIX)
verify measured two differences from think@0.24.0 in an object that had not restarted, and extra list frames.
this.messagesas it stands. A connect no longer re-windows.Tests, both configs, both failing first on the harness config: "sends a connecting tab the agent's view as it stands, with what this lifetime appended" (new), and "sends the window at connect and with a turn's lists", which now expects exactly two lists: the connect's and the turn's end.
9. Closes the last difference verify measured against think@0.24.0 under
hydrationByteBudget(WF-5): in a warm object the harness-backed Think asked the model with one message more than its view holds.Cause
The shell stamped
channel: "web"on a browser's new user message when the turn's first model call was prepared. That was a read and a second write of the message every turn, and it landed after the turn had read its window. The stamp grows the row (74 to 103 bytes in the test), so the window the turn had read could be one message longer than a read made afterwards. Think stores the message with its channel when it takes the request.Fix
ThinkHarnesstakes the host's stamp for an operation's user messages through an internal plumbing option,questionMetadata, and writes it with them when they are placed. The shell gives{ channel: "web" }for a browser's request and no longer stamps afterwards.Test
window-frames "holds the same view as Think after twenty turns in one lifetime", both configs. It now also compares what the model is asked with, turn by turn. The windowed fixture records each request's size. It failed on the harness config.
Cost
One read and one write fewer per browser turn.
10. The harness-backed Think runs each tool's
executeand each hook inside the connection of the tab the turn runs for. It asked the harness for that tab every time, and each ask read the run's record.A run's origin does not change, so it is now kept with the operation while it runs here.
Cost
One read of the run's record per operation for its origin, where there was one per tool call and hook. verify's table had the run record read 7 times by the class and 40 times by the harness-backed Think in a twenty-tool turn; verify re-measures.
No behaviour change. harness-think 225, and client-tools, hooks and tab-closes-mid-tool on the harness config are unchanged.
11. The lead's ruling: on a stop, a server call that was approved but never started stays
approval-responded, as on Think. Only a reset reports a call as interrupted.The harness-backed Think failed such a call when it kept the stopped turn's reply: as interrupted, or as "no longer available" for a tool the build lacks. A tab's later result for it then had nothing to settle, and nothing continued.
The calls an attempt starts are now noted. The reply a stop keeps leaves an approved call that was never started untouched.
Test
client-tools "an answer that arrives after a tab stopped a running continuation still continues", finish's public form of row 21, carried here. Its helper now reads the reply's calls only, since a Think that stores one message keeps the stopped continuation's step start in the same reply. It timed out on the harness config and passes on both configs.
12. A tab's reconciled list may hold replies the transcript lacks.
ThinkHarnesstook them only before the question the list ends in. A list with a reply after its question, such as a tab echoing a paused call under a message id of its own, was turned away whole asclient_role. The question was not stored and nothing answered it.Think stores the question and that reply and answers from there. The harness now does the same for a reconciled list. Input that is not a reconciled list may still only add user messages.
Test
parity's #1992 case, both configs: actions-public "does not resolve a later identical paused call a tab echoes under its own message". On the harness config neither the question nor the echoed reply was stored. It now passes on both: the first call keeps its outcome, the echoed one stays paused, and the action ran once.
13. The lead's ruling on COA-1: two approvals of durable pauses fired at the same moment join one continuation, as on think@0.24.0.
On the release the continuation after an approval is a queue item with one id. An approval that arrives before the item has run replaces it, and one model call reads both outcomes. One that arrives while its continuation runs queues the next. The harness-backed Think started the continuation at once, so two approvals fired together made two model calls (verify: 8 of 8 runs; the release makes one in 10 of 14).
The shell now starts a decision's continuation through a queue item too. The item and its callback carry the names the release queued its own under, so an item a release left queued is run after an upgrade. A stop of every turn dequeues it, and
waitUntilStablecounts it as work to come.Lands with
slim/harness-coalesce-approvalsand land'sslim/land-coalesce-tests.Test
actions-public "joins approvals that arrive before the continuation has started", on the harness config. Two calls are parked in two steps and both are approved at once: one more model call, both outcomes stored, one assistant message. It made two calls before; 5 of 5 runs pass. The class Think takes the rule with the flip, so the case is skipped there.
verify re-runs its three cells.
14. test(think): my answered-replay test follows the coalesce rule
One commit on
slim/harness-coalesce-approvals58cf7b3e6. Tests and one fixture only. It lands with harness's unit: that unit turns my test red on the harness config.Why.
durable-pause-answered-replay.test.ts(from land-pr20-devin, Devin P4ad) pinned 'an approved pause whose reply already answered is not continued, also when the report is replayed'. The lead's coalesce ruling removes that gate: the reply continues after each approval, as think@0.24.0 does. With the gate, thechat:continuation:dropped'answered' event is gone too, and my test cut the report at that event.What the test asserts now (harness-backed Think only; the class takes the rule at the flip):
What it no longer shows, said in the file: a reset BETWEEN the outcome's write and the continuation. There is no public seam at that point any more.
broadcast; the write does not go through it.decision-continue:<executionId>).Fixture: the
_emitoverride and its flag are removed (dead with the event);decisionRunsKeptForTestandresetStoredForTeststay.Runs. The file: skipped on the class config, passes twice on the harness config. actions-public, durable-pause-mid-reply and -later-turns: the class config passes; on the harness config one test fails, 'keeps the outcome when a tab that missed it resends the transcript from before the approval', which fails the same on 58cf7b3e6~1 (not from this unit or harness's).
15. Harness-backed Think: the system prompt is frozen from the window, not the whole path
One commit on harness's stack top
slim/harness-echoed-row5b7f416. One hunk in the shell (packages/think/src/harness/think.ts, 6 lines). Shell only (the harness-backed Think is unreleased): no changeset line. harness's OK on the hunk is asked.The gap. hydration-budget "a tab's resent transcript, over a socket > matches on a path too long to read root-first" timed out at 120 s on the harness config; the class answers. The chat holds 200,005 messages and a tab resends its oldest message with a new question.
The cause, measured. The reconcile itself was fine (harness's G19 work reads by id). The turn then failed while preparing its model call: the shell's
systemoption calledContext.freezeSystemPrompt()with no history, so Context read the session's whole active path, and Sessions refuses a root-first read of more than 200,000 messages (SessionPathTooLongError). I found it with a stack trace onSession.getHistory(probe removed).The fix. The shell passes the window it holds (
this.messages, bounded byhydrationByteBudget).ContextReadOptions.messagesis documented for exactly that: "a host that already holds the transcript, or a bounded window of it, passes it".Tests. The socket twin is the failing-first test: timeout before, passes after (about 10 s). No new test.
Cost. One whole-path read fewer per model-call preparation on an agent with no context blocks and no overridden
getSystemPrompt.For the reviewer and harness.
getSystemPrompt(); I believe the turn hydrates the window before this, and no test says otherwise. Say if you know a path where it is not.For verify: a tab can see it (a turn on a very long chat answers instead of failing).
16. Think on the harness: a tab that comes back before the reply's first chunk is offered the stream, as on Think
One commit on
slim/local-main8bfd95041 (rebased over harness's chain, with harness's two notes).agents/src/harness/think/harness.ts,types.tsand the shell (packages/think/src/harness/think.ts): harness's files, written by switch as the difference's owner (the conductor); harness's OK asked on the sha. No change in the chat module.What was different
A tab that asks to resume is offered the running turn once its reply has begun (its
startwas seen), and is held (cf_agent_stream_pending) before that. On Think the reply's stream has started whenbeforeStepruns (the AI SDK'sprepareStep), so a turn held there is offered; duringbeforeTurnthere is no stream and the tab is held. The harness-backed Think runs both hooks inside the harness'sbeforeTurncallback, beforestreamTextis called, so thestartcame only with the model's first output: a fresh turn held inbeforeStepanswered pending where Think offers the stream (parity-2's finding; onconnect-broadcast "tells no reconnecting tab of a failed turn once a new question is asked, while its reply has not started", red on the harness config).The fix
The hook's context gets
begin(messageMetadata?)(@internal): the host says its configuration is done and the model call starts. The shell calls it between itsbeforeTurnandbeforeStep. The loop then yields the reply'sstartat once (the message id it already chose, with the metadata the writer gives forstartand the turn's owner, by the same rule as before), and drops the model's ownstartwhen it comes; the writer is not asked twice for it. A host that never callsbeginbehaves as before.Rebased over harness's chain (8bfd95041)
harness OK'd the hunks in its three files, with two notes, both done: (a)
begingoes through#prepareCall, so the hook hears it on both paths: the model call's, and the one that runs ahead of a tab's answered tool calls (there thestartis yielded right after the preparation); the start's metadata is one private method (#replyMetadata) used by the earlystartand by the stream's own parts; (b) a model call that fails after the earlystartstill reportsstage: "turn": the shell'sonChunkdoes not count astartas streamed (client-tools '#2381 reports an approval continuation that fails before streaming' passes on the harness config).Validated
begin.)--project harness-think224 of 224; tsc (agents, think); oxlint;check:public-apiclean.chat_messageslist before the offer at connect (Think sends none): not looked at here.Cost
One promise race per model call until the reply has started.
Changeset
None (the harness-backed Think is not released).