Skip to content

fix(tasks): finish maintenance before Gateway shutdown - #154308

Merged
steipete merged 3 commits into
mainfrom
codex/task-maintenance-drain-20260920
Sep 21, 2026
Merged

steipete merged 3 commits into
mainfrom
codex/task-maintenance-drain-20260920

Conversation

@steipete

@steipete steipete commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Scheduled task maintenance could continue after its Gateway shut down and affect a later runtime in the same process. Repeated startup could also leave a delayed sweep untracked.

User Impact

Shutdown cancels maintenance still waiting for admission and waits for admitted task and flow maintenance before retiring their runtime. The scheduler owns both timers and the complete operation. Existing schemas, retention, configuration, and update behavior are unchanged.

Why This Change Was Made

Clearing timers did not settle an already-started sweep. The existing Gateway shutdown step now awaits its complete task-then-flow operation, and test cleanup callers await the same boundary. An admission-only cancellation signal lets shutdown finish while the Gateway remains suspended; it does not cancel work that already started. Timer and completion ownership live together in a small scheduler module.

Evidence

  • A controlled real Gateway lifecycle failed before the original repair: a sweep held at its existing cleanup-import await survived close, then replaced the next fixture's four resident tasks with an empty snapshot. Applying the owner repair made both cases pass in 54.85 seconds, preserving all 14 original consumer assertions.
  • The original repair passed 235 affected cases across eight files, a normal E2E build, selected checks, and independent review. Those results cover the earlier published head, before this main integration and scheduler extraction.
  • The current suspension regression failed before admission cancellation and passed afterward. After scheduler extraction, all four scheduling cases and seven matching task-registry cases passed in 190.56 seconds including worker compilation. They cover pending admission, task and flow settlement, repeated stop/start, restart, and failure handling.
  • Both registered Gateway startup maintenance cases passed on the current worker compilation in 95.59 seconds, including the update-canary preservation path.
  • Fresh independent P0–P2 review found no actionable issues. The complete changed-code gate passed at 866f2437, including production and test typechecks, typed lint, all three dead-export scans, formatting, line budgets, schema and import-cycle guards. The fixed-main integration preserves every authored added/removed line; its two overlapping test files retain main’s changes. All 100 current Gateway close/startup and maintenance scheduling cases passed in 153.73 seconds. Formatting and whitespace checks passed. Hosted CI must qualify this successor before landing.

The controlled lifecycle establishes the defect and repair; it does not identify which callback caused earlier hosted CI task-list failures.

The earlier CI preflight failure came from a duplicate test inventory entry introduced on main. This successor includes the canonical main repair f76d38a4; it does not replay the old failed merge checkout.

@clawsweeper

clawsweeper Bot commented Sep 21, 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 commands Command implementations size: M maintainer Maintainer-authored PR labels Sep 21, 2026
@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 21, 2026
@clawsweeper

clawsweeper Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 21, 2026, 1:52 AM ET / 05:52 UTC (Revision 4).

ClawSweeper review

What this changes

The PR makes Gateway shutdown cancel queued maintenance, await active task and flow cleanup, and prevent repeated starts from leaving untracked timers.

Merge readiness

✅ Ready for maintainer review

The repair remains necessary: current main still stops timers without joining active maintenance. No actionable introduced defect was found.

Likely related people: Peter Steinberger (unverified routing candidate, low confidence).

Priority: P2
Reviewed head: 678759c000bebd9018bef1641b8e8060e9a9d7bd

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused lifecycle repair with meaningful regression coverage and no concrete correctness or security findings.
Proof confidence 🌊 off-meta tidepool Not applicable: The external-contributor proof gate does not apply to this MEMBER-authored repair. The captured body reports controlled Gateway shutdown/restart evidence and current scheduling checks; this reviewer verified their source correspondence without executing them.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The external-contributor proof gate does not apply to this MEMBER-authored repair. The captured body reports controlled Gateway shutdown/restart evidence and current scheduling checks; this reviewer verified their source correspondence without executing them.
Evidence reviewed 8 items Introduced changes: Reviewed the pinned base-to-head diff. Production changes are confined to the maintenance scheduler and its integration; remaining changes await cleanup or cover scheduling behavior.
Current main still needs the repair: Current main clears the interval and delayed timer, then resets sweepInProgress without awaiting the running operation. Repeated starts also create the delayed timer before checking whether scheduling already started.
Shutdown and admission contracts: The existing Gateway shutdown step awaits the maintenance hook before database retirement. The admission owner checks cancellation before admission and retains admitted work until completion, matching the scheduler's cancellation-and-drain behavior.
Findings None None.
Security None None.

How this fits together

Task maintenance periodically reconciles task records and cleans up completed flows. Gateway shutdown must settle that work before retiring the shared runtime and databases.

flowchart TD
  A[Gateway startup] --> B[Maintenance scheduler]
  B --> C[Work admission]
  C --> D[Task cleanup]
  D --> E[Flow cleanup]
  F[Gateway shutdown] --> B
  F --> G[Cancel queued work and await completion]
  E --> G
  G --> H[Retire runtime]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +34, Tests +167. Total +201 across 11 files.

View PR surface stats
Area Files Added Removed Net
Source 2 79 45 +34
Tests 9 192 25 +167
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 11 271 70 +201

Review metrics

Metric Value Why it matters
Production versus test growth production +34 net lines; tests and test support +167 net lines Production growth consolidates timer and completion ownership; regression coverage exercises the corresponding lifecycle boundaries.

Technical review

Best possible solution:

Keep timer ownership and operation completion together, with shutdown joining admitted cleanup before runtime retirement.

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

Yes, source establishes the failure path: hold scheduled cleanup across shutdown and current main returns without settling it. The body reports a controlled failing lifecycle, but this read-only review did not execute it.

Is this the best way to solve the issue?

Yes. The patch uses the existing admission cancellation contract and awaited shutdown hook while preserving cleanup order, retention rules, configuration, and update-canary behavior.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This is a bounded lifecycle repair preventing maintenance from surviving Gateway shutdown into a later runtime.
  • 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 external-contributor proof gate does not apply to this MEMBER-authored repair. The captured body reports controlled Gateway shutdown/restart evidence and current scheduling checks; this reviewer verified their source correspondence without executing them.

Evidence

What I checked:

  • Introduced changes: Reviewed the pinned base-to-head diff. Production changes are confined to the maintenance scheduler and its integration; remaining changes await cleanup or cover scheduling behavior. (src/tasks/task-registry-maintenance-scheduler.ts:13, 678759c000be)
  • Current main still needs the repair: Current main clears the interval and delayed timer, then resets sweepInProgress without awaiting the running operation. Repeated starts also create the delayed timer before checking whether scheduling already started. (src/tasks/task-registry.maintenance.ts:1097, 784a74bed115)
  • Shutdown and admission contracts: The existing Gateway shutdown step awaits the maintenance hook before database retirement. The admission owner checks cancellation before admission and retains admitted work until completion, matching the scheduler's cancellation-and-drain behavior. (src/gateway/server-close.ts:518, 678759c000be)
  • Focused regression coverage: The scheduling tests exercise cancellation while suspended, task-then-flow settlement, concurrent stops, repeated starts, restart, and failure handling using fake timers and controlled promises. Startup coverage retains the update-canary preservation case. (src/tasks/task-registry.maintenance-scheduling.test.ts:31, 678759c000be)
  • Captured behavioral evidence and review continuity: The supplied body reports a controlled Gateway lifecycle failure before the repair and preservation of the next runtime's tasks afterward, plus 100 passing close/startup/scheduling cases on the successor. These are author-reported results, not executions by this reviewer. The supplied completed review at this same head contains no findings; the scheduler, maintenance integration, and scheduling tests are unchanged from 866f243. (678759c000be)
  • Related CI work is distinct: The supplied context for fix(ci): deduplicate database worker test inventory #154429 concerns a duplicate worker-test inventory entry and explicitly distinguishes that failure from maintenance changes. It is closed unmerged and is not a replacement for this repair.

Likely related people:

  • Peter Steinberger: 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 (3 earlier review cycles)
  • reviewed 2026-09-21T02:42:55.919Z sha 0288366 :: needs changes before merge. :: none
  • reviewed 2026-09-21T04:34:06.975Z sha 866f243 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-21T05:45:45.154Z sha 678759c :: needs maintainer review before merge. :: none

@steipete
steipete marked this pull request as ready for review September 21, 2026 04:20
@steipete
steipete merged commit 5b3646d into main Sep 21, 2026
215 of 216 checks passed
@steipete
steipete deleted the codex/task-maintenance-drain-20260920 branch September 21, 2026 06:12
@steipete

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

commands Command implementations gateway Gateway runtime 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: 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