Skip to content

refactor(cron): retain the prepared watcher handoff owner - #130373

Merged
steipete merged 1 commit into
mainfrom
codex/loc-sweep-cron-handoff-20260826
Aug 26, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/loc-sweep-cron-handoff-20260826

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

The lazy Gateway cron proxy discarded its prepared watcher-handoff handle when stopping and prepared another wrapper through a boolean-preservation helper. An additional exposed stop hook duplicated work already owned by cron.stop. This made reload shutdown ownership harder to follow after #115761.

Why This Change Was Made

Retain the exact prepared handoff and join its memoized owner drain. Remove the redundant Gateway state hook, lazy forwarding method, and hot-reload duplicate call. Keep cron.stop as the synchronous cancellation owner and preserve awaited stream-watcher cleanup in the legacy/fake drain path.

Production LOC: +12/-33 (net -21). Tests: +118/-128 (net -10; primarily tabulating existing eager/lazy real-process coverage). No public API, config, protocol, database, dependency, watcher implementation, or process-supervisor changes. This is internal owner consolidation, not a newly claimed operator bug or changed handoff-retry guarantee.

User Impact

Watched cron commands retain their existing reload behavior: the replacement adopts watchers while the original owner drains. The same live child PID survives reload and is terminated when the final owner disables it.

Evidence

  • Exact candidate: c6e89818f5135c87d345548e1989399cdbc1848c.
  • The pending-start owner test fails before the change because handoff preparation occurs twice, and passes afterward. This proves the owner contract; the old real implementation only returned wrappers, so this is not presented as a new user-visible failure.
  • 412 owner/sibling tests pass, including actual OS child processes, the real supervisor, real cron service/SQLite store and reload handler. Both eager and lazy owners retain one PID, one spawn and one marker through reload, then terminate on disable.
  • Independent review caught a test fixture override leak; after restoring its factory in finally, all 226 reload-handler tests passed again. The independent verifier separately passed 29 lazy/drain tests and both real-process paths.
  • Full selected changed gate passed; fresh structured Codex P1 and separate exact-commit independent review passed.
  • This is real-process integration proof, not a fully booted Gateway or authenticated provider test.
OPENCLAW_VITEST_MAX_WORKERS=1 node scripts/run-vitest.mjs src/gateway/server-cron-lazy.test.ts src/gateway/server-cron.test.ts src/gateway/cron-exit-watchers.test.ts src/gateway/server-reload-handlers.test.ts src/gateway/server-request-context.test.ts src/gateway/server-reload-handlers.hot-reload-status.test.ts src/agents/mcp-connection-resolver.test.ts

Maintainer-requested, AI-assisted. Required exact-head hosted CI and native landing checks remain mandatory.

@clawsweeper

clawsweeper Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime agents Agent runtime and tooling size: M maintainer Maintainer-authored PR labels Aug 26, 2026
@steipete
steipete marked this pull request as ready for review August 26, 2026 20:23
@steipete

Copy link
Copy Markdown
Contributor Author

Exact-head landing verification: Retain the exact prepared lazy cron handoff and join its memoized drain; remove the redundant stopExitWatchers hook and duplicate hot-reload stop call. cron.stop remains the cancellation owner.

Production +12/-33 (−21); tests +118/-128 (−10). 412 owner/sibling tests, final226 handler rerun after fixture cleanup, independent29 lazy/drain tests and2 actual eager/lazy supervised-child cases pass. Real process PID/spawn/marker preservation and terminal disable were observed. Full changed gate, fresh P1 and exact-head independent review pass. Hosted CI is green for c6e8981.

Best-fix judgment: Keeping boolean preservation would reconstruct and discard handoff wrappers; removing the stream drain would break awaited legacy/fake drains. Retaining the exact handle removes duplication without changing cancellation timing.

Limitations: Internal behavior-preserving owner consolidation, not a newly demonstrated operator bug or new retry behavior. Real process integration does not claim a fully booted Gateway. Latest available ClawSweeper comment is a review-start placeholder, without an actionable rank-up list; independent final-source review is complete. No new config, dependency, protocol or database schema is introduced.

@steipete
steipete merged commit f378c6c into main Aug 26, 2026
269 checks passed
@steipete
steipete deleted the codex/loc-sweep-cron-handoff-20260826 branch August 26, 2026 21:00
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

@clawsweeper

clawsweeper Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 26, 2026, 4:30 PM ET / 20:30 UTC.

ClawSweeper review

What this changes

The PR makes lazy Gateway cron reload shutdown retain the prepared exit-watcher handoff, removes the duplicate watcher-stop hook, and extends eager/lazy real-process reload coverage.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

Keep open. Current main still uses the boolean-preservation path that can prepare a second handoff; this PR retains the exact prepared owner and removes the redundant stop hook. No blocking correctness defect was found, but the maintainer label and pending exact-head checks require normal maintainer handling.

Priority: P2
Reviewed head: c6e89818f5135c87d345548e1989399cdbc1848c

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused owner-boundary refactor with direct lazy-start coverage and retained real-process reload coverage.
Proof confidence 🌊 off-meta tidepool Not applicable: This MEMBER-authored PR is exempt from the external-contributor proof gate; its body nevertheless documents real supervised-process coverage for eager and lazy reload ownership.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This MEMBER-authored PR is exempt from the external-contributor proof gate; its body nevertheless documents real supervised-process coverage for eager and lazy reload ownership.
Evidence reviewed 6 items Current-main gap: Current main still records only a preservation boolean and, during shutdown, calls prepareExitWatcherHandoff again instead of retaining the original prepared handle.
Canonical owner handoff: The PR stores the first prepared handoff and memoizes that handoff's owner drain, including cancellation while lazy startup is in flight.
Reload caller and removed duplicate: The reload path adopts watchers before stopping the prior owner; its non-handoff branch already invokes cron.stop(), whose service implementation synchronously cancels exit watchers, making the removed direct hook redundant.
Findings None None.
Security None None.

Live Verification

Command: OPENCLAW_VITEST_MAX_WORKERS=1 pnpm test src/gateway/server-reload-handlers.test.ts --testNamePattern "keeps a supervised on-exit child alive exactly once across"

Result: FAIL (failed) — step 1 run OPENCLAW_VITEST_MAX_WORKERS=1 pnpm test src/gateway/server-reload-handlers.test.ts --testNamePattern "keeps a supervised on-exit child alive exactly once across": previous terminal command was still running after 30 seconds: "OPENCLAW_VITEST_MAX_WORKERS=1 pnpm test src/gateway/server-reload-handlers.test.ts --testNamePattern \"keeps a supervised on-exit child alive exactly once across\""

$ node --import tsx scripts/test-projects.mts src/gateway/server-reload-handlers.test.ts --testNamePattern 'keeps a supervised on-exit child alive exactly once
across'
[test] starting test/vitest/vitest.gateway.config.ts

 RUN  v4.1.11 /tmp/clawsweeper-live-proof-130373-mdJhYh/target

Assertions:

  • FAIL expect_output: keeps a supervised on-exit child alive exactly once across lazy cron reload
  • FAIL expect_output: Test Files

How this fits together

Gateway reload replaces the cron scheduler while watched child commands may still be running. The old scheduler hands its watchers to the replacement, then drains its own scheduling and stream resources without terminating adopted children.

flowchart LR
  A[Gateway configuration reload] --> B[Prepare watcher handoff]
  B --> C[Replacement cron scheduler]
  C --> D[Adopt active child watchers]
  B --> E[Original scheduler drain]
  E --> F[Stop streams and scheduling]
  D --> G[Watched command continues]
Loading

Before merge

  • Resolve merge risk (P1) - The branch is behind current main and hosted checks are still pending, so merge should use an updated exact-head CI result and retain the real-process reload coverage.
Agent review details

Security

None.

PR surface

Source -21, Tests -10. Total -31 across 8 files.

View PR surface stats
Area Files Added Removed Net
Source 3 12 33 -21
Tests 5 118 128 -10
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 130 161 -31

Review metrics

Metric Value Why it matters
Production versus test LOC production -21 (12 added, 33 removed); tests -10 (118 added, 128 removed) The owner-boundary refactor removes duplicate lifecycle code while broadening existing real-process coverage to both eager and lazy owners.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Land a rebased version that keeps one prepared watcher-handoff owner, preserves the eager/lazy real-process regression coverage, and passes exact-head Gateway checks.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Land a rebased version that keeps one prepared watcher-handoff owner, preserves the eager/lazy real-process regression coverage, and passes exact-head Gateway checks.

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

Not applicable as a reported user bug: this PR tightens an internal ownership invariant, and its body plus source tests define the relevant reload scenario.

Is this the best way to solve the issue?

Yes. Retaining the exact handoff at the lazy proxy is narrower and more maintainable than reacquiring a wrapper during shutdown, while deletion of the duplicate stop hook follows the existing cron.stop ownership boundary.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: This is a bounded Gateway reload-lifecycle hardening change for watched cron commands.
  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🌊 off-meta tidepool and patch quality is 🦞 diamond lobster.

Label justifications:

  • P2: This is a bounded Gateway reload-lifecycle hardening change for watched cron commands.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🌊 off-meta tidepool and patch quality is 🦞 diamond lobster.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Authored the current change and earlier merged lazy-owner and cron-shutdown refactors in this same path. (role: lazy cron ownership contributor; confidence: high; commits: c6e89818f513, 383363e36233, 74f3af9735c2; files: src/gateway/server-cron-lazy.ts, src/gateway/server-cron.ts, src/gateway/server-reload-hot.ts)
  • Marvinthebored: Recent history credits this contributor with restoring scheduler-owned Gateway context in the same lazy cron surface. (role: adjacent Gateway cron contributor; confidence: medium; commits: 9feb1db00d62; files: src/gateway/server-cron-lazy.ts)

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.

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

Labels

agents Agent runtime and tooling gateway Gateway runtime maintainer Maintainer-authored PR size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant