Skip to content

refactor(gateway): schedule worker placement maintenance - #158662

Merged
steipete merged 1 commit into
mainfrom
hostneutral/scheduler-worker-placement-0925
Sep 26, 2026
Merged

steipete merged 1 commit into
mainfrom
hostneutral/scheduler-worker-placement-0925

Conversation

@steipete

@steipete steipete commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Worker placement uses a private recurring interval for reconciliation and disk sampling.

Change

Require the kernel scheduler and register reconciliation and disk sampling separately, preserving disk checks while reconciliation is stalled. Delete the host interval and its clearInterval plumbing. Existing startup recovery, event-driven reconciliation, idle reclaim and resource-drain ordering remain.

One scheduler instance per Gateway process, enforced by types. No private production constructor or standalone entry point is introduced.

Existing installs need no migration or operator action. Existing stores, configuration, ports, RPCs and public SDK contracts are unchanged. This timer-only slice adds no database access, schema or transaction boundary. Independent worker-thread lease heartbeats and per-operation timeouts remain unchanged.

Production: +35 / -25 / net +10. Tests/support: +99 / -25 / net +74. Docs: +0 / -0 / net 0. Required dependency/registration plumbing accounts for the growth; no unrelated cleanup offsets it.

Stack

  1. #157517 — diagnostic liveness preparation; merged.
  2. #158275 — internal auth factory naming; merged.
  3. #158423 — kernel scheduler and companion sweep; merged.
  4. #158531 — event-loop health; merged.
  5. #158537 — channel health; merged.
  6. #158614 — mention expiry; merged.
  7. #158617 — upstream monitoring; merged.
  8. Worker-placement maintenance — this slice.
  9. #158666 — idle work and prewarm; independent of this slice.
  10. Remaining reviewed migrations, obsolete-path removal and final documentation — pending.

Evidence

Current head 9eb2cc54be0b5969afa28ac055ccf3963c85e7b1 passed refreshed exact-head proof on blacksmith-testbox, lease tbx_01m3e2nta4ngefyyk0dsf55cr4, run 36220641511. Frozen dependency install, commit/tree/clean checkout, and unchanged source after testing were verified. All 10 files / 84 cases passed; summed per-file command wall 200.266s.

File Current-head wall
src/gateway/server-worker-placement-startup.test.ts 30.321s
src/gateway/server-worker-placement-session-events.test.ts 9.953s
src/gateway/server-worker-placement-recovery-events.test.ts 10.237s
src/gateway/server-worker-placement-startup-cleanup.test.ts 13.594s
src/gateway/server-worker-placement-startup-maintenance.test.ts 14.723s
src/gateway/server-worker-placement-provision-cancellation.test.ts 38.485s
src/gateway/server-worker-placement-resume.test.ts 16.645s
src/gateway/server-worker-placement-move-barrier.test.ts 10.829s
src/gateway/worker-workspace-recovery-binding.test.ts 31.899s
src/gateway/server.worker-placement-startup-context.test.ts 23.580s

The scheduler range-diff is identical. Intervening main changes to bundle retention and awaited turn release were inspected; existing shutdown joins remain intact.

The previous lease completed before an SSH refresh attempt, which ran no tests. It is verified stopped with no IP. Earlier baseline and review evidence follows.

blacksmith-testbox, lease tbx_01m3dnnvze1jmxvx1wa5ez2yb1, run 36208976081: isolated detached source rooted at fa7cedf4f2c10e042cb0e9927112b894d42f7b52, frozen install, owner baseline, then exact candidate patch/tree 87820961e996c9a2c0e30b8fa447300bdc828ede. Commit, clean baseline, patch bytes, full tree and unchanged source after testing were verified. Each file used pnpm test <file> --maxWorkers=1 after pnpm install --frozen-lockfile.

Candidate: 10 files / 84 cases passed; 192.706s summed command wall. Baseline owner files passed 24 cases. No performance improvement is claimed from sequential cold/warm order.

File Cases Candidate wall
src/gateway/server-worker-placement-startup.test.ts 8 23.717s
src/gateway/server-worker-placement-session-events.test.ts 1 10.226s
src/gateway/server-worker-placement-recovery-events.test.ts 15 11.581s
src/gateway/server-worker-placement-startup-cleanup.test.ts 4 14.049s
src/gateway/server-worker-placement-startup-maintenance.test.ts 7 14.610s
src/gateway/server-worker-placement-provision-cancellation.test.ts 26 35.624s
src/gateway/server-worker-placement-resume.test.ts 5 16.802s
src/gateway/server-worker-placement-move-barrier.test.ts 9 10.022s
src/gateway/worker-workspace-recovery-binding.test.ts 8 31.752s
src/gateway/server.worker-placement-startup-context.test.ts 1 24.323s

The first Codex pass raised a generic pending-job concern. Complete tracing showed reconciliation, recovery, disk, idle, retention and transcript-worker operations already joined before environment teardown; a second independent pass with that context was clean through P2. No speculative production join or mock-only regression was added. Deslop, cross-shard caller inspection, formatting and whitespace checks passed. The sparse full-index review tree and selected patch exactly matched full source before commit. Existing integration files retain their real lifecycle/storage contracts; no new per-test Gateway boot was added. Per-file hosted CI cost remains pending publication.

GitHub's enforced CI gate supplies changed-file validation. Final merged-main maintenance/cron/suspend/restart/shutdown live proof follows the last stack slice.

@clawsweeper

clawsweeper Bot commented Sep 26, 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 gateway Gateway runtime size: S labels Sep 26, 2026
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 26, 2026
@clawsweeper

clawsweeper Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 26, 2026, 1:24 AM ET / 05:24 UTC (Revision 2).

ClawSweeper review

What this changes

The branch replaces worker-placement's recurring interval with separate scheduler jobs for reconciliation and disk sampling, and updates the affected tests to use an injected clock.

Merge readiness

⛔ Blocked before merge - 2 items remain

Current main still uses the private worker-placement interval. This focused PR remains useful because it moves that work to the existing Gateway scheduler.

Priority: P3
Reviewed head: 9eb2cc54be0b5969afa28ac055ccf3963c85e7b1

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The scheduler cutover is focused and supported by substantial tests, while the required installed-update behavior remains unproven.
Proof confidence 🦐 gold shrimp (3/6) Not applicable: Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Real behavior proof is not required for maintainer- or bot-authored pull requests.
Evidence reviewed 9 items Introduced scheduler registration: The introduced patch replaces the private interval with separate recurring reconciliation and disk-space jobs.
Current main still uses the interval: Fetched main retains the worker-placement setInterval and clearInterval path, so the central change is not yet implemented there.
Existing scheduler contract: The shared scheduler tracks running jobs and coalesces missed recurring periods after a job settles.
Findings None None.
Security None None.

How this fits together

The Gateway starts worker-placement services for sessions running on cloud or device workers. Scheduled maintenance reconciles placements and checks disk health; shutdown must cancel and drain that work.

flowchart TD
  A[Gateway startup] --> B[Shared scheduler]
  B --> C[Reconcile placements]
  B --> D[Sample disk space]
  C --> E[Worker lifecycle]
  D --> F[Health warnings]
  G[Gateway shutdown] --> B
Loading

Before merge

  • Resolve merge risk (P1) - An update and restart from a published installation with an active worker placement has not been observed on this candidate. A lifecycle failure could delay maintenance or prevent Gateway shutdown from draining cleanly.
  • Complete next step (P2) - Provide the published-install-to-candidate update and restart result with an active worker placement before merge.
Agent review details

Security

None.

PR surface

Source +10, Tests +74. Total +84 across 11 files.

View PR surface stats
Area Files Added Removed Net
Source 2 35 25 +10
Tests 9 99 25 +74
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 11 134 50 +84

Review metrics

None.

Merge-risk options

Maintainer options:

  1. Prove the update and restart path (recommended)
    Capture an existing published installation updating into this candidate, restarting with an active worker placement, and completing maintenance and shutdown.

Technical review

Best possible solution:

Keep the shared scheduler as the timer owner and demonstrate a published-install-to-candidate update and restart with an active placement, including maintenance wakeups and shutdown.

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

Not applicable: this PR changes internal timer ownership rather than reporting an existing failure. The scheduling path is clear in source and the injected-clock tests.

Is this the best way to solve the issue?

Yes: reusing the kernel scheduler removes a competing timer owner while retaining separate disk sampling and reconciliation. The lifecycle upgrade path still needs observed proof.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

No label changes.

Label justifications:

  • P3: This is a focused internal maintenance refactor without a reported user-facing regression.
  • merge-risk: 🚨 availability: The introduced scheduler registrations change when worker maintenance runs and how it joins Gateway shutdown.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Real behavior proof is not required for maintainer- or bot-authored pull requests.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 362cee1 adds src/infra/gateway-scheduler.ts:43 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 362cee12114d; files: src/infra/gateway-scheduler.ts)

Rank-up moves

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

  • Capture the published-install-to-candidate update and restart result with an active worker placement; redact private endpoints, addresses, and credentials from the trace.

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-09-26T05:11:00.505Z sha 9eb2cc5 :: blocked before merge. :: none

@steipete
steipete merged commit b84e536 into main Sep 26, 2026
218 checks passed
@steipete
steipete deleted the hostneutral/scheduler-worker-placement-0925 branch September 26, 2026 05:44
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Sep 26, 2026
* commit '66b812f26e725cd709e08860d2cb46ba496cd308': (70 commits)
  fix(gateway): preserve typed boxed-number coercion
  chore(ui): refresh control ui locales (#158689)
  fix(gateway): reset staged headers on authority errors (#158669)
  fix(workers): keep inbound staging stable during quota scans
  fix: preserve Telegram delivery after bot identity changes (#158612)
  fix(ui): keep automation starter prompts out of startup (#158482)
  fix(cli): distinguish configuration read failures from invalid input (#158671)
  test: remove retired progress coercion suppression allowance
  refactor(gateway): schedule worker placement maintenance (#158662)
  fix(daemon): keep native service checks within their timeout (#154565)
  fix(test): restore gateway steering fixture contracts (#158478)
  fix(acpx): use SDK filesystem publication boundary
  fix(agentsapi): load OpenClaw persona and workspace context (#158328)
  fix(gateway): drop progress snapshot coercion suppression
  fix(qa): accept native Codex truncation in cache evidence (#158454)
  fix(gateway): keep chat subscriptions stable during unrelated approvals (#158633)
  perf(gateway): release event payloads from live text guards (#158643)
  perf(sessions): reduce stalls when saving large chat messages (#158402)
  fix(qa): reject history-bearing utility requests without session affinity (#158496)
  test: allow intentional progress snapshot coercion
  ...
vincentkoc added a commit that referenced this pull request Sep 26, 2026
* fix(test): verify followup completion ordering

Exercise the real presentation settlement helper with asynchronous cleanup, preserve continuation and admission semantics, and unconditionally release and join the held work. Remote proof covers the strengthened ordering contract and both missing-await faults.

* fix(test): verify followup completion ordering

* chore: retain followup test branch ancestry

The current-main reconstruction preserves the original reviewed scope and supersedes its stale base. Keep the remotely qualified candidate tree unchanged while retaining the original PR ancestry for a non-force branch update.

* commit 'ff35145de21cf6296bec05e86bee37b5ed53bcb8':
  fix(test): verify followup completion ordering

* test(auto-reply): signal queued presentation entry

* chore: refresh followup test on boundary fix

* commit '66b812f26e725cd709e08860d2cb46ba496cd308': (70 commits)
  fix(gateway): preserve typed boxed-number coercion
  chore(ui): refresh control ui locales (#158689)
  fix(gateway): reset staged headers on authority errors (#158669)
  fix(workers): keep inbound staging stable during quota scans
  fix: preserve Telegram delivery after bot identity changes (#158612)
  fix(ui): keep automation starter prompts out of startup (#158482)
  fix(cli): distinguish configuration read failures from invalid input (#158671)
  test: remove retired progress coercion suppression allowance
  refactor(gateway): schedule worker placement maintenance (#158662)
  fix(daemon): keep native service checks within their timeout (#154565)
  fix(test): restore gateway steering fixture contracts (#158478)
  fix(acpx): use SDK filesystem publication boundary
  fix(agentsapi): load OpenClaw persona and workspace context (#158328)
  fix(gateway): drop progress snapshot coercion suppression
  fix(qa): accept native Codex truncation in cache evidence (#158454)
  fix(gateway): keep chat subscriptions stable during unrelated approvals (#158633)
  perf(gateway): release event payloads from live text guards (#158643)
  perf(sessions): reduce stalls when saving large chat messages (#158402)
  fix(qa): reject history-bearing utility requests without session affinity (#158496)
  test: allow intentional progress snapshot coercion
  ...

Co-authored-by: Vincent Koc <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 27, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 27, 2026
* fix(test): verify followup completion ordering

Exercise the real presentation settlement helper with asynchronous cleanup, preserve continuation and admission semantics, and unconditionally release and join the held work. Remote proof covers the strengthened ordering contract and both missing-await faults.

* fix(test): verify followup completion ordering

* chore: retain followup test branch ancestry

The current-main reconstruction preserves the original reviewed scope and supersedes its stale base. Keep the remotely qualified candidate tree unchanged while retaining the original PR ancestry for a non-force branch update.

* commit 'ff35145de21cf6296bec05e86bee37b5ed53bcb8':
  fix(test): verify followup completion ordering

* test(auto-reply): signal queued presentation entry

* chore: refresh followup test on boundary fix

* commit '622be54be3ffe0fce27d6a4b147c76d4b19c528c': (70 commits)
  fix(gateway): preserve typed boxed-number coercion
  chore(ui): refresh control ui locales (openclaw#158689)
  fix(gateway): reset staged headers on authority errors (openclaw#158669)
  fix(workers): keep inbound staging stable during quota scans
  fix: preserve Telegram delivery after bot identity changes (openclaw#158612)
  fix(ui): keep automation starter prompts out of startup (openclaw#158482)
  fix(cli): distinguish configuration read failures from invalid input (openclaw#158671)
  test: remove retired progress coercion suppression allowance
  refactor(gateway): schedule worker placement maintenance (openclaw#158662)
  fix(daemon): keep native service checks within their timeout (openclaw#154565)
  fix(test): restore gateway steering fixture contracts (openclaw#158478)
  fix(acpx): use SDK filesystem publication boundary
  fix(agentsapi): load OpenClaw persona and workspace context (openclaw#158328)
  fix(gateway): drop progress snapshot coercion suppression
  fix(qa): accept native Codex truncation in cache evidence (openclaw#158454)
  fix(gateway): keep chat subscriptions stable during unrelated approvals (openclaw#158633)
  perf(gateway): release event payloads from live text guards (openclaw#158643)
  perf(sessions): reduce stalls when saving large chat messages (openclaw#158402)
  fix(qa): reject history-bearing utility requests without session affinity (openclaw#158496)
  test: allow intentional progress snapshot coercion
  ...

Co-authored-by: Vincent Koc <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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