Repository navigation
fix(copilot): plugin tool calls fail from the second turn of a session - #164598
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed October 3, 2026, 10:26 PM ET / October 4, 2026, 02:26 UTC (Revision 3). ClawSweeper reviewWhat this changesThe Copilot plugin restores each attempt’s async context before executing SDK tool callbacks and adds a regression test for callbacks dispatched from an earlier turn. Merge readiness✅ Ready for maintainer review This remains a useful, focused repair with no actionable correctness findings. The new runtime evidence satisfies the earlier proof request; current main and the latest release still contain the defective scheduler. Likely related people: steipete and vincentkoc, as routing candidates from prior Copilot work. Priority: P1 Review scores
Verification
How this fits togetherThe Copilot tool bridge connects the GitHub Copilot SDK’s tool requests to OpenClaw’s host-bound plugin tools. Its scheduler controls execution order and returns tool results to the SDK while preserving cancellation and access checks. flowchart TD
A[Current agent attempt] --> B[Build host-bound tools]
B --> C[Capture attempt context]
D[Pooled Copilot SDK callback] --> E[Wait for ordering barrier]
C --> F[Restore context and check cancellation]
E --> F
F --> G[Execute guarded plugin tool]
G --> H[Return SDK tool result]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +4, Tests +27. Total +31 across 2 files. View PR surface stats
Review metricsNone. Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Technical reviewBest possible solution: Keep tool callbacks in their current attempt’s context while retaining pooled clients, execution ordering, cancellation, and live host-authority checks. Do we have a high-confidence way to reproduce the issue? Yes: current source exposes the callback-context mismatch, and the submitted baseline trace reproduces the exact second-turn error through the real Gateway and SDK. This review did not execute target code. Is this the best way to solve the issue? Yes: restoring context at the attempt-owned scheduler is a narrow repair that preserves the existing pooling and tool lifecycle contracts. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 1836ae214644. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
History |
Signed-off-by: Eric Curtin <[email protected]>
|
Merged main, which clears the unrelated tool-bridge test failures, and refreshed the PR body evidence. @clawsweeper re-review |
|
Landed as c6e5ae8. Thanks @ericcurtin! |
openclaw#164598) Fixes openclaw#164470. Copilot agents' plugin and MCP tool calls failed with "Async work scope is closed" from the second turn of a session. The Copilot SDK runs tool handlers in the async context of the turn that opened its pooled client, which is closed by turn 2. The tool bridge now runs each tool in its own attempt's async context. Turn 1, non-Copilot runtimes and cancellation are unchanged. Proof: a real isolated Gateway with Copilot SDK 1.0.14 against a local HTTPS model stub (no Copilot credentials) and a plugin tool. On base, turn 1 succeeded and turn 2 failed with "Async work scope is closed"; with this change both turns succeeded in the same SDK session. Cancellation still reaches a running tool's abort signal. The regression test fails on base and passes here. A live gpt-5-mini smoke call on a non-Copilot runtime passed. Co-authored-by: Ayaan Zaidi <[email protected]>
openclaw#164598) Fixes openclaw#164470. Copilot agents' plugin and MCP tool calls failed with "Async work scope is closed" from the second turn of a session. The Copilot SDK runs tool handlers in the async context of the turn that opened its pooled client, which is closed by turn 2. The tool bridge now runs each tool in its own attempt's async context. Turn 1, non-Copilot runtimes and cancellation are unchanged. Proof: a real isolated Gateway with Copilot SDK 1.0.14 against a local HTTPS model stub (no Copilot credentials) and a plugin tool. On base, turn 1 succeeded and turn 2 failed with "Async work scope is closed"; with this change both turns succeeded in the same SDK session. Cancellation still reaches a running tool's abort signal. The regression test fails on base and passes here. A live gpt-5-mini smoke call on a non-Copilot runtime passed. Co-authored-by: Ayaan Zaidi <[email protected]> (cherry picked from commit c6e5ae8)
Audit all 253 September-only commits against da0cbcc. Port only applicable fixes and final companions, preserving October owners and shipped upgrade contracts. Exclude September-specific waivers, schema rollback, dependency changes, and credential-absence pass conditions. Adapt retained ACP archive receipts without reopening retired custody; retain SDK1.30.1 issuer fencing and explicit re-registration; exclude standalone worker copies from beta.2 updater compatibility bridges. Report settled Doctor release failures before the no-config early return. Sources below are whole backports or scoped repair selections: fix(discord): keep health inspection from blocking Gateway connections (openclaw#166736) Source-commit: dc26366 fix: avoid foreign-listener race in Gateway acquisition proof (openclaw#166883) Source-commit: bd0b97d fix(ci): admit workspace package tests in Windows replay (openclaw#166895) Source-commit: 9bc88a6 fix(release): restore beta.2 updater inventory and Podman control (openclaw#166872) Source-commit: e203c64 fix(copilot): plugin tool calls fail from the second turn of a session (openclaw#164598) Source-commit: c6e5ae8 fix(test): await WhatsApp inbound drain (openclaw#165842) Source-commit: 05170cd fix(qa-lab): keep SUT CLI in isolated launcher Source-commit: 6681bcd test(qa-lab): assert resolved companion CLI cwd Source-commit: a60b458 fix(release): accept candidate-owned child evidence (openclaw#165357) Source-commit: 500c95a fix(acp): migrate metadata from retained sessions Source-commit: 16398dc fix(release): isolate first-hop service containment (openclaw#164898) Source-commit: 85124fe fix(release): isolate upgrade survivor scenarios (openclaw#165007) Source-commit: aad828f test(release): expect isolated survivor scenarios (openclaw#165009) Source-commit: 02e7f91 fix(release): split restart auth validation (openclaw#165048) Source-commit: 6160d9f test: serialize PowerShell completion process suites (openclaw#166229) Source-commit: 320e52b fix(update): settle only this Doctor's commands in managed custody (openclaw#164868) Source-commit: bdb44e2 fix(claude-cli): replies hang until the run times out when a background agent runs Bash (openclaw#165596) Source-commit: 889611b fix(whatsapp): synchronize shutdown test with durable admission (openclaw#166531) Source-commit: 1f576e4 fix: prevent heartbeat live replies from abbreviating markers (openclaw#166777) Source-commit: c4ed37e fix(ci): keep full release validation within measured budgets (openclaw#166774) Source-commit: 471f950 improve(ci): reuse Watch cache and expose shared scan build progress (openclaw#166498) Source-commit: 66d898f fix(e2e): normalize registry helper image modes (openclaw#163188) Source-commit: 1a09bec fix: MiniMax live validation misses Code Mode file reads (openclaw#163619) Source-commit: fc23bc8 fix(test): read canonical ACP upgrade metadata Source-commit: 46c8dd2 fix(qa): remove unavailable Telegram emoji fixture (openclaw#164956) Source-commit: e785c56 fix(release): reconcile full validation regressions (openclaw#166200) Source-commit: a3e349e fix(release): unblock stable validation evidence (openclaw#166315) Source-commit: 5ac0f82 fix(release): unblock 2026.9.9 full qualification (openclaw#166341) Source-commit: 8aa6d7c test(irc): await owned monitor signals (openclaw#163180) Source-commit: 429ea8c fix(release): unblock 2026.9.9 full validation (round 4) (openclaw#166485) Source-commit: ccb390b fix(release): repair Doctor teardown and FRV evidence recovery Source-commit: 5d7fa8e fix(release): bound FRV job reads and normalize ghost evidence Source-commit: 1854d41 test(release): align priority fixture with bounded job pages Source-commit: 4fd4fcc fix(test): keep MCP validation connected after automatic pairing approval (openclaw#166849) Source-commit: 0979efd fix(release): address 2026.9.9 validation failures and retain diagnostics (openclaw#166962) Source-commit: a024875 fix(release): repair fleet and CLI validation fixtures (openclaw#166977) Source-commit: b899f42 fix: keep 2026.9.9 upgrades on state schema 19 (openclaw#166959) Source-commit: bcfc888 fix(ui): keep passive chat viewers following incoming turns Source-commit: 6d9689d fix(doctor): commit transcript archive migration progress per batch and honor interruption (openclaw#165837) Source-commit: 3a085ea fix(doctor): restore release repair settlement Source-commit: fab3a66 fix(release): reconcile FRV backports Source-commit: 0c01cc6 fix(ui): refresh end geometry during interaction (openclaw#166239) Source-commit: 5b71763 fix(ui): preserve follow intent across content growth (openclaw#166258) Source-commit: ffcdd4d fix(ui): gate content follow on height changes (openclaw#166301) Source-commit: 4964263 fix(release): preserve gateway fixture close callback (openclaw#166348) Source-commit: 64ad20a test(ui): await collaborator smooth follow (openclaw#166285) Source-commit: 90abf6a Co-authored-by: Eric Curtin <[email protected]> Co-authored-by: Ayaan Zaidi <[email protected]> Co-authored-by: Peter Steinberger <[email protected]> Co-authored-by: Abdel Gomez-Perez <[email protected]> Co-authored-by: Patrick Erichsen <[email protected]> Co-authored-by: Vincent Koc <[email protected]>
Closes #164470
What Problem This Solves
Copilot agents' plugin and MCP tool calls fail with "Async work scope is closed" from the second turn of a session. The SDK dispatches handlers in the async context of the turn that opened its pooled client; that turn's work scope has already closed.
User Impact
Plugin tools keep working on later turns of the same Copilot session. Each tool executes in its own attempt's context, preserving the existing ordering and cancellation checks. No config, dependency, or stored-data changes.
Thanks to @takyyon for the report and @ericcurtin for the fix and regression test.
Evidence
Verified
46abd50abe601cf04e4737a8b96c64f0d86ea207in isolated Linux ARM64 Docker with Node 24.21.0 and the real@github/copilot-sdk1.0.14. No Copilot account or token was used.Real Gateway → Copilot SDK → plugin tool, two turns
An actual Gateway loaded the Copilot runtime and a synthetic
proof_echoplugin. A local OpenAI-compatible HTTPS stub returned aproof_echotool call and then the tool result on each turn. Both turns used the same Gateway session and the same SDK session/pool. The real SDK, per-attempt BYOK proxy, tool bridge, host capabilities, and plugin cancellation wrapper all ran; none was mocked.The model endpoint was the only network fixture: a test-only Node TLS socket-routing preload mapped the fixture's public HTTPS hostname to the isolated local stub, with its fixture CA explicitly trusted. This was necessary because OpenClaw correctly rejects private BYOK endpoint URLs. No SSRF guard or production source was disabled or patched for the fixture.
Commands used the built
pnpm openclaw --profile p164470cand gateway runand twopnpm openclaw --profile p164470cand agent --session-key agent:main:proof164470 --message ... --jsoninvocations. Home, state, config, and workspace were isolated inside the container.tool-bridge.tsfrom main067c818979492aa78c97932f7a2f231d467acb59, rebuiltECHO:marker_5, 1 call / 0 failurestool 'proof_echo' failed: Async work scope is closed, 1 call / 1 failureECHO:marker_1, 1 call / 0 failuresECHO:marker_3, 1 call / 0 failuresBaseline SDK session:
60d862c7-a7aa-4e9c-9dd8-cf5a683bb340on both turns. Candidate SDK session:0b9ac304-89de-4e79-9297-0399e9f41d2bon both turns. The baseline bridge differs from the candidate only by this PR's context restoration.Candidate terminal receipts named
agentHarnessId: copilotandsuccessfulToolNames: [proof_echo]on both turns. Baseline turn 2 had an empty successful-tool list and the exact reported error.Controls and regression
openclawruntime also executedproof_echosuccessfully through the real Gateway:PROOF_DONE ECHO:marker_1, 1 call / 0 failures, runbcc7ebac-2bcd-496e-9241-4ecf37ca0b9f.PROOF_TOOL_EXECUTED CANCEL_CONTROL, thenchat.abortreturnedaborted: true, thenPROOF_TOOL_ABORTED CANCEL_CONTROLfour milliseconds after the abort request. The agent exited 1 withsummary: aborted,stopReason: rpc(run98808fd3-79f2-4e17-9553-2a8288c4543a).pnpm test extensions/copilot/src/tool-bridge.test.ts --maxWorkers=1 -t 'async context'fails with expectedturn-2, receivedturn-1(14.08 s wall).pnpm test extensions/copilot/src/tool-bridge.test.ts --maxWorkers=1passes all 40 tests, including the context regression and queued-abort control (42.54 s wall). Initial fixture setup overlapped a build with test compilation and invalidated the compiler snapshot; the reported passing run used frozen inputs.openclaw/ci-gateare green: https://github.com/openclaw/openclaw/actions/runs/37168147340 . No CI reruns requested.Live provider smoke
One real
openai/gpt-5-minicall on the candidate's non-Copilotopenclawruntime returnedLIVE_164470_OK(run0983d6d0-995b-43ee-9826-40becf18d245, 4.492 s, 6,128 input / 331 output tokens). Passive proxy capture recorded HTTP 200 andresponse.completed, withmax_output_tokens: 4096and reasoning effortlow. Response model wasgpt-5-mini-2025-08-07. The CLI exited 0. Capture cleanup recorded a body-abort after the completed response, and SQLite logged a reclamation cleanup rejection; neither prevented the completed model result. An earlier explicit-forward-proxy fixture was blocked locally before reaching the provider; it was corrected to passive capture.No overlap with Pash/Sarah changes.