Skip to content

fix: label incomplete scan usage and show measurement times - #1640

Merged
ianw-oai merged 4 commits into
mainfrom
dev/ianw/scan-usage-attribution
Oct 19, 2026
Merged

ianw-oai merged 4 commits into
mainfrom
dev/ianw/scan-usage-attribution

Conversation

@ianw-oai

@ianw-oai ianw-oai commented Oct 14, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Report partial token usage when scan-owned workers have missing receipts or unfinished turns. Preserve recorded tokens instead of treating missing usage as a complete zero.

Changes

  • Rebase onto current main and preserve the per-response receipt recovery, retry discovery, and final-response accounting from fix: correct underreported token totals in Codex Security scans #1657.
  • Save usage alongside SDK cost estimates, with parent and worker counts, measurement times, and historical account-limit readings.
  • Preserve interrupted or unmeasured-turn warnings after later successful work. Adapt the regressions from fix: preserve closed-turn usage coverage gaps #1759, including delayed receipts and recorded zero usage.
  • Keep the host's completion-turn handoff and sealed scan artifacts unchanged. Deep stopping rules do not change.
  • Report partial usage as “at least X tokens; some usage unavailable.” Explain that local coverage does not prove exhaustive server-side accounting or subscription allowance.
  • Shorten an equivalent test fixture literal to fix the source-size check already failing on main. Update scan-history assertions for the additive usage envelope.

Testing

  • Collector: 100 passed, two platform-specific skips, including the started-only worker and retained per-turn gap regressions.
  • Ruff lint and formatting, SDK TypeScript checks and build, plugin source compatibility, and nine source-check tests passed.
  • Full Python suite: 1,952 passed, 77 platform-specific skips, and 292 subtests passed.
  • See the Checks tab for full SDK and cross-platform CI results.

Risk and rollout

Usage metadata is additive. Existing cost fields remain unchanged. Consumers can see partial coverage where earlier versions reported complete coverage. The exact parent completion turn can extend the saved measurement window to include its final response.

These checks flag gaps visible in local records. They do not recover unrecorded server responses or establish a billing total. Native cancellation, scan results, and stopping behavior are unchanged.

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.

@github-actions github-actions Bot added the bug Something isn't working label Oct 14, 2026

@mldangelo-oai mldangelo-oai 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.

Thanks for making the measurement window and partial coverage explicit. Keeping measured usage alongside the separate cost estimate is useful, and the shared reporting guidance explains the distinction well.

One concrete cleanup before merging: test_cli_scan_history_persists_per_scan_cost still requires the raw cost_json value to equal the old flat cost object, so all three pricing variants fail. I suggest deleting only the direct SQLite read/equality block at test_workbench_scan_history.py:523-528. The preceding fresh list-scans and get-scan calls already verify the full persisted cost through the public contract. I tested that deletion in memory; all three variants passed.

Two optional follow-ups:

  • _read_rollout_usage can require a finite completion timestamp now that its production caller always supplies one. Giving the parity fixture a fixed cutoff would remove three nullable-window branches.
  • Consider preserving valid account-limit observations when only token reconciliation fails. A synthetic delayed-cache case retained a valid allowance reading in the rollout reader, but the collector's token_breakdown_unavailable return discarded it and the observation timestamps. This would also need a narrow update to the unavailable-usage validator. If deferred, a short documentation caveat would clarify that these observations can be omitted when token attribution fails.

The remaining role, window, and incomplete-measurement tests look useful; I would keep them.

@ianw-oai
ianw-oai force-pushed the dev/ianw/scan-usage-attribution branch from b61bc41 to 00b2902 Compare October 19, 2026 17:45
Adapt the closed-turn coverage checks and regression cases from #1759 to the rebased collector. Keep open-turn warnings and completion-turn handoff behavior.
@ianw-oai
ianw-oai marked this pull request as ready for review October 19, 2026 18:31
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 19, 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
🔒 Security Review ✅ Completed 2026-10-19T18:34:44.266205Z 42670e4 Draft marked ready
ℹ️ 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.

@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.

No blocking issues found in 42670e4. Recorded token counts are preserved when coverage is partial, the regression cases from #1759 are included, and Deep stopping rules are unchanged. Reviewed the code and existing CI results; no local tests were run.

@ianw-oai
ianw-oai merged commit 03c7359 into main Oct 19, 2026
109 of 149 checks passed
@ianw-oai
ianw-oai deleted the dev/ianw/scan-usage-attribution branch October 19, 2026 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants