Skip to content

feat(core): yield slow top-level tools to the background after 10s - #60706

Open
kitlangton wants to merge 1 commit into
job-seam-2-job-notifierfrom
job-seam-3-tool-wrapper
Open

kitlangton wants to merge 1 commit into
job-seam-2-job-notifierfrom
job-seam-3-tool-wrapper

Conversation

@kitlangton

Copy link
Copy Markdown
Contributor

Slow top-level plugin and MCP tools now move to the background after 10 seconds instead of blocking the turn.
Long tool calls no longer stall the agent loop: after yield_after (10 s by default, or Ctrl+B), Tool.execute returns partial progress immediately and delivers the bounded result later as a <tool> notice. Fast local file, search, and interactive tools opt out with background: false.

💡 Why

  • Slow MCP calls and custom plugin tools blocked the entire turn with no way to yield or steer past them.
  • Interactive prompts (permissions and forms) must pause the yield timer so waiting on a person never backgrounds a tool mid-approval.

🆕 Now you can

  • Let any top-level tool without background: false auto-background after 10 s (or on Ctrl+B), preserving ToolOutput truncation and saving returned file attachments for background notices.
  • Pause yield_after automatically whenever the session has a pending permission or form prompt.
- Tool.execute -> executeTool(tool, name, input, context) (blocks until exit)
+ Tool.execute -> executeTopLevel -> jobs.start + jobs.block({ yield_after: 10_000, deferYield })
+   on yield -> return partial progress + jobID; deliver bounded <tool> notice on completion

📊 Numbers

Case Before After
Slow MCP / plugin tool (> 10 s or Ctrl+B) ❌ Blocks turn until exit ✅ Yields with progress + delivers <tool> notice
Waiting on permission / form approval — ✅ Pauses yield_after timer
Oversized text or file attachment in background result — ✅ Truncated via ToolOutput + files saved

New tests in tool-auto-background.test.ts fail without this change; 58 tests pass across job.test.ts, tool-auto-background.test.ts, and session-execution.test.ts.

👀 Read: packages/core/src/job.ts (block resolving isBackgrounded vs consumeJob atomically in one SynchronizedRef.modify) and packages/core/src/tool.ts (executeTopLevel + renderResultText). The rest is routine (background: false one-liners on synchronous built-ins).

🔍 Split 3 of 6 from #60495 · no user reports

Checks run
  • bun run --cwd packages/core typecheck
  • bun --cwd packages/core test test/job.test.ts test/tool-auto-background.test.ts test/tool-todo.test.ts test/session-execution.test.ts: 59 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