Repository navigation
Conversation
There was a problem hiding this comment.
The durable agent() and idempotent llm() work as described. I checked this with the codemode unit and e2e tests (123 pass) and tsc -b on packages/core (clean), and by reading the Host.durableFn contract in packages/codemode. The suspend, resume and cancel paths match it: the child is woken in start, wait only reconnects through sessions.resume, and cancel only runs when the run is really aborted.
Public API: unchanged. CodeModeAgents.Implementation is internal to packages/core, and the only implementation is the built-in plugin.
One concern, in an inline comment: the retry accounting in waitAgent uses two separate counters. It can loop forever when resume fails without recording a new assistant message, and it can go over the retries budget when schema misses and errors mix.
|
|
||
| // A failed attempt retries the task in the same child while retries remain, counting attempts already recorded | ||
| // in its history so a resume never starts the count over. | ||
| const failed = (error: CodeModeAgents.CallError): Effect.Effect<unknown, unknown> => |
There was a problem hiding this comment.
Errors and schema misses use different retry budgets. Errors count error assistant messages (failures()); schema misses count task prompts (taskPrompts()). This causes two problems:
- Possible endless loop:
attempt()reads the last assistant message even whensessions.resumefailed. Say the turn fails before it records an assistant message (e.g. a run error at admission). After an earlier failed attempt, the last message is still that old error.failed()then sees the samefailures()count, sends the task again and callsattempt(). Nothing in that cycle increases the count, so it never ends whileretries >= 1. - Budget overrun: with
retries: 1, a schema miss followed by a provider error gets a third attempt. The error check doesn't count the earlier task prompt.
Using one count on both paths fixes both. For example, check (yield* taskPrompts()) > retries here too, since every attempt sends exactly one task prompt and that count always goes up.
There was a problem hiding this comment.
The new commit fixes the earlier retry concern. failed() now checks the task-prompt count, which goes up with every retry, so the endless loop on a stale error is gone and errors and schema misses share one retries budget. I checked with the codemode unit and e2e tests (124 pass) and tsc -b on packages/core (clean). Public API: unchanged. Nothing new to flag.
There was a problem hiding this comment.
The earlier retry-budget point stays fixed. The new commit correctly skips sending the schema reminder again when a resumed wait finds it is already the latest user message. An error in the reminder's answer is still caught first, and a retry still gets its own reminder. I checked with the codemode unit and e2e tests (125 pass, including the new reminder test) and tsc -b on packages/core (clean). Public API: unchanged. Nothing new to flag.
Summary
Follow-up to #67621: makes Code Mode's
llm()global idempotent andagent()global durable usingHost.fnandHost.durableFn.Changes
packages/core/src/codemode/agents.tsllm()with{ type: "async", idempotent: true }so a suspend detaches it without firingextension.afterand replays it on resume with the same<runId>:<callId>key.agent()toHost.durableFn({ start, wait, cancel })withAgentData = { childSessionID: string }.call.args(includingoptions.schema) inwaitso a resumed wait in a fresh runtime reconstructs its schema codec without closure state fromstart.packages/core/src/tool/plugin/codemode-agents.tsagentintostartAgent(creates child withcodemodeAgentmarker, prompts/wakes it, returns{ childSessionID }),waitAgent(stateless reconnect viasessions.resume(childID), reading results and retry counts from durable history), andcancelAgent(sessions.interrupt(childID)on real abort only, never on suspend).packages/core/test/codemode/agents.test.ts,codemode-agents-e2e.test.ts)llm()(same key,extension.afterskipped on detach),agent()(plain text & schema output in a fresh runtime without re-callingstart), real cancellation callingcancelonce,SuspendErrorduringstart, and history-backed retries.Verification
packages/core:bunx tsc -b tsconfig.json tsconfig.tests.json— clean.bun test test/codemode/ test/codemode-agents-e2e.test.ts test/tool-execute.test.ts— 123 pass, 0 fail.