Skip to content

fix(cost): coalesce overlapping cost refreshes - #177

Open
SiavashShams wants to merge 1 commit into
openai:mainfrom
SiavashShams:oss/openai-codex-security-issue-31-20260731-0117320700
Open

fix(cost): coalesce overlapping cost refreshes#177
SiavashShams wants to merge 1 commit into
openai:mainfrom
SiavashShams:oss/openai-codex-security-issue-31-20260731-0117320700

Conversation

@SiavashShams

Copy link
Copy Markdown

Fixes #31.

Summary

ScanCostTracker.refresh() appended every request to a promise chain. When a session-tree traversal exceeded the 100 ms polling interval, timer ticks accumulated full traversals and stop() queued more work behind them.

Track one active refresh and one shared follow-up refresh instead. Calls arriving during an active traversal await the same follow-up, including stop(), while successful and failed traversals both advance or reset scheduler state.

The regression blocks session reads, starts three overlapping refreshes plus stop(), and verifies that only two traversals run. On the baseline it failed after starting a third traversal. A separate case verifies recovery after a traversal error.

Verification

  • pnpm dlx bun@1.3.14 test --timeout 30000 ./tests-ts/cost.test.ts — baseline: 14 passed, 1 failed; patched: 15 passed, 0 failed.
  • pnpm dlx bun@1.3.14 test --timeout 30000 ./tests-ts — 708 passed, 5 expected skips, 0 failed.
  • pnpm run types — passed.
  • pnpm run format — passed.
  • pnpm run build — passed.
  • pnpm pack --pack-destination /private/tmp/codex-security-pack — passed.
  • npm_config_cache=/private/tmp/codex-security-npm-cache pnpm run check:package /private/tmp/codex-security-pack/openai-codex-security-0.1.4.tgz — validated the public import, CLI, bundled plugin files, and archive contents.
  • git diff --check — passed.

@mldangelo-oai mldangelo-oai added bug Something isn't working duplicate This issue or pull request already exists labels Aug 3, 2026
@mldangelo-oai mldangelo-oai changed the title Coalesce overlapping cost refreshes fix(cost): coalesce overlapping cost refreshes Aug 3, 2026
@mldangelo-oai

Copy link
Copy Markdown
Collaborator

Thank you for the original cost-polling fix. The follow-up in #198 includes your exact contributor-authored commit and narrows the change to interval polling while preserving the existing tracker API; it is the preferred working branch for #31. #198 is still a draft and requires the normal review process, so this PR is being kept open for context and attribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working duplicate This issue or pull request already exists

Projects

None yet

Development

Successfully merging this pull request may close these issues.

maxCostUsd polling queues full session-tree rescans and can delay budget enforcement

2 participants