Skip to content

fix: exclude same-millisecond replayed usage from scan budgets - #631

Open
mldangelo-oai wants to merge 7 commits into
mdangelo/codex/fix-local-diff-input-confinementfrom
mdangelo/codex/fix-scan-budget-attribution
Open

fix: exclude same-millisecond replayed usage from scan budgets#631
mldangelo-oai wants to merge 7 commits into
mdangelo/codex/fix-local-diff-input-confinementfrom
mdangelo/codex/fix-scan-budget-attribution

Conversation

@mldangelo-oai

@mldangelo-oai mldangelo-oai commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator

Summary

Replayed parent turns can share a UUIDv7 millisecond with a child scan. Comparing only that timestamp can charge inherited token snapshots to the child and inflate its scan budget.

Changes

  • Compare the complete UUIDv7 order in live TypeScript tracking and bundled Python usage collection.
  • Preserve the existing timestamp fallback for identifiers that are not UUIDv7.
  • Advance the bundled plugin identity from the parent version 0.1.45 to 0.1.46, keeping the public plugin manifest and SDK constant synchronized.
  • Cover lower-order replay exclusion, higher-order child ownership, and replacement of a previously cached collector.
  • Inherit descriptor-bound parent confinement, benign missing or unreadable file compatibility on Unix and Windows, and installed-plugin safety-identifier forwarding coverage without changing public CLI behavior.

Testing

  • bun test --timeout 30000 --seed 12345 tests-ts/cost.test.ts: 60 passed.
  • bun test --timeout 30000 --seed 12345 tests-ts/diff-rank-input.test.ts: 6 passed with 97 assertions, including the real parent-replacement race, genuine Windows missing, denied, sharing, and lock-violation leaf errors, fatal parent and reparse controls, and installed-plugin safety coverage.
  • bun test --timeout 30000 --seed 12345 --test-name-pattern 'upgrades the predecessor bundled cache and restores with the SDK-owned helper' tests-ts/runtime.test.ts: 1 passed.
  • pnpm run types, pnpm run build, and pnpm run format: passed.
  • git diff --check: passed.

Risk and rollout

Non-UUIDv7 sessions keep the existing timestamp fallback. Pricing, public APIs, and CLI behavior are unchanged. The distinct plugin version replaces older cached collectors while preserving the reviewed parent stack and installed-plugin safety forwarding.

Public disclosure review

  • No customer, partner, prospect, or user identities, data, or identifying details are included.
  • No credentials, personal data, private source, scan findings, or nonpublic links or tickets are included.
  • I reviewed the branch name, title, description, commits, changes, comments, logs, screenshots, attachments, and links for public disclosure.

@mldangelo-oai

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Aug 24, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-08-25T05:18:13.377563Z adb1201 Manual request
🔒 Security Review Completed 2026-08-25T05:19:19.831535Z adb1201 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: cb3e851450

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@kmbroai kmbroai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Critical review

Reviewed cb3e851450b603fddecdb1d8fe0a72f07285f9a3, against its declared #630 base. The same-millisecond attribution fix is justified; no blocking correctness issue found.

Necessity and correctness

Counting replayed parent usage as new child usage can terminate a scan against a user-requested cost limit. Comparing only the UUIDv7 timestamp cannot distinguish two IDs created within one millisecond. The change keeps the full ordering in both the live tracker and the bundled collector, so those paths agree about the inherited baseline. BigInt in TypeScript avoids losing the low ordering bits through Number conversion.

There is an important compatibility assumption: UUIDv7 format alone does not promise ordering within a millisecond. This relies on the producer's monotonic generator. I checked current public upstream source: Codex thread IDs and submission IDs use Uuid::now_v7, whose documented guarantee is creation order within the same process. Keep that producer relationship explicit; do not broaden this comparison to unrelated imported UUIDs or assume it proves cross-process chronology. This was a current-source check, not a rebuild of the pinned Codex runtime.

Simplification and scope

The production change is small and appropriately avoids a new attribution ledger. Keep the existing non-UUID fallback rather than adding arbitrary ID rejection. The bundle-version change is necessary for the Python collector to reach cached installations; coordinate it with the #623#626#630 stack rather than treating this as an independent version bump on main.

The test setup is much larger than the logic. The lower/higher same-millisecond controls and cross-runtime usage comparison are useful. The mock marketplace installer and exact bundle-version expectations would fit better in the existing runtime-upgrade fixture than being duplicated inside cost tests. The CODEX_SAFETY_IDENTIFIER assertion is unrelated to replay attribution and can stay in the package/environment tests. Preserve the installed-collector check, but reuse the existing setup where possible.

Verification

Ran cost.test.ts and diff-rank-input.test.ts with seed 12345: 64 passed, 0 failed, Bun 1.3.14/Linux with locally available dependencies. This includes the cached-collector and cross-runtime controls. No real billing, live model call, full clean install, or native platform matrix was exercised.

@faizan-oai faizan-oai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed this PR's replay-attribution delta against #630. All 60 cost tests, typecheck, and current-head CI pass. No blocking findings in this delta; #630's separate review discussion remains unresolved.

@mldangelo-oai

Copy link
Copy Markdown
Collaborator Author

@codex review

@mldangelo-oai

Copy link
Copy Markdown
Collaborator Author

@codex security review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: 5483c74b97

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

Security review completed. No security issues were found in this pull request.

Reviewed commit: 5483c74b97

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@faizan-oai faizan-oai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed 5483c74b against its declared #630 base; no blocking code finding in this PR's replay-attribution delta. The restack preserves the previously reviewed production logic, and 71 focused local tests plus typecheck pass. The existing within-process UUIDv7 ordering qualification still applies; this does not approve parent changes.

Holding current-head approval for the failed full CI run. In Windows Node 24 shard 6, test-reports.test.ts:113 receives spawnSync status null instead of 0; both Windows aggregate checks consequently fail. That test and its Bash resolver are unchanged, and all 60 cost tests pass in the same job. The underlying spawn error is not logged, so this is not a demonstrated budget regression or a proven flaky failure. Please obtain a successful full current-head run.

@mldangelo-oai

Copy link
Copy Markdown
Collaborator Author

@codex review

@mldangelo-oai

Copy link
Copy Markdown
Collaborator Author

@codex security review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: 7cc7c65b9c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

Security review completed. No security issues were found in this pull request.

Reviewed commit: 7cc7c65b9c

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@mldangelo-oai

Copy link
Copy Markdown
Collaborator Author

@codex review

@mldangelo-oai

Copy link
Copy Markdown
Collaborator Author

@codex security review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: adb12010bf

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

Security review completed. No security issues were found in this pull request.

Reviewed commit: adb12010bf

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@faizan-oai faizan-oai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed adb12010bf4676cb9ff9eb0c78fdb56d42a39ac2 against declared base 446ff8fdbe08bdcb9a341a25fe79c867f1ed9e03 (#630). No blocking concern in this PR's replay-attribution delta; its own patch is unchanged from the previously reviewed restack.

The 67 focused cost/diff-input/cache tests and incremental formatting, syntax, version, and diff checks passed on this head. Full current-head node-ci 32812126779, attempt 2 now passes all 25 jobs, including native Windows. Head, base, CI, and discussions were rechecked before approval; no unchanged local suite was rerun for this CI-only follow-up. My earlier CI-hold comment concerned 5483c74b, not this head.

Approval covers only this PR's delta, not its parents. The existing within-process monotonic UUIDv7 qualification remains; upstream producer behavior and live billing/model execution were not revalidated.

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.

3 participants