Skip to content

feat(core): auto-background slow Code Mode executions - #60709

Open
kitlangton wants to merge 1 commit into
job-seam-5-image-wrapperfrom
job-seam-6-codemode-yield
Open

kitlangton wants to merge 1 commit into
job-seam-5-image-wrapperfrom
job-seam-6-codemode-yield

Conversation

@kitlangton

Copy link
Copy Markdown
Contributor

Code Mode execute calls now yield as a single background job after 10 seconds while keeping nested tool calls typed in foreground inside the script.
Instead of rewriting inner tools.* return types for backgrounding, execute itself runs through executeTopLevel, streams live console.log lines and nested call status into partial progress, delivers an <execute> notice when done, and exposes "tool" jobs to idle hooks and goals.

💡 Why

  • Auto-backgrounding inner tools.* calls inside execute would break every Code Mode script expecting typed return values.
  • Active goals and session idle hooks need to see running "tool" jobs so a goal waits for a backgrounded Code Mode or MCP call before judging the round.

🆕 Now you can

  • Let slow execute scripts auto-background after 10 s (or via yield_after / background: true), returning console.log output and nested call progress so far and delivering <execute id="..." state="completed"> even after location invalidation (shell: plugin suffix rebuild drops background completion notifications #56729).
  • Inspect running "tool" jobs in SessionIdleBackground and hold GoalPlugin.idle until they finish.
- if (name === "execute" && codeModeTool) return yield* executeTool(codeModeTool, ...)
+ if (name === "execute" && codeModeTool) return yield* executeTopLevel(codeModeTool, ...)
+ SessionIdleBackground |= { kind: "tool", sessionID, tool, title? }
+ GoalPlugin.idle waits when background has kind === "tool" for sessionID

📊 Numbers

Case Before After
Slow execute script (> 10 s) ❌ Blocks turn until all nested calls finish ✅ Yields whole script with logs + call list; inner tools.* stay typed
Location invalidated mid-execute (#56729) ❌ Execution lost with location scope ✅ Finishes in global Job scope and delivers <execute> notice
Active /goal while background tool runs ❌ Reviewer runs before tool reports back ✅ Goal waits for kind === "tool" notice

New Code Mode auto-background test in tool-auto-background.test.ts fails without this change; 146 tests pass across codemode.test.ts, tool-auto-background.test.ts, job.test.ts, tool-image-generate.test.ts, session-execution.test.ts, and plugin/goal.test.ts.

👀 Read: packages/core/src/tool.ts (executeTopLevel name === "execute" branch) and packages/core/src/plugin/goal.ts (idle waiting on work.kind === "tool"). The rest is routine.

🔍 Split 6 of 6 from #60495 · closes out the #60495 split

Checks run
  • bun run --cwd packages/codemode typecheck && bun run --cwd packages/plugin typecheck && bun run --cwd packages/core typecheck
  • bun --cwd packages/codemode test test/codemode.test.ts: 54 pass
  • bun --cwd packages/core test test/tool-auto-background.test.ts test/job.test.ts test/tool-image-generate.test.ts test/session-execution.test.ts test/codemode.test.ts test/plugin/goal.test.ts: 92 pass

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant