Skip to content

improve: reduce eager imports during Gateway workspace discovery - #154115

Merged
steipete merged 4 commits into
mainfrom
codex/gateway-workspace-startup-imports
Sep 20, 2026
Merged

steipete merged 4 commits into
mainfrom
codex/gateway-workspace-startup-imports

Conversation

@steipete

@steipete steipete commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Gateway workspace discovery eagerly loads session storage, Doctor workspace inspection, and sandbox runtime code even when the configured workspaces do not need it.

User Impact

Default sandbox-off and writable-workspace paths load less code. Workspace selection, persisted sandbox requirements, read-only Doctor checks, and migration readiness keep their existing owners and behavior. No configuration or migration action is required.

Why This Change Was Made

Use the existing narrow helper definitions, load the batched sandbox classifier only for eligible workspaces, and load the storage-neutral session accessor only when a session-scoped sandbox needs its keys. Reuse that accessor within the scan. Workspace state inspection loads only for Doctor work. Remove the internal session-key re-export left unused by the caller cutover; canonical routing and SDK exports remain.

Evidence

  • The final behavior change passed 57 focused tests and matched all nine baseline workspace-selection observations, including eligibility and admission transitions. Doctor worker tests cover read-only inspection, missing stores, snapshot selection, and alias errors.
  • Independent review of the full five-file candidate completed. Its two findings concerned the old index snapshot and were resolved by staging the reviewed final source. The only later change is repository-formatter wrapping of an unchanged named import.
  • Proof uses an isolated Linux/WSL2 checkout at frozen base 0b615218, Node 24.19.0, pnpm 12.4.0, and fs-safe 0.16.0. The five affected originals are byte-identical at publication base c0e1456f; current main uses fs-safe 0.17.0, so current-head CI remains required.

The final formatted candidate passed a full build and the compiled import-boundary probe. Importing the workspace-discovery owner loads 343 modules / 2,279,059 source bytes, versus 2,281 / 15,577,691 in the original build. Sandbox-off and writable-workspace scans keep sandbox runtime, the SQLite session entry, and Doctor workspace storage unloaded. Missing-store and 32 session-scoped-agent cases still load the required owners and pass. These counts describe this isolated import probe, not the entire Gateway.

The final candidate's measured readiness and sampled peak RSS are below, alongside both original blocks from the earlier comparison:

Build / block Seeded first boot (ms) Established restart (ms) First-boot peak RSS (MiB) Restart peak RSS (MiB)
Original A1 8,898.5; 8,806.9 5,438.4; 5,573.8 892.9; 895.7 1,382.6; 1,383.9
Final candidate 8,308.2; 8,251.2 5,288.2; 5,546.1 890.5; 909.7 1,395.4; 1,397.0
Original A2 9,282.8; 11,270.1 6,867.7; 6,994.0 901.4; 895.0 1,385.3; 1,382.3

Readiness is parent spawn to both HTTP readiness and sidecar readiness. Each block has two measured samples after warmup. The final candidate is a later standalone block, not a fresh interleaved comparison; the original A2 drift prevents a stable percentage speedup claim. Startup below five seconds is not established, and no RSS reduction is claimed. RSS is sampled throughout each harness sample; restart samples include the first RPC checks, so the two columns are different measurement windows.

First boot uses newly seeded 10,000 modern plus two legacy retained-session rows, not an empty install. Restart uses that same state after a real boot and graceful shutdown, without reseeding or rewriting configuration. All 10,002 rows remained byte-equivalent. Both agents returned the expected retained session identities through real chat.history requests; the two-request sequence including connection took 752.0 and 734.9 ms after readiness. Graceful shutdown passed. The full proof completed without memory-limit or OOM events and restored source, index, and dependency manifests.

CI Status

Head 26a1ff4c integrates the verified main repair from PR #154138. All five reviewed source files are byte-identical to c7e9a615; current-head CI runs against the repaired main context.

The original c7e9a615 CI (run 35543018959) passed formatting and the Doctor custody shard, but exposed the Claw close-failure test contamination. The owning repair has an ordered failing/passing reproduction and preserves the Claw assertions. The earlier 854a9392 Doctor custody timeout did not recur on c7e9a615; its cause remains unproven, and no timeout or assertion was changed. Green current-head CI remains a landing requirement.

@clawsweeper

clawsweeper Bot commented Sep 20, 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 agents Agent runtime and tooling size: XS maintainer Maintainer-authored PR labels Sep 20, 2026
@steipete
steipete marked this pull request as ready for review September 20, 2026 22:12
@github-actions

github-actions Bot commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components. This comment is informational because the PR author has repository Maintain or Admin access.

  • Current SHA: 26a1ff4cab44aa7f043af748c00c90842aa0d777
  • Maintainer: @steipete
  • Repository role: admin

These security sensitive changes were made:

  • src/agents/sandbox/config.ts: Controls sandbox containment or tool execution authority. Check filesystem and network isolation, approval scope, and command allowlists.
  • src/agents/sandbox/shared.ts: Controls sandbox containment or tool execution authority. Check filesystem and network isolation, approval scope, and command allowlists.
  • src/agents/sandbox/tool-policy.ts: Controls sandbox containment or tool execution authority. Check filesystem and network isolation, approval scope, and command allowlists.

Carefully review these changes before merging.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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 commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed September 20, 2026, 7:34 PM ET / 23:34 UTC (Revision 5).

ClawSweeper review

What this changes

Gateway workspace discovery uses lightweight helpers and loads session storage, sandbox classification, and Doctor inspection only when needed.

Merge readiness

⛔ Needs changes before merge - 1 item remains

This remains a useful performance improvement absent from current main. No introduced correctness defect was found, and the updated evidence addresses the earlier build and performance-proof gaps.

Priority: P2
Reviewed head: 26a1ff4cab44aa7f043af748c00c90842aa0d777

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, behavior-preserving optimization with relevant real-run evidence and no actionable code finding.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The supplied final-candidate compiled probe exercises workspace discovery's deferred imports, and Linux/WSL2 Gateway boot/restart observations preserve session rows and real chat.history results. Source continuity to this head is verified; these observations support import reduction and retained behavior without establishing a stable startup or RSS improvement.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The supplied final-candidate compiled probe exercises workspace discovery's deferred imports, and Linux/WSL2 Gateway boot/restart observations preserve session rows and real chat.history results. Source continuity to this head is verified; these observations support import reduction and retained behavior without establishing a stable startup or RSS improvement.
Evidence reviewed 8 items Pinned introduced change: The introduced delta replaces broad imports with their existing definition owners, conditionally imports session storage and sandbox classification, and defers Doctor inspection. Eligibility checks, session filtering, workspace layout, and migration validation remain intact.
Still necessary on current main: Fetched main still eagerly imports the session accessor, sandbox runtime classifier, broad agent-scope module, and workspace-state store. Its affected files match the pinned base; no merged replacement for this import optimization was established.
Existing owners and public exports retained: agent-scope already re-exports the same configuration helpers; utils and workspace likewise re-export the selected narrow definitions. The removed session-key re-export has no remaining production imports from agent-scope, while SDK routing and session-key exports remain available.
Findings None None.
Security None None.

How this fits together

Gateway startup and Doctor enumerate configured workspaces and persisted sandbox copies before checking their readiness. This change reduces the code loaded during that discovery while retaining the existing configuration, storage, and migration owners.

flowchart TD
  A[Gateway startup or Doctor] --> B[Configured agent workspaces]
  B --> C{Eligible sandbox workspace?}
  C -->|Yes| D[Load session keys and sandbox classifier]
  C -->|No| E[Selected workspace paths]
  D --> E
  E --> F[Doctor inspection when requested]
  F --> G[Migration readiness check]
Loading

Before merge

  • Complete next step (P2) - Diagnose the earlier Doctor custody timeout and record its owning repair or evidence-backed resolution; a later passing shard alone does not explain the failure.
Agent review details

Security

None.

PR surface

Source +5. Total +5 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 5 30 25 +5
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 30 25 +5

Review metrics

Metric Value Why it matters
Compiled discovery import footprint 2,281 → 343 loaded modules The recorded isolated probe demonstrates the intended import reduction without claiming equivalent whole-Gateway speed or memory gains.

Technical review

Best possible solution:

Retain the existing discovery and storage owners behind conditional imports, preserving workspace selection and read-only readiness semantics.

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

Not applicable as a functional bug report; current-main source confirms the eager imports, and the supplied compiled probe measures their reduction.

Is this the best way to solve the issue?

Yes. Reusing existing narrow definitions and deferring their heavier consumers preserves one implementation of workspace selection without adding configuration or storage contracts.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The supplied final-candidate compiled probe exercises workspace discovery's deferred imports, and Linux/WSL2 Gateway boot/restart observations preserve session rows and real chat.history results. Source continuity to this head is verified; these observations support import reduction and retained behavior without establishing a stable startup or RSS improvement.

Label justifications:

  • P2: This is a bounded Gateway startup performance improvement with unchanged user configuration and workspace behavior.
  • 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. Sufficient (live_output): The supplied final-candidate compiled probe exercises workspace discovery's deferred imports, and Linux/WSL2 Gateway boot/restart observations preserve session rows and real chat.history results. Source continuity to this head is verified; these observations support import reduction and retained behavior without establishing a stable startup or RSS improvement.
  • proof: sufficient: Contributor real behavior proof is sufficient. The supplied final-candidate compiled probe exercises workspace discovery's deferred imports, and Linux/WSL2 Gateway boot/restart observations preserve session rows and real chat.history results. Source continuity to this head is verified; these observations support import reduction and retained behavior without establishing a stable startup or RSS improvement.

Evidence

What I checked:

  • Pinned introduced change: The introduced delta replaces broad imports with their existing definition owners, conditionally imports session storage and sandbox classification, and defers Doctor inspection. Eligibility checks, session filtering, workspace layout, and migration validation remain intact. (src/agents/workspace-state-dirs.ts:35, 26a1ff4cab44)
  • Still necessary on current main: Fetched main still eagerly imports the session accessor, sandbox runtime classifier, broad agent-scope module, and workspace-state store. Its affected files match the pinned base; no merged replacement for this import optimization was established. (src/agents/workspace-state-dirs.ts:6, 21f3d71a09d4)
  • Existing owners and public exports retained: agent-scope already re-exports the same configuration helpers; utils and workspace likewise re-export the selected narrow definitions. The removed session-key re-export has no remaining production imports from agent-scope, while SDK routing and session-key exports remain available. (src/agents/agent-scope.ts:41, 26a1ff4cab44)
  • Final-source continuity: All five reviewed production files are unchanged from the previous reviewed head; the latest merge brings in the main-branch filesystem-test repair. (26a1ff4cab44)
  • Recorded behavior and performance evidence: The complete supplied body reports a final formatted build and compiled discovery probe: 343 loaded modules versus 2,281 originally, with sandbox-off and writable-workspace scans leaving the deferred owners unloaded. Linux/WSL2 Gateway boot and restart observations preserved 10,002 session rows and returned expected identities through real chat.history requests. Startup seconds and sampled RSS are supplied with explicit drift and measurement-window limitations; they establish neither a stable percentage speedup nor reduced RSS. The evidence uses fs-safe 0.16.0, while current-head CI covers the newer dependency context. (src/agents/workspace-state-dirs.ts:21, 26a1ff4cab44)
  • Remaining prior validation follow-up: The updated body explicitly leaves the earlier Doctor custody timeout undiagnosed. The merged filesystem-test repair explains the separate Claw close-failure contamination, not that timeout. GitHub confirms the earlier compact-large-12 job failed; its log redirect was blocked by the reviewer network policy, so no additional cause is inferred. Root policy requires diagnosis or an owning repair rather than treating a subsequent passing shard as resolution. (AGENTS.md, 26a1ff4cab44)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)
  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)

Rank-up moves

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

  • Record the diagnosis or owning repair for the earlier Doctor custody timeout.

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 (4 earlier review cycles)
  • reviewed 2026-09-20T22:20:33.096Z sha 509d867 :: needs changes before merge. :: none
  • reviewed 2026-09-20T22:38:38.237Z sha 854a939 :: needs changes before merge. :: none
  • reviewed 2026-09-20T22:59:55.426Z sha c7e9a61 :: needs changes before merge. :: none
  • reviewed 2026-09-20T23:11:14.979Z sha c7e9a61 :: blocked before merge. :: none

@steipete
steipete force-pushed the codex/gateway-workspace-startup-imports branch from 509d867 to 854a939 Compare September 20, 2026 22:32
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Sep 20, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Sep 20, 2026
@steipete
steipete merged commit 5eeb585 into main Sep 20, 2026
222 checks passed
@steipete
steipete deleted the codex/gateway-workspace-startup-imports branch September 20, 2026 23:47
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 21, 2026
…nclaw#154115)

* improve: reduce eager imports during Gateway workspace discovery

* fix: remove unused agent session-key re-export

* perf: defer workspace session and Doctor storage imports
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. security-sensitive-changed size: S 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