Skip to content

Display agent usage data - #118

Merged
itsjling merged 10 commits into
mainfrom
codex/issue-107-usage
Sep 1, 2026
Merged

Display agent usage data#118
itsjling merged 10 commits into
mainfrom
codex/issue-107-usage

Conversation

@itsjling

@itsjling itsjling commented Aug 31, 2026

Copy link
Copy Markdown
Owner

What changed

  • collect documented provider usage from Codex, Claude, and OpenCode without estimating unsupported fields
  • aggregate Agent note, Review chat, and combined totals for the current Review
  • show complete, partial, unavailable, and zero states in both terminal output and the live Review page
  • keep the Agent note first in the reading order and place usage in a collapsed disclosure beneath the active note/chat content
  • reset usage on Review changes, count reported failed/retried calls, and keep reused notes at zero
  • fence chat usage from stale snapshot responses and stale provider completions so older work cannot discard or contaminate the current Review's totals
  • include the usage runtime in the published package

Verification

  • pnpm run lint — passed (one existing generated coverage warning)
  • pnpm run docs:check — passed with 0 errors, warnings, hints, or broken links
  • pnpm test — passed on the latest merged head: unit 201/201, integration 144/144, coverage 154/154, browser 26/26, platform 3/3
  • the 320px browser regression verifies usage is below the Agent note, collapsed by default, expandable, live-updated, accessible, and free of horizontal overflow
  • focused fake-provider suites cover complete, partial, unavailable, failed, retry, cache-read, cache-write, reuse, chat-only snapshots, Review reset, stale-response ordering, and provider completion before watcher refresh

UI proof

Captured from the final usage layout on da23bd62f5479fa3034d04f8a67687e9826b745a. Later commits only fence server-side usage state and merge upstream picker-progress/release-workflow changes.

Collapsed by default beneath the Agent note:

Collapsed Agent usage disclosure

Expanded usage details:

Expanded Agent usage disclosure

Closes #107

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Aug 31, 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-09-01T09:36:29.688381Z dbf9c43 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 chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 360d5471a5

ℹ️ 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".

Comment thread scripts/generate-summaries.mjs Outdated
@itsjling

itsjling commented Sep 1, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0e67bf3567

ℹ️ 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".

Comment thread scripts/build-diff-data.mjs
@itsjling

itsjling commented Sep 1, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: fb91aba389

ℹ️ 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".

@itsjling

itsjling commented Sep 1, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e4c2d382d8

ℹ️ 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".

Comment thread scripts/serve-built.mjs
if (!snapshot) return fileResponse(output, { live: true });
const fingerprint = snapshot?.notes?.reviewFingerprint;
if (!fingerprint) return fileResponse(output, { live: true });
const chatSummary = currentChatUsage(fingerprint);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Avoid resetting chat usage from stale snapshot reads

When refreshes overlap while the review file is replaced, an earlier readFile can return the old fingerprint after a later request has already initialized and recorded usage for the new review. Calling the mutating currentChatUsage(fingerprint) from this response path then switches the global accumulator back to the old review and discards those new-review totals; the frontend's request-order guard cannot prevent this server-side mutation. Only reset usage from the authoritative refreshed chat state, or reject snapshot fingerprints that no longer match it.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Fixed in 2884df5. Snapshot responses now use a non-mutating usage lookup; only an authoritative chat refresh or a fingerprint-guarded provider event may reset the accumulator. A deterministic read-barrier regression proves a stale response cannot erase the current Review’s chat totals. The full suite passed before the latest main merge, and the merged server/chat/presentation suite passes 47/47.

# Conflicts:
#	tests/browser/review-journey.test.mjs
@itsjling

itsjling commented Sep 1, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: da23bd62f5

ℹ️ 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".

# Conflicts:
#	app/globals.css
#	scripts/present.mjs
#	tests/review-chat.test.mjs
@itsjling

itsjling commented Sep 1, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2884df50e9

ℹ️ 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".

Comment thread scripts/serve-built.mjs
Comment on lines +472 to +476
function recordChatUsage({ reviewFingerprint, usage }) {
if (
!reviewFingerprint ||
reviewChat?.getState().fingerprint !== reviewFingerprint
) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Fence chat usage against the on-disk review

When the snapshot is replaced while a chat provider is running and the child exits before the 100 ms file watcher refreshes reviewChat, this in-memory fingerprint check still accepts the old review's usage. ChildExecution.reportUsage() runs before the provider promise settles and the controller performs its synchronous snapshot fence, so snapshotNoteUsage() can then read the new review and print a combined terminal total containing old-review chat tokens and new-review note tokens. Compare or refresh against the snapshot fingerprint before recording and formatting this usage.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Fixed in 47134b8 and included in current merge head dbf9c43. recordChatUsage now synchronously reads the published snapshot once and requires its on-disk Review fingerprint, as well as the in-memory chat fingerprint, to match the initiating provider event before recording, formatting, or broadcasting usage. The same parsed snapshot supplies Agent-note totals, preventing mixed-review terminal output. A deterministic gated-provider regression advances the published Review while chat state remains stale and verifies that no usage is logged or attributed. The complete post-merge suite passes: unit 201/201, integration 144/144, coverage 154/154, browser 26/26, platform 3/3.

@itsjling

itsjling commented Sep 1, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: dbf9c43292

ℹ️ 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".

@itsjling
itsjling merged commit 5003662 into main Sep 1, 2026
9 checks passed
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.

Display agent usage data

1 participant