Skip to content

refactor: separate session row materialization and presentation - #149771

Merged
steipete merged 2 commits into
mainfrom
steipete/perf-session-row-materialize-20260915
Sep 16, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/perf-session-row-materialize-20260915

Conversation

@steipete

@steipete steipete commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Related: #149387

What Problem This Solves

Session row construction mixes committed metadata with request-time state, so reusing a constructed row can freeze status expiry, child retention, and the selected run's control owner or fallback cost. This is PR 1 of the session row projection series.

User Impact

No intended user-visible change. Session lists, descriptions, and event snapshots preserve their existing row values and serialized property order. No configuration, protocol, storage, cache, or invalidation behavior changes.

Why This Change Was Made

One module now owns input preparation, pure materializeSessionRow, and clock-dependent presentSessionRow. The list, describe, and single-row snapshot paths compose the same pair. buildGatewaySessionRow remains a thin composition helper for its remaining callers. The materialize/present names are retained.

Filtering and viewer decoration stay at their existing caller locations. Sharing, visibility, activity permissions, placement, and active-run facts therefore retain their current authorization and post-yield freshness boundaries.

The registry index exposes its already captured snapshot map and exact in-memory winners through a narrow internal inputs contract. This approved owner extension preserves #149466's worker-prepared index and removes Gateway's duplicate snapshot-reading scaffolding; it adds no SQLite read or plugin SDK export.

Raw run candidates are required: when an older unended run ages out, a newer ended run can become the display run, changing both its controller and transcript fallback cost. Preparation reads transcript usage once for the candidate variants; presentation selects the appropriate result. Lightweight rows continue to permit token fallback while exposing only persisted cost.

The assertion-safety baseline removes exactly the row builder's obsolete one-count entry, recording the authorized shrink from 1 to 0 without restoring its redundant cast.

Series LOC ledger

PR 1 group Production LOC delta Boundary requirement
Shared row owner +65 Separate owner reads, pure materialization, and fresh presentation while retaining wire field order
Raw run/cost inputs and contracts +15 Preserve time-driven run selection and cost changes without rereading transcripts during presentation
Child-link and run projection consolidation −27 Keep retention and run policy shared while removing duplicate branches and a wrapper
Caller composition +9 Connect all three read paths to the same pair
PR 1 total +62 One row-owner module, below its line cap

PR 3 is planned to remove the 316-line sessions-list-cache.ts whole-result cache and fence, fence-only counter readers, and duplicate row preparation across list/describe/search/snapshot paths. Those removals fund the projection implementation; the complete series remains required to be net-negative. None of that later work is included here.

Evidence

  • The compact golden test pins 17 fixtures at three clocks with 51 SHA-256 hashes regenerated from the unchanged builder at base 7b47d7a65a17e7a49d943795a5b112ae4adcfe3c; every hash is unchanged. That base-compatible test was also executed in an isolated checkout. A mismatch writes canonical JSON under Vitest's temporary directory and reports its path, both hashes, and JSON in the failure log.
  • The final test materializes each fixture once, rejects clock reads during materialization, compares supplied-index and raw-input presentation, and checks that presentation does not mutate materialized state. The large snapshot file was removed.
  • All requested suites plus the registry owner and persisted-worker integration suites pass on the rebased candidate: 35 files, 804 tests. This includes golden, GC, performance, list/describe, event, lifecycle, and payload proof. The unchanged GC test protects the original display-identity discovery ordering.
  • The registry owner regression fails before the contract addition (expected undefined to be defined) and passes afterward. It verifies ungrouped snapshot rows, exact in-memory winners captured before a yield, and replay from those inputs. The lightweight-cost regression also retains its fail-before/pass-after proof.
  • Performance contracts remain intact: five thinking lookups and at most five catalog lookups for 30 rows/five tuples; five fallback-cost lookups or zero for recorded cost; at most ten catalog lookups for an 80-row list; one ACP read per list and three at the 501-entry batch boundary. Transcript batching and event-loop yielding assertions pass.
  • node scripts/check-changed.mjs and git diff --check pass. Fresh independent review of the rebased diff is scoped-clean through P2, with no actionable findings.

Fixtures cover status expiry, runs and goal timestamps, child/swarm state, placement and ACP metadata, observer ordering, inherited settings, and draft/incognito visibility. No live Gateway or release operation was performed. Documentation is unchanged because the external behavior is preserved.

@clawsweeper

clawsweeper Bot commented Sep 16, 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 gateway Gateway runtime size: XL maintainer Maintainer-authored PR labels Sep 16, 2026
@steipete
steipete marked this pull request as ready for review September 16, 2026 06:00
Capture 17 fixtures at three clocks from the unchanged row builder before
separating committed metadata from request-time presentation. Keep the
expected wire-byte hashes compact and emit mismatch JSON for diagnosis.
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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 Sep 16, 2026
@clawsweeper

clawsweeper Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 16, 2026, 3:01 AM ET / 07:01 UTC (Revision 2).

ClawSweeper review

What this changes

Separates Gateway session-row input preparation, stable metadata construction, and time-dependent presentation while preserving existing response fields.

Merge readiness

✅ Ready for maintainer review

This remains a useful, distinct refactor with no blocking correctness findings. The rebased head addresses the previous integration concern; neither related merged PR supplies this separation, and maintainer-authored work is protected from cleanup closure.

Priority: P2
Reviewed head: 4aa6d0d3c18bfd9df4438ff445e105e38f078369

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A coherent refactor with useful temporal and serialization coverage and no supported blocking defect.
Proof confidence 🌊 off-meta tidepool Not applicable: The maintainer-authored internal refactor is exempt from the external-contributor proof gate. Its body reports rebased list/describe/event and registry tests, explicitly states no live Gateway run, and makes no new runtime performance claim.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The maintainer-authored internal refactor is exempt from the external-contributor proof gate. Its body reports rebased list/describe/event and registry tests, explicitly states no live Gateway run, and makes no new runtime performance claim.
Evidence reviewed 8 items Shared production owner: The row module prepares inputs, materializes stable fields, and presents clock-dependent status, run selection, costs, and child retention. The retained builder composes the same functions rather than maintaining a parallel implementation.
Worker preparation and caller boundaries preserved: List preparation still obtains the asynchronous registry index and checks admission before constructing row metadata. List rows compose the new functions immediately; describe retains its visibility check after catalog loading and its existing viewer decoration.
Serialization and temporal regression coverage: The inspected golden test pins 17 fixtures at three clocks, compares supplied-index and reconstructed-index presentation, rejects clock reads during materialization, and checks that presentation leaves materialized state unchanged. It includes changing control owners, fallback costs, and lightweight cost gating.
Findings None None.
Security None None.

How this fits together

Gateway session reads combine stored session metadata, subagent runs, model metadata, and transcript usage into rows consumed by session lists, descriptions, and event snapshots. This refactor separates those inputs from presentation without adding cross-request caching.

flowchart TD
  A[Stored sessions and transcript usage] --> C[Prepare row inputs]
  B[Registry and model metadata] --> C
  C --> D[Materialize stable fields]
  D --> E[Present current row]
  F[Clock and current run facts] --> E
  E --> G[Lists descriptions and snapshots]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +62, Tests +653, Other -1. Total +714 across 15 files.

View PR surface stats
Area Files Added Removed Net
Source 9 554 492 +62
Tests 5 690 37 +653
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 0 1 -1
Total 15 1244 530 +714

Review metrics

Metric Value Why it matters
Production versus test growth production +62 lines; tests +653 lines The body explains the production growth as the shared preparation/presentation boundary; planned later cache removals are outside this PR.
Serialized response coverage 17 fixtures × 3 clocks = 51 pinned hashes The golden matrix protects response values and serialized property order across temporal transitions.

Technical review

Best possible solution:

Keep one session-row owner that reuses prepared metadata while evaluating temporal fields at presentation time and leaving authorization with existing callers.

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

Not applicable: this PR prepares an internal refactor rather than claiming a newly reproduced bug; its temporal and serialization contracts have focused regression coverage.

Is this the best way to solve the issue?

Yes: the split stays within the existing row owner, consumes the registry's captured inputs, and preserves caller-owned filtering and decoration without introducing another cache.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This is a bounded Gateway refactor supporting session-list performance work without an intended user-visible behavior change.
  • 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: The maintainer-authored internal refactor is exempt from the external-contributor proof gate. Its body reports rebased list/describe/event and registry tests, explicitly states no live Gateway run, and makes no new runtime performance claim.

Evidence

What I checked:

  • Shared production owner: The row module prepares inputs, materializes stable fields, and presents clock-dependent status, run selection, costs, and child retention. The retained builder composes the same functions rather than maintaining a parallel implementation. (src/gateway/session-utils-row.ts:339, 4aa6d0d3c18b)
  • Worker preparation and caller boundaries preserved: List preparation still obtains the asynchronous registry index and checks admission before constructing row metadata. List rows compose the new functions immediately; describe retains its visibility check after catalog loading and its existing viewer decoration. (src/gateway/session-utils-list.ts:184, 4aa6d0d3c18b)
  • Serialization and temporal regression coverage: The inspected golden test pins 17 fixtures at three clocks, compares supplied-index and reconstructed-index presentation, rejects clock reads during materialization, and checks that presentation leaves materialized state unchanged. It includes changing control owners, fallback costs, and lightweight cost gating. (src/gateway/session-utils-row.materialize.test.ts:476, 4aa6d0d3c18b)
  • Previous integration concern resolved: Raw test-merge records identify base 6a85e4c followed by pinned head 4aa6d0d. Its comparison against that base contains the same 15 intended paths. The captured PR body reports 804 passing tests across 35 files on the rebased candidate; this review did not execute them. (3b446a1a658c)
  • Still distinct from current main: Fetched main and the PR merge base contain the identical row-builder blob, 940eaea1867ede3efd100c252933fc90ec6a19d6. Current main still exports the combined builder rather than the proposed materialize/present separation. (src/gateway/session-utils-row.ts:91, b7d2835c93c7)
  • Release comparison: GitHub identifies v2026.9.4 as the latest release. Its row source also exports the combined builder. The local release blob was unavailable, so its contents were inspected through GitHub's read-only contents endpoint. (src/gateway/session-utils-row.ts:87, 3a9d69db306c)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)
  • obviyus: 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 (1 earlier review cycle)
  • reviewed 2026-09-16T06:23:13.448Z sha 69ebd90b60ee4f1e5dbc0ab955bc9c78158886a7 :: blocked before merge. :: none

@openclaw-barnacle openclaw-barnacle Bot reopened this Sep 16, 2026
Separate committed metadata from request clocks so later row reuse can
preserve live status, child retention, and run-dependent cost display.
Keep viewer decoration at its existing authorization boundary and capture
raw run candidates before pure materialization.

Preserve lightweight cost gating and metadata discovery ordering. Remove
the redundant assertion and shrink its baseline entry from one to zero.
@steipete
steipete force-pushed the steipete/perf-session-row-materialize-20260915 branch from 69ebd90 to 4aa6d0d Compare September 16, 2026 06:52
@steipete
steipete merged commit 40b986d into main Sep 16, 2026
191 of 192 checks passed
@steipete
steipete deleted the steipete/perf-session-row-materialize-20260915 branch September 16, 2026 07:45
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 17, 2026
…claw#149771)

* test: pin session row serialization across clocks

Capture 17 fixtures at three clocks from the unchanged row builder before
separating committed metadata from request-time presentation. Keep the
expected wire-byte hashes compact and emit mismatch JSON for diagnosis.

* refactor: separate session row materialization and presentation

Separate committed metadata from request clocks so later row reuse can
preserve live status, child retention, and run-dependent cost display.
Keep viewer decoration at its existing authorization boundary and capture
raw run candidates before pure materialization.

Preserve lightweight cost gating and metadata discovery ordering. Remove
the redundant assertion and shrink its baseline entry from one to zero.
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: XL 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