Skip to content

perf(sessions): reuse rows across unrelated subagent updates - #165932

Merged
steipete merged 2 commits into
mainfrom
steipete/perf-micro-session-row-presentation-once-20260919
Oct 6, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/perf-micro-session-row-presentation-once-20260919

Conversation

@steipete

@steipete steipete commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

An unrelated subagent publication invalidates frozen sessions.list rows and rebuilds their output snapshots even when those sessions have not changed.

User Impact

Session lists and event readers reuse unchanged frozen row presentations during unrelated subagent activity. Current run state, viewer permissions, child navigation, and expiring display fields remain live. Sidebar, full/compact lists, and the Sessions board share this presenter; sessions.catalog.list uses a separate native catalog pipeline.

Why This Change Was Made

The row-view cache included the global subagent revision. Compare the row's actual derived runtime and child facts instead, reuse unchanged child-owner vectors, and preserve equivalent swarm summaries. The existing owners still control invalidation; no new revision, timer, configuration, or schema is introduced.

Materialized inputs are mutable: preview, profile, and lineage publishers update them in place. The deep copy therefore remains when producing a genuinely changed output, preserving snapshot isolation. Quiet polls already avoided that copy on the baseline; this change removes copies triggered by unrelated publications.

Production LOC: 14 added, 13 removed (net +1). The small growth preserves all seven mutable runtime fields after removing the global revision guard. Explicit scalar comparisons avoid allocating a temporary values array for each unchanged row; the redundant global invalidators and child-owner revision state are removed.

Evidence

Synthetic Linux rig, 5,000 sessions (2,300 unarchived), 25 viewers, the same seeded identities and fixed presentation clock. The retained-allocation comparison issues 710 sidebar requests over 600 seconds, with an unrelated subagent publication before every request. The harness uses the real list/projection owner with serialized-row delivery and request active-run context. Measurement base: c20c6e5822d741c03831cac8ad805aace1735de3.

Measurement Before After
Row constructions, 25 publication/poll pairs 2,934 0
Row-output clones, same 25 pairs 2,934 0
Selection-facet clones, same 25 pairs 25 25
present() self + descendant row-clone retained bytes, ten-minute window 5,895,232 0 sampled
Whole presenter subtree retained bytes 6,697,136 75,112 (−98.9%)
Total sampled retained bytes 9,491,936 488,928 (−94.8%)

Live-only sampling uses a 4 KiB interval and measures allocations made during the window that remain alive at its end. Zero sampled bytes is not a claim of zero process memory or a leak fix. Both runs use the same workload. All 75 quiet viewer/mode row-payload hashes and all 25 publication/poll row hashes match exactly. All 75 full-response hashes also match after normalizing only the fixture-specific top-level state path; no other field is normalized.

The under-100 KB unchanged-request allocation target remains unmet. With 512-byte all-allocation sampling after warmup, unchanged requests measured:

Mode Returned rows Before, bytes/request After, bytes/request
Sidebar 117.36 average 1,789,553 1,796,003 (+0.4%)
Compact 100 1,636,670 1,666,599 (+1.8%)
Full 100 1,626,102 1,667,783 (+2.6%)

Those quiet polls already made zero row constructions/clones on the baseline. Remaining allocations include repeated authorization and temporal-signature preparation. The original lane 481 evidence scripts were unavailable, so this harness was reconstructed from the repository's session-list viewer benchmark; its absolute figures are not an exact replay of the earlier 469 KB/request result. Shared-host timing is secondary and is not used to claim a quiet-poll speedup.

The regression exercises the real sessions.list handler. It fails on the baseline after an unrelated commitOwnership publication because the unchanged row is rebuilt, and asserts stable row identity plus no row construction or cloning after the fix.

Blacksmith Testbox tbx_01m47fyzmvs8fgrsg1a2npzm86, profile openclaw-check:

  • Earlier owner-cutover proof, five focused files: 34 tests passed, 69.82 seconds Vitest / 72.52 seconds wrapper. The changed file's three tests used 2.41 seconds of test time.
  • node scripts/check-changed.mjs --staged: passed on the source-hash-verified final candidate (all 27 test typecheck graphs, lint, export scans, and repository guards). Earlier attempts caught test-spy typing and a redundant shadowed test declaration; both were corrected.
  • Replacement Testbox tbx_01m47kt2wddh8yjpxq88jv7w02, same provider/profile: final presentation/event/serialization files 10 tests passed (40.18 s Vitest / 42.23 s wrapper). Standalone pnpm test src/gateway/session-list-serialization.test.ts --maxWorkers=1: 3 passed, 8.46 s Vitest / 10.49 s wrapper, 2.09 s test time. Both leases are stopped/completed.

Codex autoreview of the production change and complete owner/sharing context: scoped-clean, no P0–P2 findings. Rebased onto current main before publication; all four candidate files retained identical SHA256 hashes. Exact-head CI run 37409317865 on 0d1187ed3e32b895ef6122b3a5ce4b47b6d50e3e completed with 44 successful jobs, including all 19 selected Node test jobs. Those shared Node jobs consumed 3,642 runner-seconds (92–342 seconds each); this is whole-shard cost, not isolated cost for the added regression.

CI is blocked by two inherited main failures:

  • security-fast: production [email protected] fails GHSA-68fv-2mgg-jv7q. The identical advisory fails main run 37408159153 at 14fe10d01c75. This PR changes no dependency files. The dedicated fix is fix: unblock CI with patched source-map-js #165902, still pending on main.
  • check-test-types-core-4: src/flows/doctor-health.migration-refusal.test.ts:84 and :182 have incomplete beginDoctorMaintenance mocks after refactor(cli): deslop CLI and commands #165900 removed the broader return annotation. Missing fields are serviceUpdateVerdict, warnings, failureFacts, and (in the first fixture) databaseWrites. The affected test blob is identical on this branch and current main (1056faefbc6d52378202559975048e63ff674392); neither the test nor the Doctor owner is changed here. The aggregate openclaw/ci-gate failure follows these upstream failures.

The main recheck at 3b9c3e35de61 still has both conditions. No rerun, dependency change, unrelated fixture fix, or merge was used to conceal these failures. The lane remains four files and one focused commit.

Remote command record

All Testbox commands used blacksmith-testbox, profile openclaw-check, with normal Crabbox sync. Initial gate/development runs used tbx_01m47fyzmvs8fgrsg1a2npzm86; final focused tests and standalone cost used replacement tbx_01m47kt2wddh8yjpxq88jv7w02. Dependencies were initially absent: pnpm install --frozen-lockfile passed once; pnpm docs:list also passed.

Command Result
node scripts/run-vitest.mjs src/gateway/session-list-serialization.test.ts --maxWorkers=1 Initial map-only fixture: 3 passed, 39.25 s wrapper. After using committed ownership publication: expected baseline regression failed, 2 other tests passed, 11.46 s wrapper.
node scripts/run-vitest.mjs src/gateway/session-list-serialization.test.ts src/gateway/session-row-presentation.test.ts src/gateway/session-row-event-parity.test.ts src/gateway/session-row-projection.invalidation.test.ts src/gateway/session-row-projection.subagent-index.test.ts --maxWorkers=1 34 passed, 72.52 s wrapper.
node scripts/check-changed.mjs --staged First run found the new test's unknown-value typing error; second found a redundant shadowed test declaration after all 27 test graphs passed. Both were corrected. Final exact-source run passed; the subsequent test command was interrupted when the lease completed (wrapper exit 255).
node scripts/run-vitest.mjs src/gateway/session-list-serialization.test.ts src/gateway/session-row-presentation.test.ts src/gateway/session-row-event-parity.test.ts --maxWorkers=1 Initial final run was interrupted after nine passing tests when the lease completed; replacement lease tbx_01m47kt2wddh8yjpxq88jv7w02 passed all 10 tests, 42.23 s wrapper.
pnpm test src/gateway/session-list-serialization.test.ts --maxWorkers=1 3 passed; 8.46 s Vitest, 10.49 s wrapper, 2.09 s test time (replacement lease).

The Linux rig ran the standalone synthetic harness through nice -n 10 ionice -c3 node --import ./scripts/tsx.mjs, with TMPDIR inside its task worktree. Quiet allocation runs used RIG_CALLS=250 after 125 warmup calls. Paired retention runs used RIG_MODES=sidebar RIG_CHURN=1 RIG_LIVE_SECONDS=600; both exited 0. Full-envelope parity runs used RIG_HASH_ONLY=1; baseline and candidate both exited 0. Sampling precedes coverage/call instrumentation to avoid measuring coverage-induced deoptimization. An intermediate signature using an array spread was rejected after attribution showed extra quiet-poll allocation; the tables above use the final explicit-scalar implementation. The rig worktree and its processes have been removed.

Key frozen row views by their actual runtime, child, and sharing facts instead of global subagent publications. Preserve live authorization and output snapshot isolation while avoiding unchanged row reconstruction and cloning.
@clawsweeper

clawsweeper Bot commented Oct 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 October 6, 2026 03:30
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S labels Oct 6, 2026
@steipete
steipete enabled auto-merge (squash) October 6, 2026 03:31
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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 Oct 6, 2026
@clawsweeper

clawsweeper Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 6, 2026, 12:05 AM ET / 04:05 UTC (Revision 3).

ClawSweeper review

What this changes

The PR reuses unchanged session-list rows across unrelated subagent publications while refreshing runtime state and child navigation.

Merge readiness

✅ Ready for maintainer review

This remains a useful, focused performance improvement absent from the inspected main revision. No introduced correctness defect was found; the latest CI failure is a database-lock assertion whose connection to this patch is unproven.

Priority: P2
Reviewed head: fc0e0f01245a2e38ba17dd7ede3c287e7b1b03d0

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused implementation with strong recorded performance and parity evidence, with no actionable introduced defect found.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The captured Linux rig evidence exercises the real list/projection owner with serialized delivery under unrelated subagent publications, showing eliminated row rebuilding and matching response hashes. Focused tests supplement that evidence; no stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The captured Linux rig evidence exercises the real list/projection owner with serialized delivery under unrelated subagent publications, showing eliminated row rebuilding and matching response hashes. Focused tests supplement that evidence; no stored-data contract changes.
Evidence reviewed 8 items Verified introduced change: The pinned base-to-head diff replaces global publication invalidators with derived runtime and child facts, preserves equivalent swarm objects, and extends the existing handler regression. The four reviewed files are unchanged from the earlier reviewed head.
Runtime and snapshot invariants: The new signature covers all seven fields produced by the runtime-state projector, the subagent model and controller, and child identities and retention decisions. Viewer restrictions are still computed before cache lookup; changed outputs still use structuredClone followed by freezing.
Still necessary on inspected main: Fetched main still contains the global subagent revision and row subagent revision in the presentation signature. The latest release ancestry check does not contain this PR head; no merged fixing replacement was established.
Findings None None.
Security None None.

How this fits together

The Gateway combines stored session metadata, current run state, and viewer permissions into session rows. Those rows feed session lists and event delivery to connected clients.

flowchart TD
  A[Stored session metadata] --> D[Session row projection]
  B[Subagent publications] --> D
  D --> E[Compare current row facts]
  C[Viewer permissions and clock] --> E
  E --> F[Reuse or rebuild frozen row]
  F --> G[Session lists and events]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +1, Tests +32. Total +33 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 3 14 13 +1
Tests 1 33 1 +32
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 47 14 +33

Review metrics

Metric Value Why it matters
Retained presenter allocations 6,697,136 → 75,112 sampled bytes The recorded ten-minute publication workload demonstrates the targeted retention reduction without claiming a quiet-poll allocation improvement.

Technical review

Best possible solution:

Keep row reuse governed by current derived facts, with live viewer checks and immutable output snapshots.

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

Yes: inspected main keys row reuse on global subagent publications, and the recorded baseline handler regression demonstrates unnecessary rebuilding after an unrelated ownership publication. This review did not execute that path.

Is this the best way to solve the issue?

Yes: comparing the facts actually consumed by presentation removes unnecessary invalidation while retaining the existing projection, permission, and snapshot owners.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a bounded session-list performance improvement with unchanged output contracts and no demonstrated urgent user-facing regression.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The captured Linux rig evidence exercises the real list/projection owner with serialized delivery under unrelated subagent publications, showing eliminated row rebuilding and matching response hashes. Focused tests supplement that evidence; no stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured Linux rig evidence exercises the real list/projection owner with serialized delivery under unrelated subagent publications, showing eliminated row rebuilding and matching response hashes. Focused tests supplement that evidence; no stored-data contract changes.

Evidence

What I checked:

  • Verified introduced change: The pinned base-to-head diff replaces global publication invalidators with derived runtime and child facts, preserves equivalent swarm objects, and extends the existing handler regression. The four reviewed files are unchanged from the earlier reviewed head. (src/gateway/session-row-presentation.ts:267, fc0e0f01245a)
  • Runtime and snapshot invariants: The new signature covers all seven fields produced by the runtime-state projector, the subagent model and controller, and child identities and retention decisions. Viewer restrictions are still computed before cache lookup; changed outputs still use structuredClone followed by freezing. (src/gateway/session-row-presentation.ts:277, fc0e0f01245a)
  • Still necessary on inspected main: Fetched main still contains the global subagent revision and row subagent revision in the presentation signature. The latest release ancestry check does not contain this PR head; no merged fixing replacement was established. (src/gateway/session-row-presentation.ts:271, ad99343036ff)
  • Recorded production-path performance proof: The captured PR body records a synthetic Linux workload using the real list/projection owner and serialized-row delivery: 5,000 sessions, 25 viewers, and unrelated publications before requests. Row constructions and output clones fell from 2,934 to zero over 25 publication/poll pairs; 75 full-response hashes matched after normalizing only the fixture state path. The ten-minute retention measurement is explicitly distinguished from total allocation, and the unmet quiet-request target is disclosed.
  • Focused regression and validation: The added case uses the actual sessions.list handler and committed subagent ownership publication, asserting unchanged row identity and no row reconstruction or cloning. The body records an intended baseline failure, final focused passes, and a 2.09-second test-time measurement for the changed suite. Existing sibling coverage exercises viewer changes, runtime clocks, preview updates, and child expiry. Tests were inspected, not executed during this read-only review. (src/gateway/session-list-serialization.test.ts:71, fc0e0f01245a)
  • Latest CI failure differs from body: Exact-head annotations identify a database-is-locked assertion in chat-metadata-session-writes.test.ts at line 409. This file has no introduced diff. Current security and test-type checks pass, so the body's earlier inherited failures no longer describe the remaining red job. The full job-log download was blocked by the network allowlist; annotations establish the failure but do not establish its root cause or an inherited-failure exception. (src/gateway/server-methods/chat-metadata-session-writes.test.ts:409, fc0e0f01245a)

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.

History

Review history (2 earlier review cycles)
  • reviewed 2026-10-06T03:35:53.106Z sha 0d1187e :: needs maintainer review before merge. :: none
  • reviewed 2026-10-06T03:47:49.207Z sha 0d1187e :: needs maintainer review before merge. :: none

@steipete
steipete merged commit 8371bb8 into main Oct 6, 2026
191 of 193 checks passed
@steipete
steipete deleted the steipete/perf-micro-session-row-presentation-once-20260919 branch October 6, 2026 04:29
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 7, 2026
…w#165932)

Key frozen row views by their actual runtime, child, and sharing facts instead of global subagent publications. Preserve live authorization and output snapshot isolation while avoiding unchanged row reconstruction and cloning.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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