Repository navigation
feat(cron): add the scheduled-run execution context (no behavior change) - #178933
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. What this changesAdds an unused scheduled-run execution context, binds its lifetime to Cron admission, and provides development replay tooling. Review scores
ProductKind: Feature · Worth it: Yes · Fix scope: Partial Merge readiness✅ Ready for maintainer review Keep this PR open as a useful foundation for scheduled-run consolidation; the prior findings are addressed, and no remaining concrete correctness blocker was found. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherCron supplies stored jobs and current parent/requester facts to a context builder; admission retains the result and releases its generation lease, while existing execution and effect owners continue making runtime decisions. flowchart TD
A[Scheduled job] --> B[Prompt executor]
B --> C[Parent and requester facts]
C --> D[Execution context builder]
D --> E[Cron admission lifetime]
E --> F[Release generation lease]
B --> G[Existing runtime execution]
Technical reviewBest possible solution: Keep this as the bounded foundation and complete consumer cutovers through the linked admission and resource-owner PRs. Do we have a high-confidence way to reproduce the issue? This is a staged feature foundation; source inspection confirms the new context is minted and retained without a production consumer, and no runtime reproduction was performed. Is this the best way to solve the issue? The builder reuses existing authority and generation owners, and the explicitly stacked admission cutover justifies retaining existing runtime decisions during this stage. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 67ff158af4ac. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +2689, Tests +804, Other +524. Total +4017 across 14 files. Added test files: 5. View PR surface stats
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:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
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 (3 earlier review cycles)
Reviewed October 22, 2026, 6:16 AM ET / 10:16 UTC (Revision 4). |
0944c7d to
3fa98ae
Compare
3fa98ae to
178526d
Compare
178526d to
b73bf86
Compare
|
Addressed the review of
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
buildScheduledExecutionContext derives one occurrence's principal, placement, authority, tool policy, resource scopes and inference account from stored job fields plus caller-read facts (parent row, requester check). No consumer reads it yet; admission minting follows in openclaw-0d5.2. Jobs with sourceConversation or operatorSource become children of that exact parent and pause when it is removed, archived or reset, or its worktree is gone. Key-only parent links stay on their legacy decisions. A parent-linked job without a recorded requester gets no owner authority. The admission-source rule moves unchanged into src/cron/admission-source.ts so the timer and the builder share one owner.
Each prompt-executor attempt reads the parent session row (for jobs with an exact parent link), rechecks the requester, builds the context and binds it to the admitted run. A parent-linked context holds the parent's session generation so assertCurrent fails once the parent is reset or removed; the lease is released when the admission closes. Nothing reads the context yet, and minting errors become a fail result instead of failing the run. The prompt executor's scheduled tool policy setup moves into the same module so the executor stays under its line cap.
execution-context-projection reproduces what the existing scheduled-run code decides for a stored job and labels where the context differs (equal, gain-intended, gain-unexpected, loss, retarget, pause). Doctor will reuse it. scripts/dev/cron-context-replay.mts is a development script: it copies a Gateway's state and agent session databases with SQLite's online backup into a private temp directory, replays every stored job against the copies, prints the labels and can emit anonymized job shapes. The fixture test pins the builder and projection results for those shapes.
Read the parent row with the same precedence the builder uses (operator source first, then the creating conversation). Expose the minted context through the admission owner until a consumer reads it, use typed rank lookups, keep real exports in test mocks, and register the replay script as a Knip script entry.
Replay now reads the parent row with the admission's parent precedence (operator source first) and resolves each job's agent through the cron owner resolver, reporting jobs with no resolvable owner instead of replaying them as main. Fixture anonymization keeps operator sources, channel requesters, lifecycle-revision changes and worktree existence, so emitted fixtures replay to the same outcome as the recorded jobs. Drops two tests that restated existing assertions and comments that named future work.
The parent-generation lease taken while minting was released only by a closed admission or the missing-fence path. Any other preparation error left it held. The prompt executor now releases it whenever preparation throws, and admission keeps releasing it on close.
854c2aa to
c90ce34
Compare
…puts Script and system-event payloads were exported unchanged, so --emit-fixtures could write private script bodies into anonymized fixtures. Trigger and runtime-authority markers were dropped, letting resolveCronRunToolsAllow widen a restricted automatic cap in the fixture.
|
Addressed the review of
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
A parent link stored without a lifecycle revision leased generation null, which the generation owner rejects against the row's revision, so a valid parent-linked occurrence minted a fail result. Admission now leases the revision of the parent row the builder validated. Also replaces the anonymizer's switch with returns that satisfy consistent-return.
|
Addressed the review of
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
…ge) (openclaw#178933) * feat(cron): add pure scheduled execution context builder buildScheduledExecutionContext derives one occurrence's principal, placement, authority, tool policy, resource scopes and inference account from stored job fields plus caller-read facts (parent row, requester check). No consumer reads it yet; admission minting follows in openclaw-0d5.2. Jobs with sourceConversation or operatorSource become children of that exact parent and pause when it is removed, archived or reset, or its worktree is gone. Key-only parent links stay on their legacy decisions. A parent-linked job without a recorded requester gets no owner authority. The admission-source rule moves unchanged into src/cron/admission-source.ts so the timer and the builder share one owner. * feat(cron): mint the scheduled execution context at run admission Each prompt-executor attempt reads the parent session row (for jobs with an exact parent link), rechecks the requester, builds the context and binds it to the admitted run. A parent-linked context holds the parent's session generation so assertCurrent fails once the parent is reset or removed; the lease is released when the admission closes. Nothing reads the context yet, and minting errors become a fail result instead of failing the run. The prompt executor's scheduled tool policy setup moves into the same module so the executor stays under its line cap. * test(cron): add execution context replay and stored-shape fixtures execution-context-projection reproduces what the existing scheduled-run code decides for a stored job and labels where the context differs (equal, gain-intended, gain-unexpected, loss, retarget, pause). Doctor will reuse it. scripts/dev/cron-context-replay.mts is a development script: it copies a Gateway's state and agent session databases with SQLite's online backup into a private temp directory, replays every stored job against the copies, prints the labels and can emit anonymized job shapes. The fixture test pins the builder and projection results for those shapes. * fix(cron): align the context's parent read with principal resolution Read the parent row with the same precedence the builder uses (operator source first, then the creating conversation). Expose the minted context through the admission owner until a consumer reads it, use typed rank lookups, keep real exports in test mocks, and register the replay script as a Knip script entry. * fix(cron): keep replay fixtures faithful to runtime admission Replay now reads the parent row with the admission's parent precedence (operator source first) and resolves each job's agent through the cron owner resolver, reporting jobs with no resolvable owner instead of replaying them as main. Fixture anonymization keeps operator sources, channel requesters, lifecycle-revision changes and worktree existence, so emitted fixtures replay to the same outcome as the recorded jobs. Drops two tests that restated existing assertions and comments that named future work. * fix(cron): release the minted context when admission preparation throws The parent-generation lease taken while minting was released only by a closed admission or the missing-fence path. Any other preparation error left it held. The prompt executor now releases it whenever preparation throws, and admission keeps releasing it on close. * fix(cron): sanitize every replay fixture payload and keep tool-cap inputs Script and system-event payloads were exported unchanged, so --emit-fixtures could write private script bodies into anonymized fixtures. Trigger and runtime-authority markers were dropped, letting resolveCronRunToolsAllow widen a restricted automatic cap in the fixture. * fix(cron): hold the observed parent generation for revisionless links A parent link stored without a lifecycle revision leased generation null, which the generation owner rejects against the row's revision, so a valid parent-linked occurrence minted a fail result. Admission now leases the revision of the parent row the builder validated. Also replaces the anonymizer's switch with returns that satisfy consistent-return.
Related: #178812
Related: #178811
What Problem This Solves
Scheduled runs decide their tools, owner status and resources in dozens of separate places that disagree with each other. No single value describes what one occurrence of an automation may do.
User Impact
User impact: none yet. This adds the scheduled-run execution context and builds it for every isolated cron occurrence, but nothing reads it. Later PRs switch each consumer to it.
Why This Change Was Made
src/cron/execution-context.tsis a pure builder. It takes a stored job plus facts read at admission (the parent session row and a fresh requester check). From those it derives the occurrence's principal, placement, authority, tool policy, resource scopes and inference account.sourceConversationor a stored operator source) becomes a child of that conversation. When both exist, the operator source wins.src/cron/execution-context-admission.tsmints the context for each prompt-executor attempt and binds it to the admitted run.assertCurrentfails once the parent is reset or removed, and the lease is released when the admission closes.failresult; they never fail the run.src/cron/execution-context-projection.tsreproduces what the existing code decides for a stored job and labels each difference from the context:equal,gain-intended,gain-unexpected,loss,retargetorpause.scripts/dev/cron-context-replay.mtsis a development script and is not shipped.src/cron/execution-context.fixtures.test.tspins the builder and projection results for the shapes the replay found. Other installs are covered by tests rather than runtime diagnostics.Evidence
scripts/run-vitest.mjs): 4 files, 62 tests pass. They cover the builder, minting, the 27 stored-shape fixtures, and the replay's anonymization. The anonymization tests cover an operator-source parent, a channel requester, a changed lifecycle revision and a missing worktree.src/cron/isolated-agentpass alongside the context tests, covering the prompt executor's admission path.equalexcept on the 5 jobs with an exact parent link. Those show onlygain-intended(memory, automations) andretarget(board, event target).gain-unexpected,lossorpause.pnpm check:changed: format, both typecheck lanes, and the SAFETY-comment, SQLite and mock-export ratchets pass. Two checks fail only on files this PR doesn't touch:ui/srcfiles);gateway-root,infra).oxlint --type-awareon the changed files reports 0 warnings and 0 errors.