Skip to content

fix(gateway): avoid diagnostic heartbeat stalls - #158530

Merged
steipete merged 6 commits into
mainfrom
perf/l08-diagnostic-attention-workers-0925
Sep 26, 2026
Merged

steipete merged 6 commits into
mainfrom
perf/l08-diagnostic-attention-workers-0925

Conversation

@steipete

@steipete steipete commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes Gateway pauses when many long-running sessions reach a diagnostic attention tick, including when the selected log sink is disabled.

User Impact

Session classification and recovery proceed without waiting for optional transcript enrichment. Enabled diagnostic detail lines may arrive after the recovery outcome; they retain bounded context and exclude incognito replies. Gateway protocol, configuration, SQLite schemas, and recovery thresholds are unchanged.

Why This Change Was Made

The heartbeat synchronously read session metadata and transcript text before checking whether its debug/warning line could be emitted. Both attention and recovery now use one sink-gated logging owner. It returns at most 140 display characters through the existing read-only history worker, verifies the current session identity, and publishes while physical-source custody remains held. Cron names use the existing exact-name worker read, and stopping diagnostics retires pending publications.

Evidence

A regression through the registered heartbeat fails on the original implementation for both enabled and disabled sinks: it executes parent-thread SQLite queries. The candidate keeps those queries off the main thread while preserving recovery and the emitted context. Coverage also exercises visible-assistant selection, Unicode bounds, current/rotated identities, agent isolation, incognito privacy, and missing stores.

Heartbeat benchmark: 50 processing sessions, 22 KB synthetic latest replies, attention at 150 seconds, instrumented log sink. Median of three isolated processes per cell on a shared macOS/arm64 host with Node 26.9.0; warm cells warm the complete enrichment path. These are callback measurements, not a live Gateway latency guarantee.

Selected sink Enrichment path Before After
Disabled Cold 824.03 ms 1.99 ms
Disabled Warm 45.15 ms 1.26 ms
Enabled Cold 800.42 ms 35.09 ms
Enabled Warm 38.14 ms 10.37 ms

Measurements precede the final main merge; conflict resolution only combined imports and the F1 implementation is unchanged. All 50 enabled detail lines retained assistant context. Worker startup/completion occurs after the callback; host preparation still has a measurable cost under contention.

Focused validation used node scripts/run-vitest.mjs with these four files and --maxWorkers=1: src/logging/diagnostic-session-context.test.ts, src/logging/diagnostic-stuck-session-recovery.runtime.test.ts, src/logging/diagnostic.test.ts, and src/logging/diagnostic-heartbeat-context.test.ts. The heartbeat file was then run alone after its fixture correction.

  • 13 context, 52 recovery, and 90 diagnostic cases passed in the final four-file run (562.98 s total wall). Its new heartbeat case exposed maintenance scheduled by the fixture's asynchronous seed writes; switching fixture setup to the existing synchronous seed operation removed that unrelated work without weakening the SQL assertion.
  • The corrected heartbeat file passed all 3 cases standalone (846.84 s command wall; 407.91 s Vitest duration, 94% transformation). The enabled case retains its SQL spies through asynchronous log completion. The disabled and incognito cases each take about 6 ms.
  • Earlier isolated per-file wall costs: context 584.12 s, diagnostic 297.92 s, recovery 258.28 s. The lifecycle sibling's 3 cases also passed. Most local wall time is native-worker compilation, imports, and artifact verification on the shared host; no sleeps or polling were added. Real SQLite and the worker boundary are necessary to detect parent-thread queries; a mocked reader cannot prove that contract.
  • The prior local changed gate passed its guards and found a test-harness Promise.withResolvers call outside the core ES2023 type target. Tests now use the existing deferred helper; extracted tests also follow the required brace style.

The final main merge preserved incoming session-list and repeated-request recovery changes; both conflicts were imports. A follow-up diagnostic/recovery run compiled its worker artifacts in 338.44 s, then produced no test result for ten minutes. Sampling showed parent-runner filesystem rename waits with its child waiting for transform responses, so that attempt was stopped after 1,132.46 s total wall. Some recovery cases completed during termination, but no full suite verdict was produced. It is incomplete, not a test pass; the successful F1 proof above predates that merge. Hosted CI is running on the final head.

Changed-gate limitation: the required node scripts/check-changed.mjs attempt on Blacksmith Testbox never reached execution. Native sync timed out after 353 s; two repository-wrapper attempts then stalled locally preparing their source snapshot (Git init/update-ref/filesystem operations), including a retry under a separate scratch directory. The task-owned lease was stopped. This is not a passing changed gate; hosted CI remains authoritative. The earlier local gate passed formatting and structural guards, then exposed the test helper type issue corrected above. No local heavy check was restarted after the campaign moved heavy proof remote.

Remote environment: Blacksmith Testbox tbx_01m3dhn68mkrj54kt3q13kq6b0, hydration run. No build, broad suite, or live Gateway was run.

Production: +297 / -146 lines (net +151). Tests/support: +299 / -167 (net +132). Documentation: +6. The production growth implements the typed internal worker boundary, exact-source validation, and safe asynchronous publication; it reuses the existing pool and removes the old synchronous context path and duplicate formatters. Context tests share one suite fixture and assert emitted logs rather than retaining test-only production exports.

Deslop completed. Independent Codex review through P2 on the final merged head: scoped-clean, no accepted/actionable findings.

Landing CI repair

Exact-head CI run 36209768090 failed check-dependencies: moving diagnostic reads to the worker removed the final production caller of loadCronJobsStoreSync, leaving an unused export. The remaining cancellations were the workflow's fail-fast response to that failure; no run was retried just to obtain green.

The repair removes the retired synchronous mutable loader. Ordinary test reads use the existing asynchronous store API. Event-notification ordering, fingerprint query counts, and cold fixture seeding retain synchronous read-only kernel observations. Durable retirement remains covered through the production worker loader; four obsolete synchronous-only duplicate cases were removed. This correction is production -19 net lines and tests/support -17 net lines, with no schema, storage, or user-facing contract change.

Targeted formatting, lint, and git diff --check passed. The changed-check dry run selected core and core-test lanes. Hosted exact-head CI is the final runtime and dependency gate under the coordinator's landing order; the existing local host limitations above remain explicit.

Independent Codex review of the landing correction completed through P2 with no accepted/actionable findings.

The next exact-head run, 36211650715, exposed two lint errors in the diagnostic context owner and one stale test assumption. The lint correction removes a redundant spread and makes the disabled-path undefined return explicit. The question-recovery test had relied on a warning spy being called even when the log sink was disabled; sink gating now correctly skips that call, leaving its answer promise pending. The regression now settles the real question through synchronous session.stalled reporting before recovery dispatch, verifies stale_session_state, and checks that resumed work is not aborted. An immediate settlement assertion prevents a missing event from becoming an unresolved wait. The failing hosted shard passed 895 other cases; the original case consumed the 120-second timeout within its 204.28-second shard. No timeout, retry, or production recovery behavior was changed.

The two-file follow-up also passed formatting, core-targeted lint, whitespace checks, and independent Codex review through P2. A generic local lint invocation stopped in an unrelated plugin-SDK declaration prerequisite (agent-harness-task-runtime.ts references projectHarnessTaskContentForPersistence); the check-changed-owned core lint configuration passed without that prerequisite. No SDK code was changed. Runtime validation of this follow-up completed in the final exact-head hosted run below.

Final landing gate: exact-head hosted CI 36213154966 completed green for 5cb72ef9754084f6b8f938c3451e0f4b51420217; the repository watcher returned rollup=green, github_rollup=SUCCESS, github_pending=0, and GREEN. ClawSweeper completed its review on that same head with no actionable findings or before-merge blockers. The unrelated local SDK prerequisite typo above is already fixed on main by #158520 (5be36d37cb73).

@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 docs Improvements or additions to documentation size: L labels Sep 26, 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 26, 2026
@clawsweeper

clawsweeper Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 25, 2026, 11:21 PM ET / September 26, 2026, 03:21 UTC (Revision 4).

ClawSweeper review

What this changes

The Gateway’s periodic session check moves optional cron-name and transcript-text logging to sink-gated background readers, removes an unused synchronous cron-store loader, and updates tests and documentation.

Merge readiness

✅ Ready for maintainer review

Current main and the latest release still perform synchronous diagnostic enrichment. This PR remains a useful, distinct repair; the review found no actionable patch defect.

Priority: P2
Reviewed head: 5cb72ef9754084f6b8f938c3451e0f4b51420217

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Production-boundary measurements, focused regressions, and successful exact-head CI support a coherent repair with no discrete defect found.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The captured PR body reports before-and-after registered-heartbeat measurements using real SQLite and the production session reader across 50 synthetic sessions; disabled-sink callbacks improved and enabled lines retained assistant context. Exact-head hosted CI later passed. No stored-data contract changed.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The captured PR body reports before-and-after registered-heartbeat measurements using real SQLite and the production session reader across 50 synthetic sessions; disabled-sink callbacks improved and enabled lines retained assistant context. Exact-head hosted CI later passed. No stored-data contract changed.
Evidence reviewed 8 items Current main remains synchronous: The fetched main revision reads the cron store and session transcript while building diagnostic context before the log-sink decision.
Release comparison: The supplied latest release, v2026.9.6, also retains the synchronous diagnostic-context imports.
Introduced logging boundary: The pinned PR head checks process diagnostics and the selected log level before scheduling enrichment, then retires pending publications when diagnostics stop.
Findings None None.
Security None None.

How this fits together

The Gateway heartbeat examines running sessions and triggers attention events or recovery. Diagnostic logging adds optional cron names and bounded assistant text to operator log lines.

flowchart LR
A[Running sessions] --> B[Gateway heartbeat]
B --> C{Log sink enabled?}
B --> F[Attention events and recovery]
C -->|Yes| D[Cron name reader]
C -->|Yes| E[Session text worker]
D --> G[Diagnostic log]
E --> G
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +131, Tests +128, Docs +6. Total +265 across 26 files.

View PR surface stats
Area Files Added Removed Net
Source 12 298 167 +131
Tests 13 356 228 +128
Docs 1 6 0 +6
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 26 660 395 +265

Review metrics

Metric Value Why it matters
Production versus test growth production net +131; tests and support net +128 The PR explains the production growth as the typed worker boundary and asynchronous publication path.

Technical review

Best possible solution:

Keep attention and recovery independent of optional logging, with one worker-backed diagnostic path that verifies current session identity and excludes Incognito text.

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

Yes. Current main synchronously reads session and cron context from the heartbeat path before checking the log sink, and the PR reports a baseline failure through the registered heartbeat; this read-only review did not execute it.

Is this the best way to solve the issue?

Yes. Reusing the existing read worker and gating enrichment at the logging owner addresses the blocking path while retaining session-identity and Incognito checks.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

No label changes.

Label justifications:

  • P2: The PR addresses measured Gateway pauses during diagnostic-heavy sessions without evidence of a general runtime 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 (terminal): The captured PR body reports before-and-after registered-heartbeat measurements using real SQLite and the production session reader across 50 synthetic sessions; disabled-sink callbacks improved and enabled lines retained assistant context. Exact-head hosted CI later passed. No stored-data contract changed.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured PR body reports before-and-after registered-heartbeat measurements using real SQLite and the production session reader across 50 synthetic sessions; disabled-sink callbacks improved and enabled lines retained assistant context. Exact-head hosted CI later passed. No stored-data contract changed.

Evidence

What I checked:

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • obviyus: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • ZengWen-DT: 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-26T01:29:41.252Z sha 6ee949c :: blocked before merge. :: none
  • reviewed 2026-09-26T02:00:40.631Z sha 255ed58 :: blocked before merge. :: none
  • reviewed 2026-09-26T03:02:31.660Z sha 5cb72ef :: needs maintainer review before merge. :: none

@openclaw-barnacle openclaw-barnacle Bot added the gateway Gateway runtime label Sep 26, 2026
@steipete
steipete merged commit d3e2e58 into main Sep 26, 2026
215 checks passed
@steipete
steipete deleted the perf/l08-diagnostic-attention-workers-0925 branch September 26, 2026 03:28
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

@roboclaw-bot

Copy link
Copy Markdown
Collaborator

Coordination only for the already-authorized Team update: @steipete, please confirm the existing landing owner for this PR and return the final merge SHA when that owner lands it. Odin is holding a separate diagnostic patch to avoid duplicate publication; Odin owns collector PR #158618. Night Watch will not edit, rebase, rerun CI, or race the landing of this PR. Odin is comparing acceptance, including its explicit four-request cap/coalescing; reuse is not yet a claim of behavioral equivalence. No technical review or merge approval is asserted by this comment.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 26, 2026
* perf(logging): move diagnostic enrichment off the heartbeat tick

* test(logging): isolate heartbeat enrichment coverage

* test(logging): isolate diagnostic heartbeat fixtures

* fix(cron): retire unused synchronous store loader

* fix(logging): align recovery proof with async diagnostics
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation gateway Gateway runtime 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: XL 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.

2 participants