Skip to content

fix(agent): isolate cancellation of shared context estimates - #19

Merged
w01fb0ss merged 2 commits into
w01fb0ss:mainfrom
agooll:fix/context-estimate-cancellation
Nov 25, 2026
Merged

w01fb0ss merged 2 commits into
w01fb0ss:mainfrom
agooll:fix/context-estimate-cancellation

Conversation

@agooll

@agooll agooll commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

What and why

Fixes #18. Concurrent context estimates for one session share a file read. The shared calculation used the first caller's cancellation signal, while a later caller awaited the shared promise without applying its own signal.

Apply cancellation to each caller's wait and keep the in-flight entry until the shared calculation settles. Both callers can still reuse a single read.

Checks

  • One topic
  • pnpm verify passes locally
  • No UI changes
  • No secrets, .env files or local paths
  • Commit signed off (DCO)

Both cancellation arrangements failed before the fix. The Agent Vitest project passed all 65 tests with the patch. Biome and git diff --check passed. The regression uses a temporary session file and a gated runtime fixture.

Keep the per-session estimate running for other callers when an individual request is cancelled.

Signed-off-by: agooll <141763834+agooll@users.noreply.github.com>
Signed-off-by: agooll <141763834+agooll@users.noreply.github.com>
@w01fb0ss

Copy link
Copy Markdown
Owner

Thanks for the clear report and the focused fix! I traced it through chat.contextHint and can confirm both arrangements on our side: a second caller failed with the first caller's timeout reason. The change looks right to me. untilAborted handles an already-aborted signal, each waiter attaches its own rejection handler so a shared failure after everyone cancelled doesn't become an unhandled rejection, and moving the cleanup to .finally keeps the in-flight entry until the read settles. The trade-off that the shared parse now always finishes (and fills the cache) even if every caller cancelled seems fine to me. Happy to merge this; it will ship in v0.0.4. Thank you!

@w01fb0ss
w01fb0ss merged commit 64c9498 into w01fb0ss:main Nov 25, 2026
6 of 7 checks passed
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.

Cancelling one context estimate can fail another request for the same session

2 participants