Skip to content

improve(gateway): prepare session placement metadata asynchronously - #150270

Merged
steipete merged 6 commits into
mainfrom
codex/placement-storage-integration-20260916
Sep 21, 2026
Merged

steipete merged 6 commits into
mainfrom
codex/placement-storage-integration-20260916

Conversation

@steipete

@steipete steipete commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Session metadata refreshes could read placement SQLite data on the Gateway thread. Delayed preparation could also reorder delete/recreate notifications or leave clients with stale roster state.

User Impact

Session reads stay responsive while placement facts load. Clients retain deletion identity and refresh after condensed or unavailable snapshots, and queued collectors no longer briefly announce themselves as running before their preparation hold ends.

Why This Change Was Made

The resident session-row owner now prepares placement, move, pending-result, and environment facts through the existing shared-state read worker. Each batch uses one committed snapshot. Private exact reads remain confined to their synchronous consumer, and archived pages retain bounded selected-row caching. Placement replies preserve the caller’s stored session-ID spelling. Event snapshots prepare the existing bounded ancestor chain so cold archived parents retain placement and move details; incomplete synchronous snapshots request the existing client refresh.

Canonical session notifications have bounded pending state and retain their shutdown owner until late publications settle. Failed preparation preserves keyed plugin notices and sends scoped roster refreshes to WebSocket clients. Publication failures are recorded without retrying a potentially partial send. Selection diagnostics retain synchronous CPU and wall time, including failed reads.

Placement mutations, live-authority checks, public contracts, schema, and retention keep their existing owners and behavior.

Evidence

Current composition at a1e28a240e32c76e5509cfc267635a58a75f8e0a carries the complete source onto actual main fd578cb8a62c0ec6c89b58991564622dd5ea1297. It preserves main’s asynchronous transcript-delta reader, abort/incognito semantics, session-list candidate cache, and physical row identity binding. Current integration passed 61 Gateway controls and four maintenance controls, including actual cursor responses and worker-backed history. A session-list privacy fixture hit the unchanged ten-second RPC deadline twice before its first history handler entered. Passive tracing measured 8.9 seconds in the existing lazy handler loader, while the actual history reads were short. The fixture now prepares that real registered handler during setup; every privacy request, assertion, and RPC deadline remains unchanged, and independent lazy-handler tests preserve production loading behavior. All 78 final-scope cases pass, including all 14 privacy cases, 45 queued-collector/lazy-handler cases, and 19 spawn-resource cases. The formerly failing privacy case now completes in 2.46 seconds with its original ten-second deadline. Full selected checks for all 53 changed paths and fresh independent P0–P2 review pass. Exact-head hosted CI and native landing remain pending.

  • The original real projection path failed a zero-host-SQLite regression; worker reads, close/reopen, private reads, and real recipient fallback proofs pass after the repair.
  • Focused coverage passes for notification ordering, delete/recreate churn, repeated shutdown drains, collector capacity, current describe metadata, and diagnostic error attribution. Shared-reader integration and the affected lifecycle siblings pass their focused regressions.
  • Full local changed-file checks, carry-specific production types, import-cycle checks, and independent P0–P2 review passed.
  • Follow-up regressions reproduce missing placement for stored session IDs with whitespace and cold archived ancestors. The combined real SQLite, recipient, UI, and describe regression passes all seven cases; the ancestor lane also passes 97 event cases and nine UI tree cases. Combined follow-up review is clean for P0–P2. The current-main integration passes another 21 cases across five files, including retained-reader cleanup; whole-branch review is clean for P0–P2.
  • The preceding exact-head CI exposed an independent shared-state fixture teardown failure in harness selection tests. Current main contains the canonical cleanup from fix(test): drain shared-state workers before harness cleanup #153663; this candidate preserves its complete fixture and native lease checks. The subsequent Linux shutdown-test failure came from a legitimate SQLite idle-close timer created during projection-fixture setup. The fake clock now starts after that setup; every assertion is unchanged, and all 1,132 tests pass in the exact original 49-file Linux order.
  • The previous hosted run passed the original 49-file Linux group (1,132 tests) and the current UI performance gate. Its sole substantive failure was an unchanged main tooling fixture; canonical improve(ui): remove redundant Systems machine tooltips #153982 fixes that expectation. This patch-identical carry incorporates that actual main fix, passes core types and 57 focused cases, and passed its previous failing UI, shutdown, and tooling jobs. That run then failed only the unchanged task-identifier fixture’s stale codec import; canonical fix(ui): avoid repeated waits in the people picker #153988 has now repaired it on main. The current patch-identical carry includes that actual repair and passes another 33 cleanup, identifier, worker, private-read, and shutdown cases plus core types. Exact-head CI for 48c8d731485d1c6912dca8893967253fe6b64352 passed all 165 jobs. The subsequent review identified three placement fixtures that did not await retained read-worker cleanup. They now await the existing async database closer before deletion and schema reopen; their 51 existing cases, 14 lifecycle/resource cases, selected checks, and independent P0–P2 review pass. Production files remain identical to that green head. CI for the fixture follow-up at 7d4bec2565f5730ee4b145d01723351573dfa7e7 has a task-profile cursor failure: a fresh task list is empty after a profile merge. The exact historical callback cause remains unknown. A separately controlled actual scheduled-maintenance producer/module-transition regression reproduced this empty-projection symptom and was fixed by joining admitted maintenance before Gateway teardown in fix(tasks): finish maintenance before Gateway shutdown #154308, now merged as 5b3646d8783ad168235b86d6af0ff6e334f05d49. This establishes that independent repair, without attributing the old CI run to an unobserved callback.
  • The earlier UI startup-budget failure remains recorded under its original limits. Current main independently changed those inputs and fixed the shared compiler arity error; this PR changes no UI source, dependency lockfile, or performance budget.

Local qualification also recorded an active-parent spawn boundary failure that reproduces unchanged on main and the earlier PR revision; the other eight boundary cases pass. One broader agent-suite terminal-settlement assertion failed locally, then passed in the scoped six-case run. These results remain recorded alongside the required hosted evidence.

Focused test cost on the preceding patch-identical carry

Each file ran through pnpm test <file> --maxWorkers=1. These real SQLite, worker, recipient, and lifecycle boundaries retain their production owners; import and transform work dominate most standalone wall times.

File Passed Case time Command wall time
src/gateway/worker-environments/placement-read-projection.worker.test.ts 1 0.888s 30.74s
src/gateway/server-methods/session-row-facts.test.ts 3 2.729s 26.92s
src/gateway/session-row-projection.prepared-read.test.ts 5 2.893s 35.81s
src/gateway/session-row-event-ancestor-placement.test.ts 1 1.500s 15.42s
src/gateway/server-methods/session-change-event.fallback.test.ts 5 1.314s 23.29s
src/gateway/server-lifetime-sidecars.test.ts 7 1.535s 29.84s
src/gateway/server-methods/chat-history-handler.test.ts 35 23.458s 39.96s

The retained detailed Linux log measured the repaired shutdown case at 304ms. The shutdown jobs passed on both preceding published heads; the prior published head retains the historical cursor failure described above. Fresh current-head CI is pending.

Fixture cleanup validation cost

The three existing files ran individually with pnpm test <file> --maxWorkers=1 before and after the cleanup repair. Original macOS cases passed; the repair addresses the source-proven unjoined lifetime, without claiming a reproduced platform deletion failure. Worker disposal now completes within each fixture lifetime.

File Cases Before wall After wall
placement-store.move.test.ts 18 16.08s 32.49s
placement-move-schema.test.ts 1 8.58s 16.66s
placement-store.turn-claim-closure.test.ts 32 16.57s 45.97s

The lifecycle/resource cases passed in 18.35s. These command wall measurements include compilation and startup; they are not production performance measurements.

@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 docs Improvements or additions to documentation 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 19:57
@steipete
steipete requested a review from a team as a code owner September 16, 2026 19:57
@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 21, 2026, 6:40 AM ET / 10:40 UTC (Revision 16).

ClawSweeper review

What this changes

Moves session placement metadata reads into the shared database worker and preserves ordered session notifications, deletion identity, and refresh fallbacks during asynchronous preparation.

Merge readiness

✅ Ready for maintainer review

This remains useful work: current main still reads placement metadata synchronously. The prior code findings are resolved, and this review found no new blocking defect.

Priority: P2
Reviewed head: a1e28a240e32c76e5509cfc267635a58a75f8e0a

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A coherent owner-based repair with substantial targeted validation and resolved prior findings.
Proof confidence 🌊 off-meta tidepool Not applicable: The external-contributor proof gate does not apply to this maintainer-authored PR. Supplied validation exercises placement SQLite reads, registered session consumers, and notification recovery; mocked recipients and unrelated picker screenshots are not claimed as live transport proof.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The external-contributor proof gate does not apply to this maintainer-authored PR. Supplied validation exercises placement SQLite reads, registered session consumers, and notification recovery; mocked recipients and unrelated picker screenshots are not claimed as live transport proof.
Evidence reviewed 10 items Pinned patch ownership: Reviewed the introduced base-to-head changes and original source at the pinned revisions. The supplied test merge has different parents and was not used to infer removal of current-main behavior.
Still necessary on current main: Current main retains getProjectionFacts, which opens SQLite synchronously and reads move and reconciliation facts. The merged placement-read reuse work reduces duplicate queries but does not implement this worker offload.
Latest-release check: The new placement-read worker module is absent from the supplied latest release, v2026.9.5; no shipped replacement for this implementation was established.
Findings None None.
Security None None.

How this fits together

The Gateway combines stored sessions with worker placement metadata to answer session-list and history requests and publish session updates. Prepared facts feed the existing per-recipient presentation and authorization owners.

flowchart TD
  A[Session requests and changes] --> B[Resident session projection]
  B --> C[Shared database read worker]
  C --> D[Committed placement snapshot]
  D --> E[Identity and freshness checks]
  E --> F[Authorized session responses]
  E --> G[Ordered notifications or roster refresh]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +880, Tests +1255, Docs +13. Total +2148 across 53 files.

View PR surface stats
Area Files Added Removed Net
Source 30 1586 706 +880
Tests 21 1418 163 +1255
Docs 2 13 0 +13
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 53 3017 869 +2148

Review metrics

Metric Value Why it matters
Production versus regression coverage Production net +880 lines; tests and test support net +1255 lines Production growth supports worker preparation and bounded notification ownership, with focused coverage for the resulting lifecycle and identity contracts.

Technical review

Best possible solution:

Keep placement preparation within the shared read worker and resident projection, with current identity checks and synchronous recipient presentation.

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

Yes: current-main source directly shows synchronous placement SQLite reads during metadata preparation. Timing and concurrency scenarios were not executed in this read-only review.

Is this the best way to solve the issue?

Yes: reusing the existing shared-state worker and resident projection preserves one owner for stored facts, invalidation, and presentation.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: Improves Gateway session refresh responsiveness and notification reliability without an established emergency 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 external-contributor proof gate does not apply to this maintainer-authored PR. Supplied validation exercises placement SQLite reads, registered session consumers, and notification recovery; mocked recipients and unrelated picker screenshots are not claimed as live transport proof.

Evidence

What I checked:

  • Pinned patch ownership: Reviewed the introduced base-to-head changes and original source at the pinned revisions. The supplied test merge has different parents and was not used to infer removal of current-main behavior. (a1e28a240e32)
  • Still necessary on current main: Current main retains getProjectionFacts, which opens SQLite synchronously and reads move and reconciliation facts. The merged placement-read reuse work reduces duplicate queries but does not implement this worker offload. (src/gateway/worker-environments/placement-store.ts:189, 0fcbb7040195)
  • Latest-release check: The new placement-read worker module is absent from the supplied latest release, v2026.9.5; no shipped replacement for this implementation was established. (src/gateway/worker-environments/placement-read-projection.ts, ec9c1a13db89)
  • Preparation lifetime and identity: Preparation rejects invalidated snapshots, resolves selected identities again after waiting, and clears transient exact facts when the synchronous consumer exits. The production Gateway supplies its existing placement store to this projection. (src/gateway/session-row-placement-projection.ts:158, a1e28a240e32)
  • Previous findings resolved: Placement replies map normalized lookup results back to requested IDs; event preparation includes the bounded ancestor chain. The three previously flagged placement fixtures now await the asynchronous database closer before deletion or reopen. (src/gateway/worker-environments/placement-store.ts:225, a1e28a240e32)
  • Notification recovery: The publisher retains the oldest deletion and latest update, issues a roster refresh after condensation or preparation failure, avoids resending after publication begins, and joins late publications during shutdown. Focused tests cover recipient filtering and client refresh behavior. (src/gateway/server-methods/session-change-event.ts:278, a1e28a240e32)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • jalehman: 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 (15 earlier review cycles; latest 8 shown)
  • reviewed 2026-09-20T10:42:32.748Z sha 434c4192a9b6fbc5d9dd8baec0ada567a85a983e :: blocked before merge. :: [P2] Preserve original requested IDs when selecting placement facts | [P2] Prepare ancestor placement facts before publishing complete snapshots
  • reviewed 2026-09-20T10:54:27.970Z sha f5bb809 :: blocked before merge. :: [P2] Preserve original requested IDs when selecting placement facts | [P2] Prepare ancestor placement facts before publishing complete snapshots
  • reviewed 2026-09-20T18:05:06.895Z sha bd38f1f :: needs maintainer review before merge. :: none
  • reviewed 2026-09-20T19:47:58.545Z sha 4d0333f :: needs maintainer review before merge. :: none
  • reviewed 2026-09-20T21:05:00.148Z sha f8e4d4eeff24a110aaa6a24c76716370c280e0c1 :: needs changes before merge. :: [P2] Drain read workers before deleting placement-test databases
  • reviewed 2026-09-20T21:23:48.833Z sha 48c8d73 :: needs changes before merge. :: [P2] Drain read workers before deleting placement-test databases
  • reviewed 2026-09-20T21:55:28.058Z sha 7d4bec2 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-21T00:17:47.887Z sha 7d4bec2 :: needs changes before merge. :: none

@steipete
steipete requested a review from a team as a code owner September 16, 2026 22:14
@openclaw-barnacle openclaw-barnacle Bot added app: web-ui App: web-ui extensions: memory-core Extension: memory-core cli CLI command changes scripts Repository scripts commands Command implementations agents Agent runtime and tooling extensions: memory-wiki extensions: codex extensions: deepinfra plugin: logbook Logbook automatic work journal plugin extensions: onepassword 1Password plugin app: linux plugin: linux-node labels Sep 17, 2026
@steipete
steipete force-pushed the codex/placement-storage-integration-20260916 branch from 93fb8cb to 954835f Compare September 20, 2026 08:36
@openclaw-barnacle openclaw-barnacle Bot removed app: web-ui App: web-ui extensions: memory-core Extension: memory-core cli CLI command changes labels Sep 20, 2026
Keep collector creation behind the completed preparation hold and avoid fallback resends after publication starts. Measure synchronous session selection CPU and wall time on success and failure.

Separate projection type contracts, preserve decoder and attachment error ownership, and align fixture preparation and SQLite snapshot proof with supported Node runtimes.
Map normalized placement reads back to stored session IDs and prepare the
existing bounded ancestor chain for complete event snapshots. Keep ordinary
exact reads selected-only and omit unavailable synchronous ancestor bundles
so clients retain their existing refresh behavior.

Real SQLite describe and recipient/UI regressions fail before the repair and
pass afterward; private preparation remains scoped to synchronous consumers.
Construct the projection fixture before enabling the session-event fake
clock. Its ACP metadata probe can retain a native SQLite coordinator with
a 30-minute idle timer, which belongs to fixture setup rather than event
publication. Keep every shutdown and zero-event-timer assertion unchanged.
@steipete
steipete force-pushed the codex/placement-storage-integration-20260916 branch from f8e4d4e to 48c8d73 Compare September 20, 2026 21:11
@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. and removed 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 20, 2026
@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. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 20, 2026
Preserve worker-backed history deltas, physical row identity bindings,
and list candidate invalidation in the placement projection carry.

Keep reservation release before lifecycle publication without expanding
the spawn module. Prepare the registered history handler in the privacy
fixture so source transformation does not consume its RPC deadline.
The requests, privacy assertions, and timeout remain unchanged.

Release-note context: session placement reads and notifications retain
responsive worker-backed preparation and current ownership at publication.
@steipete
steipete merged commit 6e70aff into main Sep 21, 2026
217 of 219 checks passed
@steipete
steipete deleted the codex/placement-storage-integration-20260916 branch September 21, 2026 11:03
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation 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. security-sensitive-changed 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