Skip to content

refactor(logging): bind diagnostic scheduling to the runtime owner - #159389

Merged
steipete merged 3 commits into
mainfrom
hostneutral/scheduler-diagnostic-sdk-0926
Sep 27, 2026
Merged

steipete merged 3 commits into
mainfrom
hostneutral/scheduler-diagnostic-sdk-0926

Conversation

@steipete

@steipete steipete commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Diagnostic sampling and cleanup previously maintained a private interval outside Gateway shutdown and next-wake visibility.

Move the diagnostic heartbeat onto the required kernel scheduler. Bind the existing SDK resource host at Gateway startup and resolve public logging helpers through that host. CLI invocations explicitly create and stop their own lifetime scheduler. Public logging signatures remain unchanged.

The invariant is one scheduler instance per Gateway process: kernel composition supplies it, and required internal scheduler dependencies prevent silently creating private owners. Shipped SDK facades resolve the bound host; standalone entry points visibly own creation and stop.

Deleted: The interval and its private start/stop plumbing are removed; diagnostic test fixtures drive the shared injected clock.

User Impact and Update Behavior

Update behavior: Existing installs keep their config, state, ports, and diagnostic settings. Gateway diagnostics follow coordinated scheduler catch-up and shutdown; existing standalone SDK start/stop calls retain their own explicit lifetime. No storage schema, config key, RPC, or public SDK signature changes.

LOC: production +135/−45/net +90; tests +470/−93/net +377; docs +5/−0/net +5. These atomic constructor/caller closures include test migrations; growth is reported directly, without splitting off unused intermediate wiring.

Evidence

Historical focused proof used provider blacksmith-testbox across two leases: 21 files / 411 cases / 406.923 s on lease tbx_01m3fm57340p6ettpaa0raecst, run 36267294712, then four files / 50 cases / 87.386 s on lease tbx_01m3fqja9r983kwbphpb3v3g5g, run 36270738491. The total remains 25 passing file executions / 461 case executions / 494.309 s wall. The continuation reused the first lease's completed receipts; it did not rerun those 21 files. Every row used pnpm test <file> --maxWorkers=1 after frozen installation. These source-pinned results cover the reviewed composition, not a new remote run of the refreshed publication head. The four continuation files were src/plugin-sdk/provider-catalog-runtime.test.ts, src/mcp/plugin-tools-serve.test.ts, src/mcp/plugin-tools-registration.stdio.test.ts, and src/mcp/codex-supervision-tools-serve.test.ts; the other 21 rows below belong to the first lease.

Focused test cost and source identity
File Passed Wall Proof tree
extensions/telegram/src/webhook.test.ts 110 32.224 s a5c7951e7fae
src/agents/cli-runner/execute.background-work.test.ts 3 23.936 s a5c7951e7fae
src/agents/embedded-agent-runner/runs.liveness.test.ts 12 22.523 s a5c7951e7fae
src/cli/runtime-cleanup.test.ts 2 2.079 s a5c7951e7fae
src/gateway/server-methods/question.recovery.test.ts 29 27.241 s a5c7951e7fae
src/gateway/server.diagnostics-policy.test.ts 1 26.739 s a5c7951e7fae
src/gateway/worker-environments/worker-turn-run-owner.test.ts 5 27.781 s a5c7951e7fae
src/logging/diagnostic-gc.test.ts 1 17.570 s a5c7951e7fae
src/logging/diagnostic-heartbeat-context.test.ts 3 15.511 s a5c7951e7fae
src/logging/diagnostic-lifecycle.test.ts 4 14.497 s a5c7951e7fae
src/logging/diagnostic-stuck-session-exec-deadline.test.ts 3 19.691 s a5c7951e7fae
src/logging/diagnostic-stuck-session-followup-recovery.integration.test.ts 11 16.283 s a5c7951e7fae
src/logging/diagnostic-stuck-session-recovery.integration.test.ts 16 16.274 s a5c7951e7fae
src/logging/diagnostic.test.ts 90 15.483 s a5c7951e7fae
src/mcp/plugin-tools-registration.test.ts 8 20.323 s a5c7951e7fae
src/plugin-sdk/logging-core.test.ts 4 17.781 s a5c7951e7fae
src/cli/run-main.cleanup.test.ts 20 19.686 s a5c7951e7fae
src/cli/plugin-invocation-resources.owner.test.ts 11 18.016 s a5c7951e7fae
src/plugins/memory-runtime.test.ts 33 18.894 s a5c7951e7fae
src/plugins/registry.runtime-config.test.ts 26 18.138 s a5c7951e7fae
src/plugins/plugin-source-capture-directory.test.ts 19 16.253 s a5c7951e7fae
src/plugin-sdk/provider-catalog-runtime.test.ts 22 23.597 s a5c7951e7fae
src/mcp/plugin-tools-serve.test.ts 22 21.100 s a5c7951e7fae
src/mcp/plugin-tools-registration.stdio.test.ts 3 24.178 s a5c7951e7fae
src/mcp/codex-supervision-tools-serve.test.ts 3 18.511 s a5c7951e7fae

Current-composition refresh: provider blacksmith-testbox, lease tbx_01m3fz4ar9ygxxkxh5y2qjc40x, run 36278033418. Changed source remains byte-identical except preservation of main’s proxy-capture finalizer. Refreshed focused results:

File Passed Wall
src/plugins/plugin-source-capture-directory.test.ts 21 18.834 s
src/plugins/plugin-source-capture-recovery.test.ts 12 15.168 s
src/plugins/plugin-metadata-lifecycle.test.ts 13 14.280 s
src/cli/runtime-cleanup.test.ts 2 2.371 s
src/plugin-sdk/logging-core.test.ts 4 20.304 s
src/gateway/server.diagnostics-policy.test.ts 1 26.645 s

The same current composition passed full pnpm build (326.589 s), pnpm plugin-sdk:api:diff --base 0e27650f8e89afa47a839182e8018e5fb9382ce3 --head e06a34e17bceaaca9f04c5af68f4a52f7f84defe (130.200 s), export/surface/import guards, scoped docs sanity, and the existing MCP UI fixture (2 cases, 64.325 s). The isolated import profiler covered 19 packaged SDK consumers (6.229 s) plus three source-only QA consumers (0.918 s). The initial profiler command incorrectly selected private, non-packaged qa-lab and was rejected before import; the corrected routes preserve coverage. All source was verified, and no suite/build ran locally.

SDK API acknowledgement: digest 5e457d84 reports 125 affected exports (124 reachable, one signature-text change), with no added or removed entrypoints. startDiagnosticHeartbeat keeps the same optional config/options types through Parameters<...>[1]/[2]; its internal scheduler parameter is not part of the public call. Public createAuthRateLimiter retains its name, parameters and return contract; its declaration now belongs to the wrapper instead of the aliased internal constructor. The remaining reachable diff adds readonly to three synthesized reason?: undefined fields in recovery unions whose source is byte-identical. This is a nonempty declaration/reachability diff, with no public contract migration required.

Deslop and independent Codex review completed with no accepted/actionable findings. Rejected hypothetical findings retain source-backed dispositions. Required GitHub openclaw/ci-gate validates the exact published head; final Gateway/cron/SIGSTOP/SIGCONT/restart/SIGTERM proof follows the final stack slice.

Stack

Earlier slices include kernel scheduler #158423, session delivery #159275, update watcher #159291, and update campaign #159306. The independent MCP fixture preparation #159372 is being landed alongside this slice. Remaining sequence: diagnostic/CLI/SDK lifetime → auth pruning → MCP fixture preparation → CLI settlement → MCP scheduler cutover → final timer census and docs. Earlier full stack links appear in predecessor PRs.

Merged scheduler slices

Late caller: main added a foreground-Agent backend liveness case after the initial preparation. Its required constructor dependency now uses the shared manual scheduler clock, with ordinary 30-second heartbeat advances preserving the existing 14-minute + 14-minute + 1-minute scenario and every assertion. A single large advance would instead simulate sleep and correctly discount scheduler lateness. This was corrected from source inspection before any test executed. The complete owner-context delta passed fresh Codex review through P2. Remote proof: provider blacksmith-testbox, lease tbx_01m3ge5z33tbzfkv8jyx0v6y0a, run 36291231330. After frozen install (9.245 s), pnpm test src/logging/diagnostic-backend-liveness.test.ts --maxWorkers=1 passed all 13 cases in 20.843 s, on exact tree 232976c209eb2455b3c1a26f579b7f2921a001d1. Source guards passed and the private proof checkout was removed.

Previous publication head 5f49a4323f800e1937d91f676e86b06febe3b7d4, base c5b1eee718431609d13ab14633ea60a44c102c5f. The rebase preserves main’s node-runtime destructuring cleanup; scheduler changes and test assertions are unchanged.

CI correction: run 36292134084 stopped at the assertion-safety ratchet because the new global singleton identity read lacked its required SAFETY invariant. The value remains unknown and is compared only by identity. A one-line comment documents that existing invariant; no runtime expression, test assertion or baseline allowance changed. Fresh Codex P2 review of the correction is scoped-clean. Remote proof on blacksmith-testbox, lease tbx_01m3ge5z33tbzfkv8jyx0v6y0a, run 36291231330: pnpm check:assertion-safety --base c5b1eee718431609d13ab14633ea60a44c102c5f failed the original published source with exactly legacy-sdk-resource-host.ts: 1 > 0 (20.394 s), then passed after only the comment (21.311 s). The target file hash and unchanged baseline/runtime expressions were verified.

Corrected publication head a1ad9fa57a6eb983159acfd02b3a6dcf0612a004 is rebased onto main 4c3181e2386c2317e2525471ec22ab2fc2d70dca. The only new source delta after the focused proof is the verified comment-only assertion annotation. Exact-head CI remains the merge gate.

@clawsweeper

clawsweeper Bot commented Sep 27, 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 docs Improvements or additions to documentation channel: telegram Channel integration: telegram gateway Gateway runtime cli CLI command changes agents Agent runtime and tooling size: L labels Sep 27, 2026
@steipete
steipete enabled auto-merge (squash) September 27, 2026 03:56
@steipete
steipete force-pushed the hostneutral/scheduler-diagnostic-sdk-0926 branch from 5f49a43 to a1ad9fa Compare September 27, 2026 05:03
@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. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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 27, 2026
@clawsweeper

clawsweeper Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

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

ClawSweeper review

What this changes

The branch moves diagnostic heartbeats to the Gateway scheduler, binds public logging helpers to their runtime owner, and gives CLI and MCP services explicit scheduler lifetimes.

Merge readiness

⛔ Blocked before merge - 3 items remain

Keep open: current main still runs diagnostics on a private interval, and the merged scheduler groundwork does not include this lifetime cutover.

Priority: P3
Reviewed head: a1ad9fa57a6eb983159acfd02b3a6dcf0612a004

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The owner-level refactor and focused tests are coherent, but the required upgrade and Gateway lifecycle observation is still missing.
Proof confidence 🦐 gold shrimp (3/6) Not applicable: The repository state identifies a member-authored internal refactor, so the external-contributor proof gate does not apply. Source-pinned injected-clock tests cover scheduler wiring, while the separate required published-updater and real Gateway lifecycle trace remains outstanding; no stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The repository state identifies a member-authored internal refactor, so the external-contributor proof gate does not apply. Source-pinned injected-clock tests cover scheduler wiring, while the separate required published-updater and real Gateway lifecycle trace remains outstanding; no stored-data contract changes.
Evidence reviewed 8 items Current main retains the private timer: The fetched main revision still declares and starts the diagnostic heartbeat interval, so the central change is absent from main.
Introduced scheduling path: The proposed heartbeat registers a recurring job with the supplied scheduler and cancels it when that scheduler aborts.
SDK and CLI lifetime paths: The public logging facade selects a bound host scheduler or a standalone scheduler; CLI cleanup stops and joins scheduled work before dependent resources.
Findings None None.
Security None None.

How this fits together

The Gateway kernel schedules server background work; its diagnostic heartbeat samples activity and emits stability events and recovery requests. CLI and MCP processes can use the same logging API through their own runtime lifetimes.

flowchart LR
A[Gateway startup] --> B[Kernel scheduler]
C[CLI or MCP entry] --> D[Resource host]
B --> D
D --> E[Diagnostic heartbeat]
E --> F[Events and recovery]
B --> G[Wake and shutdown tracking]
Loading

Before merge

  • Resolve merge risk (P1) - A published updater has not been shown taking an existing installation into this candidate's Gateway and SDK lifetime arrangement.
  • Resolve merge risk (P1) - A real Gateway suspend, restart, and shutdown trace has not shown that diagnostic heartbeats resume and scheduled work closes cleanly.
  • Complete next step (P2) - Provide a published-driver × candidate update trace and a Gateway suspend, restart, and shutdown run showing heartbeat recovery and clean close before merge.
Agent review details

Security

None.

PR surface

Source +90, Tests +377, Docs +5. Total +472 across 28 files.

View PR surface stats
Area Files Added Removed Net
Source 9 135 45 +90
Tests 18 470 93 +377
Docs 1 5 0 +5
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 28 610 138 +472

Review metrics

None.

Merge-risk options

Maintainer options:

  1. Prove upgrade and lifecycle behavior (recommended)
    Capture a published-driver update into this candidate and a Gateway suspend, restart, and shutdown run showing resumed heartbeats and clean close.

Technical review

Best possible solution:

Keep diagnostics on the kernel-owned scheduler with the public logging API intact, backed by a published-driver update and Gateway lifecycle trace.

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

Not applicable as a bug reproduction: current main's private interval and the proposed scheduler path are visible in source, but this PR addresses internal ownership.

Is this the best way to solve the issue?

Yes in principle: the existing kernel scheduler is the right owner, and explicit standalone lifetimes preserve the public logging calls. Upgrade and lifecycle behavior still needs direct proof.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

No label changes.

Label justifications:

  • P3: This is an internal scheduling refactor with no demonstrated current user-facing regression.
  • merge-risk: 🚨 compatibility: The PR changes how existing Gateway, CLI, MCP, and public SDK logging calls acquire scheduler lifetime ownership during upgrades.
  • merge-risk: 🚨 availability: Heartbeat continuity and scheduled-work shutdown after a real suspend or restart remain unobserved.
  • 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: The repository state identifies a member-authored internal refactor, so the external-contributor proof gate does not apply. Source-pinned injected-clock tests cover scheduler wiring, while the separate required published-updater and real Gateway lifecycle trace remains outstanding; no stored-data contract changes.

Evidence

What I checked:

  • Current main retains the private timer: The fetched main revision still declares and starts the diagnostic heartbeat interval, so the central change is absent from main. (src/logging/diagnostic.ts:831, ad3103420e40)
  • Introduced scheduling path: The proposed heartbeat registers a recurring job with the supplied scheduler and cancels it when that scheduler aborts. (src/logging/diagnostic.ts:1018, a1ad9fa57a6e)
  • SDK and CLI lifetime paths: The public logging facade selects a bound host scheduler or a standalone scheduler; CLI cleanup stops and joins scheduled work before dependent resources. (src/plugin-sdk/logging-core.ts:14, a1ad9fa57a6e)
  • CLI settlement behavior: The new CLI cleanup path waits for scheduler settlement before running the later resource finalizers. (src/cli/runtime-cleanup.ts:52, a1ad9fa57a6e)
  • Focused lifecycle coverage: Injected-clock tests cover bound and standalone SDK calls, restart, coalesced heartbeats, and CLI cleanup ordering. The PR body reports source-pinned remote test and build results. (src/plugin-sdk/logging-core.test.ts:25, a1ad9fa57a6e)
  • Prior review and remaining proof: The previous ClawSweeper review examined this same head, recorded no findings, and requested a published-driver update trace. The PR body says the full Gateway suspend, restart, and shutdown proof follows the final stack slice; it does not supply that trace for this candidate. (a1ad9fa57a6e)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

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

  • Attach a published-driver × candidate update trace showing resumed diagnostics and clean Gateway close after restart.

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-27T05:11:23.246Z sha a1ad9fa :: blocked before merge. :: none

@steipete
steipete merged commit 0ef4357 into main Sep 27, 2026
208 checks passed
@steipete
steipete deleted the hostneutral/scheduler-diagnostic-sdk-0926 branch September 27, 2026 05:21
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 28, 2026
…penclaw#159389)

* refactor(logging): bind diagnostic scheduling to the runtime owner

* test(logging): drive backend liveness with the shared scheduler clock
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling channel: telegram Channel integration: telegram cli CLI command changes docs Improvements or additions to documentation gateway Gateway runtime merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: L 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