Files
openclaw/docs/reference
weiqinlandPeter Steinberger 0fef6319fa fix(usage): preserve agent ownership for matching session IDs (#128803)
* fix(usage): attribute named sessions to their store owner in all-agent list

The all-agent `sessions.usage` list labeled durable (store-backed) session
rows with whichever agent discovery surfaced, instead of the store owner.
When a subagent spawned from a session left a discovery transcript that
reused the parent sessionId, the Sessions dashboard card showed the
subagent's id (e.g. `scout-research`) instead of the owning agent
(`main`).

Resolve the owner from the durable store key via
`resolveSessionStoreAgentId`, re-resolve the owner's transcript file, and
de-duplicate by store key so a reused subagent transcript cannot shadow or
duplicate the owner row. Unnamed discovery-only sessions keep using the
discovered agent id.

Closes #128755

* fix(usage): reject cross-agent transcript fallback for named sessions

Address the ClawSweeper review finding on #128755: when owner transcript
resolution returned no file, the `?? discovered.sessionFile` fallback
could load the subagent's reused transcript under the owner row, leaving
attribution and usage totals inconsistent.

Resolve only an owner-associated transcript for store-backed named rows.
When the owner transcript is absent the row stays attributed to the owner
with no usage loaded (cold cache) instead of substituting another agent's
transcript.

Move the two #128755 regression tests into a dedicated
`usage.sessions-usage-owner-attribution.test.ts` so the existing
oversized test file stays under the max-lines limit, and add a case
covering the unresolved-owner path.

* fix(usage): bind transcript resolution to the durable store owner marker

Address the ClawSweeper re-review finding on #128755: the owner-file
resolver accepted a store entry SQLite marker by sessionId alone, so a
marker reusing the sessionId under a different agent (e.g. a subagent)
could still substitute that agent's transcript for a main-owned row.

Guard the resolver call: parse the store entry marker and only forward the
entry when its embedded agent matches the resolved owner. When the marker
belongs to another agent, drop the entry so the resolver falls back to the
owner agent's own transcript directory (or no file), never the subagent's.

Add a regression covering a durable row whose stored marker names a
different agent.

* fix(usage): drop redundant type assertion for store entry sessionFile

SessionEntry already declares sessionFile?: string, so accessing it
directly avoids a non-const type assertion. Restores the assertion-safety
ratchet (8 > 7 baseline) without changing behavior.

* fix(usage): validate entry marker agent in transcript resolver

Move the store-entry SQLite marker ownership check into
resolveExistingUsageSessionFile itself: matchingEntryMarker now requires
entryMarker.agentId to equal the requested agentId, so a subagent marker
reusing a parent sessionId can no longer be substituted for the owner
transcript. This lets the all-agent usage list drop its redundant outer
guard (and its non-const type assertion) and simply request the owner
agent, restoring the assertion-safety ratchet baseline.

Adds a regression test in session-cost-usage.test.ts covering the mismatched
agent marker path.

* fix(usage): preserve selected-agent ownership for global list rows (#128755)

- Only resolve durable owner for agent-scoped named keys; keep discovered
  agentId for global/unknown so a scoped request keeps its own global row.
- Add scoped-global list-path regression test.
- Add real-state remote-proof test (no internal mocks) logging the RPC trace.
- Add positive marker-match test; trim verbose comments.

* fix(usage): drop unused eslint-disable directive in remote-proof test

* fix(usage): resolve global durable rows to owner in all-agent lists (#128755)

ClawSweeper P1: all-agent discovery is newest-first, so a subagent transcript
that reuses a global durable row's sessionId could still relabel the row.
Resolve global/unknown rows to their logical owner in all-agent lists while
keeping the explicitly requested agent for scoped lists.

- Add all-agent global-row regression test.
- Add authenticated Gateway WebSocket proof test capturing the RPC trace.

* test(usage): restore gateway token env after ws-proof server

* test(usage): add real-Gateway UI e2e proof for #128755 owner attribution

Add a real-Gateway Control UI e2e test that seeds the #128755 scenario
(main owns the durable telegram DM row; an opus subagent transcript reuses
its sessionId, discovery-only) and drives a real Chromium browser against a
loopback token-free Gateway. The Sessions usage dashboard must attribute the
Telegram DM card to its store owner (agent:main), never to the reused opus
subagent, with no duplicate/shadow row.

- Asserts the .session-bar-row for agent:main:telegram:dm shows agent:main
  in its meta and no agent:opus row appears.
- Captures a redacted isolated dashboard screenshot when
  OPENCLAW_CAPTURE_UI_PROOF=1 (sanitized test fixtures, loopback, no tokens).
- Registered in the checks-ui-e2e-real-gateway CI lane and excluded from the
  standard ui-e2e shard via uiE2eRealGatewayTestFiles.

* fix(usage): bind owner transcript to canonical durable target (#128755 P1)

ClawSweeper P1: resolveExistingUsageSessionFile still received storeMatch.entry,
whose sessionFile can hold a cross-agent legacy JSONL path. resolveSessionFilePathCore
intentionally accepts absolute paths from other agents, so a main-owned row
carrying an opus path would be labeled main while the opus transcript loaded
into main's usage group.

Resolve via the canonical durable owner target instead: pass a complete
sessionTarget (owner agentId + sessionId + store key + owner storePath) so
resolveExistingUsageSessionFile validates owner identity and returns the owner's
canonical SQLite marker, never consulting the cross-agent legacy file.

- Add regression: owner target rejects an existing cross-agent opus transcript
  file on the durable entry and returns the owner's sqlite:main: marker.

* fix(usage): join sessions by agent and transcript identity

Carry projected session ownership into usage reporting and preserve independent
cross-agent transcripts with equal IDs. Scope historical-family suppression to
the same identity, retaining canonical aliases within each agent.

Replace re-attribution and deduplication branches with one owner-aware join.
Add real-state ownership coverage and retain real-Gateway browser proof.
Stabilize neighboring cache range coverage by awaiting its real refresh.

Fixes #128755. Refines #128803. Thanks to @yetisoldier for the report.

Co-authored-by: LiuwqGit <liu.weiqin@xydigit.com>

* test(usage): seed browser transcripts within the active date window

* test(ui): assert reader anchoring across transcript growth

---------

Co-authored-by: Peter Steinberger <steipete@gmail.com>
2026-08-27 23:13:44 -07:00
..
…
…