Skip to content

fix(ui): prevent usage exports from mixing session instances - #140573

Merged
steipete merged 1 commit into
mainfrom
codex/qa-usage-instance-export-20260907
Sep 7, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/qa-usage-instance-export-20260907

Conversation

@steipete

@steipete steipete commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Closes #140567

What Problem This Solves

Fixes Usage JSON exports that attach a replacement session's prompt context to an older displayed usage row after the logical session key is reused. This affects both Current instance and the default Historical lineage view.

Why This Change Was Made

The existing shared export key now includes the concrete session ID alongside agent and logical key. Map construction, required-context validation and context lookup all use that one identity. The existing refresh error handles replacement; the original lazy-loading behavior and same-instance updates are preserved.

User Impact

An export keeps the displayed usage snapshot and loads details belonging to that same instance. If it has been replaced, the UI asks the operator to refresh instead of downloading mixed data. Refreshing then exports the replacement correctly. The Usage reference documents this recovery.

Evidence

  • The rendered-page regression failed before the repair: the replacement case downloaded a file when it should not. Nine other tests passed. The identical fixed file passes all ten tests; 41 related Usage/refresh/query tests also pass.
  • The complete three-path changed gate passed, including core/UI typechecks, i18n, lint and repository guards. Independent P0–P2 review was clean. Signed head: c864dc2389cdc40578c34fd9c4774d121a4612c0; fresh uncached build passed.
  • Six runs of the real compiled UI used public mock Gateway snapshots, normal menu clicks and actual browser downloads. Both views reproduced A/100 tokens plus B context before the fix. Both reject that export afterward and show the existing refresh message. Refresh-B recovery and fresh-context/same-ID controls pass on both builds.
Browser result Before After
Replacement exports mixing A's row with B's report 2 0
Replacement exports visibly requesting refresh 0 2
Valid refresh/same-instance downloads 3 3

All eight downloaded files, 20 screenshots and six videos were inspected. Complete source, dependency and generated-artifact checks passed before and after every run; browser, context, server and listeners closed normally. This is a real UI snapshot scenario with a mocked Gateway, not a live deletion/recreation or provider test.

Production +3/−2: two executable lines replaced and one ownership comment added. Tests +60/−2; docs +1. The affected owners are unchanged on inspected main 6df7c32f477a458950f01a541119944b5bd85557.

Provenance: the parent-relative diff of #132064 (d9f3d88409358603ab4c0ad1afd7eab846c6a0d8) introduced the weaker join. Stable v2026.9.2 retains it; that is source evidence only.

Inspected synthetic browser evidence

Before: the export completes without a refresh warning; the actual downloaded JSON contains row A with context B. After: the existing refresh message prevents that mixed download. The short recordings also include successful refresh-B recovery.

Before: export completes with no refresh message; downloaded fields are shown in the report

After: the UI asks to refresh when the session instance changed

attachment-845718765.mp4
attachment-3851279919.mp4

Include the concrete session ID in the existing export hydration key so
reusing a logical key cannot mix old usage with a replacement session's
prompt report. Preserve fresh details for the same instance and the
existing refresh-and-retry error.

Cover replacement, matching-instance, unrelated-agent, and cancellation
behavior through the rendered Usage page, and document export recovery.
@clawsweeper

clawsweeper Bot commented Sep 7, 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.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: web-ui App: web-ui size: S maintainer Maintainer-authored PR labels Sep 7, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 7, 2026
@clawsweeper

clawsweeper Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 6, 2026, 9:23 PM ET / September 7, 2026, 01:23 UTC.

ClawSweeper review

What this changes

Usage JSON exports match prompt details to the displayed session’s concrete instance, with regression coverage and refresh-recovery documentation.

Merge readiness

✅ Ready for maintainer review

This remains a useful, focused fix: current main and v2026.9.2 retain the weaker export join. No actionable introduced defects were found, and the captured browser results support the intended behavior.

Priority: P2
Reviewed head: c864dc2389cdc40578c34fd9c4774d121a4612c0

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A narrow shared-owner repair with meaningful regression coverage and specific before/after browser download results.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): Captured results exercise the compiled Usage export owner through normal browser clicks and actual downloads against synthetic Gateway snapshots, showing replacement rejection and successful same-instance and refresh recovery in both views. This is browser boundary proof, not live session deletion/recreation; linked media inspection was blocked by reviewer network access.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): Captured results exercise the compiled Usage export owner through normal browser clicks and actual downloads against synthetic Gateway snapshots, showing replacement rejection and successful same-instance and refresh recovery in both views. This is browser boundary proof, not live session deletion/recreation; linked media inspection was blocked by reviewer network access.
Evidence reviewed 8 items Shared export identity repair: The introduced change adds sessionId to the existing identity helper. Map construction, required-context validation, and hydration all use this helper; snapshot totals and connection fencing remain unchanged.
Current main still needs the fix: Fetched main still identifies export rows using only agentId and key, allowing replacement-instance context to match an older displayed row.
Latest release retains the same join: Source inspection of v2026.9.2 confirms the two-field identity remains in the release; this was not a packaged runtime reproduction.
Findings None None.
Security None None.

How this fits together

The Control UI Usage page displays session accounting from the Gateway. JSON export fetches omitted prompt details and combines them with the displayed accounting snapshot before downloading the file.

flowchart TD
  A[Displayed usage snapshot] --> C[JSON export]
  B[Gateway prompt details] --> C
  C --> D{Same agent, key and instance?}
  D -->|Yes| E[Download snapshot with matching details]
  D -->|No required context| F[Show refresh message]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +1, Tests +58, Docs +1. Total +60 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 3 2 +1
Tests 1 60 2 +58
Docs 1 1 0 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 64 4 +60

Review metrics

None.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #140567
Summary: This PR directly addresses the linked open report’s replacement-instance export mismatch.

Members:

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

Technical review

Best possible solution:

Keep lazy context loading and snapshot accounting while requiring the existing agent, logical key, and concrete instance to match before attaching prompt details.

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

Yes: current-main source permits an old displayed row and replacement hydration row with the same agent/key to join despite different session IDs. The supplied compiled-browser results exercise that case; this reviewer did not execute it.

Is this the best way to solve the issue?

Yes: extending the shared identity repairs all three export matching operations without adding another loading path, changing the response format, or rewriting stored state.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 0cd1ca7552a0.

Labels

Label changes:

  • add P2: Repairs incorrect exported context after session-key reuse, with a bounded Usage-page impact.
  • add proof: sufficient: Contributor real behavior proof is sufficient. Captured results exercise the compiled Usage export owner through normal browser clicks and actual downloads against synthetic Gateway snapshots, showing replacement rejection and successful same-instance and refresh recovery in both views. This is browser boundary proof, not live session deletion/recreation; linked media inspection was blocked by reviewer network access.
  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): Captured results exercise the compiled Usage export owner through normal browser clicks and actual downloads against synthetic Gateway snapshots, showing replacement rejection and successful same-instance and refresh recovery in both views. This is browser boundary proof, not live session deletion/recreation; linked media inspection was blocked by reviewer network access.

Label justifications:

  • P2: Repairs incorrect exported context after session-key reuse, with a bounded Usage-page impact.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): Captured results exercise the compiled Usage export owner through normal browser clicks and actual downloads against synthetic Gateway snapshots, showing replacement rejection and successful same-instance and refresh recovery in both views. This is browser boundary proof, not live session deletion/recreation; linked media inspection was blocked by reviewer network access.
  • proof: sufficient: Contributor real behavior proof is sufficient. Captured results exercise the compiled Usage export owner through normal browser clicks and actual downloads against synthetic Gateway snapshots, showing replacement rejection and successful same-instance and refresh recovery in both views. This is browser boundary proof, not live session deletion/recreation; linked media inspection was blocked by reviewer network access.

Evidence

What I checked:

  • Shared export identity repair: The introduced change adds sessionId to the existing identity helper. Map construction, required-context validation, and hydration all use this helper; snapshot totals and connection fencing remain unchanged. (ui/src/pages/usage/export.ts:12, c864dc2389cd)
  • Current main still needs the fix: Fetched main still identifies export rows using only agentId and key, allowing replacement-instance context to match an older displayed row. (ui/src/pages/usage/export.ts:11, 0cd1ca7552a0)
  • Latest release retains the same join: Source inspection of v2026.9.2 confirms the two-field identity remains in the release; this was not a packaged runtime reproduction. (ui/src/pages/usage/export.ts:11, 3928bad9badf)
  • Gateway supplies concrete instance identity: The usage response emits merged.sessionId together with its stored prompt report. Family grouping preserves the base sessionId while collecting historical instances, so the added identity component applies to both supported views. (src/gateway/server-methods/usage.ts:287, c864dc2389cd)
  • Behavioral regression coverage: The rendered-page test checks replacement rejection, fresh context for an unchanged instance, unrelated-agent replacement, preserved snapshot totals, and cancellation after scope changes. Tests were inspected, not executed during this read-only review. (ui/src/pages/usage/usage-page-details.test.ts:288, c864dc2389cd)
  • Captured browser proof: The supplied PR body reports six runs of the compiled UI using synthetic Gateway snapshots and actual browser downloads: mixed exports fell from two to zero, both replacement cases showed refresh recovery, and three valid downloads remained successful. This exercises the changed export owner rather than only its mocked unit test. Captured context sourceRevision: cc0093184174d86a26cbc37f30dbb31c0b58b88f8a3be6df418cf00de4612972. Linked media could not be independently inspected because github.com did not resolve. (c864dc2389cd)

Likely related people:

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

@steipete
steipete merged commit b39b627 into main Sep 7, 2026
137 checks passed
@steipete
steipete deleted the codex/qa-usage-instance-export-20260907 branch September 7, 2026 01:34
@steipete

steipete commented Sep 7, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Sep 7, 2026
…137098

* commit '8a540c252002878f3c3e9d8dfb837b83c8602a78': (2210 commits)
  perf(plugins): keep bundled catalog lookups lightweight (#140597)
  refactor: streamline skills JSON serialization (#140581)
  fix(feishu): expand quoted merged-forward messages (#136231)
  fix(talk): keep opaque realtime routes out of public config (#129144)
  fix(ci): avoid Linux packaging on pull requests (#140589)
  fix(usage): release completed request payloads (#140588)
  fix(tooling): omit Trae machine squash credit (#140562)
  fix(ui): stop catalog paging in hidden tabs (#140583)
  fix(portals): reach IPv6 loopback with IPv4-only localhost records (#140580)
  fix(transcripts): preserve fixed and legacy capture history (#140563)
  fix(ui): prevent Talk E2E audio capture stalls (#138803)
  fix(media): release completed document source buffers (#140561)
  fix(anthropic): preserve resumed CLI caches across Git changes (#140566)
  chore(ui): refresh control ui locales (#140586)
  fix(ui): keep usage exports bound to their session instance (#140573)
  refactor(exa): test response readers through tool execution (#140572)
  fix(macos): omit incompatible worker binaries from app bundles (#140557)
  fix: avoid retaining discarded tool output (#140570)
  refactor(gateway): share placement move matching (#140569)
  fix(gateway): preserve child turns during systemd drain (#140568)
  ...

# Conflicts:
#	.agents/skills/release-openclaw-maintainer/SKILL.md
#	docs/reference/RELEASING.md
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 7, 2026
…#140573)

Include the concrete session ID in the existing export hydration key so
reusing a logical key cannot mix old usage with a replacement session's
prompt report. Preserve fresh details for the same instance and the
existing refresh-and-retry error.

Cover replacement, matching-instance, unrelated-agent, and cancellation
behavior through the rendered Usage page, and document export recovery.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui docs Improvements or additions to documentation maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor 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.

Usage JSON exports can mix context from a replacement session

1 participant