Skip to content

perf(sessions): reduce cold history child lookup overhead - #148775

Merged
steipete merged 1 commit into
mainfrom
codex/swarm-child-metadata-20260915
Sep 17, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/swarm-child-metadata-20260915

Conversation

@steipete

@steipete steipete commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Related: #130741

What Problem This Solves

Cold session lookup still decodes unused child skill snapshots and prompt reports, and direct child discovery can scan retained session history. Embedded TUI history requests a complete selected entry together with child metadata, so retained Swarm children can add unnecessary preparation work.

User Impact

Reduces work in cold child lookup while preserving the selected session's complete data, child links, visibility, ownership, and fresh deletion results. Ordinary session lists and descriptions keep the current resident-row owner. No configuration, schema, retention, or queue policy changes are required. The overall 500 ms responsiveness target remains open.

Why This Change Was Made

Child discovery uses the existing list metadata projection and the existing parent/spawn indexes in one ordered, deduplicated query. Guards keep child metadata from replacing selected full entries. This port preserves #150625's prepared store discovery and selection and #150196's resident list/describe behavior. Payload regressions now exercise the actual cold loader while retaining the current real registry and resident lifecycle checks.

Evidence

Candidate 4e7a66ec3a09a3b0fb423f59693544a5f8709c70 is based on main bfb531c055e27cff373116fa715174b7d3b85222, with tree 5fbc526cca2d833e9a602ff31c6aa6ce442a1cb5. The four-file source change passed fresh independent P0–P2 review, formatting, and diff sanity. Fresh Linux proof passed all 194 selected candidate cases. Exact-head CI completed successfully with 142 successful jobs and 16 skipped. The full selected gate passed, including production and core-test typechecking, all three unused-export scans, lint, formatting, and the state and contract guards. The Linux command returned exit 0 after 35m16.841s; a subsequent external runner portal-sync request timed out. The downloaded native reports and complete command result were verified before normal owned-lease cleanup.

The two complete regression files produced matching 35-case inventories: the baseline passed 31 and failed exactly the four intended assertions; the candidate passed all 35. The failures reproduced a full-table scan and unnecessary persisted/main/worker child payload retention through the cold loader. Nine current consumer selections added 159 passes covering prepared lookup ownership, retained children, resident descriptions and sharing, diagnostics, clean-read SQLite behavior, incognito generation fences, registered chat history/startup, and embedded history. The history filter selected 9 TUI cases and deliberately excluded 128 others; no selected case skipped or failed. All 13 native reports and the reconciliation summary were downloaded and independently verified. Embedded history's mock boundary checks are not live TUI proof. Retired list-worker suites remain deleted.

The provider fell back from targeted sync to full sync within this single invocation, then verified the exact source and tree before execution. The trusted review of this head, completed at 14:11 UTC, found no introduced correctness or security finding and confirmed merge composition. Its request for completed current-head integration evidence is answered by these retained results; this text does not claim that the public review marker changed.

No timing benchmark was repeated. Earlier SQL measurements and the original 17 of 1,316 foreground observations above 500 ms remain attributed below; none establish latency for this new integrated head. This PR does not close #130741.

Retained evidence from earlier source revisions

The previously qualified candidate was fa202e5c1d6323ce6decac288b5bfb3549bfc359, based on main 62507cc516f706f40a1985086f06d066917f2d92, with source tree cc0c136e5443f8bd2c1c0abcd02ce6bf6248f3c9. Range-diff confirms the same five-file patch as the previously verified candidate. Main now includes #149971’s conversation-read workers and shared-cache changes, plus the canonical CI fixture repairs in #150655. Fresh Linux proof verified this exact source and passed all 116 candidate cases on Node 24.19.0. The matching 59-case current-baseline comparison produced 55 passes and exactly four intended failures; all 59 cases passed on the candidate, with matching test identities and assertion locations. Seven current sibling suites contributed 57 additional passes covering worker/cache independence, concurrent inventory ordering, capacity and native-close lifetime, current async page-access decisions, diagnostics, and recursive spawning. All 13 native reports were downloaded and verified locally, with no skipped cases, retries, or reporting gaps. The full selected gate passed, including production typechecking, all 20 core test-type graphs, lint, formatting, export scans, and contract guards. Exact-head CI completed successfully with 141 successful jobs and 16 skipped jobs. No timing benchmark was repeated. The Linux command completed with exit 0; a subsequent external runner portal-sync request timed out. The retained reports and source bindings were verified, and the owned Testbox was stopped and its local capsule removed.

The prior Blacksmith proof belongs to head b918ab166fb1c2b757065683cda1045656e463ba on base 7a3160e582776548a9ec73c0b5a9139fa714c61d, using Linux and Node 24.19.0. All 59 candidate session/Gateway cases and 15 session-list diagnostics cases passed. Its matching 59 baseline cases produced 55 passes and four exact regressions: sessions.describe decoded two child skill snapshots and two prompt reports; registry-only child reads decoded unused payloads for both main and worker agents; and the child-query test observed a full session-table scan. Every failing baseline case passed on that candidate. The full selected gate passed, including all 20 core test-type graphs, production typechecking, lint, formatting, export scans, and contract guards.

That proof’s initial driver stopped after the expected Gateway failures before starting the baseline exact-read shard, leaving its aggregate report incomplete. A continuation ran only that unstarted shard and found the fourth baseline regression; its overly strict expected count also returned nonzero. Both driver exits are retained. Native reports were reconciled by exact test identities and assertion locations. All candidate phases and the full selected gate exited zero.

On the same prior head/base comparison, both revisions passed the 16-case recursive-spawn production-boundary suite, including all three descendant-model inheritance cases. Actual owner queries returned identical five-child results on the same 4,622-row synthetic retained state, with schema, data-version, row-count, and total-change counters unchanged. The baseline query scanned the session table; the candidate used both existing covering lineage indexes plus keyed row lookup. Forty alternating pairs measured median SQL time of 4.119 ms before and 0.091 ms after. These measurements belong to b918ab/7a3160e5; they have not been repeated for the refreshed runtime and are not Gateway latency measurements.

The prior hosted CI run tested merge 7d449a56361d475c4c250412bcee516989d56585, containing main 34f548cb280836ea60ec99276116d63ec23eeeec and b918ab. It had 139 successful jobs, 16 skipped jobs, and one independent Doctor fixture failure plus the aggregate gate. The fixture expected only busctl but the existing unavailable-service diagnostic legitimately called systemctl. Its source came from newer main; all five candidate files were unchanged in the tested merge. The canonical fix is included in the refreshed base. The trusted ClawSweeper review of fa202e5c, updated September 17 at 13:02 UTC, accepted the refreshed integration evidence and historical timing scope with no introduced correctness or security findings. Newer main changes caused a merge conflict, requiring the current cold-history port. That review does not qualify the new head.

Historical evidence from the original September 15 candidate

These results belong to original head be4cdc61d59a0ef0d1f19b50a7dcf28e1511c7c8. Focused coverage passed 147 tests across five files, 31 selected history/TUI cases, and 11 single-row cases. Prompt-decoding regressions failed on the original lookup; changed checks, review, and the normal build passed.

On retained synthetic state, the two SQL queries returned identical rows. Forty alternating measurements averaged 1.95 ms before and 0.08 ms after. The original query-plan test verified indexed execution but did not reproduce the old planner choice in that earlier run. These are SQL measurements, not Gateway latency measurements.

The real-provider natural20, Stop9, recovery2, and held20 campaigns passed functional, settlement, and durable-deletion checks. All 1,316 foreground RPC observations succeeded, but 17 exceeded the unchanged 500 ms target: 14 of 958 UI foreground observations and 3 of 358 held foreground observations. Held reads reached 3,862.680 ms. Stop took 669 ms at the Gateway, 906.800 ms in the native browser request, and 2,010.947 ms through relay acknowledgement; these clocks remain separate. Public deletion took 7,188.631 ms and is separate from foreground reads. No original failure or slow sample was removed.

The original CI run failed its older recursive-spawn case waiting for model execution; nine siblings passed. Later main included #149199’s measured cold-entry fixture repair, #149179’s model-catalog isolation, and #149036’s model-inheritance coverage. The failure did not recur in the subsequent b918ab/7a3160e5 comparison; the cause of the historical failure remains unestablished.

@clawsweeper

clawsweeper Bot commented Sep 15, 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 the gateway Gateway runtime label Sep 15, 2026
@steipete
steipete marked this pull request as ready for review September 15, 2026 04:35
@openclaw-barnacle openclaw-barnacle Bot added size: M maintainer Maintainer-authored PR labels Sep 15, 2026
@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 15, 2026
@clawsweeper

clawsweeper Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 17, 2026, 10:11 AM ET / 14:11 UTC (Revision 6).

ClawSweeper review

What this changes

Cold session-history lookups use existing SQLite lineage indexes and load compact child metadata while preserving complete selected-session data.

Merge readiness

⛔ Blocked before merge - 2 items remain

This remains a useful, focused optimization absent from current main. No introduced correctness or security defect was found, and the previous conflict blocker is resolved in the verified test merge.

Priority: P2
Reviewed head: 4e7a66ec3a09a3b0fb423f59693544a5f8709c70

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused implementation with meaningful regression coverage and no supported correctness findings; refreshed integration validation remains pending.
Proof confidence 🌊 off-meta tidepool Not applicable: The maintainer-authored PR is exempt from the external-contributor proof gate. Historical SQLite and runtime evidence remains valid for its recorded revisions, but does not validate this refreshed cold-loader integration; related UI screenshots do not demonstrate it.
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 PR is exempt from the external-contributor proof gate. Historical SQLite and runtime evidence remains valid for its recorded revisions, but does not validate this refreshed cold-loader integration; related UI screenshots do not demonstrate it.
Evidence reviewed 8 items Current main still has the targeted overhead: The fetched main retains the ordered OR query and propagates the selected projection into child reads; its production-file difference from the pinned head matches the introduced optimization.
Existing metadata and storage contracts are reused: Child discovery uses the existing list projection and guards selected keys against replacement. That projection omits only saved skill snapshots and prompt reports; canonical validation, owner projection, and participant enrichment remain. Both lineage indexes already exist.
Concrete cold-history caller: Embedded history requests a full selected entry with child entries. Gateway chat history and incognito row materialization already request list metadata; ordinary durable list/describe presentation remains resident-owned. This path does not depend on the Codex runtime or protocol.
Findings None None.
Security None None.

How this fits together

The session store supplies saved session data and child relationships to Gateway and embedded terminal history readers. Child metadata supports navigation and presentation without requiring saved child prompts.

flowchart TD
  A[History request] --> B[Resolve selected session]
  B --> C[Complete selected entry]
  B --> D[Discover child sessions]
  E[SQLite lineage indexes] --> D
  F[Retained run registry] --> D
  D --> G[Compact child metadata]
  C --> H[History and session presentation]
  G --> H
Loading

Before merge

  • Resolve merge risk (P1) - The captured evidence has no completed integration validation for the refreshed cold-loader implementation; earlier results and timings remain specific to their recorded revisions.
  • Complete next step (P2) - Complete and record the planned baseline/candidate cold-loader regression comparison and affected consumer validation for this refreshed head.
Agent review details

Security

None.

PR surface

Source +1, Tests +169. Total +170 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 2 13 12 +1
Tests 2 200 31 +169
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 213 43 +170

Review metrics

Metric Value Why it matters
Production versus regression coverage Production +1 net line; tests +169 net lines Production growth is minimal and justified by indexed discovery and selected-entry preservation; most growth exercises the affected contracts.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Keep child discovery within the existing SQLite and metadata owners while preserving complete selected entries and resident list/describe behavior.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Keep child discovery within the existing SQLite and metadata owners while preserving complete selected entries and resident list/describe behavior.

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

Yes for unnecessary payload decoding: current main's embedded-history caller requests full entries and propagates that projection to children. The current SQLite planner outcome was not executed during this review.

Is this the best way to solve the issue?

Yes. The patch reuses existing indexes and metadata projection without adding storage, configuration, or a competing reader.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This is a bounded cold-history performance improvement without evidence of an urgent outage.
  • 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 PR is exempt from the external-contributor proof gate. Historical SQLite and runtime evidence remains valid for its recorded revisions, but does not validate this refreshed cold-loader integration; related UI screenshots do not demonstrate it.

Evidence

What I checked:

  • Current main still has the targeted overhead: The fetched main retains the ordered OR query and propagates the selected projection into child reads; its production-file difference from the pinned head matches the introduced optimization. (src/config/sessions/session-accessor.sqlite-entry.ts:170, 9bea925e27aa)
  • Existing metadata and storage contracts are reused: Child discovery uses the existing list projection and guards selected keys against replacement. That projection omits only saved skill snapshots and prompt reports; canonical validation, owner projection, and participant enrichment remain. Both lineage indexes already exist. (src/gateway/session-utils-store-lookup.ts:542, 4e7a66ec3a09)
  • Concrete cold-history caller: Embedded history requests a full selected entry with child entries. Gateway chat history and incognito row materialization already request list metadata; ordinary durable list/describe presentation remains resident-owned. This path does not depend on the Codex runtime or protocol. (src/tui/embedded-backend.ts:538, 4e7a66ec3a09)
  • Meaningful regression coverage: The revised tests exercise the cold loader, selected full payload preservation, persisted and registry-only children, cross-agent deletion freshness, ordered deduplication, and indexed discovery under stale statistics. Tests were inspected but not executed in this read-only review. (src/gateway/session-utils.single-row-cache.test.ts:374, 4e7a66ec3a09)
  • Verified merge composition: The recorded test merge has the pinned base followed by the exact PR head as its two parents, and differs from that base only in the four introduced files. The previous review's conflict warning does not carry forward. (466a3208d80c)
  • Latest-release check: The supplied latest release, v2026.9.4, also uses the ordered OR child query; it does not contain this query optimization. (src/config/sessions/session-accessor.sqlite-entry.ts:189, 3a9d69db306c)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • vincentkoc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

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

  • Record the already-planned baseline/candidate cold-loader comparison and affected consumer results for the current head.

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 (5 earlier review cycles)
  • reviewed 2026-09-15T04:43:05.867Z sha be4cdc6 :: blocked before merge. :: none
  • reviewed 2026-09-15T05:28:46.052Z sha be4cdc6 :: blocked before merge. :: none
  • reviewed 2026-09-17T08:24:40.468Z sha b918ab166fb1c2b757065683cda1045656e463ba :: needs maintainer review before merge. :: none
  • reviewed 2026-09-17T11:32:41.178Z sha fa202e5 :: blocked before merge. :: none
  • reviewed 2026-09-17T13:02:44.601Z sha fa202e5 :: blocked before merge. :: none

@steipete
steipete force-pushed the codex/swarm-child-metadata-20260915 branch 2 times, most recently from b918ab1 to fa202e5 Compare September 17, 2026 11:25
Use the existing parent and spawn indexes for direct child discovery, and
load child metadata without unused skill snapshots or prompt reports.
Preserve complete selected entries and current ownership, lineage, and
deletion behavior for persisted and retained-run children.

Keep resident list and describe ownership intact. Exercise the cold loader
used by embedded history while retaining current resident lifecycle tests.
Related: #130741; the broader Gateway latency target remains open.

Source review is scoped-clean through P2. Runtime proof and exact-head CI
for this integration remain pending; earlier proof belongs to fa202e5c.
@steipete
steipete force-pushed the codex/swarm-child-metadata-20260915 branch from fa202e5 to 4e7a66e Compare September 17, 2026 14:04
@steipete steipete changed the title fix: reduce session read overhead with retained Swarm children perf(sessions): reduce cold history child lookup overhead Sep 17, 2026
@steipete
steipete merged commit 44bc6b4 into main Sep 17, 2026
217 of 219 checks passed
@steipete
steipete deleted the codex/swarm-child-metadata-20260915 branch September 17, 2026 15:05
@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 18, 2026
Use the existing parent and spawn indexes for direct child discovery, and load compact child metadata without unused skill snapshots or prompt reports. Preserve complete selected entries, current ownership and lineage, and fresh deletion results. Keep ordinary list/describe reads with the resident owner; cover the real cold loader used by embedded history. Related: openclaw#130741.

On Linux/Node 24.19.0, the full 35-case baseline/candidate comparison produced exactly four intended failures on baseline and 35 passes on candidate. Nine current consumer selections added 159 passes. All 194 selected candidate cases passed; the TUI history filter intentionally left 128 other cases unselected. All 13 native reports and assertion identities were independently verified. Exact-head CI run 35231150085 succeeded with 142 successful jobs and 16 skipped. The full selected gate passed, including production/core-test types, export scans, lint, formatting and contract guards. The Linux command exited 0; a subsequent portal-sync request timed out. Reports and source bindings were verified before owned cleanup.

Fresh source review and the trusted exact-head ClawSweeper review found no introduced correctness/security defect. Prior SQL medians of 4.119 ms and 0.091 ms belong to b918ab/3d08e342 and were not repeated. The original live campaign's 17 of 1,316 observations above 500 ms and historical recursive-failure attribution gap remain documented; the broader Gateway target remains open.
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