Repository navigation
feat(cron): resume a parked run after an approval (#581, part 1) - #638
Merged
Merged
Conversation
An allow on a cron run's parked Write (POST /approvals/{id}/decision for
a session serve does not host) continues the run in place.
- tole-core ledger: a new `resume` record claims the continuation of a
run that settled awaiting_approval, at most once. The fold ignores a
resume line for any other run (not parked, other job, already
resumed), so a hand-written line cannot revive a finished run or run
a parked one twice. The continuation is an ordinary pending fire (same
scheduled_for) that settles with its own done and dies with its lease;
the parked done stays, and the continuation's outcome is the job's
latest.
- tole-cli cron: resume_parked runs the claim checks (provider, delivery,
skills and profile, daily cap) before writing the record, reads the
run's session from the job's workdir without following a symlink or
blocking (size-capped, regular file only), refuses a session whose
turn already ended, then reopens the session and resumes the parked
turn with no new prompt; the approver's one-shot lets exactly the
approved call run.
- serve: the allow route resumes a serve session as before and hands
any other session to the cron resume.
- Docs: automation-design section 5 (how resume works, what is not
resumable), threat model row and scheduled-jobs note, CHANGELOG.
🔍 Cora AI Code Review✅ No issues found. Code looks good! Review powered by cora-code · BYOK · MIT |
The resume arm called resume_turn_with_cancel directly, without the plan's observer, so a continuation had no step budget (only the wall clock and the token meter bounded it). - tole-core: resume_turn_with_observer passes an observer to the replan loop; resume_turn_with_cancel keeps its behavior (no observer). - tole-cli: turn_runner::resume_turn_with resumes under a TurnPlan, and the cron resume arm uses it with the same plan and metered provider as a fresh run: model pin, max_steps, token budget, cancel. Each budget counts the continuation alone. - A run's done reports only its own tokens, so the daily cap no longer counts the parked run's tokens a second time on a continuation. - Docs and CHANGELOG say plainly that an allow runs the call only if the resumed model makes that same call again.
| Some("cron"), | ||
| ) { | ||
| let opened = match resume { | ||
| // Checked again right before the reopen: the session file sits in |
…581) The cron resume checked the session file (no symlink, regular file, size cap) and then re-opened the path with JsonlStorage::open. The job can write its workdir, so it could swap the checked file for a symlink in between and have the resumed turn append through it. - tole-core: JsonlStorage::open opens the session file once and replays, repairs a torn tail and appends through that handle; the path is never re-opened. On unix the open uses O_NOFOLLOW and O_NONBLOCK. On every platform an fstat of the handle must show a regular file. The .lock sidecar (whose pid write truncates the file) and compaction's temp file and reopen are opened the same way. - New JsonlStorage::open_bounded also caps the size on the handle and stops reading at the cap if the file grows during the replay. - tole-cli cron: the resume opens the session with open_bounded and checks that the turn is still parked on that same storage, instead of a separate check followed by a re-open. - Docs (automation-design section 5, threat model) and CHANGELOG.
This was referenced Nov 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Part 1 of #581: a cron run parked on a Write resumes after an
/approvalsallow. An allow on a cron run's parked call continues that run in the same session, and only the approved call runs.Requirement 1 (
allow[]is the only pre-authorization;Destructivecannot be registered) and the parking half of requirement 2 shipped in #579. This PR adds the resume. Agent-created jobs (created_by, createdpaused,allow[]limited to the creator's) and config-sourced job trust follow in part 2, also based on develop.Why
Before this,
tole serve --cronparked a cron Write that the job'sallowlist did not cover, but an allow could only resume serve sessions. The cron run stayedawaiting_approvalfor good, so the only option was to re-run the whole job.Changes
How true resume works with the append-only ledger and session
resumerecord{fire_id, resumes, job_id, claimed_at, lease}is appended under the ledger lock.resumesrun settledawaiting_approvalfor the same job, was not resumed before, and the newfire_idis unused. Any otherresumeline, hand-written or repeated, is ignored and never runs.scheduled_for. It settles with its owndone, andrecoversettles itinterruptedwhen its lease dies, like any run.doneis never changed.last_donenow prefers the later of two runs with the samescheduled_for, so the continuation's outcome becomes the job's latest.Ledger::resumerefuses a run that is unsettled, not awaiting approval, or already resumed, and re-checks after appending (lost race).cron::tick::resume_parkedhandles the rest.awaiting_approvalrun with that session and runs the claim checks before writing the record: provider, delivery targets, skills and profile (pins and approval), and the daily cap. A refused continuation writes nothing, so the run stays resumable once the cause is fixed.O_NOFOLLOW | O_NONBLOCK, requires a regular file and caps it at 64 MiB.JsonlStorage::open_bounded(path, 64 MiB)and checks the parkedpcon the storage it opened. The replay and every append use that one handle, so a file swapped after the pre-claim check is refused at the open.JsonlStorage::openfor all callers rather than add a resume-only entry point. It now opens the file once, on unix withO_NOFOLLOW | O_NONBLOCK, and on every platform anfstatof the handle must show a regular file. The replay reads through a duplicate of that handle, the torn-tail repair truncates through it, and appends write through it; the path is never re-opened..locksidecar is opened the same way. Its pid write truncates the file, so a planted.locksymlink would otherwise truncate its target.open_boundedis the one addition: it applies the size cap to the handle, and stops reading at cap + 1 if the file grows during the replay.libcwas already used here). The flags arecfg(unix); other platforms keep their behavior apart from the regular-file check.--no-default-featuresbuilds and passes..toleor.tole/sessions) swapped for a symlink. That could only reach a file with the same random session id in another directory, but the.locksidecar would be created there. This is recorded in the threat model.TurnPlanand metered provider as a fresh run: the job's model pin, itsmax_stepsstep budget, its token budget, itsmax_minuteslimit and the cancel token. A newtole_core::turn::resume_turn_with_observerpasses the plan's observer to the replan loop (resume_turn_with_cancelis unchanged), andturn_runner::resume_turn_withresumes under a plan.docs/automation-design.md§5). The continuation is a run of its own with its owndone, and every resume needs a human allow. Itsdonereports only its own tokens, so the daily cap does not count the parked run's tokens twice.POST /approvals/{id}/decisionresumes a session that serve hosts as before. Any other session is handed tocron::resume_after_approval.Nothing is auto-approved. A resume without an allow (denied or expired) parks the call again and never runs it.
Not resumable
tole cron tick: there is no queue, so there is no approval to give. Re-run them.tole serverestarts, because the queue is in memory. The run staysawaiting_approval; re-run it.Docs
docs/automation-design.md§5: how resume works and what is not resumable.docs/threat-model.md: a new row and a scheduled-jobs paragraph.Testing
TDD. Each rule was broken on purpose and a test failed for each:
resumeof a run that is not parkeda_forged_resume_line_never_revives_a_runresumeof the same runa_forged_resume_line_never_revives_a_runLedger::resumeskips the status checka_parked_run_resumes_once_as_a_new_pending_runLedger::resumeskips the already-resumed checka_parked_run_resumes_once_as_a_new_pending_runlast_donekeeps the strict>a_parked_run_resumes_once_as_a_new_pending_runresume_parkedignoresresumed_byan_allowed_parked_write_resumes_the_run_oncepccheck removeda_parked_record_whose_turn_ended_is_not_resumedunwrap_or_default)a_skill_changed_while_parked_refuses_the_resumeopen(follows symlinks, blocks on a FIFO)a_planted_session_symlink_or_fifo_refuses_the_resumea_resumed_run_stops_at_the_jobs_max_stepsa_resumed_run_uses_the_jobs_pinned_modela_resumed_run_keeps_the_token_budgeta_resumed_run_keeps_the_token_budgetO_NOFOLLOWa_session_swapped_for_a_symlink_after_the_check_is_refused_at_the_open,a_symlinked_lock_sidecar_is_refused_and_its_target_left_alone,compaction_never_writes_through_a_planted_temp_symlink,a_session_swapped_after_the_resume_check_is_refused_at_the_openO_NONBLOCKa_session_swapped_for_a_fifo_is_refused_without_blocking(the read-only open blocks)open_boundedignores the capopen_bounded_refuses_a_session_over_the_cap.locksidecar opened without the hardened opena_symlinked_lock_sidecar_is_refused_and_its_target_left_aloneFile::createcompaction_never_writes_through_a_planted_temp_symlinkThe open hardening was red first. All 5 new
tole-coretests failed against the oldopen, withopen_boundedstubbed to ignore the cap: the symlink was followed, the FIFO open blocked, the.locksymlink truncated its target, compaction wrote through the temp-file symlink, and the cap was not applied.The regular-file check has no test of its own. With
O_NONBLOCK, a FIFO or a directory already errors on Linux (EAGAINorEISDIR), so removing the check fails nothing. The check matters for device nodes, and a test would needmknod, which needs root.Before the budget fix, the step-budget test failed (the continuation settled
Errorfrom the loop guard instead ofBudget), and the token test failed on the double count (6 tokens instead of 4). The model-pin test already passed, because both arms used the provider built from the pinned config. Breaking the pin on the resume arm only proves that the test now guards it.New tests:
crates/tole-core/tests/ledger_core.rs: one resume per parked run; forged and repeatedresumelines ignored by the fold; a continuation dies with its lease.crates/tole-core/tests/untrusted_session_open.rs(unix): replays the race, where the check passes, then the file is swapped for a symlink to an outside copy, thenopenoropen_boundedrefuses it and the outside copy is byte for byte unchanged. Also covered:open,open_boundedandopen_read_onlywithin 5 s;.locksidecar is refused and its target left alone;open_boundedenforces the cap and still commits within it.crates/tole-cli/tests/cron_agent.rs:donestays, a second resume isNone;max_steps, counting its own steps;run_agentis entered directly, as it would be afterresume_parked's check. The run errors within 5 s, the outside copy is unchanged, and the approved write never runs.Gates:
cargo fmt --allcargo clippy --workspace --all-targets --all-features -- -D warningscargo test --workspace: 1608 passedcargo test -p tole-core --no-default-features: 565 passedcora review --no-llm --staged: no issuesNot covered automatically: the serve route hand-off to
cron::resume_after_approval. An end-to-end test would wait up to 61 s for the in-process ticker. The resume itself is tested at the library level with the same queue.