Repository navigation
improve: reduce scheduling work in busy worker pools - #139069
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed September 5, 2026, 8:19 AM ET / 12:19 UTC. ClawSweeper reviewWhat this changesThe 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 Review scores
Verification
How this fits togetherOpenClaw’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]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource 0. Total 0 across 1 file. View PR surface stats
Review metrics
Technical reviewBest 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. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Merged via squash.
|
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
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.Timeoutcreations 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.git diff --checkpassed. 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. NativeOPENCLAW_TESTBOX=1 scripts/pr prepare-run 139069verified these hosted gates; Testbox was not applicable.7428c4a5e850016e34336b382e345ef0017f71f4, containing all 20 batch changes and this exact worker-owner blob, passed a real OpenAI run onopenai/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.