Skip to content

fix(agents): avoid false subagent sweep failures during shutdown - #147904

Merged
obviyus merged 4 commits into
mainfrom
bugloop/sweeper-shutdown-tick
Sep 14, 2026
Merged

obviyus merged 4 commits into
mainfrom
bugloop/sweeper-shutdown-tick

Conversation

@obviyus

@obviyus obviyus commented Sep 14, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

A sweep due during Gateway shutdown reported a failure when restart drain correctly refused admission.

Why This Change Was Made

The sweeper cancels pending scheduling on stop. Drain refusals record skipped work and skip rearming while preserving recurring intent for restart. This state has one writer.

User Impact

Expected shutdown refusals no longer appear as sweep failures. Normal reconciliation and genuine error reporting remain intact.

Evidence

Real Gateway: pnpm openclaw gateway run --port <port>, then pnpm openclaw gateway stop --force --json while a service holds cleanup open.
Before: subagent run sweep failed: gateway is draining for restart.
After: subagent run sweep skipped: gateway is draining for restart.
pnpm openclaw gateway restart --json also passed and reached ready again. All CLI and Gateway exits were 0.

Compatibility

No config, schema, protocol, or public API change.

Consumers

Registry activation, recovery scheduling, and last-run cleanup retain one scheduler.

Invalidation

Stop clears the pending timer and rerun; restart activation restores the regular cadence.

Tests

34 registry lifecycle and recovery tests passed on the candidate and its merge with main. They exercise registration, last-row release, repeated activation, suspension, and overlapping timeout callbacks. Tests detect broken release/activation wiring and loss of periodic reconciliation after restart. Local preflight passed.

@clawsweeper

clawsweeper Bot commented Sep 14, 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: S maintainer Maintainer-authored PR labels Sep 14, 2026
@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 14, 2026
@clawsweeper

clawsweeper Bot commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 14, 2026, 5:38 AM ET / 09:38 UTC (Revision 3).

ClawSweeper review

What this changes

The PR cancels pending subagent maintenance sweeps when stopped, reports restart-drain refusals as skipped work, and adds lifecycle regression coverage.

Merge readiness

✅ Ready for maintainer review

The fix remains useful: current main and v2026.9.4 retain the false-failure path. The reviewed patch has no blocking correctness findings, and the supplied Gateway observations demonstrate the intended result.

Priority: P2
Reviewed head: ac76e73da13e31f64c01fc5703652540667c06d3

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused scheduler repair with relevant real Gateway observations, meaningful lifecycle coverage, and no blocking findings.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The captured PR body exercises the real Gateway stop path while cleanup remains open and shows the sweeper changing restart-drain output from failure to skipped work; restart then reaches ready. Registry lifecycle tests supplement that runtime observation.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The captured PR body exercises the real Gateway stop path while cleanup remains open and shows the sweeper changing restart-drain output from failure to skipped work; restart then reaches ready. Registry lifecycle tests supplement that runtime observation.
Evidence reviewed 9 items Introduced scheduler behavior: The pinned merge-base-to-head patch changes timer ownership, stop cancellation, and restart-drain handling. Normal errors remain reported, and admitted work retains its existing completion and admission-release path.
Current main still needs the fix: Current main only clears recurring intent on stop; its catch reports every admission rejection as a sweep failure and its finally block rearms recurring work.
Latest release comparison: The v2026.9.4 source also retains the uncancelled pending timer and unconditional failure logging/rearming. The requested behavior is not already supplied by that release.
Findings None None.
Security None None.

How this fits together

The subagent registry periodically reconciles interrupted runs and cleans up completed work. Its scheduler passes maintenance through Gateway work admission, which refuses new work during restart drain.

flowchart TD
  A[Registered subagent runs] --> B[Sweep scheduler]
  C[Registry activation or last-run release] --> B
  B --> D{Gateway admits work?}
  D -->|Yes| E[Reconcile and clean up runs]
  D -->|Restart drain| F[Record skipped sweep]
  E --> B
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +1, Tests +150. Total +151 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 23 22 +1
Tests 2 181 31 +150
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 204 53 +151

Review metrics

Metric Value Why it matters
Production versus test growth production +1 net line; tests +150 net lines Growth is concentrated in lifecycle regression coverage using existing registry entry points, without adding a production test seam.

Technical review

Best possible solution:

Keep scheduling in the existing sweeper, cancel pending work on stop, and preserve restart activation and genuine failure reporting.

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

Yes: a scheduled sweep encountering restart drain reaches unconditional failure logging on current main. The supplied real Gateway before/after output corroborates that path; this review did not execute it.

Is this the best way to solve the issue?

Yes: the patch repairs the existing scheduler and uses the established drain-error predicate while preserving admission, reconciliation, and activation behavior.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This is a bounded maintenance-scheduling and shutdown-diagnostic fix without evidence of an urgent user-facing outage.
  • 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 captured PR body exercises the real Gateway stop path while cleanup remains open and shows the sweeper changing restart-drain output from failure to skipped work; restart then reaches ready. Registry lifecycle tests supplement that runtime observation.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured PR body exercises the real Gateway stop path while cleanup remains open and shows the sweeper changing restart-drain output from failure to skipped work; restart then reaches ready. Registry lifecycle tests supplement that runtime observation.

Evidence

What I checked:

  • Introduced scheduler behavior: The pinned merge-base-to-head patch changes timer ownership, stop cancellation, and restart-drain handling. Normal errors remain reported, and admitted work retains its existing completion and admission-release path. (src/agents/subagents/registry/subagent-registry-sweeper.ts:110, ac76e73da13e)
  • Current main still needs the fix: Current main only clears recurring intent on stop; its catch reports every admission rejection as a sweep failure and its finally block rearms recurring work. (src/agents/subagents/registry/subagent-registry-sweeper.ts:109, ca513db612ba)
  • Latest release comparison: The v2026.9.4 source also retains the uncancelled pending timer and unconditional failure logging/rearming. The requested behavior is not already supplied by that release. (src/agents/subagents/registry/subagent-registry-sweeper.ts:115, 3a9d69db306c)
  • Restart activation preserves cadence: Registry activation schedules a sweep before the repeated-activation early return. Keeping recurring intent after a drain refusal therefore allows that activation sweep to restore the regular cadence. (src/agents/subagents/registry/subagent-registry-restore.ts:147, ac76e73da13e)
  • Meaningful lifecycle coverage: The new tests exercise real registry registration, last-row release, repeated activation, suspension followed by drain, overlapping timer callbacks, and admission settlement. The recovery suite separately checks that an ordinary exception remains a failure after drain starts. Tests were inspected, not executed in this read-only review. (src/agents/subagents/registry/subagent-registry-sweeper-lifecycle.test.ts:65, ac76e73da13e)
  • Supplied real Gateway proof: The captured PR body, sourceRevision 56fb957305cd819c9655ec0807ba4d71a62cbca16706b01cba04c3beb948773f, reports running the real Gateway and stopping it while cleanup remained open. Its copied before/after output changes the drain refusal from a sweep failure to skipped work; restart subsequently reached ready and CLI/Gateway exits were zero. This directly exercises the scheduler's changed admission-error handling. (ac76e73da13e)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • fuller-stack-dev: 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.

History

Review history (2 earlier review cycles)
  • reviewed 2026-09-14T04:53:41.194Z sha f86909b :: needs changes before merge. :: none
  • reviewed 2026-09-14T05:20:54.698Z sha cc8d9fb :: needs maintainer review before merge. :: none

@obviyus
obviyus marked this pull request as ready for review September 14, 2026 05:14
@obviyus

obviyus commented Sep 14, 2026

Copy link
Copy Markdown
Collaborator Author

landpr-approve-admin-merge
pr: 147904
head: cc8d9fb
scope: owner-review

@obviyus

obviyus commented Sep 14, 2026

Copy link
Copy Markdown
Collaborator Author

landpr-approve-unrelated-red
pr: 147904
head: cc8d9fb
run: 34808911417 attempt: 1
failed: control-ui-performance job=103866278585 conclusion=failure
check: openclaw/ci-gate

@obviyus

obviyus commented Sep 14, 2026

Copy link
Copy Markdown
Collaborator Author

landpr-approve-admin-merge
pr: 147904
head: ac76e73
scope: owner-review

@obviyus

obviyus commented Sep 14, 2026

Copy link
Copy Markdown
Collaborator Author

landpr-approve-unrelated-red
pr: 147904
head: ac76e73
run: 34827666808 attempt: 1
failed: checks-node-compact-small-19 job=103926382577 conclusion=failure
check: openclaw/ci-gate

@obviyus
obviyus merged commit f4ffd8c into main Sep 14, 2026
184 of 186 checks passed
@obviyus
obviyus deleted the bugloop/sweeper-shutdown-tick branch September 14, 2026 11:15
@obviyus

obviyus commented Sep 14, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks @obviyus!

Proof: A real Gateway stopped and restarted with a sweep due during drain. The sweep was recorded as skipped, and registry lifecycle tests passed.

  • Bug: Expected shutdown admission refusal appeared as a subagent sweep failure.
  • Fix: The sweeper cancels pending work on stop and skips drain refusals while preserving restart cadence.
Before After
Shutdown logged a sweep failure for its own drain refusal. Shutdown records skipped work; recurring sweeps resume after restart.

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

## What Problem This Solves

A sweep due during Gateway shutdown reported a failure when restart drain correctly refused admission.

## Why This Change Was Made

The sweeper cancels pending scheduling on stop. Drain refusals record skipped work and skip rearming while preserving recurring intent for restart. This state has one writer.

## User Impact

Expected shutdown refusals no longer appear as sweep failures. Normal reconciliation and genuine error reporting remain intact.

## Evidence

Real Gateway: `pnpm openclaw gateway run --port <port>`, then `pnpm openclaw gateway stop --force --json` while a service holds cleanup open.
Before: `subagent run sweep failed: gateway is draining for restart`.
After: `subagent run sweep skipped: gateway is draining for restart`.
`pnpm openclaw gateway restart --json` also passed and reached ready again. All CLI and Gateway exits were 0.

## Compatibility

No config, schema, protocol, or public API change.

## Consumers

Registry activation, recovery scheduling, and last-run cleanup retain one scheduler.

## Invalidation

Stop clears the pending timer and rerun; restart activation restores the regular cadence.

## Tests

34 registry lifecycle and recovery tests passed on the candidate and its merge with main. They exercise registration, last-row release, repeated activation, suspension, and overlapping timeout callbacks. Tests detect broken release/activation wiring and loss of periodic reconciliation after restart. Local preflight passed.

Co-authored-by: Ayaan Zaidi <[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. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M 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