Skip to content

refactor(trace): reuse the canonical usage counter type - #140444

Merged
steipete merged 1 commit into
mainfrom
steipete/cleanup-trace-usage-types
Sep 6, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/cleanup-trace-usage-types

Conversation

@steipete

@steipete steipete commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Raw trace reporting repeats the same five optional token counters in seven type declarations. Those copies can drift from the runtime accounting owner.

This is a cleanup contribution to the #135868 split campaign, independent of its feature stages.

Why This Change Was Made

Use a private five-key Pick of the existing NormalizedUsage type for all seven declarations. The selected properties have exactly the same names, optionality and numeric types. The type import shares an existing module import, and no executable code changes.

The full accounting type also contains context, reasoning and cost fields; those do not become new declared trace fields. Original usage objects still pass through unchanged, preserving context accounting, formatting, authorization and supported transcript artifact reads. This removes duplicated declarations rather than retiring a shipped contract.

User Impact

No user-visible behavior change. Raw trace output and its authorization rules remain unchanged.

Evidence

  • All 108 existing tests pass before and after in agent-runner-trace.test.ts and agent-runner.misc.runreplyagent.test.ts. These include raw output, session/last-turn totals, and withholding persisted raw traces from unauthorized senders.
  • Actual-source comparison passes 107 contract assertions in each optional-property mode, including all seven usage surfaces and exported signatures; five intentional type mutations are rejected in each mode.
  • Emitted JavaScript is byte-identical, including imports. A deliberate runtime projection is detected by that comparison. No build is needed for this erased private type change.
  • The supplementary strict-optional run retains six existing implementation diagnostics on each side; complete diagnostics match after expanding only the new alias's displayed name. Contract assertions have zero errors. This is not a claim that the existing owner compiles under that extra option.
  • Full changed-check plan passes: core/core-test types, formatting/lint, all three Knip export scans and architecture/storage guards. Runtime import cycles: zero.
  • Independent Codex review is clean through P2. ClawSweeper also found no correctness/security findings or before-merge requests; no rank-up changes were requested.

Judged production: one file, 599 → 553 lines; +13/−59 = −46. Tests, tooling, docs and baselines are unchanged.

@clawsweeper

clawsweeper Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
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.

@steipete
steipete marked this pull request as ready for review September 6, 2026 20:58
@openclaw-barnacle openclaw-barnacle Bot added size: S maintainer Maintainer-authored PR labels Sep 6, 2026
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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. labels Sep 6, 2026
@clawsweeper

clawsweeper Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 6, 2026, 5:14 PM ET / 21:14 UTC.

ClawSweeper review

What this changes

Reuses OpenClaw’s canonical token-counter type across seven raw-trace declarations while preserving their five optional numeric fields.

Merge readiness

✅ Ready for maintainer review

Useful, behavior-preserving cleanup with no actionable correctness findings. The repeated declarations remain on pinned main and in the latest release; the maintainer-owned PR should remain open for normal landing.

Priority: P3
Reviewed head: db86fe1efd6138a61ce8f8c2c3b5964afacfe20f

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Focused, maintainable cleanup with equivalent field types and no identified correctness or security defect.
Proof confidence 🌊 off-meta tidepool Not applicable: Repository State identifies this as a member-authored PR, and the trace formatter changes only erased types; no authority-sensitive behavior changes trigger additional proof requirements.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Repository State identifies this as a member-authored PR, and the trace formatter changes only erased types; no authority-sensitive behavior changes trigger additional proof requirements.
Evidence reviewed 7 items Complete introduced diff: The pinned base-to-head diff changes only type annotations and adds a type-only import to an existing import. All seven replacements retain the same five fields; executable expressions are unchanged.
Canonical type contract: NormalizedUsage declares input, output, cacheRead, cacheWrite and total as optional numbers. The private Pick excludes additional accounting fields without projecting or replacing runtime objects. This contract is owned by OpenClaw; no Codex dependency contract is involved.
Caller and authorization boundary: The unchanged caller gates raw diagnostics on traceAuthorized and raw trace level, then passes the original agent usage objects into the formatter. The patch does not alter authorization, transcript selection or context-token derivation.
Findings None None.
Security None None.

How this fits together

Raw-trace reporting combines agent results and transcript usage into diagnostic reply text. Its caller controls whether an authorized sender receives those diagnostics.

flowchart LR
  A[Agent result counters] --> D[Raw trace formatter]
  B[Transcript usage] --> D
  C[Canonical counter type] --> D
  E[Authorized raw trace request] --> D
  D --> F[Diagnostic reply text]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source -46. Total -46 across 1 file.

View PR surface stats
Area Files Added Removed Net
Source 1 13 59 -46
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 1 13 59 -46

Review metrics

None.

Technical review

Best possible solution:

Keep the trace-specific view private and derive its existing counter fields from the accounting owner without changing runtime objects.

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

Not applicable: this PR removes repeated type declarations rather than fixing a reported runtime defect.

Is this the best way to solve the issue?

Yes. The private five-key Pick preserves the existing structural contract while reusing the established accounting type.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 98adc95c79d4.

Labels

Label justifications:

  • P3: This is a type-only maintenance improvement with no changed user-facing behavior.
  • 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: Repository State identifies this as a member-authored PR, and the trace formatter changes only erased types; no authority-sensitive behavior changes trigger additional proof requirements.

Evidence

What I checked:

  • Complete introduced diff: The pinned base-to-head diff changes only type annotations and adds a type-only import to an existing import. All seven replacements retain the same five fields; executable expressions are unchanged. (src/auto-reply/reply/agent-runner-trace.ts:10, db86fe1efd61)
  • Canonical type contract: NormalizedUsage declares input, output, cacheRead, cacheWrite and total as optional numbers. The private Pick excludes additional accounting fields without projecting or replacing runtime objects. This contract is owned by OpenClaw; no Codex dependency contract is involved. (src/agents/usage.ts:67, db86fe1efd61)
  • Caller and authorization boundary: The unchanged caller gates raw diagnostics on traceAuthorized and raw trace level, then passes the original agent usage objects into the formatter. The patch does not alter authorization, transcript selection or context-token derivation. (src/auto-reply/reply/agent-runner-result-diagnostics.ts:67, db86fe1efd61)
  • Existing behavior coverage: Existing tests cover withholding persisted raw traces from unauthorized senders and retaining session/last-turn usage blocks. The captured PR body reports 108 passing tests, type-contract comparisons and byte-identical emitted JavaScript; these claims were not rerun during this read-only review. (src/auto-reply/reply/agent-runner.misc.runreplyagent.test.ts:2048, db86fe1efd61)
  • Main and release necessity: Pinned main retains the duplicated declarations, and the supplied latest release v2026.9.2 also contains the inline five-counter types. No merged replacement is established by the supplied related-item context. (src/auto-reply/reply/agent-runner-trace.ts:19, 3928bad9badf)
  • Recent area history: Main history records Peter Steinberger on recent diagnostics, token-formatting and prompt-scan changes. This supports routing relevance, not an attribution of feature introduction; deeper blame and parent comparisons were unavailable. (src/auto-reply/reply/agent-runner-trace.ts, 56da574752d3)

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
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.

Workflow

  • 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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-09-06T21:04:11.376Z sha a8e87ef6b8ec360e9f48cee18128bd33c590bbb7 :: needs maintainer review before merge. :: none

@steipete
steipete force-pushed the steipete/cleanup-trace-usage-types branch from a8e87ef to db86fe1 Compare September 6, 2026 21:08
@steipete
steipete merged commit c1fbb46 into main Sep 6, 2026
173 checks passed
@steipete
steipete deleted the steipete/cleanup-trace-usage-types branch September 6, 2026 21:20
@steipete

steipete commented Sep 6, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Sep 6, 2026
* commit '294df333c58f2da104eccffc623ccb3c4d43d4d8': (1802 commits)
  fix: clear stale diagnostics after Gateway changes (#140426)
  fix: keep plugin catalogs intact after discovery timeouts (#140441)
  perf(tui): prepare session picker rows once per overlay (#140462)
  refactor(config): reuse environment substitution for write-back (#140460)
  refactor(discord): remove retired auto-presence templates (#140463)
  fix(ui): finish roster refreshes during session activity (#140459)
  fix(setup): match prepared credentials to the model provider (#140461)
  fix: keep MiniMax discovery on the selected credential (#140438)
  refactor(tests): remove unused parent context cache reset (#140456)
  fix: avoid repeated xAI OAuth refresh during discovery (#140434)
  perf(routing): reuse prepared event session targets (#140454)
  fix(media): keep deferred audio and extraction providers discoverable (#139231)
  refactor(codex): remove redundant app-server forwarding (#140451)
  fix(test): avoid false native polling timeouts (#140119)
  test(gateway): retain saved source in reload fixtures (#140453)
  fix(gateway): reduce repeated model work when listing sessions (#140414)
  fix(feishu): fall back to post mode over table limit (#136382)
  fix: use the bundle-compatible Proxyline runtime under Bun (#140411)
  refactor(trace): reuse the canonical usage counter type (#140444)
  refactor(node-host): share execution policy result fields (#140446)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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.

1 participant