Repository navigation
fix(gateway): avoid diagnostic heartbeat stalls - #158530
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed September 25, 2026, 11:21 PM ET / September 26, 2026, 03:21 UTC (Revision 4). ClawSweeper reviewWhat this changesThe 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 Review scores
Verification
How this fits togetherThe 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
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +131, Tests +128, Docs +6. Total +265 across 26 files. View PR surface stats
Review metrics
Technical reviewBest 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. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
History |
|
Merged via squash.
|
|
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. |
* 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
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.
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.mjswith 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, andsrc/logging/diagnostic-heartbeat-context.test.ts. The heartbeat file was then run alone after its fixture correction.Promise.withResolverscall 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.mjsattempt 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 ofloadCronJobsStoreSync, 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 --checkpassed. 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
undefinedreturn 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 synchronoussession.stalledreporting before recovery dispatch, verifiesstale_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.tsreferencesprojectHarnessTaskContentForPersistence); 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 returnedrollup=green,github_rollup=SUCCESS,github_pending=0, andGREEN. 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).