Skip to content

refactor(gateway): split worker environment service by ownership - #122138

Merged
steipete merged 6 commits into
mainfrom
steipete/worker-service-split-0811
Aug 11, 2026
Merged

steipete merged 6 commits into
mainfrom
steipete/worker-service-split-0811

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

src/gateway/worker-environments/service.ts mixed provider lifecycle, credential delivery, tunnel/desktop access, and security-sensitive worker-turn authority in one 2,036-line composition root. That ownership blur made worker admission, placement, terminal-fence, and turn-claim logic harder to review safely.

Why This Change Was Made

The service is split by ownership while keeping shared KeyedAsyncQueue serialization, active-operation tracking, reconciliation scheduling, and shutdown draining in the facade. Worker authority checks and their inline invariant comments move intact into worker-turn-rpc.ts; placement gate types move to their owner. Desktop observation remains a dynamic import inside environment-access.ts.

A pure deriveEnvironmentIntent now owns both deterministic IDs in service-contract.ts. All consumers use it directly, the former service export is removed without a compatibility alias, and the last production static value import of service.ts is gone.

User Impact

No intended user-visible behavior change. The split preserves provisioning, reconciliation, credential, tunnel/desktop, admission, placement, ACK, inference, session-tool, and shutdown semantics while making their owners independently reviewable. Every implementation module is below the 700-line production limit, and both prior max-lines exceptions are removed.

Evidence

  • pnpm build — passed; no [INEFFECTIVE_DYNAMIC_IMPORT] warning.
  • Six split worker-environment suites — 94 original cases retained; combined run reached 92/94 before two missing test-only imports were restored, then provider-provisioning.test.ts passed 33/33.
  • src/worker/worker.fault-injection.test.ts — 7/7 passed.
  • pnpm check:import-cycles — 0 runtime value cycles.
  • pnpm check:madge-import-cycles — 0 cycles.
  • pnpm lint:tmp:export-name-collisions — passed.
  • pnpm check:wrapper-shadowing — passed, 30/30 baseline.
  • pnpm plugin-sdk:surface:check — passed, 152 public entrypoints / 4,866 exports.
  • pnpm check:max-lines-ratchet --base origin/main — passed, baseline shrank by two entries.
  • pnpm check:test-types — core test types passed after correcting the shared fixture declaration; extensions lane could not acquire the shared local check lock before the repository timeout.
  • node scripts/check-changed.mjs — formatting, max-lines, dependency, wildcard-export, duplicate-coverage, and preliminary architecture gates passed; it stopped on broad unrelated Plugin SDK API hash drift across 16 untouched entrypoints. The dedicated Plugin SDK surface guard is green, so no unrelated baseline was regenerated.
  • Final Codex autoreview — clean; no accepted/actionable findings.

Raw git diff --numstat origin/main classification:

  • Production: +2,155 / -1,765 = +390 lines.
  • Tests and test support: +3,410 / -3,173 = +237 lines.
  • Tooling/baseline: +0 / -2 = -2 lines.
  • Total: +625 lines.

The positive production delta is the explicit narrow injected interfaces and composition wiring required to preserve one shared lock/drain owner without introducing a shared-context back-module. Authority bodies themselves were moved, not expanded or simplified.

@clawsweeper

clawsweeper Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: XL maintainer Maintainer-authored PR labels Aug 11, 2026
@steipete
steipete marked this pull request as ready for review August 11, 2026 16:26
@steipete
steipete marked this pull request as draft August 11, 2026 16:27
@steipete
steipete marked this pull request as ready for review August 11, 2026 16:27
@clawsweeper clawsweeper Bot added merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. 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 Aug 11, 2026
@clawsweeper

clawsweeper Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 11, 2026, 1:54 PM ET / 17:54 UTC.

ClawSweeper review

What this changes

The PR splits Gateway worker-environment lifecycle, credential delivery, access, and worker-turn RPC handling into owner-specific modules while retaining a coordinating facade.

Merge readiness

⚠️ Ready for maintainer review - 4 items remain

No concrete patch-introduced defect was found in the authority or lifecycle split. This maintainer-owned, security- and availability-sensitive refactor should remain open for exact-head CI completion and maintainer approval.

Priority: P2
Reviewed head: 4e9b4bcf8577adec984f8a123bf46f11fb170770
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The extracted owner boundaries and focused regression coverage are solid, with final confidence appropriately gated on exact-head validation.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored internal refactor is assessed through its source-level invariants and exact-head CI rather than external contributor proof.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored internal refactor is assessed through its source-level invariants and exact-head CI rather than external contributor proof.
Evidence reviewed 5 items Authority boundary preserved: Worker RPC requests still validate the live placement claim, credential hash and epoch, attachment state, and terminal fence; awaited transcript and session-tool work is revalidated before an ACK or result is returned.
Lifecycle ownership preserved: The facade retains the shared queues, active-operation drain, reconcile single-flight, and shutdown sequence; lifecycle teardown stops tunnels before provider destruction.
Focused regression coverage retained: The removed monolithic suite has 72 cases, and the six replacement suites also total 72 cases while covering placement revocation, credential rotation, terminal fences, reconciliation, tunnel ordering, and shutdown.
Findings None None.
Security None None.

How this fits together

Gateway provisions remote worker environments, issues their credentials, admits worker RPCs, and manages their teardown. Session placement requests flow through the facade to provider, tunnel, state-store, and worker-turn owners.

flowchart LR
  A[Gateway session placement] --> B[Worker environment facade]
  B --> C[Provider lifecycle]
  B --> D[Credential broker]
  B --> E[Environment access]
  B --> F[Worker turn RPC]
  C --> G[Provider and state store]
  D --> G
  E --> G
  F --> G
Loading

Decision needed

Question Recommendation
Should this maintainer-owned worker-environment ownership split merge after its exact-head Gateway checks complete successfully? Validate then approve: Merge after exact-head CI is green and a maintainer accepts the preserved queue, authority, and teardown ownership boundaries.

Why: Source review found the expected authority and lifecycle fences, but the change redistributes security- and availability-critical behavior across new owners and carries the repository’s maintainer label.

Before merge

  • Resolve merge risk (P1) - Credential, placement, and teardown responsibilities now cross several modules; exact-head CI and human review remain necessary before merging this security- and availability-sensitive refactor.
  • Resolve merge risk (P1) - The refactor is production net +390 lines, increasing review surface even though the prior monolith and its tests are removed or redistributed.
  • Complete next step (P2) - No mechanical repair is identified; the remaining action is maintainer review of this protected Gateway refactor after exact-head validation.
Agent review details

Security

None.

PR surface

Source +846, Tests -229, Other -2. Total +615 across 20 files.

View PR surface stats
Area Files Added Removed Net
Source 10 2622 1776 +846
Tests 9 2941 3170 -229
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 0 2 -2
Total 20 5563 4948 +615

Review metrics

Metric Value Why it matters
Production versus test delta production +390, tests +237, tooling -2 The net production growth is attributed to injected owner interfaces and facade wiring, so it warrants maintainer scrutiny despite the deleted monolith.

Stored data model

Persistent data-model change detected: durable storage schema: src/gateway/worker-environments/credential-broker.test.ts, durable storage schema: src/gateway/worker-environments/credential-broker.ts, durable storage schema: src/gateway/worker-environments/environment-access.test.ts, durable storage schema: src/gateway/worker-environments/environment-access.ts, durable storage schema: src/gateway/worker-environments/placement-dispatch.test.ts, durable storage schema: src/gateway/worker-environments/placement-worker-gate.ts, and 23 more. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Finish exact-head Gateway validation (recommended)
    Wait for the current head’s Gateway and security checks, then approve the retained authority and teardown invariants.
  2. Pause for a concrete owner-boundary concern
    Keep the refactor open only if maintainer review identifies a specific delegation that needs correction.

Technical review

Best possible solution:

Keep the facade as the sole owner of serialization and shutdown, with the extracted modules retaining their current narrow owner boundaries, then merge after exact-head validation and maintainer sign-off.

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

Not applicable: this is an internal ownership refactor, not a report of a separately reproducible user failure.

Is this the best way to solve the issue?

Yes: the split follows the existing owner boundaries while the facade retains shared serialization and shutdown; source review found no narrower change that would make the monolith independently reviewable.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against d9766c3d5723.

Labels

Label justifications:

  • P2: This is a bounded Gateway refactor with meaningful but non-emergency operator impact.
  • merge-risk: 🚨 security-boundary: Credential issuance and worker turn-authority checks move into newly separated modules.
  • merge-risk: 🚨 availability: Provisioning, reconciliation, tunnel handling, and shutdown delegation are redistributed.
  • 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 maintainer-authored internal refactor is assessed through its source-level invariants and exact-head CI rather than external contributor proof.

Evidence

What I checked:

Likely related people:

  • steipete: Authored the four-commit worker-environment split and is assigned to this PR. (role: recent area contributor; confidence: high; commits: d5817cfa83c3, 87f2262e6d61, 82dc4aa7ce49; files: src/gateway/worker-environments/service.ts, src/gateway/worker-environments/provider-lifecycle.ts, src/gateway/worker-environments/worker-turn-rpc.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Let the current head’s Gateway and security checks complete before merge.

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 (1 earlier review cycle)
  • reviewed 2026-08-11T17:01:31.674Z sha e89cceb :: needs maintainer review before merge. :: none

@steipete
steipete force-pushed the steipete/worker-service-split-0811 branch from c7a2399 to 9bfa22e Compare August 11, 2026 17:35
@openclaw-barnacle openclaw-barnacle Bot added the docs Improvements or additions to documentation label Aug 11, 2026
@steipete steipete self-assigned this Aug 11, 2026
@steipete
steipete force-pushed the steipete/worker-service-split-0811 branch from 9bfa22e to 4e9b4bc Compare August 11, 2026 17:49
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation and removed docs Improvements or additions to documentation labels Aug 11, 2026
@steipete
steipete force-pushed the steipete/worker-service-split-0811 branch from b56726b to d90c587 Compare August 11, 2026 18:33
@steipete
steipete merged commit 2d6a5d7 into main Aug 11, 2026
120 checks passed
@steipete
steipete deleted the steipete/worker-service-split-0811 branch August 11, 2026 18:48
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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

* refactor(gateway): split worker environment service by ownership

* refactor(gateway): derive environment intent at the contract owner

* chore(lint): ratchet max-lines baseline after worker-service split

* style(gateway): prune unused symbols after worker-service split

* refactor(gateway): narrow worker-service seam exports

* chore(plugin-sdk): refresh API baseline
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. 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