Repository navigation
perf(memory): move admission off the Gateway thread and reuse clean receipts - #171322
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bc869cf26b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| get isOpen(): boolean { | ||
| return !this.closed && (this.nativeDb?.isOpen ?? true); |
There was a problem hiding this comment.
Tie isOpen to the worker owner's revocation
When bundled callers use the new asynchronous status path, nativeDb remains unset, so this getter stays true even after the agent-database lifecycle revokes the retained publication worker. MemoryIndexManager.get() consequently reuses the stale manager; if Doctor or recovery replaced the database file, its captured admission identity no longer matches and subsequent publications fail until the manager or process is explicitly restarted. Preserve a worker-owner liveness signal so lifecycle revocation invalidates the registry entry without requiring the deprecated synchronous reader to have been opened.
AGENTS.md reference: AGENTS.md:L70-L70
Useful? React with 👍 / 👎.
| if (initialized) { | ||
| database.publicationWorker = Promise.resolve({ | ||
| store: initialized.worker, | ||
| busyTimeoutMs: 5_000, | ||
| }); |
There was a problem hiding this comment.
Close the retained worker when manager construction fails
When MemoryIndexManager construction throws after openPublished() returns—for example, a missing or throwing runInBackgroundContext during default-manager setup—this worker has already transferred into database, but the constructor catch calls only release() and the outer creation catch has no assigned manager to close. Because release() does not close publicationWorker, the failed acquisition leaks its worker and database execution ownership, potentially retaining resources or preventing clean shutdown; the ownership-transfer failure path needs to close the worker as well.
AGENTS.md reference: AGENTS.md:L50-L52
Useful? React with 👍 / 👎.
|
Post-merge measurement completed on the exact squash merge and its parent, after green CI and the published-driver update cell. One pair only; the shared harness was copied solely to append two same-device clean restart cycles. Both 13-turn workloads, child/cron/compaction/RPC checks, restarts, and process cleanup passed. Base Memory-owned MAIN is 9 → 0 at initial connection, 9 → 0 at first clean reconnect, and 2 → 0 at second clean reconnect. Static scoped T1 remains 0 → 0 because the inventory does not count these native/transitive admissions. The baseline call chain is manager registry → manager creation →
The four candidate raw-window MAIN reads are background
First clean restart memory schema setup drops 125 → 4, and the second stays 4 → 4. Those remaining statements are two provenance backfill statements, FTS row-count reconciliation, and path-FTS backfill; they preserve data repair. Initial memory setup is 250 statements on both sides, shifted from connection + first turn into first turn. Across the extended workload, memory-matched statements fall 696 → 572. The original workload increases by 64 statements (1.25%) and two requests (0.20%), within the authorized cold worker-move allowance. Memory-tagged cold admission/session projections account for +31 statements and memory-origin requests for +2; the remaining +33 statements are other background work. The extended workload saves 267 statements and one request. No warmed causal owner or shared-family increase occurs.
These request rows exclude nested requests from the parent's SQL count. Memory-origin request totals are 28 → 30 before restarts and 39 → 41 overall. Reindex and shadow operations are unchanged; async reads and background session synchronization account for the cold differences. The successful-statement census excludes one baseline and two candidate failed Final CI passed all 61 executed jobs, including static gates and owner regressions; update validation passed. The two documented P2 lifecycle follow-ups remain deferred under the requested review limit. The released synchronous status compatibility contract remains deprecated; bundled flows use worker status without a synchronous fallback. |
Return Workboard cards and worker context from one owner read, and skip empty related-card snapshots. Let memory search use published status facts without unused diagnostic count queries while preserving full diagnostic status and visibility checks. Add real-store regressions for a committed Workboard edit and refreshed memory contents. Preserve the async memory status owner introduced by #171322. No schema, retention, or configuration changes.
…eceipts (openclaw#171322) Keep memory admission and bundled status reads in the memory workers, publishing admitted facts to the manager instead of opening a second native reader on the Gateway thread. Republish memory schema receipts after committed FTS/vector replacement so clean restarts reuse them while unclean shutdowns still trigger integrity checks. Retain and deprecate the released synchronous status API; bundled callers use async status. Preserve already-returned worker metadata across shared index repairs without adding database reads. Validation: focused admission, clean/unclean restart, and concurrent repair regressions; final PR CI and published-driver update validation. Runtime statement evidence follows in the PR after merge.
…#171387) Return Workboard cards and worker context from one owner read, and skip empty related-card snapshots. Let memory search use published status facts without unused diagnostic count queries while preserving full diagnostic status and visibility checks. Add real-store regressions for a committed Workboard edit and refreshed memory contents. Preserve the async memory status owner introduced by openclaw#171322. No schema, retention, or configuration changes.
Retain the remaining raw-byte behavior from local8039fc5195d on upstreamf91bca9546f5. The host fs-safe append option recognizes leadingLF only; a proposed delta beginning withCR orCRLF must not receive an extraLF. Apply the same separator decision in sandbox writes and provenance contentAfter without changing replay rejection, source authority or path guards. Do not replay the old aggregate maintenance/routing patch: upstream#168123 owns duplicate-note rejection,openclaw#138786 reindex backoff,openclaw#168471 and8fc0987fb08 Gateway CLI recall routing,openclaw#168860/openclaw#171322 worker-owned memory publication and admission. Raw proposed Markdown remains verbatim; no prefix stripping or normalized-offset mapping is retained. Proof: four actual host/sandbox wrapper cases fail before the repair, then24tests pass including replay rejection, authority revocation and exact provenance/disk bytes forCRLF,CR,indentation,hard-break spaces and non-BMP text. Targeted agents-root types,scoped lint,format andline-cap pass; fresh independentP0-P2 review scoped-clean. Full candidate build,Doctor andactivation remain separate gates. Related:openclaw#125309. Local-Feature: memory-append-raw-separators Semantic-Source: 39a740d Upstream-Tracking: openclaw#125309 Drop-When: Upstream host/sandbox append and provenance preserve leading CR and CRLF bytes. Rebase-Base: ed9d493
Retain the remaining raw-byte behavior from local8039fc5195d on upstreamf91bca9546f5. The host fs-safe append option recognizes leadingLF only; a proposed delta beginning withCR orCRLF must not receive an extraLF. Apply the same separator decision in sandbox writes and provenance contentAfter without changing replay rejection, source authority or path guards. Do not replay the old aggregate maintenance/routing patch: upstream#168123 owns duplicate-note rejection,openclaw#138786 reindex backoff,openclaw#168471 and8fc0987fb08 Gateway CLI recall routing,openclaw#168860/openclaw#171322 worker-owned memory publication and admission. Raw proposed Markdown remains verbatim; no prefix stripping or normalized-offset mapping is retained. Proof: four actual host/sandbox wrapper cases fail before the repair, then24tests pass including replay rejection, authority revocation and exact provenance/disk bytes forCRLF,CR,indentation,hard-break spaces and non-BMP text. Targeted agents-root types,scoped lint,format andline-cap pass; fresh independentP0-P2 review scoped-clean. Full candidate build,Doctor andactivation remain separate gates. Related:openclaw#125309. Local-Feature: memory-append-raw-separators Semantic-Source: 39a740d Upstream-Tracking: openclaw#125309 Drop-When: Upstream host/sandbox append and provenance preserve leading CR and CRLF bytes. Rebase-Base: ed9d493
Retain the remaining raw-byte behavior from local8039fc5195d on upstreamf91bca9546f5. The host fs-safe append option recognizes leadingLF only; a proposed delta beginning withCR orCRLF must not receive an extraLF. Apply the same separator decision in sandbox writes and provenance contentAfter without changing replay rejection, source authority or path guards. Do not replay the old aggregate maintenance/routing patch: upstream#168123 owns duplicate-note rejection,openclaw#138786 reindex backoff,openclaw#168471 and8fc0987fb08 Gateway CLI recall routing,openclaw#168860/openclaw#171322 worker-owned memory publication and admission. Raw proposed Markdown remains verbatim; no prefix stripping or normalized-offset mapping is retained. Proof: four actual host/sandbox wrapper cases fail before the repair, then24tests pass including replay rejection, authority revocation and exact provenance/disk bytes forCRLF,CR,indentation,hard-break spaces and non-BMP text. Targeted agents-root types,scoped lint,format andline-cap pass; fresh independentP0-P2 review scoped-clean. Full candidate build,Doctor andactivation remain separate gates. Related:openclaw#125309. Local-Feature: memory-append-raw-separators Semantic-Source: 39a740d Upstream-Tracking: none (no upstream issue or PR tracks CR-led append separators); related openclaw#125309 (closed completed 2026-10-24, memory-maintenance scope) Drop-When: Upstream host/sandbox append and provenance preserve leading CR and CRLF bytes. Rebase-Base: 0220489
What Problem This Solves
Memory manager creation opened a native reader on the Gateway thread after its worker had already admitted the database. This repeated nine admission statements on the first turn and after reconnect. Initial reindexing also invalidated the memory schema receipt by replacing its FTS/vector tables, causing the next clean restart to repeat schema setup.
User Impact
Memory admission and bundled status reads use the memory workers. Clean restart can reuse the schema receipt after a successful reindex; unclean shutdown still requires integrity verification. Stored data, schema versions, configuration, and retention are unchanged.
The released
MemorySearchManager.status()API remains deprecated synchronous compatibility. Built-in callers usestatusAsync()throughreadMemorySearchManagerStatus; a worker failure never falls back to the native reader. Third-party managers that implement only the released synchronous API retain their existing behavior.Why This Change Was Made
The publication worker returns admitted schema version, physical identity, table/index presence, and index facts. The manager keeps that worker and consumes its receipt instead of opening a second native connection. Retrieval workers admit read-only managers and provide status snapshots. Search retains the metadata it already received so a pre-existing manager observes a repair by another manager without another read or write. Owner-controlled derived-table replacement republishes the existing memory schema receipt only after commit, alongside existing transaction staging.
Removed duplicate checks and accepted edges:
Static T1 in this scope: 0 → 0. The five-primitive inventory does not count these native reader/admission executions, so nine MAIN statements are not nine static T1 sites. The remaining synchronous status contract is explicitly retained compatibility debt.
Evidence
oxfmt,oxlint, andgit diff --checkpass.9ac15b453c421f92bc984d712bbd9541c4559f10. The package/image preparation and published-driver update job both passed.1798288f352286af4471a26a98b0d7feb3848a97, merge05848c1714bd6987caf2a69392a30f861d1e5512. Both ran all 13 turns, control-plane/cron/compaction work, and two clean restarts; all fixture children exited. Node 26.11.1 / SQLite 3.53.4 on both sides. Counts only; no latency claim on the loaded host.The first-start memory admission occurs in the connection window before the first turn. The remaining four restart statements are existing provenance/FTS data repair, not repeated schema validation. Memory-matched SQL across the extended workload fell 696 → 572. Original-workload totals rose 5,136 → 5,200 statements (+1.25%) and 1,006 → 1,008 requests (+0.20%): 31 extra memory-tagged cold worker-admission/session-projection statements and 33 other background statements. This uses the authorized ≤2% cold worker-move allowance; all warmed causal owner/family counts are unchanged. Initial schema setup shifted from connection to first turn, with the combined 250 setup statements unchanged.
Raw warmed-window medians remain 147 statements / 41 requests. Candidate has four background plugin-lease MAIN reads in its first warmed window; the same four occur during baseline's first turn (13 total lease reads on each side). There is no new MAIN work: total MAIN drops by exactly the 20 removed memory-reader executions. Full phase and per-operation counts are in the post-merge evidence comment.
Attribution of the prior nine: quarantine version + decision (2), agent schema metadata (1), expected canonical schema construction (5), expected-definition read (1). Caller: manager registry → manager creation →
MemoryIndexDatabase.openPublished→openMemoryDatabaseReadOnlyAtPath→ canonical read-only admission.LOC: production +474/−197 (net +277); tests +252/−35 (net +217); docs +29/−3 (net +26); tooling +4/−1 (net +3).
Follow-ups from automated review
Two P2 lifecycle findings are deferred under the requested two-round/P0–P1 review limit: propagate worker-owner revocation into manager-registry liveness (otherwise a manager retained across database replacement can require restart), and close the retained publication worker when manager construction throws. Existing worker publication authority remains enforced; neither finding demonstrates a stale write, data loss, or a security bypass. These are recovery/resource-cleanup follow-ups, not additional admission checks.