Skip to content

fix: integrate cumulative ACP usage snapshots and deltas - #662

Merged
lodystage[bot] merged 14 commits into
mainfrom
fix/acp-usage-snapshots-and-deltas
Sep 15, 2026
Merged

lodystage[bot] merged 14 commits into
mainfrom
fix/acp-usage-snapshots-and-deltas

Conversation

@lodystage

@lodystage lodystage Bot commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

Related issue

Supersedes the closed implementation in #661.

Problem / pressure

Grok reports per-prompt model totals while accounting consumers require cumulative snapshots. Queueing every prompt does not resolve that mismatch. DSH previously did not report token/USD accounting.

Summary

  • Pin Core, Grok and DSH accounting changes; preserve and validate optional Core delta at the client boundary.
  • Coalesce cumulative snapshots instead of the superseded Grok-specific prompt queue; retain acknowledgement-based retry.
  • Update bilingual Spec/Note and remove the obsolete queue-only reproducer.
  • Delta is already included in modelUsage and is not added or sent to the legacy persistence endpoint.

Visual explanation

flowchart LR
  G[Grok prompt totals] --> A[Core operation accumulator]
  D[DSH request usage and USD estimate] --> A
  A --> S[Cumulative modelUsage]
  A --> X[Already-included delta]
  S --> C[CLI snapshot delivery]
  X --> P[Validated optional client field]
Loading

Before / after

Before After
Grok prompt totals consumed as cumulative Adapter accumulates before delivery
DSH lacks accounting updates Per-request tokens and official list-price estimates
Core counter scopes unclear Documented cumulative/delta and replay/reset semantics

Dependencies and rollout

Dependency PRs (publish Core before adapters):

Publish Core first, then release/rebuild Grok and DSH, then ship the consuming application. Do not merge this as a claim that dependencies are already published.

Test plan

  • Core 2, Grok 58, DSH 15, CLI delivery 8 and CLI parser 12 tests passed (95 total).
  • Core build/typecheck, DSH build/format check, Grok build/syntax check, docs check, and public/platform boundary guards passed.
  • CLI suites ran bundled in an isolated dependency harness with real narrow shared exports.
  • Full root check blocked by missing Claude dependencies; root format blocked by a package missing Prettier.
  • No authenticated runtime requests, real transcripts, backend changes or historical data repair.

Context handoff

Instructions for reviewing agents

  • Review focus: Validate adapter cumulative/delta semantics, late corrections, disjoint buckets and dependency gitlinks.
  • Decisions to challenge: Process-local operation retention, request-completion pricing, and keeping legacy Codex compaction separate.
  • Plausible failures / evidence gaps: Restart baselines, unreported background usage, and runtime release/source mapping remain unverified.

Authoring context

  • User goal / directives: Define cumulative and incremental usage semantics in Core and integrate Grok/DSH accounting.
  • Constraints / non-goals: Synthetic fixtures only; no backend mutation, transcript publication or package release.
  • Risk-bearing decisions: Consumers reconcile cumulative snapshots; deltas must never be added twice.
  • Destructive or irreversible behavior: Removed obsolete synthetic reproducer, recoverable through Git; no user data deletion.
  • Deliberately not done or tested: Full-root validation unavailable due missing dependencies; no production model or billing calls.
  • Unknowns / confidence: Synthetic boundaries verified; restart continuity, deployment and invoice accuracy are not guaranteed.

Independent audit follow-up

Updated in this PR, with Core #9 and DSH #16 updated in place. Additional provider source dependencies:

Repairs: real deepseek-official pricing route; Codex disjoint buckets, cache writes, unattributed cumulative accounting and compaction retention; Claude thinking/unknown-cost/cancelled-result handling and delta; Kimi serialized success-only delta baseline; CLI acknowledged legacy compaction offsets and unknown-cost preservation; Core empty aggregate cost omitted.

Current targeted verification supersedes earlier counts above: Core 3, DSH 16, Codex usage 9, Claude usage 10, Kimi projection 7, CLI delivery 15 (60 passing synthetic tests). Narrow actual Kimi emission methods also pass failure/retry checks. Core/DSH builds and Codex bundle pass; docs/public/platform boundary checks pass. Root check stops at Claude mid_conv_system SDK union mismatch; root format stops at cloud-api missing Prettier. Full Codex typecheck has harness Vitest mock signature incompatibilities. Full Kimi session regression added but not run in complete engine workspace.

Not resolved / not ready to claim complete conformance: same-ID resume/reset needs durable baseline or a consumer accounting-lifetime protocol. Private backend changes require separate approval. Kimi managed artifact remains unchanged and must be released later. Codex USD stays unknown without native per-model attribution. No package publication, paid runtime calls, production rollout, or historical repair. The owning bilingual Note and draft Spec contain evidence and limitations.

Core 0.1.5 publication follow-up

Core 0.1.5 is now verified available on npm. All five provider manifests pin 0.1.5: Grok/DSH already did; Codex/Claude/Kimi manifests and standalone lockfiles are now updated, and this PR pins those source commits. Root workspace links intentionally remain workspace references.

Codex/Claude npm ci dry-run passes; published tarball exports and empty-aggregate cost behavior verified. Kimi lock diff independently reviewed; frozen lock validation blocked by Node below >=24.15.0. Root check/format remain blocked by missing workspace dependencies. No adapter package or Kimi managed artifact release performed.

Update Core, Grok, and DSH references; preserve accounting deltas at the client boundary and coalesce cumulative snapshots. Replace the superseded queue-only research and delivery contract.

Model: gpt-6

@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: 9c1e0ff80a

ℹ️ 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 thread packages/acp-extension-dsh Outdated
@@ -1 +1 @@
Subproject commit ce194fd6766292df0726680ccbb3a1737c609b5c
Subproject commit ee3a7044328641bfc02fe262b5ad5df033d250cd

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Route DeepSeek usage through the consumer

This gitlink adds DSH usage emission, but builtin DeepSeek sessions still discard every update in MessageHandler.handleUsageUpdate: that method accepts only isManagedBuiltinAgentType(meta.agentType), while packages/shared/src/ai.ts deliberately excludes deepseek from the managed-runtime list and its test explicitly asserts that predicate is false. Consequently none of the new DSH token or cost snapshots can reach UsageTrackingService or the persistence endpoint; widen the usage-attribution path and its CliType typing to include builtin DeepSeek.

Useful? React with 👍 / 👎.

Preserve optional delta coverage for all builtin providers and document accounting lifetime and normalization gaps.

Model: gpt-6

@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: 1e314e377d

ℹ️ 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 thread packages/acp-extension-grok Outdated
@@ -1 +1 @@
Subproject commit c962338e3e6e68858e0bf92e9671a84b9a07e055
Subproject commit 3a397a79724ebff6e74488fe3cf20bbef5800624

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Give restarted Grok accounting a fresh identity

When a Grok session is resumed after a CLI/adapter restart, this pin starts its cumulative modelUsage from a fresh process baseline while Lody confirms and persists the same ACP session ID in session-manager.ts; the PR's own reproduction in .agents/notes/proposed/bug-fix/2026-09-12-grok-token-accounting.md records that a same-key total of 1000 followed by a fresh lifetime's 200 produces no increment. Since UsageTrackingService also keys delivery by that unchanged acpSessionId, post-restart usage below the previous total is silently lost. Restore the cumulative baseline or supply a distinct accounting-lifetime identity before emitting restarted snapshots.

AGENTS.md reference: AGENTS.md:L85-L87

Useful? React with 👍 / 👎.

@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: b5028cb0e4

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

(base.usage.cacheCreationInputTokens ?? 0) + (delta.usage.cacheCreationInputTokens ?? 0),
reasoningOutputTokens:
(base.usage.reasoningOutputTokens ?? 0) + (delta.usage.reasoningOutputTokens ?? 0),
webSearchRequests: (base.usage.webSearchRequests ?? 0) + (delta.usage.webSearchRequests ?? 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.

P1 Badge Omit unsupported web-search counts from aggregate usage

Whenever legacy Codex accounting crosses a compaction boundary, this merge unconditionally adds webSearchRequests—usually as 0—to the top-level usage object. The public upsertSessionUsageFromCli contract in packages/cloud-api/src/index.ts lines 711–719 does not permit that field (it is permitted only within modelUsage), so the mutation is rejected and every subsequent post-compaction snapshot remains stuck in the retry queue instead of being persisted. Keep this field out of aggregate usage unless the endpoint contract is extended.

AGENTS.md reference: AGENTS.md:L83-L88

Useful? React with 👍 / 👎.

@lodystage
lodystage Bot merged commit 8fb002b into main Sep 15, 2026
6 checks passed
@lodystage
lodystage Bot deleted the fix/acp-usage-snapshots-and-deltas branch September 15, 2026 11:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant