Skip to content

fix(sessions): isolate native workers from host session imports - #182156

Merged
vincentkoc merged 12 commits into
mainfrom
fix/session-actor-registry-independent-20261023
Oct 27, 2026
Merged

vincentkoc merged 12 commits into
mainfrom
fix/session-actor-registry-independent-20261023

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Oct 24, 2026 •

Copy link
Copy Markdown
Member

Related: #181432

What Problem This Solves

Native SQLite session workers load actor creation, host orchestration, and configuration modules they do not need. Every isolate retains its own copy of that import graph.

User Impact

Existing session operations keep their behavior while loading less host code in native workers. No feature is disabled and no public configuration, schema, protocol, or SDK surface is added. Stable process RSS and latency savings are not yet established.

Why This Change Was Made

  • Separate the existing actor registry and binding reads from actor creation/acquisition. Preserve global registry identity, binding precedence, stale-handle custody, and release ordering.
  • Move Goal receipt storage, synchronous session reload, and transcript append into native leaf modules. Keep the existing public SDK facade.
  • Prepare routing dependencies for each relevant command, including a Goal command arriving after worker initialization. Keep preparation outside transactions.
  • Preserve the original CLI turn/persistence failure if stale fork restoration also fails.

Current head fb751906e73206984c917e17cc644aa82b642f25, tree 2c765381b7446075747aaa4ad4aac960dce618f3, integrates main c5d77b74ab192b446564a35eda787660727676e2. The two test conflicts use main's independently repaired SQL counter and worker-profile expectations exactly: #184662 and #184667.

With rename/copy detection disabled: production +908/−814 (net +94), tests/support +386/−129 (net +257), plus two wrapper inventory lines. The production growth establishes native/host ownership boundaries without adding duplicate state or fallback paths.

Evidence

  • Current integrated head: 50/50 tests across five files, covering initialization/rollback, worker-profile fencing, real Gateway agent deletion/recreation, WeakRef retention, and eager import closures. Local macOS arm64, pinned Bun, Node 26.7.0 launcher.
  • Independent P0–P2 review: scoped-clean. A separate source-overlap audit found no lost main changes or harmful auto-merge.
  • The configured Linux Testbox remained queued; no test/build command ran. Its native allocation is stopped. Local proof does not establish Linux equivalence.
  • Private-QA full build reached the declaration-size gate: candidate 5,554,514 bytes, ceiling 5,340,536. Regenerating the same private-QA declarations from main c5d77b74 with the same installed dependencies produced 5,554,513 bytes and the same failure: inherited baseline excess, candidate +1 byte. The normal build completed runtime/plugin bundling and declaration compilation, then failed with ENOSPC while publishing declarations; final build gates remain unverified. No size ceiling was raised.
  • All 5/5 real Gateway node-control-plane cases pass locally, including pairing, invocation, presence, upgrades and rollbacks (155.82 s total). These used the candidate's generated private-QA runtime artifacts; the separate size-gate failure remains recorded above.
  • Targeted source/privacy checks and git diff --check pass. No private paths or addresses were added.
  • Direct Codex contract inspection at 414782450952a196bbb64b1605a458c2531c47b6: codex-rs/exec/src/exec_events.rs:10-56 defines thread identity and failed-turn events; codex-rs/exec/src/lib.rs:990-1050 preserves failed/interrupted turn state through shutdown and exits nonzero. The generic CLI restoration change preserves that original failure as the aggregate cause.

Remaining qualification

Current-head CI is green: https://github.com/openclaw/openclaw/actions/runs/40449158099 completed successfully at fb751906e73206984c917e17cc644aa82b642f25, including the normal build and PostgreSQL conformance. Exact-head ClawSweeper review is clean, with no findings or remaining pre-merge actions. Earlier failed runs and local build limitations remain recorded below.

Preceding head 2c203f87 failed Linux CI https://github.com/openclaw/openclaw/actions/runs/40318146438 in memory-manager deletion cleanup, one surviving WeakRef, and QA node-control-plane setup. Its actual hosted merge passed 117/117 tests across 15 files locally with temporary diagnostic probes, which were removed; that did not explain the Linux failures.

Main now includes #184616, a separately reproduced fix preventing new cache-trim writes during memory-manager shutdown. This integration does not claim that fix caused or resolves the preceding hosted deletion failure.

Historical loaded measurements

Prior-head packaged diagnostics used Node 24.22.1 on macOS arm64, concurrency 2, 32 seeded sessions with 20 × 1,024-character histories, control-plane/history/memory-search probes, and a mock provider paced at 1,000 ms. Each arm verified all turns plus two warmups and fresh samples from all 30 workers.

Workload Worker heap MiB, control → candidate Peak RSS MiB, control → candidate CPU ms, control → candidate History p95 ms, control → candidate
4 turns, control first 1182.51 → 1107.02 2688.53 → 2560.23 1217.18 → 1249.46 15.53 → 25.63
40 turns, candidate first 1176.67 → 1108.87 2677.42 → 1939.06 8708.90 → 8799.36 14.72 → 7.88

These are historical diagnostics, not a current-head RSS percentage or latency claim. The affected SQLite worker used about 62–63 MiB instead of 88–89 MiB. Aggregate worker heap fell about 68–75 MiB, but much larger RSS variation lacks equivalent heap attribution. Main heap increased in the longer candidate run. The short-run history slowdown did not repeat in reverse order. Earlier package-startup, checkpoint, and readiness qualification failures remain failures.

Rank-up disposition: the optional full comparative performance campaign remains deferred. A matched cohort must compare the final integrated head against its corresponding main baseline; this PR claims removal of a demonstrated unnecessary import graph.

Follow-up

  • fix(cron): avoid loading provider runtimes in state workers #184598 has landed the separate Cron shared-writer classification import fix; its numeric RSS effect remains unmeasured.
  • Gateway transcript commits still reach the host entry-acquisition graph.
  • Memory-index transcript statistics remain tracked by fix(memory): avoid session rendering during index scans #181594, still on its explicit performance hold.
  • Nine observed transcript-reader isolates accounted for about 342 MiB of heap. Idle retirement exists; no duplicate creation or missing-release leak is established. Small-device sizing must preserve lane ordering while reducing per-isolate cost.

@vincentkoc vincentkoc self-assigned this Oct 24, 2026
@clawsweeper

clawsweeper Bot commented Oct 24, 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 app: web-ui App: web-ui gateway Gateway runtime scripts Repository scripts agents Agent runtime and tooling size: L labels Oct 24, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 24, 2026
@clawsweeper

clawsweeper Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR separates native session kernels and registry reads from host actor acquisition, prepares Goal routing on demand, and preserves CLI failures during failed fork restoration.

Example: An ordinary session turn runs before the worker receives its first Goal.

  • Before: Worker initialization loads Gateway routing dependencies even for ordinary turns.
  • After: Ordinary turns avoid those imports, and the later Goal prepares its routing dependencies before its transaction.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Useful ownership repair with preserved storage contracts, retained runtime evidence, and green exact-head CI; quantitative performance qualification remains outside the accepted scope.
Proof confidence 🐚 platinum hermit (4/6) Maintainer authorship exempts this PR from the ordinary contributor proof gate; retained packaged Gateway diagnostics exercise session turns, history, and search, while current-head Gateway cases and CI support compatibility without establishing current-head RSS savings.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Refactor · Worth it: Yes · Fix scope: Partial
User problem: Unneeded host modules consume memory in native session-worker isolates, adding pressure on small hosts.
Reason: The maintainer-authored direction removes a verified unnecessary import graph while explicitly leaving the broader memory issue open and deferring unestablished performance claims.

Merge readiness

✅ Ready for maintainer review

This PR provides a useful native-worker import isolation repair with no actionable defect found; exact-head CI is green.

Priority: P2
Reviewed head: fb751906e73206984c917e17cc644aa82b642f25

Before merge

None.

Findings

None.

Agent review details

How this fits together

Gateway session operations enter the existing database executor, whose native kernels commit transcript and Goal changes and return facts for host publication.

flowchart LR
  A[Gateway session operations] --> B[Host preparation]
  B --> C[Database executor]
  C --> D[Native session kernels]
  D --> E[Session database]
  E --> F[Committed facts]
  F --> A
  B --> G[Memory actor acquisition]
Loading

Technical review

Best possible solution:

Land the existing ownership extraction while keeping broader RSS qualification and the related memory investigations separate.

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

Base and current-main source show registry reads and native kernels reaching host acquisition or unconditional routing preparation; the supplied packaged diagnostics support the import-footprint problem, though no target code was executed during this review.

Is this the best way to solve the issue?

The extraction uses existing owners, removes the replaced implementations, preserves public exports and transaction guards, and prepares routing for later commands rather than only at worker initialization.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

PR surface statistics unavailable: the file list is incomplete.

Review metrics

Metric Value Why it matters
Production versus test LOC Production +908/−814; tests/support +386/−129 Most production changes relocate existing implementations; the remaining growth supplies import boundaries and an explicit owner type without duplicate state.

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.

Label justifications:

  • P2: Removing unnecessary per-worker imports is a bounded memory-footprint improvement without an established urgent regression caused by this patch.
  • 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.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (6 earlier review cycles)
  • reviewed 2026-10-24T03:33:38.860Z sha 076ddc9 :: needs changes before merge. :: none
  • reviewed 2026-10-26T09:58:52.052Z sha 17b66e3 :: needs changes before merge. :: none
  • reviewed 2026-10-26T10:33:47.964Z sha 255f812 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-26T11:17:01.255Z sha 38f216e :: needs maintainer review before merge. :: none
  • reviewed 2026-10-26T11:30:31.214Z sha bf04204 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-26T12:01:21.047Z sha 2c203f8 :: needs maintainer review before merge. :: none

Reviewed October 27, 2026, 12:51 AM ET / 04:51 UTC (Revision 7).

@vincentkoc
vincentkoc force-pushed the fix/session-actor-registry-independent-20261023 branch from 076ddc9 to 36ce5c3 Compare October 24, 2026 03:38
@vincentkoc
vincentkoc force-pushed the fix/session-actor-registry-independent-20261023 branch from 36ce5c3 to 3231618 Compare October 24, 2026 03:45
@vincentkoc
vincentkoc marked this pull request as ready for review October 24, 2026 03:46
@clawsweeper clawsweeper Bot removed the clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. label Oct 26, 2026
@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

Please review exact head bf0420471cf5040a8768e476d7372c3278b7573a. Since the last reviewed head, only the incognito preflight test was aligned with the already-merged cleanup in #184463, resolving the merge conflict; all five preflight checks pass. Production is unchanged. The PR body records the two unresolved previous-head Bun CI failures and passing focused Node/Bun replays without claiming a proven fix or green hosted CI.

@clawsweeper

clawsweeper Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

Please review exact head 2c203f871987de9922d7c548d4073f9f70d53538. Since the prior reviewed head, two test-only changes count the raw transcript payload SELECT introduced on main and preserve the original memory-close error in the real Gateway deletion test while retaining plugin cleanup authority. The SQL regression was reproduced red and passed green on the actual CI merge. The Linux deletion failure remains unresolved; local Gateway proof passed, and the new CI run will retain its failing phase if it recurs. The PR body records the exact evidence and limits.

@clawsweeper

clawsweeper Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

Please review exact head fb751906e73206984c917e17cc644aa82b642f25, integrating main c5d77b74ab192b446564a35eda787660727676e2. Both test conflicts take main's independent fixes exactly. Independent full-delta review is scoped-clean; 50 focused cases and all five real Gateway node-control-plane cases pass locally. Current-head hosted run https://github.com/openclaw/openclaw/actions/runs/40449158099 has passed its normal build and focused test jobs; PostgreSQL conformance remains in progress. The body retains previous-head failures, the inherited private-QA declaration-size limit, and the explicitly deferred comparative RSS qualification. No current-head numeric RSS improvement is claimed.

@clawsweeper

clawsweeper Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 27, 2026
@vincentkoc
vincentkoc merged commit 8e5abec into main Oct 27, 2026
238 checks passed
@vincentkoc
vincentkoc deleted the fix/session-actor-registry-independent-20261023 branch October 27, 2026 07:10
@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via squash.

scribe-dandelion-cult added a commit to karmaterminal/openclaw that referenced this pull request Oct 27, 2026
…after upstream openclaw#182156

Upstream openclaw#182156 (8e5abec) moved acquireSessionActorStorage from
session-actor-storage-binding.ts into session-actor-storage-acquisition.ts
and updated its own callers. The fork's recipient-authority incognito test
still imported it from the binding module, so at the j8 merge 203d9e3 it
called undefined: tsgo:core:test TS2724, and both cases red with
"acquireSessionActorStorage is not a function". The test now imports each
name from its owner; no assertion changed.

RED (203d9e3, file unchanged): 2 failed, TypeError.
GREEN: 2 passed; tsgo core:test, test:root, scripts, extensions:test exit 0.

Refs karmaterminal/openclaw-bootstrap#1727

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 28, 2026
…claw#182156)

* fix(sessions): separate actor registry reads from acquisition

* fix(sessions): separate memory owner type contract

* test(gateway): avoid racing kill confirmation ownership

* fix(sessions): preserve unbound memory owner callbacks

* fix(sessions): keep native workers free of host runtime imports

* fix(sessions): preserve CLI failures through stale fork restoration

* test(sessions): drop redundant worker RPC count assertion

* test(gateway): align incognito preflight coverage with main

* test(sessions): count raw initialization payload reads

* test(gateway): retain agent deletion shutdown diagnostics
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling app: web-ui App: web-ui gateway Gateway runtime 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