Skip to content

refactor(gateway): isolate cold history reads - #149876

Merged
vincentkoc merged 6 commits into
mainfrom
fix/history-worker-kernels-20260915
Sep 16, 2026
Merged

vincentkoc merged 6 commits into
mainfrom
fix/history-worker-kernels-20260915

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Sep 16, 2026 •

Copy link
Copy Markdown
Member

Related: #143610
Builds on #149670.

What Problem This Solves

A downstream native history check timed out during a cold worker read. Instrumentation showed substantial time in the history-kernel import; individual dependency costs and the end-to-end benefit of this refactor remain unmeasured.

User Impact

RPC and HTTP history use narrower worker readers while preserving paging, authorization and transcript behavior. Native latency improvement remains unverified. No schema-version change, migration or new operator action is introduced.

Why This Change Was Made

Prepare the physical database and logical transcript target before queueing, share the history kernels, and retain one read-only connection scope. Existing owners retain cache invalidation, question-answer custody, worker-generation checks and canonical session admission. CLI, incognito and profile handling stay with their callers. Remove obsolete reader wrappers and exports, with tests using their canonical owners.

The integration preserves current main's row-presence worker request and imports its retained scope constructor from the canonical scope owner. The separate row-presence request still reaches broad session-entry acquisition; narrowing that dependency closure remains follow-up work while its admission and lifetime contract stays intact.

Production net +217 lines establishes these ownership boundaries; tests and test support net +624 lines cover their shared contracts.

Evidence

Source: 852cf41afeff4e2a010fa42855f23e50f355481b, integrated with 0cb61c67b1058c8d96e3d3f78641a72866203bc3.

  • Full branch source review: four evidence passes, no actionable P0–P2 findings.
  • Captured remote proof: package-boundary declarations passed; normal targeted lint reported zero warnings and errors. All five runtime test files passed, with 64 tests passed, including all 15 import-boundary guards, four canonical-admission snapshot cases, real-worker row-presence/lifecycle and history integration, and the complete prepared-harness source-delivery file.
  • Private QA build passed. Build stamps and the emitted relative-import inventory bind to the tested source tree.
  • A newly built JavaScript worker, with no source loader, returned the exact expected messages for RPC and HTTP using one retained worker. One observation measured 266.16 ms for the first RPC and 5.98 ms for HTTP reuse, with an existing filesystem cache. This is a focused execution check, not a comparative benchmark or native-client latency result.

Required hosted CI, including all 19 core test-type graphs and the full side-question and managed-service handoff lifecycle files, remains pending. Composed native cold-history qualification remains in #143610; no measured native improvement is claimed.

@vincentkoc vincentkoc self-assigned this Sep 16, 2026
@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 scripts Repository scripts commands Command implementations agents Agent runtime and tooling size: XL maintainer Maintainer-authored PR labels Sep 16, 2026
@vincentkoc
vincentkoc marked this pull request as ready for review September 16, 2026 08:19
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. 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 Sep 16, 2026
@clawsweeper

clawsweeper Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 16, 2026, 4:56 AM ET / 08:56 UTC (Revision 2).

ClawSweeper review

What this changes

Separates Gateway history paging from host initialization and prepares transcript targets before dispatching reads to a retained SQLite worker.

Merge readiness

⛔ Blocked before merge - 2 items remain

The earlier worker-constructor finding is resolved, and no remaining blocking defect was found. This remains a distinct, maintainer-owned prerequisite beyond the merged reader extraction.

Priority: P2
Reviewed head: 852cf41afeff4e2a010fa42855f23e50f355481b

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A coherent extraction with meaningful boundary coverage and the prior blocker repaired; no new blocking correctness finding remains.
Proof confidence 🌊 off-meta tidepool Not applicable: The MEMBER-authored internal refactor is exempt from ordinary contributor proof. Its body reports expected RPC/HTTP results through the built worker and retained connection; private captures were not inspected, and native latency remains explicitly unclaimed. No material new authority contract requires an additional proof gate.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The MEMBER-authored internal refactor is exempt from ordinary contributor proof. Its body reports expected RPC/HTTP results through the built worker and retained connection; private captures were not inspected, and native latency remains explicitly unclaimed. No material new authority contract requires an additional proof gate.
Evidence reviewed 8 items Previous finding resolved: Both metadata-first and history-first worker requests now acquire the constructor from the extracted scope module. Existing lifecycle coverage exercises row presence before history, missing databases, and worker retirement.
Reader validation remains at use time: The prepared reader retains the requested transcript identity, repeats conditional row validation, and uses the existing canonical-admission and projection-snapshot owners. Tests cover changed rows, policy changes, participant validation, shared stores, and mismatched transcript fences.
Authorization and storage boundaries preserved: HTTP publication still rechecks authentication, profile identity, scopes, session lifetime, and sharing before sending history. The patch moves query ownership and a table-name constant without changing schema versions, persisted formats, or permission policy.
Findings None None.
Security None None.

How this fits together

Gateway history readers turn stored conversation transcripts into paginated RPC and HTTP responses. This change separates worker-side queries from host-side restoration, profile decoration, and CLI history imports.

flowchart TD
  A[RPC and HTTP history requests] --> B[Host target preparation]
  B --> C[Retained history worker]
  C --> D[Database and transcript validation]
  D --> E[Shared paging readers]
  E --> F[Host decoration and authorization]
  F --> G[Conversation history response]
Loading

Before merge

  • Resolve merge risk (P2) - The original native cold-history timeout and comparative latency improvement remain unverified; the reported worker timings do not establish that downstream outcome.
  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.
Agent review details

Security

None.

PR surface

Source +211, Tests +624, Other +6. Total +841 across 57 files.

View PR surface stats
Area Files Added Removed Net
Source 34 1488 1277 +211
Tests 22 686 62 +624
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 8 2 +6
Total 57 2182 1341 +841

Review metrics

Metric Value Why it matters
Production versus validation growth Production/tooling net +217; tests/support net +624 The body justifies production growth through explicit reader ownership boundaries, while most net growth covers their contracts.

Stored data model

Persistent data-model change detected: database schema: src/config/sessions/session-canonical-key-read.ts, database schema: src/config/sessions/session-canonical-key.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Keep shared paging and transcript queries behind the narrow reader boundary, with restoration and presentation remaining host-owned and native latency qualification tracked in the linked native work.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Keep shared paging and transcript queries behind the narrow reader boundary, with restoration and presentation remaining host-owned and native latency qualification tracked in the linked native work.

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

No high-confidence reproduction of the original native timeout was established here; source confirms the import boundary, while the supplied worker observation does not reproduce or benchmark the native failure.

Is this the best way to solve the issue?

Yes for the bounded isolation goal: the patch shares existing query behavior and preserves host-owned restoration and presentation; its native performance benefit remains unproven.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This is a bounded Gateway history-loading improvement supporting active native work, without a demonstrated urgent production regression.
  • 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 MEMBER-authored internal refactor is exempt from ordinary contributor proof. Its body reports expected RPC/HTTP results through the built worker and retained connection; private captures were not inspected, and native latency remains explicitly unclaimed. No material new authority contract requires an additional proof gate.

Evidence

What I checked:

  • Previous finding resolved: Both metadata-first and history-first worker requests now acquire the constructor from the extracted scope module. Existing lifecycle coverage exercises row presence before history, missing databases, and worker retirement. (src/config/sessions/session-transcript.worker.ts:113, 852cf41afeff)
  • Reader validation remains at use time: The prepared reader retains the requested transcript identity, repeats conditional row validation, and uses the existing canonical-admission and projection-snapshot owners. Tests cover changed rows, policy changes, participant validation, shared stores, and mismatched transcript fences. (src/gateway/session-history-readonly-reader.ts:17, 852cf41afeff)
  • Authorization and storage boundaries preserved: HTTP publication still rechecks authentication, profile identity, scopes, session lifetime, and sharing before sending history. The patch moves query ownership and a table-name constant without changing schema versions, persisted formats, or permission policy. (src/gateway/sessions-history-http.ts:229, 852cf41afeff)
  • Current main still uses host history modules: The fetched main worker still imports the host paging and history-state modules. The extracted reader and paging kernel are absent there; this PR supplies additional isolation beyond the merged prerequisite. (src/config/sessions/session-transcript.worker.ts:145, d0dd991b4c08)
  • Merged prerequisite and release boundary: GitHub confirms refactor(sessions): separate transcript read owners #149670 merged as 932846b; its body explicitly leaves worker integration for subsequent work. Inspection of v2026.9.4 found neither the new reader nor the transcript worker at the checked paths, so that release does not establish this isolation as shipped. (3a9d69db306c)
  • Captured validation claims: The supplied complete body, captured under sourceRevision 89ebccd49b11652a6a0d41e1df264d3acf543ff20e7f7a8d2c15fa1193abc269, reports 64 passing targeted tests, a private QA build, and expected RPC/HTTP messages from a built JavaScript worker sharing one retained worker. Reported timings are 266.16 ms and 5.98 ms with an existing filesystem cache; the body expressly makes no comparative or native-latency claim. Private captures were not independently inspected. (852cf41afeff)

Likely related people:

  • Vincent Koc: Raw commit 932846b adds src/config/sessions/session-accessor.sqlite-history-query.ts:23 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 932846b521c0; files: src/config/sessions/session-accessor.sqlite-history-query.ts)
  • 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 (1 earlier review cycle)
  • reviewed 2026-09-16T08:26:31.610Z sha 0338a98 :: blocked before merge. :: [P1] Migrate the row-presence worker to the extracted scope

@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. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 16, 2026
@vincentkoc

Copy link
Copy Markdown
Member Author

The two Rank-up moves in the prior review are addressed on 852cf41afeff4e2a010fa42855f23e50f355481b.

  • The row-presence branch now imports OpenClawAgentDatabaseReadOnlyScope from its extracted owner, preserving canonical entry admission and the retained database scope.
  • A fresh private-QA build of this head passed the requested sequence through dist/config/sessions/session-transcript.worker.js: metadata presence as the first request in a new worker returned true, then RPC history and HTTP history each returned the exact three expected message IDs, roles and texts. The probe verified one worker creation, execArgv: [], three ordered successful diagnostics, and worker join before fixture cleanup.

Observed request durations were 432.92 ms for metadata, 67.42 ms for history after metadata, and 3.13 ms for HTTP reuse. This used an existing filesystem cache; it is sequence/custody proof, not a comparative benchmark or native iOS latency result.

Retained capture SHA256: 9a236f40ed7f5c38bc9c37233b2790dd0d0e1fc8a10b73b6b3de5a10e1c1af67. Built worker SHA256: a50e749e466a34add258f4e3f28302917aa98a6eb685c03ba09e5f6bad60ac04. Full hosted qualification remains a separate merge gate.

@vincentkoc

Copy link
Copy Markdown
Member Author

Maintainer disposition for the two remaining checklist items in the current review, at 852cf41afeff4e2a010fa42855f23e50f355481b:

  • Native qualification: take the review's offered mitigation: retain this bounded reader-isolation prerequisite, with restoration and presentation still host-owned. The original 10-second native history check and wire/effect assertions remain required for the composed app stack in feat(ios): add selected-conversation actions #143610. This PR makes no native or comparative latency improvement claim.
  • Stored-data compatibility: this extraction introduces no persisted-model change requiring a migration. Against base 0cb61c67b1058c8d96e3d3f78641a72866203bc3, the 949-byte isCanonicalSqliteSessionMainKeyCurrent declaration moves verbatim into session-canonical-key-read.ts; its startup caller only changes imports. Agent and canonical-session-validation schema versions remain 21. Canonical schema, canonical-validation schema and session/participant migration owners are byte-identical. SESSION_PARTICIPANTS_TABLE retains the same session_participants value; its DDL/ensure owner and schema-helper bodies only change imports.
  • Observed regression coverage: the exact-head captured proof passed all 16 actual readonly-reader cases, including cold/warm/policy/receipt admission snapshots, retained-handle revalidation, committed main-key changes, current participant validation, and reads that do not create a missing additive participant table. The metadata-first → RPC → HTTP sequence is separately documented in the verified proof reply.

The reader-test capture SHA256 is 5bbefdeccc40eb6d5f5cee5a98d30f2115ff5f74666bc3d1deabfbeff56d47c9. Full hosted CI remains required before merge.

@vincentkoc
vincentkoc merged commit 63b1488 into main Sep 16, 2026
338 of 341 checks passed
@vincentkoc
vincentkoc deleted the fix/history-worker-kernels-20260915 branch September 16, 2026 09:31
@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 17, 2026
* refactor(history): isolate worker query kernels

* test(history): align fixtures with storage and display contracts

* test(history): cover retained reader admission

* test(history): preserve fixture session key type

* refactor(history): remove obsolete reader exports
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling commands Command implementations 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. scripts Repository scripts 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