Skip to content

improve: reduce worker tool startup imports - #119644

Merged
steipete merged 2 commits into
mainfrom
codex/test-perf-worker-core-tools
Aug 5, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/test-perf-worker-core-tools

Conversation

@steipete

@steipete steipete commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Restricted workers currently cold-load the generic agent tool assembly graph before their first inference even though the Gateway has already authorized a fixed six-tool surface: read, write, edit, apply_patch, exec, and process. That generic graph reaches channel, plugin, message, system-agent, TUI, and other runtime families the worker cannot expose, making the worker integration test and real worker startup unnecessarily import-bound.

Why This Change Was Made

This extracts one canonical core coding/shell materializer and one canonical tool-finalization pipeline from the generic agent factory. Both normal agents and workers now use those same owners. The worker supplies its Gateway-authorized six-tool policy directly, while retaining OpenClaw read/write/edit behavior, workspace-contained apply-patch, lazy scoped exec/process tools, schema normalization, before-tool hooks, abort wrapping, and deferred follow-up descriptions.

No worker authority, tool names, test declarations, shard topology, worker counts, scheduling, concurrency, or timeout settings change.

User Impact

Worker turns start with a substantially smaller eager module graph. Normal agent tool construction keeps the same policy and wrapper pipeline.

Production delta is +112 lines: the positive delta creates the shared owner boundary used by both generic agents and restricted workers, replacing a worker dependency on the much broader policy/materialization graph while preserving the generic factory's existing constructor seams.

Evidence

  • AWS Crabbox cbx_abb114186b2c, run run_553b7ac6714b: all 28 worker runtime integration tests and 118 representative generic tool-construction tests passed (146 total).
  • Same-host exact before/after benchmark, AWS Crabbox run run_81a913e2023c: alternating baseline → candidate → candidate → baseline with separate cold compile/module caches. Worker-file duration averaged 18.415s → 15.295s (16.9% faster); the cold full embedded turn averaged 13.282s → 8.550s (35.6% faster); maximum RSS averaged 2,288,830 KiB → 2,176,298 KiB (4.9%, about 110 MiB lower).
  • AWS Crabbox run run_5d694621081d: the corrected follow-up passed all 159 focused cases, including the two filesystem-constructor suites that CI had caught.
  • AWS Crabbox run run_592d9b6c8abb: pnpm tsgo:prod passed after the follow-up.
  • AWS Crabbox run run_523a08a4b914: full pnpm build passed in 4m36.951s, including CLI bootstrap import, plugin SDK export, runtime postbuild, and Control UI performance gates.
  • Direct oxlint, oxfmt --check, and git diff --check passed for all eight changed files.
  • Autoreview: clean, no accepted/actionable findings (gpt-5.6-sol, high reasoning).

This is an incremental step toward the frozen raw full-suite target; it does not claim normalized or final 30% success.

@steipete steipete self-assigned this Aug 5, 2026
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: L maintainer Maintainer-authored PR labels Aug 5, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. labels Aug 5, 2026
@clawsweeper

clawsweeper Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 5, 2026, 11:17 AM ET / 15:17 UTC.

ClawSweeper review

What this changes

The PR extracts shared core coding-tool construction and finalization so restricted workers avoid importing the broader generic agent tool assembly path at startup.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

Keep open for normal maintainer review. The refactor preserves the Gateway-authorized worker surface while moving common construction and finalization into shared owners; no concrete correctness or security regression surfaced, but the performance claim still needs an exact-head before/after startup or RSS measurement.

Priority: P2
Reviewed head: 661dce3b5dc9401649fafcf90f63036b68581cca

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch has a coherent shared-owner design and strong focused/CI validation; a direct before/after startup measurement would substantiate its performance goal.
Proof confidence 🌊 off-meta tidepool Not applicable: The PR is marked as maintainer work, so the external-contributor proof gate does not apply; the reported Gateway integration and exact-head CI remain useful supplemental validation.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The PR is marked as maintainer work, so the external-contributor proof gate does not apply; the reported Gateway integration and exact-head CI remain useful supplemental validation.
Evidence reviewed 5 items Worker owner boundary: The proposed worker path builds the core file/shell tools, applies the shared finalization pipeline, and only supplies the Gateway-authorized names to the embedded session.
Generic-path reuse: The generic tool factory calls the same extracted core materializer and shared finalizer, avoiding a worker-specific duplicate implementation.
Existing worker contract: Current-main worker integration coverage verifies the full six-tool surface, a restricted read/exec surface, and an empty authorized surface through the Gateway protocol seam.
Findings None None.
Security None None.

How this fits together

Gateway worker turns receive an authorized subset of local coding tools, which the embedded worker exposes to model inference. The generic agent factory and restricted worker both need the same file, shell, schema, hook, and abort behavior.

flowchart LR
  A[Gateway worker request] --> B[Authorized six-tool policy]
  B --> C[Embedded worker runtime]
  C --> D[Core coding tool materializer]
  D --> E[Schema and hook finalization]
  E --> F[Model inference and local execution]
Loading

Before merge

  • Resolve merge risk (P1) - The refactor is source-plausible, but the supplied timing notes intentionally do not provide the scoped guide's before/after startup-seconds and RSS comparison, so the claimed import-startup improvement is not yet directly demonstrated.
Agent review details

Security

None.

PR surface

Source +112, Tests +2. Total +114 across 8 files.

View PR surface stats
Area Files Added Removed Net
Source 6 514 402 +112
Tests 2 6 4 +2
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 520 406 +114

Review metrics

Metric Value Why it matters
Production vs test delta production +514/-402 (net +112); tests +6/-4 (net +2) The positive production delta is justified by the shared ownership boundary, but its size makes the direct performance measurement useful before merge.

Stored data model

Persistent data-model change detected: durable storage schema: src/worker/embedded-agent.runtime.ts, unknown-data-model-change: src/worker/embedded-agent.runtime.ts, vector/embedding metadata: src/agents/agent-tools.finalize.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Land one shared materializer and finalizer while preserving the Gateway's six-tool authority, supported by an exact-head before/after startup or RSS/import measurement.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Land one shared materializer and finalizer while preserving the Gateway's six-tool authority, supported by an exact-head before/after startup or RSS/import measurement.

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

Not applicable: this PR is a startup-import refactor rather than a report of broken behavior; current worker integration tests cover the authorized tool surface and Gateway turn flow.

Is this the best way to solve the issue?

Yes, the shared materializer and finalizer are a better owner boundary than a worker-only copy because both generic agents and workers retain the same wrappers; the remaining gap is measurement of the intended performance outcome.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The PR is marked as maintainer work, so the external-contributor proof gate does not apply; the reported Gateway integration and exact-head CI remain useful supplemental validation.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: This is a bounded agent-runtime performance and maintainability improvement with limited user blast radius.
  • 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: The PR is marked as maintainer work, so the external-contributor proof gate does not apply; the reported Gateway integration and exact-head CI remain useful supplemental validation.

Evidence

What I checked:

  • Worker owner boundary: The proposed worker path builds the core file/shell tools, applies the shared finalization pipeline, and only supplies the Gateway-authorized names to the embedded session. (src/worker/embedded-agent.runtime.ts:130, 661dce3b5dc9)
  • Generic-path reuse: The generic tool factory calls the same extracted core materializer and shared finalizer, avoiding a worker-specific duplicate implementation. (src/agents/agent-tools.ts:557, 661dce3b5dc9)
  • Existing worker contract: Current-main worker integration coverage verifies the full six-tool surface, a restricted read/exec surface, and an empty authorized surface through the Gateway protocol seam. (src/worker/worker.runtime.test.ts:766, ce06e7924e88)
  • Exact-head validation: The supplied exact-head follow-up reports successful CI plus 159 focused cases, production typechecking, and a full build for 661dce3. (661dce3b5dc9)
  • Current-source provenance: Local shallow-history blame attributes the current worker and generic-factory anchor lines to the grafted baseline commit, so deeper ownership attribution remains low confidence. (src/worker/embedded-agent.runtime.ts:126, 47ce26985d40)

Likely related people:

  • Jason (Json): Local blame assigns the current worker and generic tool-factory anchors to the available grafted baseline; the checkout lacks deeper history for stronger attribution. (role: current source-line ancestor; confidence: low; commits: 47ce26985d40; files: src/worker/embedded-agent.runtime.ts, src/agents/agent-tools.ts)

Rank-up moves

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

  • Add an exact-head before/after startup-seconds and RSS or import-graph measurement, with the same worker scenario on both sides.

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-05T14:18:18.516Z sha 7fb9f26 :: needs real behavior proof before merge. :: none

@steipete

steipete commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

Exact-head follow-up proof for 661dce3b5dc9401649fafcf90f63036b68581cca:

  • CI run 31017405916 completed successfully: 79 checks passed, including check-prod-types, check-test-types, check-lint, check-dependencies, extension package boundaries, build artifacts, and all compact Node shards.
  • AWS Crabbox run run_5d694621081d ran the corrected focused surface. Terminal summary: 5 test files passed, 159 tests passed; this includes all 28 worker runtime integration cases, 118 generic tool-construction cases, and the 13 filesystem constructor/lazy-root cases that the prior CI run caught.
  • AWS Crabbox run run_592d9b6c8abb ran pnpm tsgo:prod; terminal result: exitCode: 0.
  • AWS Crabbox run run_523a08a4b914 ran the full build; terminal result: exitCode: 0, including CLI bootstrap imports, plugin SDK exports, runtime postbuild, and Control UI performance gates.
  • The two raw worker timings were 14.108s and 17.674s on separate AWS hosts. They are intentionally reported as host-variant context, not normalized proof or a 30% success claim.

The old-head exact-check failures and prior rank-up moves are therefore resolved. @clawsweeper re-review

@steipete

steipete commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 5, 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 repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added 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. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 5, 2026
@steipete

steipete commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Command router queued. I will update this comment with the next step.

@steipete
steipete merged commit 6edf4a2 into main Aug 5, 2026
140 checks passed
@steipete
steipete deleted the codex/test-perf-worker-core-tools branch August 5, 2026 15:42
@steipete

steipete commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 6, 2026
* perf(worker): narrow core tool imports

* fix(worker): preserve generic tool factories

---------

Co-authored-by: Peter Steinberger <[email protected]>
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. 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