Repository navigation
feat(sdk)!: report worker spawn attempts and failures - #2607
Aditya-linux wants to merge 1 commit into
Conversation
1df4e42 to
33985eb
Compare
Emit onWorkerEvent dispatch and failed signals from live spawn_agent tool calls so CI guards can see the delegated-work boundary without relying on model-emitted status markers. Fixes openai#956
33985eb to
dc60dea
Compare
|
Updated in |
mldangelo-oai
left a comment
There was a problem hiding this comment.
An unrelated MCP server can trigger the CI signal this PR adds. I replayed an mcp_tool_call from a synthetic inventory server with a tool named spawn_agent, followed by a native collab_tool_call. The MCP call emitted dispatch and failure for attempt 1. The first native call then received attempt 2. Both of the added API tests use MCP items, so they accept this false positive. Please restrict dispatch detection to the native item type and exact tool name, and keep an unrelated MCP call as a negative control.
There is also a concrete compatibility cost in the existing callback. A previously valid onWorkerEvent(event) { const worker: number = event.worker; } consumer fails with TS2339 at this head. Existing JavaScript consumers receive the new payloads with worker undefined.
I recommend using #2679 for best-effort notification. At 246da9d8, the same replay ignored the MCP call, numbered the native attempt 1, and sent it only to the opt-in spawn callback. The legacy consumer compiled. The two observer test files passed on both heads (59 here, 60 on #2679). Keep #956 open for the timing guarantee: the v2 runtime can omit the parent spawn item, and observer delivery cannot veto a worker start.
Summary
SDK callers can observe live
spawn_agentattempts and failures before persisted worker sessions appear. Addresses #956.Changes
onWorkerEventnow includes runtimedispatchandfailedvariants. Both carry a scan-localattemptordinal; failures reuse the corresponding attempt when its start was observed. A successful completion supplies the dispatch event when the stream omitted its start item.The API deliberately does not infer a worker phase, planned worker count, or successful-worker count from runtime events. Existing
{ kind: "observed", worker }session notifications remain unchanged. The SDK guide and package-consumer fixture document the expanded union.Testing
bun test --timeout 30000 ./tests-ts/worker-progress.test.ts- 15 passedtsc --noEmit- passedtsc -p tsconfig.ci.json- passedThe broader
api-events.test.tsfile was attempted locally, but this checkout does not contain the generated_bundled_pluginfixture it requires. The added API regression cases remain enabled for PR CI.Risk and rollout
This intentionally expands the public
ScanWorkerEventunion and requires exhaustive consumers to handle two new variants, so the PR remains marked as breaking. Runtime events report only facts present in the parent stream. They do not replace persistedobservedevents and do not claim that a dispatched attempt successfully started.Public disclosure review