Skip to content

improve: reduce scheduling work in busy worker pools - #139069

Merged
steipete merged 1 commit into
mainfrom
codex/perf10-worker-handoff
Sep 5, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/perf10-worker-handoff

Conversation

@steipete

@steipete steipete commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Busy worker pools repeatedly allocate idle timers between consecutive queued tasks and scan the backlog after completed tasks have already left it. This adds avoidable scheduling work to Code Mode, compaction planning, and other pooled worker workloads. This is a maintainer-requested performance improvement.

Why This Change Was Made

Keep queue removal with dispatch, queued cancellation, and close. A completing worker now enters its existing idle lifecycle only when no queued task is waiting, preserving the worker reference during immediate handoff. Cancellation, worker retirement, input release, and result validation retain their existing owners.

User Impact

Queued work uses fewer short-lived timers while preserving FIFO settlement, cancellation, and idle process exit. No configuration or protocol changes. Production LOC: +5/-5 (net 0); no test-source changes.

Evidence

  • Before and after: 61 tests passed using OPENCLAW_VITEST_MAX_WORKERS=1 node scripts/run-vitest.mjs src/infra/worker-task-pool.test.ts src/agents/code-mode-worker-lifecycle.test.ts src/agents/compaction-planning-worker.test.ts. These exercise real worker threads, queued cancellation, asynchronous preparation, retirement, input transfer/release, and headless process exit.
  • Five independent pools per arm, each draining 5,001 tasks through one warm real worker: exact FIFO and worker reuse passed; parent Timeout creations fell from 5,001 to 1 in every sample. Mean wall time was 99.63 → 78.63 ms and process CPU 107.01 → 86.85 ms. Timings are descriptive sequential measurements on a shared host with instrumentation, not a whole-Gateway or retained-memory claim.
  • Formatting and git diff --check passed. The changed-check plan selected core/coreTests; the broad local check was interrupted and is not claimed as passing. Required exact-head CI 33965398157 and Workflow Sanity 33965345848 passed. Native OPENCLAW_TESTBOX=1 scripts/pr prepare-run 139069 verified these hosted gates; Testbox was not applicable.
  • Managed independent P2 autoreview: scoped-clean, no actionable findings. The committed source is checked against the frozen reviewed bytes.
  • Compiled integration candidate 7428c4a5e850016e34336b382e345ef0017f71f4, containing all 20 batch changes and this exact worker-owner blob, passed a real OpenAI run on openai/gpt-5.6-luna: 10 outer turns, 14 stages and 50 phases across Code Mode and tool-search profiles. Run B1 completed with stable identities, clean unforced shutdown, all 69 owned process identities absent, and both listeners/private runtimes cleared. The publisher verified the worker source is byte-identical to this PR. Verification identity SHA-256: 3e949e2dd485ab1da7ad1faeb707b9b7ff33062906e2af8b6fc7a9ff0343594c. This proves compiled batch behavior, not isolated attribution or a final aggregate performance improvement; remaining controlled measurement arms are still running.

@clawsweeper

clawsweeper Bot commented Sep 5, 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 size: XS maintainer Maintainer-authored PR labels Sep 5, 2026
@steipete
steipete marked this pull request as ready for review September 5, 2026 12:12
@clawsweeper clawsweeper Bot added 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 Sep 5, 2026
@clawsweeper

clawsweeper Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 5, 2026, 8:19 AM ET / 12:19 UTC.

ClawSweeper review

What this changes

The PR reduces scheduling overhead in busy worker pools by avoiding redundant backlog scans and idle timers between queued tasks.

Merge readiness

✅ Ready for maintainer review

Keep open: the optimization remains absent from inspected current main, and the shared lifecycle change has no blocking correctness findings.

Priority: P2
Reviewed head: 6a88a8849791b8609c1c46dde0154af3cfb7025f

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, net-neutral optimization with relevant reported measurements, existing lifecycle coverage, and no blocking findings.
Proof confidence 🌊 off-meta tidepool Not applicable: The ordinary contributor-proof gate is exempt under the supplied MEMBER association. The captured body reports real-worker queue-drain measurements through the changed pool and supplemental lifecycle tests; no live Gateway result is claimed.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The ordinary contributor-proof gate is exempt under the supplied MEMBER association. The captured body reports real-worker queue-drain measurements through the changed pool and supplemental lifecycle tests; no live Gateway result is claimed.
Evidence reviewed 10 items Introduced change and merge ownership: The pinned introduced diff contains only the worker-pool optimization. Raw test-merge parents match the pinned base followed by the exact PR head, and its comparison against that base contains the same change.
Queue and lifecycle invariant: run enqueues before handling an already-aborted signal; dispatch removes the queue entry before assigning its slot; close drains the queue before settlement. Cancellation checks task.done first. Successful completion still validates results before dispatch, while active failures retain the retirement-before-settlement path.
Current-main necessity: Inspected current main still searches the queue in finish and unconditionally enters idle before dispatching queued successors; both targeted costs therefore remain.
Findings None None.
Security None None.

How this fits together

OpenClaw’s shared worker pool sends queued computation to reusable Node worker threads and returns results to callers such as Code Mode and compaction planning. It also owns cancellation, worker retirement, and idle process-exit behavior.

flowchart TD
  A[Code Mode and background jobs] --> B[Task queue]
  B --> C[Available worker]
  C --> D[Validate and settle result]
  D --> E{Queued work remains?}
  E -->|Yes| C
  E -->|No| F[Idle and release process reference]
  B --> G[Cancellation or pool close]
  G --> H[Reject task and retire active worker]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source 0. Total 0 across 1 file.

View PR surface stats
Area Files Added Removed Net
Source 1 5 5 0
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 1 5 5 0

Review metrics

Metric Value Why it matters
Production versus tests Production +5/-5 (net 0); tests unchanged The optimization rearranges existing lifecycle ownership without growing production code or adding another execution path.
Reported timer allocation 5,001 → 1 parent Timeouts in each of 5 samples The measurement directly targets busy-pool handoff overhead; it does not establish whole-Gateway performance.

Technical review

Best possible solution:

Keep scheduling optimization in the shared pool while preserving its existing cancellation, result-validation, and retirement boundaries.

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

Not applicable as a bug reproduction: this is a performance optimization; current source confirms the redundant work and the supplied benchmark reports its reduction.

Is this the best way to solve the issue?

Yes: the shared pool owns both queue membership and idle transitions, so changing that owner avoids duplicated caller-specific optimizations.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: A focused performance improvement benefits shared background workloads without evidence of an urgent user-facing failure.
  • 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 ordinary contributor-proof gate is exempt under the supplied MEMBER association. The captured body reports real-worker queue-drain measurements through the changed pool and supplemental lifecycle tests; no live Gateway result is claimed.

Label justifications:

  • P2: A focused performance improvement benefits shared background workloads without evidence of an urgent user-facing failure.
  • 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 ordinary contributor-proof gate is exempt under the supplied MEMBER association. The captured body reports real-worker queue-drain measurements through the changed pool and supplemental lifecycle tests; no live Gateway result is claimed.

Evidence

What I checked:

  • Introduced change and merge ownership: The pinned introduced diff contains only the worker-pool optimization. Raw test-merge parents match the pinned base followed by the exact PR head, and its comparison against that base contains the same change. (src/infra/worker-task-pool.ts:201, a0cd877d8041)
  • Queue and lifecycle invariant: run enqueues before handling an already-aborted signal; dispatch removes the queue entry before assigning its slot; close drains the queue before settlement. Cancellation checks task.done first. Successful completion still validates results before dispatch, while active failures retain the retirement-before-settlement path. (src/infra/worker-task-pool.ts:193, 6a88a8849791)
  • Current-main necessity: Inspected current main still searches the queue in finish and unconditionally enters idle before dispatching queued successors; both targeted costs therefore remain. (src/infra/worker-task-pool.ts:225, 140eb569a0b8)
  • Caller and sibling coverage: Read Code Mode, compaction, model-catalog preparation, auth warmup, session-context reads, disk accounting, and plugin history consumers. Their queue admission uses the shared pool; lifecycle-bound catalog validation still runs before successor dispatch. No caller-specific scheduling implementation is needed. (src/agents/prepared-model-catalog-worker.ts:247, 6a88a8849791)
  • Existing behavioral tests: Read the pool tests and fixtures plus Code Mode lifecycle and compaction tests. Coverage includes bounded worker reuse, queued expiry, cancelled preparation, termination before replacement, rejected-generation fencing, idle retirement, buffer transfer, and headless process exit. Tests were inspected, not executed during this read-only review. (src/infra/worker-task-pool.test.ts:117, 6a88a8849791)
  • Captured performance evidence: The supplied PR body reports five real-worker pools per arm, each draining 5,001 tasks: FIFO and reuse passed, and parent Timeout creations fell from 5,001 to 1 in every sample. It also reports 61 passing tests before and after. The author explicitly limits timing claims to instrumented shared-host measurements and does not claim a live Gateway run. (6a88a8849791)

Likely related people:

  • steipete: 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.

@steipete
steipete merged commit 44db57b into main Sep 5, 2026
251 checks passed
@steipete
steipete deleted the codex/perf10-worker-handoff branch September 5, 2026 13:31
@steipete

steipete commented Sep 5, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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: XS 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