Repository navigation
fix: agent_end hook context is missing jobId for scheduled agent runs - #167124
Conversation
The cron executor supplies jobId and the attempt dispatcher forwards it, but the shared embedded hook projection did not select it, so plugin hook contexts for cron-started runs had no jobId. Select and return the optional field. The completed-attempt lifecycle test now exercises the real end-context builder and hook adapter instead of mocking the builder, and covers success, failure and abort with and without a job id.
|
🦞👀 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. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Codex review: needs maintainer review before merge. What this changesThe branch forwards the scheduler-supplied job ID into shared agent hook contexts and extends lifecycle regression coverage. Example: A plugin observes a completed scheduled agent run
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR addresses a documented defect still present on current main. No actionable patch findings remain; the large reported surface comes from merged main changes. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe scheduler supplies job identity when starting an agent run. Shared context builders carry execution facts into the lifecycle callbacks that plugins receive. flowchart TD
A[Scheduled job] --> B[Agent execution parameters]
C[Ordinary chat] --> B
B --> D[Shared agent hook context]
D --> E[Sparse plugin context]
E --> F[Plugin lifecycle callback]
A --> G[Scheduled run history]
Technical reviewBest possible solution: Keep scheduler-supplied identity in the existing shared projection and preserve sparse ordinary-run contexts at the plugin boundary. Do we have a high-confidence way to reproduce the issue? Yes: current-main source proves that the scheduler supplies jobId and the shared projection drops it, corroborated by recorded Gateway callbacks; this review did not execute the reproduction. Is this the best way to solve the issue? Yes: forwarding the existing optional field at its shared owner repairs the cause without session-key parsing, another API, or configuration changes. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 3f76fe021990. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
PR surfacePR surface statistics unavailable: the file list is incomplete. Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (1 earlier review cycle)
Reviewed October 8, 2026, 9:13 PM ET / October 9, 2026, 01:13 UTC (Revision 2). |
Security-sensitive guard clearedCurrent revision: This PR no longer changes files in the maintainer security-review tier. Separate CODEOWNERS requirements still apply to security policy and enforcement files. |
|
Maintainer override: the only red job is inherited and outside this diff.
ClawSweeper is ready on this exact head. |
…openclaw#167124) Pass the cron `jobId` into the `agent_end` plugin hook context for scheduled (cron) agent runs, so plugins can link a finished run to its job. Non-cron runs are unchanged. Fixes openclaw#167123. Co-authored-by: Ayaan Zaidi <[email protected]>
Closes #167123
What Problem This Solves
Fixes: a plugin's
agent_endhook context has nojobIdwhen the run was started by a scheduled (cron) job.User Impact
Plugin authors can tell which scheduled job a finished run belongs to from the typed
jobIdfield, without parsing the session key. Runs the cron service did not start still have nojobId. No configuration, migration or public type change.Why This Change Was Made
The cron executor already supplies
jobIdand the attempt dispatcher forwards it; the shared embedded hook projection did not select it, so every hook context built from that projection lost it. The change selects and returns that one optional field. Nothing is inferred from the session key.Evidence
Running gateway, before and after (source build, loopback gateway, isolated state,
env -i, a local scripted OpenAI-compatible provider, a recorder plugin loaded throughplugins.load.paths; a client subscribed withsessions.subscribebeforecron.add, jobs fired on their own schedule):cron.addidcron.runsjobIdagent_endcontextjobId99fbe932-2b06-43e2-98d9-2f86c435fe19ok1654bf0c-ddff-4899-8d74-4b44e1569cfcerrorchat.sendbf322ad9-b29e-4307-870e-b01f4f1240d1bf322ad9-b29e-4307-870e-b01f4f1240d1ok8c87061c-da7c-4583-bb56-1595e20e4ffa8c87061c-da7c-4583-bb56-1595e20e4ffaerrorchat.sendAbsence was checked with
Object.hasOwn(context, "jobId")in the recorder. The scripted provider makes the runs deterministic; this is not vendor-provider proof.Captured contexts (trace fields and the workspace path omitted)
Before, scheduled run that succeeds:
{"runId":"ea2111bf-4650-4cd9-97a3-d72999fc3042","agentId":"main","sessionKey":"agent:main:cron:99fbe932-2b06-43e2-98d9-2f86c435fe19:run:37d1f345-fe3e-4169-bedc-663d037ec328","sessionId":"37d1f345-fe3e-4169-bedc-663d037ec328","sandboxed":false,"modelProviderId":"c1-scripted","modelId":"c1-model","trigger":"cron"}After, scheduled run that succeeds:
{"runId":"95792de2-d9cd-4969-8a11-51a372b7e4e9","jobId":"bf322ad9-b29e-4307-870e-b01f4f1240d1","agentId":"main","sessionKey":"agent:main:cron:bf322ad9-b29e-4307-870e-b01f4f1240d1:run:eddab87d-263d-4e28-98bb-878fbc5dbc87","sessionId":"eddab87d-263d-4e28-98bb-878fbc5dbc87","sandboxed":false,"modelProviderId":"c1-scripted","modelId":"c1-model","trigger":"cron"}Tests
src/agents/embedded-agent-runner/run/attempt-phase-lifecycle.test.ts: the completed-attempt test now runs the real end-context builder and hook adapter (its mock ofagent-end-context.jshid this defect) and covers success, failure and abort, each with and without a job id. Without the fix: 3 failures, 15 passes. With it: 18 of 18.pnpm test <file> --maxWorkers=1: about 8 s in Vitest locally.src/agents/harness/hook-context.test.tsandlifecycle-hook-helpers.test.ts: 10 of 10, unchanged.config/test-mock-exports-baseline.txt(pruned with the repository's command).Checks
Changed-file lint, formatting and typechecking pass.
pnpm checkfails locally at the core lintmax-linesrule on 12 files this PR does not touch; the same 12 fail with the patch removed.Scope and risk
The projection is shared by the other embedded hook contexts, so they receive the same optional field when the scheduler supplied it. Validated on
fc3e0973; the branch is based on currentmain.Maintainer verification
Preserved @xyrolle's fix and regression coverage, and merged main because the lifecycle test and mock baseline changed there. No overlap with Pash/Sarah changes.
Built Gateway verification on baseline
c9a0c00b8691bda5bd7a38ee494b5edd8ecb9254and candidate6a6303284761a8bf4e2cf60f214141b9827a88b1, using an isolated local recorder plugin andopenclaw cron run:97262cbc-dcf2-40b9-8a10-0570caaff5a3: successful callback omittedjobId.3239dc08-7591-47d3-80e8-6a92c40e9e5a: successful callback supplied exactly that job ID.jobIdon both builds.5b3e722b-285d-469d-b4db-87a132139c5fto the hook.pnpm build, realpnpm tsgo, and all 28 tests across the lifecycle and two harness suites passed. The lifecycle suite took 19.67 seconds; all three routed suites took 54.47 seconds including preparation. Both builds printed an existing advisory Control UI gzip-budget violation; the build commands completed successfully.Merge risk: two-way door; reverting restores the previous projection without changing stored state or configuration. Blast radius is plugin consumers of shared embedded-agent hook contexts on scheduler-supplied runs.