Skip to content

fix(usage): reject pre-cancelled quota waits - #734

Open
outlier27-cell wants to merge 1 commit into
openpi-dev:mainfrom
outlier27-cell:fix/issue-733-usage-cancel
Open

outlier27-cell wants to merge 1 commit into
openpi-dev:mainfrom
outlier27-cell:fix/issue-733-usage-cancel

Conversation

@outlier27-cell

Copy link
Copy Markdown
Contributor

Problem

Closes #733. waitForUsage() can return an already-fulfilled credential or quota result after its caller's AbortSignal has already been cancelled. This lets a cancelled /usage collection observe stale data at the shared waiting boundary.

Value

Cancellation now wins before a provider result becomes observable, preserving the caller's lifecycle boundary without taking ownership of Pi's credential-refresh operation.

Approach

Check signal.throwIfAborted() before registering the promise race. Keep the existing in-flight abort listener and cleanup behavior unchanged. Add a deterministic regression that uses a pre-cancelled signal and an already-fulfilled promise, and verifies that the original cancellation Error identity is preserved.

Validation

  • node --test --experimental-strip-types tests/extensions/usage/providers.test.ts (13 passed)
  • Direct production-helper repro now reports { "returnedResult": false, "keptReason": true }.
  • bun run check completed its config, docs, discipline, web, format, lint, and typecheck gates without reported errors.
  • bun run test was run after the isolated worktree dependency install; its child processes completed without a reported failure.
  • git diff --check

Impact

  • User-visible behavior: a cancelled /usage wait no longer emits a result that was already available.
  • Model-visible tools and schema: unchanged.
  • Runtime lifecycle: only pre-cancelled wait admission changes; in-flight cancellation, provider requests, and cache storage retain their existing owners.
  • Persisted data and configuration: unchanged.

@outlier27-cell

Copy link
Copy Markdown
Contributor Author

@tt-a1i 请审核此 PR。#733 的最小取消边界修复已在 0cdac2c 完成,完整 exact-head GitHub CI(Node、Windows、UI、E2E)均通过;当前可合并,仅等待审核。

@outlier27-cell

Copy link
Copy Markdown
Contributor Author

@testikun @tt-a1i 请审核此 PR。最新提交的 CI 已通过,当前仅等待维护者审核与合并。

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.

fix(usage): reject a pre-cancelled quota wait before returning a cached result

1 participant