Repository navigation
fix(cron): emit message.queued/processed for isolated-agent turns - #79214
Conversation
|
Codex review: needs maintainer review before merge. Reviewed May 25, 2026, 1:15 PM ET / 17:15 UTC. Summary PR surface: Source +48, Tests +184, Docs +1. Total +233 across 3 files. Reproducibility: yes. from source inspection: current main's isolated cron path prepares and executes a real agent turn without the diagnostic lifecycle calls already used by dispatch and embedded-runner paths. I did not run the runtime in this read-only review, but the missing call path is directly visible. Review metrics: none identified. Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Next step before merge Security Review detailsBest possible solution: Land this PR after maintainer review and CI if maintainers agree isolated-cron turns should share the existing diagnostic lifecycle contract; track heartbeat-runner parity separately if needed. Do we have a high-confidence way to reproduce the issue? Yes from source inspection: current main's isolated cron path prepares and executes a real agent turn without the diagnostic lifecycle calls already used by dispatch and embedded-runner paths. I did not run the runtime in this read-only review, but the missing call path is directly visible. Is this the best way to solve the issue? Yes; reusing the existing diagnostic helpers and gating them through AGENTS.md: found and applied where relevant. Codex review notes: model gpt-5.5, reasoning high; reviewed against 5ae91f01fa33. Label changesLabel justifications:
Evidence reviewedPR surface: Source +48, Tests +184, Docs +1. Total +233 across 3 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
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. How this review workflow works
|
|
Thanks @clawsweeper. All three findings addressed in 275f1bb430:
Also added a focused regression test at Live verification (redacted bridge subscriber output) added to the PR body. Acceptance criteria status:
@clawsweeper re-review. |
21e24aa to
0170cd9
Compare
0170cd9 to
3690afc
Compare
6ede7c3 to
c99d162
Compare
c99d162 to
f792455
Compare
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Thanks @clawsweeper. Gating fix landed in 9e802930e7:
@clawsweeper re-review. |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
9e80293 to
1af5584
Compare
1af5584 to
ac85a4b
Compare
b5e283d to
289238a
Compare
289238a to
734264b
Compare
734264b to
9328a27
Compare
…sion.state lifecycle, add regression test + changelog
Address clawsweeper P2: cron isolated-agent lifecycle (message.queued, session.state, message.processed) now mirrors the dispatch path and respects the diagnostics.enabled master toggle. Added regression test for the disabled-config path. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
9328a27 to
dbbeb7b
Compare
|
Verification before landing:
Thanks @arniesaha! |
Summary
The diagnostic-event seam for
message.queued/session.state/message.processedis currently emitted only by channel-driven dispatch (src/auto-reply/reply/dispatch-from-config.ts:417) and the embedded runner (src/agents/pi-embedded-runner/runs.ts:75,89). The isolated-cron agent path (src/cron/isolated-agent/run.ts) executes full agent turns including LLM calls, but never emits these events. Anything subscribed to the diagnostic-events bus for per-session attribution silently drops 100% of cron-isolated traffic.This PR adds a paired
logMessageQueued→logSessionStateChange("processing")→ ... →logSessionStateChange("idle")→logMessageProcessedlifecycle insiderunCronIsolatedAgentTurn, using the preparedrunSessionId/runSessionKeyand a stablecron-isolatedsource label. This mirrors the dispatch path's lifecycle sostate.queueDepthis incremented and decremented symmetrically and downstream subscribers see the full per-run lifecycle.Problem
Any consumer of
message.queuedfor per-session attribution — diagnostics exporters, OTel bridges, custom observability plugins — currently sees zero spans for cron-isolated runs. LLM calls fire, sessions exist, but downstream subscribers cannot distinguish runs from each other and tend to bucket them under whatever static fallback id their integration uses.In a deployment with several daily isolated cron jobs over a 13-day window, an OTel subscriber observed 63 distinct cron-driven sessions in the native JSONL shipper but only 4 distinct
session.idvalues reaching its trace store — a 94% gap that this single emission point closes.Solution
Added paired diagnostic-event calls to
runCronIsolatedAgentTurn:logMessageQueued({sessionId, sessionKey, channel: "cron", source: "cron-isolated"})afterprepared.ok.logSessionStateChange({state: "processing"})immediately after queued.logSessionStateChange({state: "idle"})infinally(decrementsstate.queueDepth).logMessageProcessed({outcome, durationMs, error?})infinally.Outcomes: success →
completed; aborted/thrown/finalizer-error →errorwith reason.Changes
src/cron/isolated-agent/run.ts— added the diagnostic lifecycle calls insiderunCronIsolatedAgentTurn.src/cron/isolated-agent/run.diagnostic-events.test.ts— new focused regression test asserting the queued → processing → idle → processed sequence with consistentsessionKey.CHANGELOG.md— entry under## Unreleased/### Fixes.Real Behavior Proof
message.queued/message.processedevents for isolated-cron agent turns, even though those runs make LLM calls and have a real session UUID. Downstream attribution buckets every cron-isolated run under whatever static fallback id the integration declares, hiding distinct sessions from traces.pr/cron-isolated-message-queued, head275f1bb430) on Linux 6.12.30 / Node 24.13.0. Gateway run as a systemd user unit (openclaw-gateway.service). A diagnostic-events subscriber registered viaonDiagnosticEventwas attached to verify event emission per run.Tests:
sessionId/sessionKey. The bridge subscriber attached viaonDiagnosticEventreceivesmessage.queued, thensession.state(processing → idle), thenmessage.processed, all sharing the samesessionKeyfor the same isolated cron run.state.queueDepthreturns to 0 after the run because the pairedlogSessionStateChange("idle")runs infinally. Distinct cron run UUIDs now reach downstream span/aggregation logic instead of collapsing into a single static fallback id.src/infra/heartbeat-runner.ts:1266shares a similar shape but is intentionally out of scope for this PR — left as a follow-up if maintainers agree the same seam belongs there.pnpm checkwas not run end-to-end; the changed-surface gates above plus the build are the proof bar this PR carries.Notes
logMessageQueuedruns afterprepared.okto avoid noisy queued/processed pairs for runs that bail out at preparation; matches the existing pattern where dispatch only logs after route resolution.logSessionStateChangecalls andlogMessageProcessedrun inside thefinallyblock, ensuring thestate.queueDepthdecrement and processed event always fire even on early returns / throws.logMessageQueued/logSessionStateChange/logMessageProcessedare existing exports.Review feedback addressed (rev 2, commit 275f1bb430)
logMessageQueuedcall now passes only{sessionId, sessionKey, channel, source}, matching the helper's typed parameter and event schema onmain.logSessionStateChange({state: "processing"})immediately afterlogMessageQueued, andlogSessionStateChange({state: "idle"})in thefinallyblock beforelogMessageProcessed. This pairs thestate.queueDepthincrement with its decrement and matches the dispatch path's lifecycle.## Unreleased/### Fixes.run.diagnostic-events.test.tscovering queued / processing / idle / processed sequencing and session-key consistency.🤖 Generated with Claude Code