Skip to content

fix(gateway): restore SQLite usage details - #118918

Merged
vincentkoc merged 1 commit into
mainfrom
fix/gateway-sqlite-usage-details
Aug 3, 2026
Merged

vincentkoc merged 1 commit into
mainfrom
fix/gateway-sqlite-usage-details

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Aug 3, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

Fixes an issue where operators opening usage details for stored sessions could receive invalid or empty results after session transcripts moved to SQLite.

Repair Ledger

  • Root cause: current canonical session entries intentionally strip the retired sessionFile and transcriptPath locators, but Gateway usage detail lookup still rebuilt a JSONL path from the session id. sessions.usage then applied fs.statSync to that result, which is invalid when the canonical resolver returns a SQLite marker.
  • Architectural owner: the Gateway usage resolution boundary, consuming the canonical session-store target owned by the session store.
  • Canonical fix: all stored-session summary, timeseries, and log requests now resolve through one target containing agentId, sessionId, sessionKey, and storePath. SQLite markers are accepted as canonical session sources, and requested/stored identity mismatches fail closed.
  • Removed paths: stored sessions no longer consume or synthesize file-era JSONL locators; SQLite markers no longer reach filesystem stat calls; stale target mismatches no longer continue into transcript reads.
  • History: the failure became visible after refactor(sessions): remove file-era transcript runtime #113233 correctly removed file-era locators on July 28, 2026. Gateway usage retained the incompatible JSONL derivation path and is migrated here.
  • Production LOC: +83/-46, net +37. The remaining growth is one shared owner-boundary resolver plus marker-aware existence handling that unifies three RPCs and removes duplicate file-era policy; it is not a consumer-side workaround.
  • Sibling coverage: tests cover stored summary and specific lookup, timeseries, logs, storeless JSONL artifacts, stale identity mismatch, legacy/global/deterministic lookup, and session-family lookup.
  • Observed behavior: an authenticated Gateway client can request SQLite-backed stored-session usage summary, timeseries, and logs without a JSONL sidecar; historical storeless JSONL artifacts continue to resolve.

User Impact

Usage summaries and detail views can read current SQLite-backed session transcripts consistently, while historical storeless JSONL artifacts continue to work.

Evidence

ClawSweeper rank-up move applied: rebased onto the reviewed current-main freeze and reran both the focused Gateway usage test and changed-path checks on the resulting exact head.

Latest ClawSweeper rank-up move applied: all exact-head checks completed with no failures; the repository merge wrapper will verify the current merge result before landing.

AI-assisted: yes. The implementation and evidence above were reviewed before submission.

@vincentkoc vincentkoc self-assigned this Aug 3, 2026
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: M maintainer Maintainer-authored PR labels Aug 3, 2026
@vincentkoc
vincentkoc marked this pull request as ready for review August 3, 2026 19:59
@vincentkoc
vincentkoc force-pushed the fix/gateway-sqlite-usage-details branch from 98ee1a2 to 507a80c Compare August 3, 2026 20:29
@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@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. P2 Normal backlog priority with limited blast radius. labels Aug 3, 2026
@clawsweeper

clawsweeper Bot commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 3, 2026, 6:03 PM ET / 22:03 UTC.

ClawSweeper review

What this changes

The PR repairs Gateway session-usage summaries, time series, and logs so stored SQLite transcripts use canonical session-store identity while storeless historical JSONL artifacts continue to resolve.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep open for maintainer review. Current main still resolves stored usage details through the retired file-path flow, while this PR routes the three Gateway detail paths through the canonical SQLite session target; no blocking patch defect was found. The author is a repository member and the PR carries the protected maintainer label, so final merge remains an explicit maintainer decision after the exact-head checks finish.

Priority: P2
Reviewed head: bb1e0ce817ac9b53ba03ab25f1dffe08bc169bef
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, source-aligned repair with regression coverage and reported remote validation; final readiness depends on the protected maintainer review and remaining exact-head checks.
Proof confidence 🐚 platinum hermit (4/6) Not applicable: The author is a repository member, and the PR body supplies focused Testbox and exact-head validation evidence; this external-contributor proof gate does not apply.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The author is a repository member, and the PR body supplies focused Testbox and exact-head validation evidence; this external-contributor proof gate does not apply.
Evidence reviewed 6 items Current-main defect: The current Gateway detail resolver loads the session entry but still derives a filesystem path with resolveSessionFilePath, rather than passing a complete session-store target to the marker-aware usage resolver.
Canonical repair boundary: The PR centralizes stored-session resolution in resolveSessionUsageTarget; stored entries supply { agentId, sessionId, sessionKey, storePath }, while sessions without a store entry retain file-artifact lookup.
Storage contract: The shared usage resolver treats a complete session target as authoritative, validates agent/session/key consistency against the session store, and returns a canonical SQLite marker rather than a filesystem path.
Findings None None.
Security None None.

How this fits together

Gateway usage methods accept an operator-selected session key and load transcript-backed cost details for the control surface. They translate session-store metadata into a usage source, then pass that source to summary, time-series, and log readers that support current SQLite transcripts and retained JSONL artifacts.

flowchart LR
  A[Gateway usage request] --> B[Session key and agent scope]
  B --> C[Canonical session-store lookup]
  C --> D[Usage target resolution]
  D --> E[SQLite transcript marker]
  D --> F[Historical JSONL artifact]
  E --> G[Summary time series and logs]
  F --> G
Loading

Decision needed

Question Recommendation
Should this member-authored Gateway repair be merged once the remaining exact-head checks complete and the merge result still preserves the reviewed target-resolution behavior? Merge after exact-head validation: Merge the reviewed repair when pending checks complete successfully and the current merge result retains the canonical SQLite-target and JSONL-artifact behavior.

Why: The protected maintainer label and member authorship require an explicit maintainer merge decision even though the source review found no blocking patch defect.

Before merge

  • Resolve merge risk (P1) - GitHub reports the branch as mergeable but behind current main; finish the remaining exact-head checks and review the merge result or a refreshed head before landing, without assuming base drift removes current-main behavior.
Agent review details

Security

None.

PR surface

Source +37, Tests +44. Total +81 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 83 46 +37
Tests 1 64 20 +44
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 147 66 +81

Review metrics

Metric Value Why it matters
Usage detail entry points 3 paths unified The same canonical target resolver now governs stored-session summary, time-series, and log requests, reducing divergence across operator-visible detail views.
Production versus test delta production +37 net, tests +44 net The production growth is tied to one shared owner-boundary resolver and marker-aware existence handling; the added tests cover the three repaired detail paths and identity failures.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Keep one Gateway resolver that turns stored sessions into validated canonical SQLite targets and limits JSONL lookup to genuinely storeless historical artifacts, then merge after current-head validation completes.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Keep one Gateway resolver that turns stored sessions into validated canonical SQLite targets and limits JSONL lookup to genuinely storeless historical artifacts, then merge after current-head validation completes.

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

Yes, from source: a stored entry on current main reaches the file-era resolveSessionFilePath route, whereas the shared usage resolver accepts a complete SQLite target. The PR adds focused regression coverage for that boundary, though this read-only review did not execute the test.

Is this the best way to solve the issue?

Yes. Resolving the source once at the Gateway/session-store boundary is the narrowest maintainable repair because the shared usage reader already validates canonical SQLite targets and retains the supported JSONL artifact path.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This is a bounded regression in Gateway session usage details with meaningful operator impact but no evidence of data loss, security bypass, or runtime unavailability.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The author is a repository member, and the PR body supplies focused Testbox and exact-head validation evidence; this external-contributor proof gate does not apply.

Evidence

What I checked:

Likely related people:

  • vincentkoc: Current-line blame identifies Vincent Koc on the existing Gateway resolver, and the PR's parent-era Gateway usage tests and resolver are in the same maintained surface. (role: recent Gateway usage maintainer; confidence: high; commits: 5150670c72d9, bb1e0ce817ac; files: src/gateway/server-methods/usage.ts, src/gateway/server-methods/usage.sessions-usage.test.ts)
  • steipete: The related merged SQLite transcript-runtime refactor established the canonical structured session-target contract this Gateway repair now consumes. (role: session-storage refactor author; confidence: high; commits: 4273ca9dbd9b; files: src/infra/session-cost-usage-collection.ts, src/gateway/server-methods/usage.ts)

Rank-up moves

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

  • Let the pending exact-head checks finish, then review the current merge result before landing.

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 (2 earlier review cycles)
  • reviewed 2026-08-03T21:05:58.017Z sha 507a80c :: needs maintainer review before merge. :: none
  • reviewed 2026-08-03T21:12:34.619Z sha 507a80c :: needs maintainer review before merge. :: none

@vincentkoc
vincentkoc force-pushed the fix/gateway-sqlite-usage-details branch from 507a80c to bb1e0ce Compare August 3, 2026 21:56
@vincentkoc
vincentkoc merged commit d3ea24c into main Aug 3, 2026
132 checks passed
@vincentkoc
vincentkoc deleted the fix/gateway-sqlite-usage-details branch August 3, 2026 22:09
@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Aug 3, 2026
* origin/main: (90 commits)
  fix(googlechat): recover durable lanes after oversized attachments (#118986)
  test(qa): cover runtime telemetry evidence (#118950)
  fix(gateway): resolve SQLite usage details (#118918)
  test(cron): cover durable scheduler state (#118981)
  test(gateway): cover node exec approval relay (#118825)
  test(qa): add Active Memory recall coverage (#118963)
  test(qa): promote package-backed Docker artifact proof (#118826)
  test(qa): cover diagnostic event boundary (#118844)
  test(gateway): cover WebSocket runtime contracts (#118797)
  fix(signal): drain accepted websocket messages before shutdown (#118975)
  fix(plugins): remove stale load paths during uninstall (#118930)
  test(qa): cover bundled runtime discovery (#118922)
  chore(clawhub): cover plugin release policy contracts (#118971)
  test(qa): cover support export and stability (#118956)
  fix(feishu): enforce exact signed webhook request boundaries (#118758)
  feat(sms): add Twilio MMS support (#118664)
  test(gateway): prove TLS certificate pinning (#118812)
  test(qa): cover tool policy and sandbox gates (#118925)
  fix(cli): keep update dry-run state immutable (#118856)
  fix(scripts): honor last repeated CLI flag value (#118710)
  ...

# Conflicts:
#	pnpm-workspace.yaml
vincentkoc added a commit that referenced this pull request Aug 3, 2026
…r-admin-20260803

* origin/main: (89 commits)
  fix(googlechat): align doctor policy ownership with canonical account configuration (#118972)
  test(tui): prove editor input through PTY (#118982)
  fix(memory): persist trusted owner provenance at canonical transcript boundary (#118987)
  test(qa): cover health monitor and cache boundaries (#118961)
  fix(macos): restore dashboard frame double-click zoom (#118976)
  fix(googlechat): recover durable lanes after oversized attachments (#118986)
  test(qa): cover runtime telemetry evidence (#118950)
  fix(gateway): resolve SQLite usage details (#118918)
  test(cron): cover durable scheduler state (#118981)
  test(gateway): cover node exec approval relay (#118825)
  test(qa): add Active Memory recall coverage (#118963)
  test(qa): promote package-backed Docker artifact proof (#118826)
  test(qa): cover diagnostic event boundary (#118844)
  test(gateway): cover WebSocket runtime contracts (#118797)
  fix(signal): drain accepted websocket messages before shutdown (#118975)
  fix(plugins): remove stale load paths during uninstall (#118930)
  test(qa): cover bundled runtime discovery (#118922)
  chore(clawhub): cover plugin release policy contracts (#118971)
  test(qa): cover support export and stability (#118956)
  fix(feishu): enforce exact signed webhook request boundaries (#118758)
  ...
vincentkoc added a commit that referenced this pull request Aug 3, 2026
…ansports-20260803

* origin/main: (120 commits)
  test(ui): add service-worker update primary QA proof (#118805)
  test(qa): cover CLI onboarding and plugin install sources (#118882)
  test(qa): cover remote logging boundaries (#118951)
  fix(sms): retry transient MMS failures before durable adoption (#118994)
  test(qa): cover video generation invocation (#118864)
  test(qa): cover media reference intake (#118858)
  test(qa): cover image generation task lifecycle (#118915)
  feat(sms): track Twilio delivery status (#118665)
  test(tasks): cover TaskFlow registry lifecycle (#118983)
  test(gateway): verify SSH tunnel fallback (#118818)
  fix(security): harden network tool output at canonical owner boundaries (#118984)
  fix(googlechat): align doctor policy ownership with canonical account configuration (#118972)
  test(tui): prove editor input through PTY (#118982)
  fix(memory): persist trusted owner provenance at canonical transcript boundary (#118987)
  test(qa): cover health monitor and cache boundaries (#118961)
  fix(macos): restore dashboard frame double-click zoom (#118976)
  fix(googlechat): recover durable lanes after oversized attachments (#118986)
  test(qa): cover runtime telemetry evidence (#118950)
  fix(gateway): resolve SQLite usage details (#118918)
  test(cron): cover durable scheduler state (#118981)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 4, 2026
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 P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M 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