Skip to content

fix(gateway): keep session lists responsive with retained subagent history - #116533

Merged
vincentkoc merged 1 commit into
mainfrom
perf/subagent-sqlite-topology
Jul 30, 2026
Merged

vincentkoc merged 1 commit into
mainfrom
perf/subagent-sqlite-topology

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Jul 30, 2026 •

Copy link
Copy Markdown
Member

Fixes #116506

What Problem This Solves

Fixes an issue where operators listing sessions with retained subagent history would repeatedly hydrate every full retained-run payload from SQLite, even when the requested page was tiny. Large histories could make sessions.list increasingly slow.

Why This Change Was Made

Session-list reads now use a canonical SQLite projection containing only the topology and display fields required by the existing read index. Lifecycle, recovery, control, and delivery paths continue using full records. The projection has its own short-lived cache, preserves process-local authoritative updates, and does not change the SQLite schema version.

User Impact

Session lists remain responsive as retained subagent history and payload size grow, without changing session metadata or subagent status behavior.

Evidence

  • Implementation benchmark, 5,000 retained rows with 8 KB payloads:
    • full canonical hydration: 413.76 ms
    • projected session-list read: 52.26 ms
    • 7.92x faster; both returned 5,000 rows
  • Exact-head affected tests: 27/27 passed across gateway and agent-registry shards after rebasing onto current main.
  • The identical patch also passed those tests on Blacksmith Testbox tbx_01kyt7h229ys5x1q5ya0wfp61n: https://github.com/openclaw/openclaw/actions/runs/30574398883
  • Exact-head Kysely guardrails, generated-type verification, formatting, and git diff --check passed.
  • Autoreview passed with no actionable findings after its cache-coherence finding was fixed and covered by regression test.
  • No SQLite schema-version bump.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime agents Agent runtime and tooling size: L maintainer Maintainer-authored PR labels Jul 30, 2026
@vincentkoc vincentkoc self-assigned this Jul 30, 2026
@vincentkoc
vincentkoc marked this pull request as ready for review July 30, 2026 19:11
@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

@vincentkoc
vincentkoc force-pushed the perf/subagent-sqlite-topology branch from 837807d to 3938d04 Compare July 30, 2026 19:24
@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@vincentkoc
vincentkoc force-pushed the perf/subagent-sqlite-topology branch from 3938d04 to d197856 Compare July 30, 2026 19:25
@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Jul 30, 2026
@vincentkoc
vincentkoc force-pushed the perf/subagent-sqlite-topology branch from d197856 to c5963dc Compare July 30, 2026 20:01
@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

@vincentkoc
vincentkoc force-pushed the perf/subagent-sqlite-topology branch from c5963dc to d1003d7 Compare July 30, 2026 20:04
@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added 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. P2 Normal backlog priority with limited blast radius. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Jul 30, 2026
@clawsweeper

clawsweeper Bot commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 30, 2026, 4:13 PM ET / 20:13 UTC.

ClawSweeper review

What this changes

The PR makes gateway session lists load a smaller SQLite projection of retained subagent records, avoiding full payload hydration for topology and display metadata.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep this PR open for maintainer review. The current head is the same head assessed in the prior ClawSweeper cycle, which found no actionable defect and specifically noted cache-coherence coverage; the author is a repository member and the PR carries the protected maintainer label, so automated cleanup is not appropriate.

Priority: P2
Reviewed head: d1003d721240cc0b53493bad6ec19d0f7ac6f753
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch has a focused boundary, reported exact-head benchmark and test evidence, and no concrete code defect from this re-review; its remaining gate is maintainer acceptance of the separate cache contract.
Proof confidence 🐚 platinum hermit (4/6) Not applicable: The PR author is a repository member; the body nevertheless provides exact-head benchmark results, focused test results, and a linked Testbox run as useful supplemental evidence.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The PR author is a repository member; the body nevertheless provides exact-head benchmark results, focused test results, and a linked Testbox run as useful supplemental evidence.
Evidence reviewed 5 items PR intent and bounded owner path: The PR body and linked issue identify the existing session-list path as hydrating full retained subagent payloads, while the patch changes the gateway projection to use a dedicated list-read index rather than the full registry index.
Dedicated projection and cache separation: The patch adds a session-list projection cache and a SQLite list loader alongside the existing full-record loaders, retaining the existing full registry path for lifecycle, recovery, control, and delivery consumers.
Focused regression coverage: The PR changes state-cache and SQLite-store tests to cover the reduced record projection, including preserved fields used for status and delivery display.
Findings None None.
Security None None.

How this fits together

The gateway’s sessions.list response enriches stored sessions with subagent topology, lifecycle status, and display metadata from the agent registry. This change introduces a list-specific registry read path that projects only those needed fields from SQLite while other registry consumers continue to use full records.

flowchart LR
  A[Session-list request] --> B[Gateway session projection]
  B --> C[Subagent session-list index]
  C --> D[SQLite reduced record projection]
  D --> E[Short-lived registry cache]
  E --> F[Session rows with subagent status]
  G[In-memory authoritative runs] --> C
Loading

Decision needed

Question Recommendation
Does the current cache-coherence coverage provide sufficient confidence to merge a separate SQLite projection cache for session-list status and topology? Approve the bounded projection: Merge after confirming the exact-head regression tests cover persisted changes and in-memory authoritative overlays for all session-list-visible fields.

Why: The patch deliberately introduces a second cached view of persisted subagent state; choosing the accepted freshness and maintenance tradeoff is a maintainer judgment, and the protected label plus member authorship prevent automated cleanup.

Before merge

  • Resolve merge risk (P1) - The new reduced record shape and independent 500 ms cache must continue to reflect both persisted mutations and authoritative in-memory subagent updates; a missed field or invalidation path could make session-list status/topology temporarily stale even though full-record consumers remain correct.
Agent review details

Security

None.

PR surface

Source +317, Tests +111. Total +428 across 11 files.

View PR surface stats
Area Files Added Removed Net
Source 8 367 50 +317
Tests 3 118 7 +111
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 11 485 57 +428

Review metrics

None.

Stored data model

Persistent data-model change detected: serialized state: src/gateway/session-utils-contracts.ts, serialized state: src/gateway/session-utils-projection.ts, unknown-data-model-change: src/gateway/session-utils-projection.ts, unknown-data-model-change: src/gateway/session-utils.single-row-cache.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Verify projection-cache coherence before merge (recommended)
    Confirm exact-head tests prove persisted registry updates and process-local authoritative run changes refresh the list projection without stale topology or status.
  2. Accept the bounded freshness tradeoff
    Merge with the existing 500 ms cache contract if maintainers agree that the stated tests cover all list-visible state needed by operators.
  3. Pause the separate cache design
    Hold this PR if maintainers want session lists to reuse a single registry snapshot rather than maintain a dedicated projection cache.

Technical review

Best possible solution:

Land the dedicated projection only after maintainer review confirms its regression tests cover every list-visible status field and both persisted-write and in-memory-overlay cache refresh paths at the merge head.

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

Yes, source-reproducible: the linked issue supplies a concrete retained-row benchmark and the PR changes the session-list index from full registry hydration to a projected SQLite read. I could not independently execute that benchmark because the read-only command environment rejected inspection commands.

Is this the best way to solve the issue?

Yes, with a maintainer cache-contract check: a list-specific projection preserves the full-record owner boundary for lifecycle and delivery paths while removing unnecessary payload hydration from session-list reads.

AGENTS.md: unclear because the file could not be read completely.

Codex review notes: model internal, reasoning high; reviewed against 78fd4f99fe96.

Labels

Label changes:

  • add merge-risk: 🚨 session-state: The PR adds a cached, reduced representation of persisted subagent state that drives session-list topology and status, so stale or omitted fields could misrepresent active session state after merge.

Label justifications:

  • P2: The linked bug affects session-list responsiveness for operators with large retained histories but does not report data loss, delivery failure, or an unusable default workflow.
  • merge-risk: 🚨 session-state: The PR adds a cached, reduced representation of persisted subagent state that drives session-list topology and status, so stale or omitted fields could misrepresent active session state after merge.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit 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 PR author is a repository member; the body nevertheless provides exact-head benchmark results, focused test results, and a linked Testbox run as useful supplemental evidence.

Evidence

What I checked:

  • PR intent and bounded owner path: The PR body and linked issue identify the existing session-list path as hydrating full retained subagent payloads, while the patch changes the gateway projection to use a dedicated list-read index rather than the full registry index. (src/gateway/session-utils-projection.ts:30, d1003d721240)
  • Dedicated projection and cache separation: The patch adds a session-list projection cache and a SQLite list loader alongside the existing full-record loaders, retaining the existing full registry path for lifecycle, recovery, control, and delivery consumers. (src/agents/subagent-registry-state.ts:23, d1003d721240)
  • Focused regression coverage: The PR changes state-cache and SQLite-store tests to cover the reduced record projection, including preserved fields used for status and delivery display. (src/agents/subagent-registry-state.test.ts:56, d1003d721240)
  • Prior review continuity: The latest completed ClawSweeper review assessed this same head, reported no findings, and stated that cache-coherence coverage for persisted writes and authoritative in-memory updates was the remaining merge-approval check. (src/agents/subagent-registry-state.test.ts:1, d1003d721240)
  • Current-main status: The change is not on the supplied current main SHA, so it remains a live implementation candidate rather than an implemented-on-main cleanup. (src/gateway/session-utils-projection.ts:30, 78fd4f99fe96)

Likely related people:

  • vincentkoc: The GitHub context shows this repository member authored the linked performance report, authored the proposed implementation, and is assigned to this PR; no independent main-history attribution could be completed in the read-only execution environment. (role: current area contributor and assigned reviewer route; confidence: medium; commits: d1003d721240; files: src/agents/subagent-registry-state.ts, src/agents/subagent-registry.store.sqlite.ts, src/gateway/session-utils-projection.ts)

Rank-up moves

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

  • Confirm the exact merge head retains regression coverage for persisted writes and in-memory authoritative updates.

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-07-30T20:09:01.552Z sha d1003d7 :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added the merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. label Jul 30, 2026
@vincentkoc

Copy link
Copy Markdown
Member Author

Maintainer decision: accept the dedicated session-list projection and two-cache design.

Exact head d1003d721240cc0b53493bad6ec19d0f7ac6f753 preserves the required cache coherence:

  • 12/12 subagent-registry-state tests passed, including successful persisted writes, incremental writes, best-effort write failures, exact deletions, in-memory authoritative overlays, moved scope membership, and return to scoped SQL.
  • 27/27 focused registry/gateway tests passed overall.
  • Kysely guardrails, formatting, and git diff --check passed.
  • Hosted openclaw/ci-gate passed with zero failing checks.
  • Exact-head ClawSweeper review reported no actionable findings.

The Rank-up move is satisfied; proceeding with the squash merge.

@vincentkoc
vincentkoc merged commit 610346b into main Jul 30, 2026
130 of 136 checks passed
@vincentkoc
vincentkoc deleted the perf/subagent-sqlite-topology branch July 30, 2026 20:21
vincentkoc added a commit that referenced this pull request Jul 30, 2026
…iter-timeout-v20

* origin/main:
  fix(gateway): project subagent topology for session lists (#116533)
@vincentkoc

Copy link
Copy Markdown
Member Author

Exact merge-result verification for 610346b8a6ff158e2da6ff3b6216ade5cf898f99 is complete.

  • Immutable manual CI: run 30580397749 resolved target_ref to the exact merge SHA; all required jobs and openclaw/ci-gate passed. Final matrix: 133 success, 2 intentional skips, 0 failures.
  • Focused Blacksmith Testbox tbx_01kytbz8rvyhzfxzhqbj0rdbtw: 27/27 relevant registry/store/session-cache tests passed from the exact merge SHA; wrapper exit 0.
  • The automatic push CI's sole unrelated MCP timeout reproduced 3/3 green on Testbox tbx_01kytc2qxmfhgx4g6b53x67f9f; the immutable manual CI also passed that shard.
  • The merge SHA remains an ancestor of live origin/main.

This satisfies the existing ClawSweeper rank-up move for persisted writes and in-memory authoritative updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L 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.

[Bug]: sessions.list hydrates retained subagent payloads for topology reads

1 participant