Skip to content

improve(gateway): defer worker workspace execution imports - #143496

Merged
vincentkoc merged 2 commits into
mainfrom
perf/worker-workspace-execution-imports-20260909
Sep 13, 2026
Merged

vincentkoc merged 2 commits into
mainfrom
perf/worker-workspace-execution-imports-20260909

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Sep 9, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

Importing the worker-turn launcher eagerly loads execution implementations and their workspace-settlement dependencies before a turn passes admission.

Why This Change Was Made

Keep workspace validation, placement authority and turn-claim cleanup in their existing owners. Load only the selected execution implementation on each recovery-loop iteration, inside the existing claim-cleanup boundary. Revalidate admission, placement and the exact claim after loading and before registering the execution owner.

Preserve the worker-specific composed admission callback through asynchronous context preparation, while remote execution retains its existing caller callback. Redispatch retains the composed callback and abort signal. Admission notification, persistence, release-before-reconciliation, pending-result custody and identity-based cleanup remain unchanged.

Move the unchanged reconciliation error constructor and workspace-settlement functions into shared leaves. Redirect the three eager settlement consumers so they do not restore the cold-import dependency path. No configuration, protocol, schema or persistence-contract changes.

User Impact

Less execution code is loaded eagerly. No measured startup, latency or RSS improvement is claimed. Revocation, claim replacement, loader failure, rollback and recovery continue through their existing owners, without a new operator action.

Evidence

Current Integrated Source

  • Signed head: 9ec456dcfc26775b5a871307ea972b506701668e.
  • Parents: published 6b5db794123fb767af6e80ce2aaf2734b3004881 and main integration snapshot 2700b9e34e6f79afba980dac67508af4c6eb707e. Both ancestries are preserved; this is not replacement of the published branch.
  • The ten-file residual against that main snapshot preserves its recovery loop, composed writer-admission fence and redispatch signal. Production: +187 / -160, net +27, including an unchanged 149-line settlement move. Tests: +469 / -4. The remaining growth implements selected lazy-loading boundaries and post-await authority checks.
  • One fresh source-review invocation across four batches, 108 context files and six complete owning guides reported zero findings and zero abstentions. Its native invocation and outer process completed successfully with frozen source preserved.

Current Local Qualification

  • Normal frozen install completed at the exact signed head with the repository-pinned pnpm 12.3.4 and Node 26.7.0. Native TypeScript 7.0.2, TypeScript API 6.0.3 and tsdown 0.23.0 resolved inside the isolated validation checkout.
  • Normal full pnpm build passed in 273.777 seconds, with all sixteen build phases completed and build metadata bound to the exact head. This is not a whole-environment cold-build or performance claim.
  • The new initial-setup regression pauses the real asynchronous model-context read, changes the authoritative writer while caller and placement remain valid, and checks rejection before credentials, tunnel or worker launch plus claim release. Replacing only the composed worker callback with the raw callback failed the intended credential-call assertion; restoring the exact candidate passed. This is an integration-regression mutant, not a claim that the old published head had the newer asynchronous path.
  • Current owner and sibling proof: 210 unique passing cases across 19 files, zero failures and zero excluded cases. Coverage includes cold imports, recovery-loop reloads, admission and claim replacement, cancellation, detached context, error identity, ordered workspace settlement and placement resume. The focused GREEN case is included in those 210, not an additional case.
  • Canonical changed checks passed against the explicit main integration snapshot: core and core-test type graphs, scoped formatting/lint, dead exports, boundaries, import cycles and store guards. The tests, full build and targeted checks exited successfully; owned processes and streams closed, and tracked source and install inputs were preserved.
  • These are local owner-boundary observations. They are not live Gateway/provider, Windows, latency or RSS proof. Current-head required CI and native landing checks remain separate gates.

Retained History And Limits

  • Original proof base 008cf5d9b0a4b1dcae5517706ea06d31ec1082ff and signed source d90d6944c42ef023d964eeee8cec08d11ac1f930 supplied four intended baseline cold-import failures. Twenty new cases had passing observations across recorded revisions, not one final-byte twenty-case run: an initial fixture error was corrected using the actual claim return, and the affected cases were rerun. A selector-miss attempt selected zero tests and is not proof.
  • Historical launcher/recovery siblings passed 83 cases. The original ordered workspace run had 30 passes and one timeout at the unchanged 120-second deadline; its cause remains unknown.
  • A matched, temporarily instrumented --no-cache diagnostic pair preserved staged-results -> repository -> finalize order and passed 31/31 on both baseline and candidate. The original timeout was not reproduced under those diagnostic conditions. Instrumentation was removed. A later uninstrumented published-head run passed 13 + 15 + 3 = 31, without explaining or erasing the original timeout.
  • Published 6b5db794123fb767af6e80ce2aaf2734b3004881 had successful CI run 34424900129 and normal Node 26.1.0 / Ubuntu compatibility run 34429388774, including full pnpm build. The declaration-restore step was skipped; no broader cold-build claim follows. These runs remain old-head evidence, not current-head CI.
  • The earlier incomplete source-review attempt and all adverse receipts remain retained. The later historical clean review and the current four-batch invocation are distinct evidence, not retrospective rerating of an incomplete attempt.

@clawsweeper

clawsweeper Bot commented Sep 9, 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.

@vincentkoc vincentkoc added the r: too-many-prs-override Maintainer override for the active-PR limit auto-close. label Sep 9, 2026
@vincentkoc vincentkoc self-assigned this Sep 9, 2026
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: L maintainer Maintainer-authored PR labels Sep 9, 2026
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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 9, 2026
@clawsweeper

clawsweeper Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 13, 2026, 2:00 PM ET / 18:00 UTC (Revision 6).

ClawSweeper review

What this changes

Defers worker execution and sandbox imports until needed, extracts shared workspace-settlement helpers, and adds admission and loading regression coverage.

Merge readiness

✅ Ready for maintainer review

This PR remains useful: current main and the latest release still eagerly import worker execution. No blocking defect was found in the introduced changes.

Priority: P3
Reviewed head: 9ec456dcfc26775b5a871307ea972b506701668e

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, maintainable loading change with meaningful regression coverage and no blocking findings.
Proof confidence 🌊 off-meta tidepool Not applicable: This MEMBER-authored internal loading PR is exempt from contributor live-proof requirements. Its reported exact-head build and owner-boundary tests cover the changed launcher and settlement paths; inspection found no unresolved introduced authority violation requiring additional final-effect proof.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This MEMBER-authored internal loading PR is exempt from contributor live-proof requirements. Its reported exact-head build and owner-boundary tests cover the changed launcher and settlement paths; inspection found no unresolved introduced authority violation requiring additional final-effect proof.
Evidence reviewed 8 items Introduced loading boundary: The pinned base-to-head diff adds selected dynamic imports inside the existing cleanup boundary. Admission, placement identity, and the exact turn claim are checked before run-owner registration; worker execution retains the composed admission callback.
Existing settlement ownership preserved: The extracted journal, conflict-finalization, and settlement functions retain their existing behavior. Recovery, reclaim, and repository mutation consumers now import the shared module directly; no stored format or migration changes were introduced.
Main still has the eager imports: The fetched main launcher still statically imports both execution implementations and calls them directly. The requested loading boundary is therefore still absent from main.
Findings None None.
Security None None.

How this fits together

The Gateway's worker launcher routes admitted session turns to local or remote execution. Placement and turn claims control execution authority, while workspace settlement preserves completed file results before releasing ownership.

flowchart TD
  A[Session turn] --> B[Placement admission]
  B --> C[Local execution]
  B --> D[Load selected worker execution]
  D --> E[Recheck admission and exact claim]
  E --> F[Worker or remote execution]
  F --> G[Settle workspace and release claim]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +27, Tests +465. Total +492 across 10 files.

View PR surface stats
Area Files Added Removed Net
Source 7 187 160 +27
Tests 3 469 4 +465
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 10 656 164 +492

Review metrics

Metric Value Why it matters
Production versus test growth Production +187/-160; tests +469/-4 Production growth is net 27 lines after extracting a 149-line settlement module, with the remaining growth supporting deferred loading and post-await admission checks.

Technical review

Best possible solution:

Keep execution loading behind admitted placement selection while preserving the existing claim, recovery, and workspace-settlement owners.

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

Not applicable as a user-facing bug reproduction: source inspection confirms the eager-import boundary, and the added tests target its removal and admission preservation.

Is this the best way to solve the issue?

Yes. The PR reuses the existing lazy-runtime utility and extracts shared settlement code without creating a competing execution or persistence owner.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P3: This is an internal loading improvement with no claimed measured performance gain or user-visible behavior change.
  • 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: This MEMBER-authored internal loading PR is exempt from contributor live-proof requirements. Its reported exact-head build and owner-boundary tests cover the changed launcher and settlement paths; inspection found no unresolved introduced authority violation requiring additional final-effect proof.

Evidence

What I checked:

  • Introduced loading boundary: The pinned base-to-head diff adds selected dynamic imports inside the existing cleanup boundary. Admission, placement identity, and the exact turn claim are checked before run-owner registration; worker execution retains the composed admission callback. (src/gateway/worker-environments/worker-turn-launcher.ts:329, 9ec456dcfc26)
  • Existing settlement ownership preserved: The extracted journal, conflict-finalization, and settlement functions retain their existing behavior. Recovery, reclaim, and repository mutation consumers now import the shared module directly; no stored format or migration changes were introduced. (src/gateway/worker-environments/workspace-result-settlement.ts:20, 9ec456dcfc26)
  • Main still has the eager imports: The fetched main launcher still statically imports both execution implementations and calls them directly. The requested loading boundary is therefore still absent from main. (src/gateway/worker-environments/worker-turn-launcher.ts:30, 201f11afefdb)
  • Latest release comparison: The v2026.9.4 launcher also statically imports worker and remote execution. Local release-blob inspection failed, but the GitHub contents endpoint supplied the release source successfully. (src/gateway/worker-environments/worker-turn-launcher.ts:30, 3a9d69db306c)
  • Admission regression coverage: The new tests intercept module loading and exercise current, revoked, replaced-claim, drained-placement, and loader-failure cases. The additional detached-context case changes the authoritative session writer and checks rejection before credential acquisition, tunnel creation, or launch. (src/gateway/worker-environments/worker-turn-detached-context.test.ts:343, 9ec456dcfc26)
  • Captured validation and review continuity: The supplied PR body reports an exact-head full build, changed checks, and 210 passing cases across 19 files, including an intended-failure writer-fence mutant. It explicitly distinguishes these observations from live Gateway and performance proof and retains the unexplained historical timeout. The previous completed review contains no findings or published rank-up moves. Tests and builds were not rerun during this read-only review. (9ec456dcfc26)

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 (5 earlier review cycles)
  • reviewed 2026-09-09T23:46:37.130Z sha 6b5db79 :: blocked before merge. :: none
  • reviewed 2026-09-10T02:03:50.564Z sha 6b5db79 :: blocked before merge. :: none
  • reviewed 2026-09-10T02:38:22.350Z sha 6b5db79 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-10T03:00:06.525Z sha 6b5db79 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-10T09:37:40.325Z sha 6b5db79 :: needs maintainer review before merge. :: none

@vincentkoc
vincentkoc marked this pull request as ready for review September 10, 2026 01:17
@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@vincentkoc
vincentkoc merged commit e38a36f into main Sep 13, 2026
187 checks passed
@vincentkoc
vincentkoc deleted the perf/worker-workspace-execution-imports-20260909 branch September 13, 2026 18:12
@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Sep 13, 2026
* commit '2d87daf04b78992382299d552f15ac84a86a23ed': (1815 commits)
  fix(ui): distinguish tool activity with semantic icons (#147207)
  fix(linux): recover completed Quick Chat replies without resending (#146048)
  feat(desktop): unify Tauri title bar and window controls (#147097)
  refactor(test): share plugin fixture server shims (#147225)
  perf(gateway): defer worker workspace execution imports (#143496)
  fix(gateway): post-ack webhook work fails with "Async work scope is closed" (#144801)
  refactor(scripts): centralize upgrade survivor version floors (#146975)
  fix(ci): check publication registries before FRV fanout (#147184)
  fix(qa): align system-agent delegation with channel contracts (#145905)
  improve: reduce repeated chat message identity work (#147210)
  fix(channels): remove stale pre-tool previews from Slack and Telegram (#147106)
  fix: keep catalog discovery scoped and execution lazy (#147159)
  fix: serialize reclamation worker shutdown with foreground writes (#147178)
  test(sessions): cover abrupt committed transcript recovery (#143984)
  fix: stop transcript storms during context overflow recovery (#147202)
  fix: reduce CPU overhead for small history and usage reads (#147205)
  fix: resume tasks after tools finish and the model times out (#147203)
  refactor(scripts): share SQLite reliability message waits (#146900)
  feat(exec): configure approval reviewer thinking and fastMode (#147192)
  test: remove redundant Bonjour module headers (#146981)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. r: too-many-prs-override Maintainer override for the active-PR limit auto-close. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L 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