Skip to content

refactor(sessions): move target preparation callers into workers - #169340

Merged
steipete merged 44 commits into
mainfrom
dbasync/discovery-images
Oct 11, 2026
Merged

steipete merged 44 commits into
mainfrom
dbasync/discovery-images

Conversation

@steipete

@steipete steipete commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Gateway session-target callers still performed synchronous discovery for media, attachments, terminal launch, companion context, and session creation. They now await the existing discovery and entry worker operations. Process-held incognito sessions retain their existing owner. The worker-only availability reader is renamed, and admitted canonical databases no longer repeat full canonical-row validation on ordinary reads.

This completes the bundled caller follow-up to #169311. There is no new schema, retention policy, configuration, migration, or service lifecycle behavior. The Doctor-context change only follows the availability module rename; it does not alter the migration path. No published-driver update cell is required for that import-only change.

Removed checks and accepted edges:

  • Canonical readiness reuses physical-database admission. Unsupported foreign writes while the Gateway owns the file are not rediscovered on ordinary reads; offline import revokes admission.
  • Suggestion rollback trusts the confirmed delete receipt. Independent recreation after deletion does not retroactively change the result.
  • Companion preparation removes three repeated session-ID reads. Reset during preparation is handled by the retained checks before model execution or response disclosure.
  • Terminal connection, launch policy, node command, and incognito authority remain checked after awaited discovery and immediately before launch.

Main-thread inventory

Raw discovery T1 calls: 5 → 4. targets-read-availability.worker.ts is now worker-only. The remaining four conservative mixed-kernel entries are:

  • session-canonical-key.ts: assertCanonicalSqliteSessionKeysCurrent and markCanonicalSessionValidationPending. These kernels also serve native/incognito canonical validation and offline alias import/repair. First admission and real effect authority remain intact.
  • targets.ts: listKnownSessionStoreAgentIds and resolveExistingAgentSessionStoreTargets. Workers use these kernels, but the published synchronous complete-session SDK view (plugin-sdk/session-transcript-hit.ts) and legacy native lookup path still reach them. Completing that cutover requires the SDK/native owner migration; these shared files are not mislabeled worker-only.

Three alternating measurement pairs

The shared harness ran M,C,M,C,M,C on one Hetzner lease at base 21939642b1952 and candidate 28544b47f9a11; run 72c19e708cbc571d5d127621f34966d6. Later changes integrate main and repair fixtures; measurements are reused for unchanged runtime behavior.

Phase Base statements Candidate statements Base requests Candidate requests
01.boot 2010 [2010–2010] 2010 [2010–2011] 68 [68–68] 68 [68–68]
01.connect 1007 [970–1008] 876 [865–1020] 49 [45–50] 49 [46–50]
02.first-turn 1008 [1002–1034] 1149 [988–1161] 192 [183–197] 197 [193–201]
03.warmed 308.5 [306.8–310.2] 308.8 [308.6–310.1] 89.8 [89.7–90.2] 89.6 [89.4–90.2]
04.second-session 1277 [1272–1282] 1277 [1275–1280] 328 [324–333] 326 [326–328]
05.control-plane 91 [14–92] 91 [91–92] 22 [3–22] 22 [22–22]
06.cron 522 [522–565] 521 [521–521] 133 [133–145] 133 [133–133]
07.compaction 173 [173–173] 173 [173–173] 33 [33–33] 33 [33–33]
08.shutdown 83 [77–85] 83 [79–86] 15 [14–16] 14 [14–16]
total 9231 [9210–9274] 9262 [9259–9280] 1735 [1721–1748] 1738 [1737–1745]

Warmed MAIN statements: 0→0. Warm duration 18.588→18.839s (ratio 1.014). Whole-workload statements +0.34%; requests +0.17%.

The warmed discovery operations emit identical statement/request counts. The +0.1 warmed statement median for acpSessions.metadata is at unchanged state-worker source with exactly 20 requests per 10 turns; domain publication and exact-entry request medians decrease.

First-turn publication redistributes from connect: database.domain.publish connect statement arrays [87,133,133]→[0,0,133], first-turn [95,51,53]→[184,184,52]. Combined boot+connect+first totals are base[3982,4026,4051], candidate[4035,4036,4019] (median +0.22%). First-turn standalone comparison must be read with this deferred startup attribution; the moved publication command is schema.admit, confirmed in request-subtypes.csv.

Whole workload owner medians (statements/requests): target-inventory 9/107→11/104; store-target 0/3→0/3; entry 51/10→56/11; list 35/4→33/4; exact 349/150→348/150; actor 53/53→52/52; corpus 52/9→51/9; lifecycle-artifact-plan 0/0→13/1. Cold moved-read growth fits the T1 +2% exception; no warmed discovery growth.

Verification and scope

Two final Codex autoreview rounds were scoped-clean; the requested two-round limit is retained. Prior proof includes 456 tests in 14 files, 105 tests in six Gateway files, six affected test type graphs, and SDK API/surface checks. The final merged tree additionally passes repaired canonical/session-creation/diff fixtures (112 tests in 9 files, 151s), cron validation (135 tests, 38s), partial-mock owner suites (71 tests in 5 files, 67s), and wrapper inventory closure (1 test, 5s). Commands use pnpm test <listed files> --maxWorkers=1; aggregate final focused test wall time is 286s including the 7 runtime guard tests. There are no new behavioral tests in the final fixture-only cleanup.

Final verified head: 3486f7d987bd256534eb595e2861a3d9b7e2e281. Final static gates pass: core (11s), affected config/Gateway type graphs (9s/12s), export collisions (24s), Madge (15s), SDK surface (4s), runtime guard (7 tests, 25s), T1 (6s), dialect (1s), and test-mock ratchet (18s). The only changed-file lint exception is inherited sessions-files.ts max-lines: candidate 777 versus main 782 (main blob d8faa4dbcf01870c99996fd447919a965afe4deb). Knip reports the exact same 84 entries as the parent baseline, with no additions or removals. Full check:changed is not claimed; its affected type graphs and explicit static gates are recorded instead. Unrelated current CI UI typing failures are outside this diff.

Fixture closeout removes obsolete repeated-admission assertions, supplies the async sessions.diff mock, updates the wrapper inventory, documents isolation for eight partial mocks, removes an unused import, and shrinks six stale mock baseline entries. No assertion is weakened to hide a product regression.

LOC versus landed parent before final comment/baseline cleanup: 55 files, +536/-467. Final cleanup is +8/-7 across eight files (comments, unused import, shrink-only baseline).

Landing follows the authorized relaxed v4 policy: no ClawSweeper wait or re-review request; required static gates remain mandatory, with inherited failures recorded explicitly. Remote proof was attempted through Testbox, AWS, then Hetzner; after capacity and transfer stalls, final checks use the allowed local proof slot. All task-owned remote leases and the remote slot are released.

Direct inherited-static proof: a fresh frozen install at current main d0df645f66013c79290904ac9c4e69f9749b94fd reproduces exactly the final-head hosted type errors: TS2345 in mcp-app-unmount.test.ts:40 and TS2339 in mcp-app-view.test.ts:801,804,815. The same UI-components type graph has no additional errors. Final-head security-fast and all seven Security High checks passed. The accepted native auto request was explicitly retired through merge-recover --cancel-auto before the head-pinned v4 fallback.

Move combined topology, search, cron, delivery, and runtime candidate preparation through the existing discovery and session workers. Keep native SDK and effect-boundary contracts explicit; remove repeated descriptive discovery checks.
Await cron delivery discovery outside synchronous writer publication, preserve wake authority at enqueue, and share explicit topology types without import cycles. Keep synchronous SDK and security-boundary discovery for the owning API cutover.
Reuse the media read owner for durable cleanup, preserving missing versus unavailable ownership. Keep unbound process-held incognito reads on their existing native owner until that owner cuts over. Remove duplicate durable discovery and its availability caches.
# Conflicts:
#	src/gateway/managed-image-attachments.sqlite-visibility.test.ts
#	src/gateway/managed-image-attachments.ts
#	src/gateway/managed-image-session-read.ts
Move channel avatar, direct status, companion context, and post-create session reads through the existing worker discovery owner. Preserve companion synchronous identity checks at execution and reply boundaries.
Await initial send target discovery and companion identity reads. Check current identity when reusing a thread and before execution or reply, replacing duplicate preparation reads. Preparation may be discarded at the effect boundary when its session changes.
Use existing worker readers for session creation, runtime target selection, terminal preparation, task suggestions, MCP, and file-route planning. Keep final execution and authority checks at their effect boundaries.

Reuse the selected parent row for ordinary inheritance and trust successful session deletion receipts during suggested-task rollback. A session recreated after rollback is a new session and does not invalidate the completed deletion.
Skip the pending-table lookup for durable stores whose shared canonical
readiness is already valid. Ordinary writers validate their serialized rows;
offline import and repair still invalidate readiness before validation.
False, unadmitted, in-memory, and Doctor validation paths remain intact.

Name the existing worker/Doctor-only target availability leaf as a worker
module and update every importer. Discovery T1 inventory falls from 5 to 4
(total repository T1: 612 to 611); this is a classification correction, not
a claim that additional SQL moved off-thread.

Accepted edge: independently initialized admission handles retain the
existing cache lifecycle; no additional cross-thread handshake is added.

Proof: the new fresh-reader regression fails on the base with one pending
SELECT, then passes with zero and rejects invalid lineage after an in-process
writer marks validation pending. All 15 canonical-validation tests pass
(47.03s suite, 59.24s wrapper). Isolated Codex review: no P0-P2 findings.
Restore retired maintenance targets and native incognito project rows across the worker cutover. Align caller fixtures with asynchronous reads and settled notifications, remove the unused prepared synchronous reader, and delete the obsolete registry-close check test.
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Oct 11, 2026
Refresh the wrapper inventory for the worker-only availability module and align session diff mocks with async discovery. Remove assertions that require repeat canonical validation after physical admission; retain row validation and effect-boundary tests.
Base automatically changed from dbasync/discoveryasync to main October 11, 2026 22:48
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation cli CLI command changes size: XL scripts Repository scripts and removed size: L labels Oct 11, 2026
# Conflicts:
#	src/gateway/server-methods/cron-wake.ts
@openclaw-barnacle openclaw-barnacle Bot removed docs Improvements or additions to documentation cli CLI command changes labels Oct 11, 2026
@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. label Oct 11, 2026
@steipete
steipete enabled auto-merge (squash) October 11, 2026 23:28
@steipete
steipete disabled auto-merge October 11, 2026 23:34
@steipete
steipete merged commit a9b40cf into main Oct 11, 2026
170 of 181 checks passed
@steipete
steipete deleted the dbasync/discovery-images branch October 11, 2026 23:44
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash auto-merge.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 12, 2026
…nclaw#169340)

* refactor(sessions): await target discovery in gateway readers

Move combined topology, search, cron, delivery, and runtime candidate preparation through the existing discovery and session workers. Keep native SDK and effect-boundary contracts explicit; remove repeated descriptive discovery checks.

* refactor(sessions): complete async discovery caller chains

Await cron delivery discovery outside synchronous writer publication, preserve wake authority at enqueue, and share explicit topology types without import cycles. Keep synchronous SDK and security-boundary discovery for the owning API cutover.

* fix(cron): align local wake adapter with async contract

* test: prune repaired session mock exceptions

* fix(sessions): retain current visibility for async search

* refactor: use worker discovery for managed media cleanup

Reuse the media read owner for durable cleanup, preserving missing versus unavailable ownership. Keep unbound process-held incognito reads on their existing native owner until that owner cuts over. Remove duplicate durable discovery and its availability caches.

* test(cron): simplify awaited wake assertion

* fix(sessions): guard topology publication before installing rows

* test(sessions): drop obsolete ambient listing rejection

* fix(sessions): preserve unbound incognito discovery namespace

* refactor(sessions): await discovery in auxiliary entrypoints

Move channel avatar, direct status, companion context, and post-create session reads through the existing worker discovery owner. Preserve companion synchronous identity checks at execution and reply boundaries.

* refactor(sessions): finish async send and companion discovery

Await initial send target discovery and companion identity reads. Check current identity when reusing a thread and before execution or reply, replacing duplicate preparation reads. Preparation may be discarded at the effect boundary when its session changes.

* refactor: move session target callers to async discovery

Use existing worker readers for session creation, runtime target selection, terminal preparation, task suggestions, MCP, and file-route planning. Keep final execution and authority checks at their effect boundaries.

Reuse the selected parent row for ordinary inheritance and trust successful session deletion receipts during suggested-task rollback. A session recreated after rollback is a new session and does not invalidate the completed deletion.

* test: align target discovery fixtures with async readers

* refactor(sessions): remove unused synchronous discovery exports

* fix(sessions): retain process-local incognito federation

* docs(sessions): clarify incognito discovery ownership

* test(cron): align delivery fixtures with worker reads

* refactor: keep session target preparation within owner modules

* perf(sessions): reuse admitted canonical readiness

Skip the pending-table lookup for durable stores whose shared canonical
readiness is already valid. Ordinary writers validate their serialized rows;
offline import and repair still invalidate readiness before validation.
False, unadmitted, in-memory, and Doctor validation paths remain intact.

Name the existing worker/Doctor-only target availability leaf as a worker
module and update every importer. Discovery T1 inventory falls from 5 to 4
(total repository T1: 612 to 611); this is a classification correction, not
a claim that additional SQL moved off-thread.

Accepted edge: independently initialized admission handles retain the
existing cache lifecycle; no additional cross-thread handshake is added.

Proof: the new fresh-reader regression fails on the base with one pending
SELECT, then passes with zero and rejects invalid lineage after an in-process
writer marks validation pending. All 15 canonical-validation tests pass
(47.03s suite, 59.24s wrapper). Isolated Codex review: no P0-P2 findings.

* refactor(cron): drop unused routing import

* refactor(cron): drop unused routing import

* test(gateway): export hoisted cron mock after declaration

* fix(sessions): preserve maintenance and incognito discovery

Restore retired maintenance targets and native incognito project rows across the worker cutover. Align caller fixtures with asynchronous reads and settled notifications, remove the unused prepared synchronous reader, and delete the obsolete registry-close check test.

* test(sessions): align cron and registry discovery fixtures

* fix(sessions): retain requested discovery owners during recovery

* test(cron): extract delivery target fixture

* test(gateway): provide runtime snapshot for registry cleanup

* test(sessions): update discovery cutover fixtures

Refresh the wrapper inventory for the worker-only availability module and align session diff mocks with async discovery. Remove assertions that require repeat canonical validation after physical admission; retain row validation and effect-boundary tests.

* test(sessions): document isolated discovery fixtures
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 P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts size: XL status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant