openclaw/scripts/dev
Josh Lehman 240a90ef9f
feat(cron): add the scheduled-run execution context (no behavior change) (#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.
2026-10-22 03:30:28 -07:00
..
computer-use-gateway-live-proof.ts feat(automations): migrate heartbeat jobs through Doctor (#179387) 2026-10-21 05:46:54 -07:00
computer-use-linux-x11-fixture.py
computer-use-macos-live-proof.ts fix(scripts): macOS computer-use live proof aborts before its first check (#172479) 2026-10-21 16:24:26 -07:00
computer-use-macos-live-rig.sh
cron-context-replay.mts feat(cron): add the scheduled-run execution context (no behavior change) (#178933) 2026-10-22 03:30:28 -07:00
discord-acp-plain-language-smoke.ts
gateway-smoke.ts
ios-node-e2e.ts
realtime-talk-live-smoke.ts
test-device-pair-telegram.ts
tui-pty-test-watch.ts
tui-questions-proof.ts