Skip to content

fix: never call the provider for a task cancelled during model setup - #101

Open
nvtoan0201-swe wants to merge 1 commit into
CopilotKit:mainfrom
nvtoan0201-swe:fix/cancel-before-model-run
Open

nvtoan0201-swe wants to merge 1 commit into
CopilotKit:mainfrom
nvtoan0201-swe:fix/cancel-before-model-run

Conversation

@nvtoan0201-swe

Copy link
Copy Markdown

What changed

executeModelTask awaits the agent identity and memories before it registers its abort listener. AbortSignal.addEventListener never fires for an already-aborted signal, so a task paused or cancelled during those reads still started a full model run — provider calls and credits spent for work the user had already stopped.

The task signal is now checked right after the setup reads, before agent.run() is reached, so the cancellation path re-queues/pauses without contacting the provider.

The new regression test in tests/model-worker.test.ts delays the identity read, pauses the task while it is preparing, and asserts the fixture provider received zero requests. I verified the test fails on the previous code (1 !== 0) and passes with the fix.

Verification

  • pnpm test — 277 pass, 0 fail (1 new)
  • pnpm lint
  • pnpm typecheck

Integration limits

Fixtures only; no live provider was called. This closes the setup window; aborts after agent.run() starts were already handled by the existing listener.

AI assistance was used to prepare this change; I reviewed the code, tests and checks above.

executeModelTask reads the agent identity and memories before registering its abort listener, and addEventListener never fires for an already-aborted signal. A task paused or cancelled inside that window still started a full model run. Check the signal after the setup reads so the run is rejected before any provider request. The new regression test cancels while the identity read is pending and asserts the fixture provider saw zero requests.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant