Repository navigation
fix: internal memory and skill reviews omit usage diagnostics - #169179
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesRecords separate token usage and available estimated cost for completed memory-flush and Skill Workshop review runs. Example: A memory flush reports 111 input tokens and 22 output tokens with configured synthetic pricing.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this PR repairs a current accounting gap with a focused implementation and no actionable findings; exact-head CI remains pending. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherMemory-flush and Workshop owners receive completed inference results; the shared helper converts their usage into trusted diagnostic events consumed by existing exporters. flowchart TD
A[Ordinary Gateway turns] --> B[Memory flush]
A --> C[Workshop review]
B --> D[Internal usage settlement]
C --> D
D --> E[Trusted diagnostic events]
E --> F[OpenTelemetry metrics and spans]
Technical reviewBest possible solution: Retain the shared settlement helper at both completed-result boundaries and land through the existing CI gates. Do we have a high-confidence way to reproduce the issue? Supplied baseline Gateway traces reproduce real internal HTTP calls without corresponding usage settlement, corroborating the current-main result boundaries; no target code was executed during this review. Is this the best way to solve the issue? The patch fixes the missing settlement at its two owners, reuses existing accounting contracts and preserves foreground accounting, failure handling and inference behavior. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 97d22d3a5b5a. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +90, Tests +278, Docs +4. Total +372 across 7 files. Added test files: 1. View PR surface stats
Review metrics
LabelsLabel changes: No label changes. Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (10 earlier review cycles; latest 8 shown)
Reviewed October 23, 2026, 3:34 AM ET / 07:34 UTC (Revision 11). |
|
@clawsweeper re-review The PR body now includes Gateway/entry-point runtime proof for both changed owners: detached memory-flush and Skill Workshop review turns each emit exactly one trusted |
|
🦞👀 Re-review progress:
|
8ad0263 to
633d8b9
Compare
|
@clawsweeper re-review Rebased onto current |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
Remaining CI failure: reproduced without this PR's production changesHead: Failing job: checks-node-changed-compact-small-5. Its three failing cases are in the unchanged
All three fail at line 763 because I reproduced the identical three cases in a secretless Linux-amd64 Node 24.22.1 Docker container, using the repository-pinned Bun fork and the original hosted cron group. The arm64 Node and Bun runs had passed, so they were not used to dismiss hosted evidence.
The baseline mismatch is the same assertion shape: This diff adds usage settlement only after completed memory-flush/review inference and moves the existing memory-flush failure recorder unchanged. It does not modify cron continuation, restart marking, or this test. The same failures with all production changes reverted establish that this PR is not their cause. Retained local evidence: No failed hosted job was rerun. Cancelled checks on this head: 0. Waiting for maintainer disposition of this inherited red; no further push to chase green. |
|
Maintainer override: checks-node-changed-compact-small-5 is an inherited failure, not caused by this PR. The three failing cases are in src/cron/isolated-agent/run.operator-continuation.test.ts (restart cases disagreeing only on restartRecoveryDeliverySourceRunId), a file this PR doesn't touch: https://github.com/openclaw/openclaw/actions/runs/39917946482/job/120296528138. In a Linux amd64 Node 24.22.1 container with the pinned Bun and the exact hosted test groups, this head fails 3/309, and the same groups with only this PR's production diff reverted to main 2fe4b72 fail the same 3/309. Evidence: #169179 (comment). This PR only changes internal memory-flush and Skill Workshop usage accounting. All other required checks pass. |
|
Landed in f92d068. Thanks @PratikRai0101. Memory flush and Skill Workshop runs now show up in usage and cost. |
…aw#169179) fix(usage): record usage for internal memory-flush and Skill Workshop review runs Completed internal memory-flush and Skill Workshop review inference used provider-reported tokens but skipped the existing model.usage settlement, so operators lost the token counts and estimated cost for that work. These runs now settle usage the same way ordinary turns do. Evidence: built Gateway with a local provider fixture that reports usage, a natural memory flush and a Skill Workshop review. On main three 133-token flushes and a 90-token review produced no usage records; with this change they produce exactly four usage spans and a 489-token, $0.001476 cost entry. Ordinary chat (208) and summary (234) totals are unchanged. Thanks @PratikRai0101. Co-authored-by: Ayaan Zaidi <[email protected]>
Related: #169156.
What Problem This Solves
Completed memory-flush and Skill Workshop review inference returns provider-reported usage but never settles it through the existing model.usage diagnostic path. Operators therefore lose token counts and available estimated cost for that internal work.
User Impact
Diagnostics now record those internal calls independently. Their usage is not added to the foreground conversation's totals. Returned-error results still account for consumed tokens; diagnostics-disabled, no-usage, and unknown-pricing behavior remain conservative.
Why This Change Was Made
Use one shared internal-run settlement helper at the two completed-result boundaries. It reuses existing usage normalization, pricing, diagnostic enablement, and trace-context owners. No diagnostic schema, exporter permission, plugin SDK surface, or configuration option changes.
The existing memory-flush failure recorder is moved unchanged out of the large orchestration module. Cancellation, source authority, retry limits, and persisted failure behavior are preserved.
Evidence
Captured real provider requests, exported OTLP usage spans/counters, and red/green owner tests.
Built Gateway/CLI artifacts on Node 24.22.1 in isolated Linux Docker. Ordinary shipped chat.send/agent.wait turns naturally crossed the existing 1024-byte transcript trigger. Workshop had actual tool availability, auto mode, ten successful ordinary turns, and its normal quiet period. A finite owned Responses service returned legal synthetic usage; the official diagnostics-otel plugin exported to an authorized passive local OTLP receiver. No private subscriber, injected event/result, seeded maintenance row, held response, or external provider account was used.
Simplification: one narrow helper serves both owners; no new accounting state or generalized framework. Most production lines touched move the existing failure path without changing it. Production net +90 lines; tests +279; documentation +4. Retaining the failure helper keeps the orchestration module smaller instead of duplicating or compressing its lifecycle rules.
Merge Danger
Two-way door: reverting removes the added diagnostic settlement; no migration or stored format changes. Blast radius is token/cost observability for these two internal inference paths. Foreground accounting and inference behavior remain unchanged.