Skip to content

refactor(gateway): share transcript usage aggregation - #129199

Merged
steipete merged 2 commits into
mainfrom
codex/cleanup20k-gateway-transcript-usage-owner-20260825
Aug 25, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/cleanup20k-gateway-transcript-usage-owner-20260825

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Gateway transcript readers duplicated token-usage aggregation across their JSONL artifact and SQLite-derived paths, increasing maintenance cost and making subtle intentionally different storage semantics difficult to preserve.

Why This Change Was Made

Share one canonical usage aggregation flow while preserving each storage owner's required differences: JSONL's nested nonnegative cost, trimmed API values, positive totals, and role rules; SQLite's direct cost, zero values, and untrimmed fields.

User Impact

No transcript, public artifact, raw trace, schema, protocol, or security behavior changes. Production code decreases by 192 lines; meaningful owner tests increase by 17 lines, and the changed owner's assertion baseline is tightened from 16 to 10.

Evidence

  • The original Gateway owner suite passed 116 tests; the final suite passed 118 tests.
  • Two added zero-cost semantic regressions failed before the canonical repair and passed after it.
  • Full assertion-safety and maximum-line ratchets passed across 4,270 files and 897 line baselines.
  • Formatting, whitespace checks, independent source review, and fresh structured autoreview passed.

@clawsweeper

clawsweeper Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: M maintainer Maintainer-authored PR labels Aug 25, 2026
@steipete
steipete marked this pull request as ready for review August 25, 2026 09:37
@clawsweeper

clawsweeper Bot commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 25, 2026, 5:58 AM ET / 09:58 UTC.

ClawSweeper review

What this changes

The PR moves JSONL-artifact and SQLite transcript usage aggregation into one Gateway helper while preserving their distinct cost, role, and token-normalization rules.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

No blocking defect found in the shared aggregation refactor. This maintainer-authored PR remains useful, but its clean branch is behind current main and should be rebased with focused validation on the resulting head before merge.

Priority: P3
Reviewed head: 7e69f636c873af1063a739d9579eb7c21dafcdb6

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, net-negative refactor with preserved source-specific rules; exact-head validation remains after rebase.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored internal refactor is exempt from the external-contributor real-behavior-proof gate.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored internal refactor is exempt from the external-contributor real-behavior-proof gate.
Evidence reviewed 6 items Artifact semantics retained: The artifact mode filters non-assistant records, trims API values, requires positive totals, accepts nonnegative nested cost, and preserves delivery-mirror handling.
Both storage owners use the helper: The JSONL reader normalizes each artifact record before calling artifact mode, while the SQLite full and bounded readers retain the default SQLite mode.
Regression coverage: The added table-driven test protects zero-cost JSONL snapshots for both unattributed assistants and delivery mirrors; adjacent tests retain unavailable-context and estimated-context behavior.
Findings None None.
Security None None.

Live Verification

Command: pnpm test src/gateway/session-utils.fs.test.ts

Result: PASS (completed)

pnpm test src/gateway/session-utils.fs.test.ts
runner@runnervm76f27:/tmp/clawsweeper-live-proof-129199-8xbkyW/target$ pnpm test src/gateway/session-utils.fs.test.ts
$ node --import tsx scripts/test-projects.mts src/gateway/session-utils.fs.test.ts
pnpm test src/gateway/session-utils.fs.test.ts
[test] starting test/vitest/vitest.gateway.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-129199-8xbkyW/target

 ✓  gateway-core  ../../src/gateway/session-utils.fs.test.ts (85 tests) 842ms

 Test Files  1 passed (1)
      Tests  85 passed (85)
   Start at  09:59:11
   Duration  12.86s (transform 9.56s, setup 930ms, import 10.73s, tests 842ms, environment 0ms)

[test] passed 1 Vitest shard in 18.37s
runner@runnervm76f27:/tmp/clawsweeper-live-proof-129199-8xbkyW/target$ pnpm test src/gateway/session-utils.fs.test.ts
pnpm test src/gateway/session-transcript-readers.test.ts
$ node --import tsx scripts/test-projects.mts src/gateway/session-utils.fs.test.ts
[test] starting test/vitest/vitest.gateway.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-129199-8xbkyW/target

 ✓  gateway-core  ../../src/gateway/session-utils.fs.test.ts (85 tests) 755ms

 Test Files  1 passed (1)
      Tests  85 passed (85)
   Start at  09:59:30
   Duration  6.05s (transform 2.92s, setup 416ms, import 4.66s, tests 755ms, environment 0ms)

[test] passed 1 Vitest shard in 11.46s
runner@runnervm76f27:/tmp/clawsweeper-live-proof-129199-8xbkyW/target$ pnpm test src/gateway/session-transcript-readers.test.ts



















Assertions:

  • PASS expect_output: passed
  • PASS expect_output: passed

How this fits together

Gateway transcript readers turn JSONL artifacts and SQLite session rows into usage snapshots for session and transcript views. The shared helper consumes stored messages and produces aggregated token, context, model, and cost fields.

flowchart LR
A[JSONL transcript artifact] --> C[Shared usage aggregation]
B[SQLite session rows] --> C
C --> D{Storage-specific rules}
D --> E[Usage snapshot]
E --> F[Gateway session and transcript views]
Loading

Before merge

  • Resolve merge risk (P1) - GitHub reports a clean but behind branch; rebase onto current main and rerun the focused Gateway tests so validation covers the actual merge head.
  • Complete next step (P2) - No mechanical repair is identified; refresh the branch and validate the exact merge head.
Agent review details

Security

None.

PR surface

Source -188, Tests +17, Other 0. Total -171 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 3 150 338 -188
Tests 1 17 0 +17
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 1 0
Total 5 168 339 -171

Review metrics

Metric Value Why it matters
Production versus test LOC production +150/-338 (net -188); tests +17/-0; assertion baseline 1 changed The refactor materially removes duplicated production logic while adding focused artifact-cost coverage.

Stored data model

Persistent data-model change detected: serialized state: src/gateway/session-transcript-derived-readers.ts, serialized state: src/gateway/session-transcript-readers.ts, serialized state: src/gateway/session-utils.fs.ts, unknown-data-model-change: src/gateway/session-transcript-derived-readers.ts, unknown-data-model-change: src/gateway/session-utils.fs.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Land one canonical aggregation owner after rebasing, while retaining explicit artifact-versus-SQLite behavior at the extraction boundary.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Land one canonical aggregation owner after rebasing, while retaining explicit artifact-versus-SQLite behavior at the extraction boundary.

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

Not applicable: this PR consolidates existing behavior rather than reporting a separate user-facing failure.

Is this the best way to solve the issue?

Yes: the helper keeps source-specific semantics explicit rather than forcing JSONL artifacts and SQLite rows through one undifferentiated contract.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P3: This is a behavior-preserving Gateway cleanup with limited operator impact.
  • 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 maintainer-authored internal refactor is exempt from the external-contributor real-behavior-proof gate.

Label justifications:

  • P3: This is a behavior-preserving Gateway cleanup with limited operator impact.
  • 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 maintainer-authored internal refactor is exempt from the external-contributor real-behavior-proof gate.

Evidence

What I checked:

Likely related people:

  • steipete: Current head ownership, blame on the aggregation call sites, and recent transcript/session history all point to this contributor. (role: recent area contributor; confidence: high; commits: 7e69f636c873, fa0fcef9f624; files: src/gateway/session-transcript-derived-readers.ts, src/gateway/session-utils.fs.ts, src/gateway/session-transcript-readers.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Rebase onto current main and rerun the focused Gateway transcript-reader tests on the resulting head.

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-08-25T09:32:09.022Z sha 1bceddd :: needs maintainer review before merge. :: none

@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 Aug 25, 2026
@steipete
steipete merged commit a6b8eb5 into main Aug 25, 2026
240 checks passed
@steipete
steipete deleted the codex/cleanup20k-gateway-transcript-usage-owner-20260825 branch August 25, 2026 10:17
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 26, 2026
* refactor(gateway): share transcript usage aggregation

* refactor(gateway): preserve transcript usage type ownership
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime 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: L 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