Skip to content

fix: persist prompt response token usage#407

Merged
vincentkoc merged 2 commits into
mainfrom
clawsweeper/issue-openclaw-acpx-406
Jun 23, 2026
Merged

fix: persist prompt response token usage#407
vincentkoc merged 2 commits into
mainfrom
clawsweeper/issue-openclaw-acpx-406

Conversation

@clawsweeper

@clawsweeper clawsweeper Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Fold successful PromptResponse.usage / JSON-RPC result.usage into the session conversation after the prompt update drain completes.
  • Preserve the existing usage_update._meta.usage and usage_update.cost paths.
  • Add regression coverage for a prompt response with usage while usage_update only carries { used, size }, including getStatus().usage.

Fixes #406

Validation

  • pnpm run build:test
  • node --test dist-test/test/integration.test.js dist-test/test/runtime-manager.test.js
  • pnpm run check

@clawsweeper
clawsweeper Bot requested a review from a team as a code owner June 23, 2026 10:30
@clawsweeper clawsweeper Bot added clawsweeper Tracked by ClawSweeper automation clawsweeper:autogenerated PR created automatically by ClawSweeper clawsweeper:autofix Maintainer opted this PR into bounded ClawSweeper-reviewed autofix without merge labels Jun 23, 2026
@clawsweeper

clawsweeper Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor Author

Codex review: passed. Reviewed June 23, 2026, 6:59 AM ET / 10:59 UTC.

Summary
The branch records successful ACP prompt response token usage into the existing session conversation usage fields and adds regression coverage for persisted runtime status usage.

Reproducibility: yes. source-level reproduction is high confidence: on current main, usage normalization only reads usage_update payloads and runPromptTurn drops successful prompt response usage before session persistence. I did not run a live adapter session in this read-only review.

Review metrics: 2 noteworthy metrics.

  • Changed files: 4 files changed. The repaired branch now touches only the runtime/session implementation and regression tests for the linked usage persistence bug.
  • Release-owned files: 0 changed. The previous CHANGELOG.md blocker is gone from the current merge diff.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #406
Summary: This PR is the implementation candidate for the narrow prompt-response token-usage persistence bug tracked by the linked issue.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🌊 off-meta tidepool
Patch quality: 🐚 platinum hermit
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • none.

Next step before merge

  • No ClawSweeper repair remains; the changelog hunk identified in the previous review is gone, so the PR can proceed through normal required checks and maintainer review.

Security
Cleared: The diff only changes runtime/session TypeScript and tests; it does not change dependencies, workflows, secrets, install scripts, release metadata, or package publishing paths.

Review details

Best possible solution:

Keep the focused prompt-response usage persistence and regression tests, with release notes handled by the release-owned process.

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

Yes, source-level reproduction is high confidence: on current main, usage normalization only reads usage_update payloads and runPromptTurn drops successful prompt response usage before session persistence. I did not run a live adapter session in this read-only review.

Is this the best way to solve the issue?

Yes, recording prompt-response usage after the update drain reuses the existing token normalization and persisted/status surfaces without adding new config or public naming conventions.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against a6907746b5bd.

Label changes

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This is a ClawSweeper-generated bot autofix PR, so the external-contributor real behavior proof gate does not apply; regression tests and CI still validate the behavior.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove merge-risk: 🚨 other: Current PR review selected no merge-risk labels.

Label justifications:

  • P2: The PR fixes a normal-priority persisted session-state bug with bounded runtime and test changes.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This is a ClawSweeper-generated bot autofix PR, so the external-contributor real behavior proof gate does not apply; regression tests and CI still validate the behavior.
Evidence reviewed

What I checked:

  • Target policy read: AGENTS.md was read fully; its bug-fix evidence, runtime validation, and changelog/release-note guidance apply to this runtime/session PR. (AGENTS.md:220, a6907746b5bd)
  • Current-main source reproduction: On current main, token usage normalization reads from usage_update._meta.usage or top-level usage-update fields only, so { used, size } updates produce no persisted token breakdown. (src/session/conversation-model.ts:445, a6907746b5bd)
  • Current-main prompt usage drop: On current main, runPromptTurn awaits the prompt response but returns only stopReason/source, so successful PromptResponse.usage is not folded into session persistence. (src/runtime/engine/prompt-turn.ts:24, a6907746b5bd)
  • Existing status dependency: getStatus().usage is built from persisted cumulative_token_usage and request_token_usage, matching the linked issue's empty-status symptom when those fields are never populated. (src/runtime/engine/manager.ts:329, a6907746b5bd)
  • Adjacent response usage path: The CLI output formatter already reads final JSON-RPC result.usage, confirming the response-side source is part of current behavior. (src/cli/output/output.ts:1190, a6907746b5bd)
  • PR implementation path: The PR records response.usage after the post-success update drain, so prompt-response usage reaches the session conversation before persistence. (src/runtime/engine/prompt-turn.ts:41, 62a39174d78e)

Likely related people:

  • DaniAkash: Authored the merged runtime/status usage work that added persisted usage exposure through the runtime manager, public contract, reducer, and tests. (role: feature introducer; confidence: high; commits: f6de6dd18aae; files: src/runtime/engine/manager.ts, src/runtime/public/contract.ts, src/session/conversation-model.ts)
  • steipete: Authored the quiet-output prompt-result usage path and the release snapshot that introduced the current prompt-turn and conversation-model files on main. (role: adjacent runtime/output contributor; confidence: high; commits: ea2c1cfb5ab3, 9149b26f4971; files: src/cli/output/output.ts, src/runtime/engine/prompt-turn.ts, src/session/conversation-model.ts)
  • Onur Solmaz: Introduced the runtime embedding API and central conversation/runtime manager surfaces that this persistence/status path builds on. (role: runtime API introducer; confidence: medium; commits: be510ba918d4; files: src/runtime/engine/manager.ts, src/runtime/public/contract.ts, src/session/conversation-model.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. P2 Normal priority bug or improvement with limited blast radius. merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. labels Jun 23, 2026
@clawsweeper

clawsweeper Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor Author

🦞✅
ClawSweeper autofix is complete for this exact head.

Source: clawsweeper[bot]
Feedback: structured ClawSweeper verdict: pass (sha=62a39174d78e8893041d26a2d1c42533fc7f17de)
Head: 62a39174d78e

No actionable findings remain. I removed the repair-loop label and left the PR open for maintainer review and merge.

Automerge progress:

  • 2026-06-23 10:36:51 UTC review requested repair 5ff8a535ce13 (structured ClawSweeper marker: fix-required (finding=review-feedback sha=5ff8a5...)
  • 2026-06-23 10:48:21 UTC review queued 62a39174d78e (after repair)
  • 2026-06-23 11:00:12 UTC review passed 62a39174d78e (structured ClawSweeper verdict: pass (sha=62a39174d78e8893041d26a2d1c42533fc7f1...)

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. clawsweeper:autofix Maintainer opted this PR into bounded ClawSweeper-reviewed autofix without merge labels Jun 23, 2026
@vincentkoc
vincentkoc merged commit 06ef8af into main Jun 23, 2026
16 checks passed
@vincentkoc
vincentkoc deleted the clawsweeper/issue-openclaw-acpx-406 branch June 23, 2026 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clawsweeper:autogenerated PR created automatically by ClawSweeper clawsweeper Tracked by ClawSweeper automation merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. P2 Normal priority bug or improvement with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Persisted token usage is always empty — breakdown rides on the prompt response (result.usage), not usage_update._meta.usage

1 participant