Coalesce overlapping cost refreshes - #177
Open
SiavashShams wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 andstop()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.