Skip to content

feat(amp): support enterprise workspaces with daily cost history - #5128

Open
gmmeyer wants to merge 1 commit into
steipete:mainfrom
gmmeyer:amp-enterprise-cost-history
Open

gmmeyer wants to merge 1 commit into
steipete:mainfrom
gmmeyer:amp-enterprise-cost-history

Conversation

@gmmeyer

@gmmeyer gmmeyer commented Nov 19, 2026

Copy link
Copy Markdown

Summary

Amp accounts whose usage is paid by an enterprise workspace report no balance or quota, only a line like Workspace <name>: usage paid by your enterprise. The parser rejected that output with "Missing Amp usage data", so Amp showed nothing for these accounts.

  • Parse enterprise-paid workspaces; plan shows as "Enterprise" with a Workspace <name> row under Credits.
  • Feed the shared cost history from amp usage --details: 30-day recorded cost and tokens, plus per-day cost, tokens, cache split, and per-model breakdowns.
  • Opt Amp into the inline menu card dashboard (Today / 30d / Latest tokens / 30d tokens, daily chart, top model), the cost-history submenu, and Usage & Spend.

How it works

amp usage --details only reports tokens and models for the whole requested range; its daily table has cost only. So the probe runs one 30-day query, then one single-day query per day that had spend, up to eight at a time in a drained task group. Days that ended more than six hours ago are cached in memory for the life of the process. A failed day query drops that day and marks the history partial; a failed 30-day query leaves the account loaded without history.

Costs are labelled "Recorded cost reported by Amp" and carry vendorMetered provenance, since they are billed amounts and not estimates. Days are bucketed by the local calendar.

Trade-offs

  • First refresh after launch is slow for active accounts: about 12 seconds for an account with spend on most of the last 30 days. Later refreshes should only re-query unsettled days; I have not timed one.
  • Only the CLI source gets history. Non-enterprise accounts are unchanged.

Testing

  • swift test --filter 'InlineCostHistoryDashboardLabelTests|AmpUsageParserTests|SpendDashboardModelTests|MenuCardModelTests|AmpTierMenuRegressionTests': 229 tests pass.
  • New tests cover enterprise parsing, the probe with a stub amp script (daily tokens/cost/models, partial history, details failure), local-day overlap, and the Amp inline dashboard tiles.
  • Ran the packaged app and CLI against a real enterprise account; CLI output shows the 30-day cost and token totals. I did not capture a screenshot of the menu card.

Not run: make check (SwiftFormat/SwiftLint are not installed on this machine) and the full suite. Leaving both to CI.

Enterprise-paid Amp workspaces report no balance, so the parser failed with "Missing Amp usage data". Parse them, and feed the shared cost-history chart and inline menu card with per-day recorded cost, tokens, and models from `amp usage --details`.
@clawsweeper

clawsweeper Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-19T16:19:31.566731Z 0d019bb PR opened
ℹ️ 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: 0d019bba3e

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +130 to +131
sessionTokens: today?.totalTokens ?? 0,
sessionCostUSD: today?.costUSD ?? 0,

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 Preserve unknown values when today's Amp query fails

When today's per-day amp usage --details call times out or fails, recentUsage omits that day and sets dailyUsageIsPartial, but these fallbacks still publish exact zeroes for today's tokens and cost. The new inline Amp dashboard consumes the session fields directly, so it reports 0 / $0.00 instead of an unknown value even though today's bucket was never read; keep these fields nil when the relevant day is missing from a partial scan.

Useful? React with 👍 / 👎.


public init() {
self.arguments = ["usage"]
self.calendar = .current

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 Use the configured statistics zone for Amp buckets

When the user selects a Statistics time zone different from the Mac's current zone, or travels after the zone was pinned, this hard-coded .current makes Amp's query bounds and day keys use the Mac zone while UsageStore and Usage & Spend interpret those keys with settings.costUsageBucketCalendar. Midnight-adjacent usage is then assigned to the wrong configured day and can cross a reporting-period boundary, so the configured bucket calendar needs to be threaded into the probe.

Useful? React with 👍 / 👎.

@clawsweeper clawsweeper Bot added clawsweeper:intake:feature Preliminary submission classification; full source review pending. P2 Normal priority bug or improvement with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:feature Preliminary submission classification; full source review pending. labels Nov 19, 2026
@clawsweeper

clawsweeper Bot commented Nov 19, 2026

Copy link
Copy Markdown

Codex review: needs real behavior proof before merge.

What this changes

This PR recognizes enterprise-paid Amp workspaces and adds CLI-derived daily cost, token, and model history to existing spend displays.

Example: Amp returns Workspace acme: usage paid by your enterprise without a balance.

  • Before: CodexBar rejects the response with “Missing Amp usage data.”
  • After: CodexBar displays the Enterprise account and attempts to collect its recorded usage history.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The enterprise repair is useful, but two reporting defects remain and the asserted live run is not accompanied by reviewable evidence.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🦪 silver shellfish (2/6) 2 actionable review findings remain.

Product

Kind: Feature · Worth it: Needs a maintainer decision · Fix scope: Complete
User problem: Enterprise-paid Amp users see no account usage because their CLI response contains no balance; they also lack recorded spend history.
Reason: The parser repair is justified, while automatic multi-query history collection and enabling additional spend surfaces extend the existing product contract.

Merge readiness

⛔ Blocked before merge - 3 items remain

Keep open: enterprise-only accounts expose a real parser gap, but this PR introduces two reporting defects and its broader history feature needs owner direction.

Priority: P2
Reviewed head: 0d019bba3e12f826e0684b777c5eafe6cd2e17dc
Owner decision: Required. See Decision needed.

Decision needed

  • Question: Should enterprise recognition include automatic 30-day history collection with up to eight simultaneous Amp subprocesses, or should recognition land first?
  • Recommendation: Land enterprise recognition first: Keep the parser and account display repair focused, and review history collection separately.
  • Why: The parser repair has clear value, but the additional history capability changes refresh cost and presentation without a recorded owner decision.

Before merge

  • Add real behavior proof - The body reports a packaged app and CLI run against an enterprise account but supplies no transcript, logs, screenshot, or linked artifact; the supplied executable coverage uses a stub Amp script rather than the installed provider. After adding proof, update the PR body, then request a new review with @clawsweeper re-review. The PR author or someone with repository write access can request it.
  • Preserve unknown totals when today's detail query fails (P2) - If yesterday's detail query succeeds but today's query fails, recentUsage omits today and marks history partial. These fallbacks nevertheless publish session cost and tokens as exact zeroes, so the Today cost tile displays $0.00 despite unread usage. Preserve nil for unavailable fields in a partial scan, while retaining zero for a successfully established empty day.
  • Use the configured statistics calendar throughout Amp history (P2) - With Statistics time zone set to UTC and the Mac in America/New_York, usage at 2026-11-19T02:00:00Z is queried and labelled as November 18 instead of November 19. UsageStore and Usage & Spend interpret those date keys using settings.costUsageBucketCalendar, producing incorrect daily attribution and reporting-period boundaries. Pass the configured calendar through production querying and snapshot conversion instead of fixing the probe to .current.

Findings

  • [P2] Preserve unknown totals when today's detail query fails — Sources/CodexBarCore/Providers/Amp/AmpUsageSnapshot.swift:130-131
  • [P2] Use the configured statistics calendar throughout Amp history — Sources/CodexBarCore/Providers/Amp/AmpCLIProbe.swift:12-14

Tests

  • Missing end-to-end proof: Provide redacted branch-built CLI output showing enterprise history and a menu capture showing its dashboard; focused regressions should also demonstrate base failure and corrected-head success for missing-today and pinned-time-zone cases.
Agent review details

How this fits together

The Amp provider reads CLI or API display text, parses account usage, and projects snapshots into shared menu and spend models.

flowchart TD
  A[Amp fetch strategy] --> B[Amp CLI usage]
  B --> C[Usage parser]
  C --> D[Enterprise snapshot]
  D --> E[Daily detail queries and memory cache]
  E --> F[Shared cost snapshot]
  F --> G[Menu and Usage Spend]
Loading

Technical review

Best possible solution:

Preserve enterprise recognition and, if history is approved, use the configured statistics calendar and retain unknown values for unread days.

Do we have a high-confidence way to reproduce the issue?

Main's parser deterministically rejects enterprise-only output because it requires a recognized quota or balance; this was verified from source without executing target code.

Is this the best way to solve the issue?

Enterprise recognition fits the existing parser and detail-row owners; the history implementation reuses shared displays but currently violates unknown-value and statistics-calendar semantics.

Full review comments:

  • [P2] Preserve unknown totals when today's detail query fails — Sources/CodexBarCore/Providers/Amp/AmpUsageSnapshot.swift:130-131
    If yesterday's detail query succeeds but today's query fails, recentUsage omits today and marks history partial. These fallbacks nevertheless publish session cost and tokens as exact zeroes, so the Today cost tile displays $0.00 despite unread usage. Preserve nil for unavailable fields in a partial scan, while retaining zero for a successfully established empty day.
    Confidence: 0.99
  • [P2] Use the configured statistics calendar throughout Amp history — Sources/CodexBarCore/Providers/Amp/AmpCLIProbe.swift:12-14
    With Statistics time zone set to UTC and the Mac in America/New_York, usage at 2026-11-19T02:00:00Z is queried and labelled as November 18 instead of November 19. UsageStore and Usage & Spend interpret those date keys using settings.costUsageBucketCalendar, producing incorrect daily attribution and reporting-period boundaries. Pass the configured calendar through production querying and snapshot conversion instead of fixing the probe to .current.
    Confidence: 0.98

Overall correctness: patch is incorrect
Overall confidence: 0.97

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 1f6da9bec444.

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit ae159ec adds Sources/CodexBarCore/Providers/Amp/AmpProviderDescriptor.swift:67 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: ae159ec81f18; files: Sources/CodexBarCore/Providers/Amp/AmpProviderDescriptor.swift)
  • Josh Black-Star: Raw commit 5e119a9 adds Sources/CodexBarCore/Providers/Amp/AmpUsageSnapshot.swift:161 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 5e119a9ad76e; files: Sources/CodexBarCore/Providers/Amp/AmpUsageSnapshot.swift)
  • Lucas Duailibe: Raw commit 7c1d0a2 adds Sources/CodexBarCore/Providers/Amp/AmpProviderDescriptor.swift:12 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 7c1d0a2bc987; files: Sources/CodexBarCore/Providers/Amp/AmpProviderDescriptor.swift)

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add P2: Useful enterprise-provider support with limited scope; the introduced defects affect usage reporting rather than core application availability.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Label justifications:

  • P2: Useful enterprise-provider support with limited scope; the introduced defects affect usage reporting rather than core application availability.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed November 19, 2026, 11:25 AM ET / 16:25 UTC.

This branch has not been deployed

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

Labels

P2 Normal priority bug or improvement with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant