Repository navigation
Conversation
…elled job cleanup Refuse a background execute on its call during a planned handoff, so no job row is written before its script would start. Clear the handoff signal before discarding saved runs, so a failed handoff settles them instead of leaving them running. Settle a released saved background job as failed, and deliver and complete the outbox row of a caller-cancelled job.
There was a problem hiding this comment.
The change looks sound. I ran the focused core tests (183 passed), the server handoff test, and type-checked core and server with tsc -b (both clean). I couldn't reproduce the agent() polling spin or the empty-step resume end to end: they need full_codemode with a real agent run, which the simulated model can't drive.
Public API: unchanged. This is internal Code Mode behaviour behind full_codemode.
Two of the new tests pass without the fix, so they don't guard what they describe (see the inline comments). With the previous code swapped in, only the locked-body text() fetch test fails. The reader-only GC test, the invalid-JSON test and the dead-worker restart test all still pass. I found nothing blocking in the code itself.
Related: #66478
| } | ||
| }) | ||
|
|
||
| test("a body reader the script still holds blocks a suspend after a collection", async () => { |
There was a problem hiding this comment.
This test also passes with the base fetch.ts swapped in, so it doesn't show that the new retain wrapping of getReader() is what keeps the run live. Bun.gc(true) probably isn't collecting the response here, or something else is still blocking the suspend. Could you make it fail on the old code, or drop it? The invalid-JSON test below also passes on base, so it doesn't guard a change either.
|
|
||
| // A dead worker's script is discarded and its running part failed, but no notice is admitted: one would wake the | ||
| // worker for a turn nobody waits on. | ||
| it.live("does not wake a dead worker for its interrupted Code Mode call", () => |
There was a problem hiding this comment.
This passes with the parent commit's restart.ts/job.ts too, and still passes when I remove closed: true from the marker. So it doesn't exercise the new behaviour (fail the part, admit no notice). The old path apparently never admitted a visible synthetic message or drained the worker in this setup either. Could you seed a case where the old code did wake the worker, or drop the test?
…ing, and stop waking dead workers
50028f5 to
486209f
Compare
Issue for this PR
Related to #66478
Type of change
What does this PR do?
This is PR 2 of 3, stacked on #68400 (
codemode-fix-tear-bugs): its base isdev, so it includes PR 1's commits until that PR merges. Every change is behindfull_codemode; with the flag off, Code Mode never enters full mode and flag-off behavior is unchanged.waitAgentnow waits onCodeModeJob.waitBackground, where each job delivery registers aDeferredbefore itsforkIn({ startImmediately: true }), so a delivery that completes synchronously cannot leave a stale entry that spins at 100% CPU. The 10ms poll loop and its full-tablependingBackgroundscans are gone. Only acodemode-sourced synthetic notice resumes an idle child, and an active child is waited on withsessions.wait, so a resume can no longer force an empty LLM step.liveResponses,fullyReadandtargetscollapse intoMap<string, Set<Tracked>>. A recursiveretainproxy reads stream getters with the raw receiver, binds methods, and wrapsgetReader()/values()results so holding only a reader still keeps the tracked entry alive across GC. Body methods recordreadin.finallyonly when the body was unlocked before the call and was actually used, so invalid JSON counts as consumed whiletext()on a locked body does not clear the live body. The single guardedBun.gc(true)stays inCodeModeTool.suspendAll.recoverCodeModeCallsresumes only when the session is not a worker. The duplicate shell-settle loops are one pass over the union, the redundant recovery sets are removed, and the dead/orphaned session loops merge with guards so only a dead session releases its claim and only an orphaned worker gets the closed marker.REMINDER_PROMPT,schemaMissError, and the unshadowedassistantCallErrorincodemode-agents;AgentOptionsnow spreadsStartOptionsandAskOptions.How did you verify your code works?
packages/core:nice -n 19 bunx tsc -b tsconfig.json tsconfig.tests.json(pass)packages/core(173 passed):test/codemode/execute-durable.test.ts,test/session-execution.test.ts,test/durable-tool-restart.test.ts,test/codemode-agents-e2e.test.ts,test/codemode/agents.test.tsbody.getReader()acrossBun.gc(true)and still blocksuspendAll, verify invalidres.json()lets a later suspend save, and verifyres.text()on a reader-locked body keeps the body live.bunx prettier --checkandbunx oxlinton every changed file (pass)Screenshots / recordings
N/A (no UI change)
Checklist
Added by the opencode bot (AI-generated).
Related: #66478