Skip to content

refactor(gateway): schedule media maintenance with the kernel - #159126

Merged
steipete merged 1 commit into
mainfrom
hostneutral/scheduler-media-0926
Sep 26, 2026
Merged

steipete merged 1 commit into
mainfrom
hostneutral/scheduler-media-0926

Conversation

@steipete

@steipete steipete commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Delivery-queue media and general media cleanup maintain private timers and duplicate pending-work bookkeeping.

User Impact

Media cleanup keeps its existing hourly policy, independently schedules each cleanup owner, and joins running work on stop. A stuck prior generation still defers only media cleanup; the existing five-second stop watchdog and shared-state drain custody remain.

Why This Change Was Made

Register delivery-queue media, playback cache, managed outgoing media and general media cleanup as separate jobs. Remove the media interval, lazy-promise wrappers, delivery cleanup timestamp polling and duplicate in-flight/start promises. Existing queue/tombstone and attachment policies remain unchanged.

One scheduler instance per Gateway process, enforced by types. No private fallback or standalone scheduler constructor is introduced. Existing state, configuration, spools and ports remain unchanged on update. No storage, schema, config, SDK or RPC contract changes are required.

Production +49/−102/net −53; tests +32/−22/net +10; docs +0/−0/net 0. This slice depends on the periodic maintenance scheduler injection.

Evidence

Publication head bb5704274e6ce769ebb323bd07752784bde45af1. The reviewed media patch applies unchanged after periodic maintenance; newer main's first-hour worktree policy and its tests remain intact. Independent Codex P2 review, deslop, whitespace and caller closure passed.

Blacksmith-testbox lease tbx_01m3f70jxsg7e3036jppdwwv8j, run 36253776173: all three media files passed (45 cases, 36.508s command wall) on exact tree c2a5feaba852172869afdb88b440e2ff0dcd25c1, following the proven periodic composition.

Current-parent proof used blacksmith-testbox lease tbx_01m3fe5xws0vqv7gvgg8bg9q61, run 36261201574, frozen install and exact tree 116f5484fe92c41e16025484e8fbec4672b563d0. All 45 cases passed again, with source verified clean before and after. Each row is pnpm test <file> --maxWorkers=1:

File Cases Current-parent wall
src/gateway/server-maintenance.test.ts 30 26.98s
src/gateway/server-maintenance.delivery-queue.test.ts 3 8.51s
src/gateway/server-maintenance.telemetry.test.ts 12 4.09s

Sum: 39.58s. Prior periodic-phase measurements for these files were 21.396s, 8.086s and 3.536s; these command costs include setup and are not a performance comparison. Coverage retains hourly execution, TTL/default branches, independent cleanup, in-flight non-overlap, previous-generation custody and shutdown joins. No new sleeps or Gateway boots were added. Publication rebase preserves the reviewed patch. GitHub's enforced openclaw/ci-gate supplies changed-file validation; final merged-stack live proof follows the last slice.

CI checkpoint: exact-head run 36266641884 failed its core-test type lanes with TS2741: three newly landed cron fixtures omitted the required scheduler (ops-lifecycle.start-arm.test.ts, cron.history-publication.test.ts, cron.history.test.ts). The remaining red lanes were fail-fast cancellations. The fixture correction is now on main in c0e6951d6f02, with ancestry verified. This PR has not yet been rebased or rechecked after that fix. The stack is paused at the maintainer's reviewed-design boundary because a separate, unlanded session-delivery slice needs an elapsed-preemption contract correction. This existing auto-merge request remains armed; no passing current-head CI is claimed.

Scheduler stack

Earlier slices: diagnostic preparation #157517, auth factory naming #158275, kernel scheduler #158423, event-loop health #158531, channel health #158537, mention expiry #158614, upstream monitoring #158617, worker placement #158662, idle/prewarm #158666, Incognito expiry #158690, OAuth maintenance #158717, initial lifetime maintenance #158727, worker reconciliation #158812, PR subscriptions #158821, update checks #158909, Gmail renewal #158913, metadata capture maintenance #158959, and audit maintenance #158982.

This is the media cleanup slice after periodic maintenance #159111. Merged predecessors also include task #159038, generation #159042, post-ready #159047, approval #159081, cold storage #159088, outbound recovery #159096, cron due #159099, and foreign receipts #159114.

Remaining reviewed work includes diagnostic/SDK lifetimes, session delivery, update watchers and cron system-job retry. Final timer exceptions and the merged-main Gateway/cron/suspend/shutdown proof follow the last 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: M labels Sep 26, 2026
@steipete
steipete enabled auto-merge (squash) September 26, 2026 19:38
@steipete
steipete force-pushed the hostneutral/scheduler-media-0926 branch from bb57042 to bce298b Compare September 26, 2026 20:47
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. 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, 4:55 PM ET / 20:55 UTC.

ClawSweeper review

What this changes

Moves delivery-queue, playback-cache, managed-outgoing, and general media cleanup onto the Gateway kernel scheduler and updates maintenance tests.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⛔ Blocked before merge - 5 items remain

Keep open. Current main has not made this media lifecycle cutover, but the proposed patch lets a stuck cleanup block whole-Gateway shutdown beyond the existing five-second watchdog.

Priority: P2
Reviewed head: bce298b24e0821023e5e3bdc54287b42ae40d971

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The focused cutover has a source-proven shutdown blocker: its five-second media watchdog cannot bound the scheduler-wide join.
Proof confidence 🌊 off-meta tidepool Not applicable: Maintainer-authored proof is exempt from the external-contributor gate. The PR reports injected-clock maintenance tests, but no installed Gateway update and full shutdown observation; the separate repository lifecycle proof requirement remains outstanding. No stored-data contract changes.
Patch quality 🧂 unranked krab (1/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Maintainer-authored proof is exempt from the external-contributor gate. The PR reports injected-clock maintenance tests, but no installed Gateway update and full shutdown observation; the separate repository lifecycle proof requirement remains outstanding. No stored-data contract changes.
Evidence reviewed 10 items Current main still needs the cutover: The fetched main revision retains the private media interval and delivery-queue cleanup polling, so the central change is not already implemented.
Introduced scheduling trigger: The pinned merge-base-to-head patch places all four media callbacks in GatewayScheduler jobs; the verified test merge retains this change against its main parent.
Media stop watchdog: Media stop cancels the new jobs and waits through the existing five-second shared drain, which can return timed-out while cleanup remains pending.
Findings 1 actionable finding [P1] Preserve the five-second media shutdown bound
Security None None.

How this fits together

The Gateway starts maintenance after readiness and uses its kernel scheduler to wake cleanup work. Cleanup prunes queue and attachment media; shutdown must join or safely retain running work before shared state closes.

flowchart LR
  A[Gateway ready] --> B[Kernel scheduler]
  B --> C[Queue cleanup]
  B --> D[Playback and outgoing cleanup]
  B --> E[General media cleanup]
  C --> F[Media stores]
  D --> F
  E --> F
  G[Gateway shutdown] --> B
  B --> H[Cleanup drain]
Loading

Before merge

  • Preserve the five-second media shutdown bound (P1) - These registrations put running media cleanup in GatewayScheduler's global pending set. After stopMediaCleanup returns timed-out at five seconds, the Gateway close sequence still awaits the lifetime sidecar's scheduler.stop(), which waits for that same cleanup without a timeout. A stuck cleanup therefore prevents close and restart; add a full close-path regression and retain the bounded media drain handoff.
  • Resolve merge risk (P1) - A never-settling media cleanup remains in the scheduler-wide pending set after the five-second media drain times out, preventing Gateway close and restart from completing.
  • Resolve merge risk (P1) - The PR has no published-driver × candidate installed-update and shutdown observation for this lifecycle change; the reported focused tests do not cover that boundary.
  • Complete next step (P2) - Repair the scheduler/media shutdown handoff so a stuck cleanup cannot block Gateway close past five seconds, then provide installed-update and shutdown proof.
  • Improve patch quality - Prove a full Gateway close with a media cleanup pending beyond five seconds after repairing the join, then record a published-driver × candidate update and shutdown result.

Findings

  • [P1] Preserve the five-second media shutdown bound — src/gateway/server-maintenance.ts:303-307
Agent review details

Security

None.

PR surface

Source -53, Tests +10. Total -43 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 49 102 -53
Tests 2 32 22 +10
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 81 124 -43

Review metrics

Metric Value Why it matters
Independent cleanup schedules 4 media jobs Each job is now tracked by the scheduler-wide shutdown join, so one stuck cleanup can affect Gateway close.

Merge-risk options

Maintainer options:

  1. Restore bounded Gateway close (recommended)
    Keep scheduled wakeups, prevent pending media work from extending whole-Gateway close beyond the existing watchdog, and verify the repaired path on an installed update.
  2. Pause the media cutover
    Hold this slice until the scheduler and media drain owners have a safe handoff that preserves the existing shutdown bound.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Preserve the five-second media drain and cross-generation shared-state custody when a scheduled cleanup never settles. Add a regression through the full Gateway close path, preserve scheduler stop behavior for non-media jobs, and verify the installed-update shutdown path.

Technical review

Best possible solution:

Let the kernel scheduler own media wakeups while the existing cross-generation media drain owns bounded shutdown custody, retaining shared state until late cleanup settles.

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

Yes, by source: leave a scheduled media cleanup pending past five seconds, then close the Gateway; scheduler.stop still awaits that callback. This read-only review did not execute the scenario.

Is this the best way to solve the issue?

No. Central scheduling is a suitable wakeup owner, but the patch also moves running media work into an unbounded shutdown join; the bounded media drain must retain that custody.

Full review comments:

  • [P1] Preserve the five-second media shutdown bound — src/gateway/server-maintenance.ts:303-307
    These registrations put running media cleanup in GatewayScheduler's global pending set. After stopMediaCleanup returns timed-out at five seconds, the Gateway close sequence still awaits the lifetime sidecar's scheduler.stop(), which waits for that same cleanup without a timeout. A stuck cleanup therefore prevents close and restart; add a full close-path regression and retain the bounded media drain handoff.
    Confidence: 0.96

Overall correctness: patch is incorrect
Overall confidence: 0.95

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: The patch creates a bounded-trigger Gateway shutdown regression that needs repair before merge.
  • add merge-risk: 🚨 availability: A pending media callback can keep the scheduler's whole-Gateway shutdown join open after the media watchdog expires.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🌊 off-meta tidepool and patch quality is 🧂 unranked krab.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: Maintainer-authored proof is exempt from the external-contributor gate. The PR reports injected-clock maintenance tests, but no installed Gateway update and full shutdown observation; the separate repository lifecycle proof requirement remains outstanding. No stored-data contract changes.

Label justifications:

  • P2: The patch creates a bounded-trigger Gateway shutdown regression that needs repair before merge.
  • merge-risk: 🚨 availability: A pending media callback can keep the scheduler's whole-Gateway shutdown join open after the media watchdog expires.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🌊 off-meta tidepool and patch quality is 🧂 unranked krab.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: Maintainer-authored proof is exempt from the external-contributor gate. The PR reports injected-clock maintenance tests, but no installed Gateway update and full shutdown observation; the separate repository lifecycle proof requirement remains outstanding. No stored-data contract changes.

Evidence

Acceptance criteria:

  • [P1] pnpm test src/gateway/server-maintenance.test.ts --maxWorkers=1.
  • [P1] pnpm test src/gateway/server-maintenance.delivery-queue.test.ts --maxWorkers=1.
  • [P1] pnpm test src/gateway/server-shutdown.test.ts --maxWorkers=1.
  • [P1] git diff --check.

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)
  • he-yufeng: 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.

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. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: M status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant