Skip to content

feat(cron): run scheduled children in their parent conversation's workspace and sandbox - #179669

Merged
jalehman merged 6 commits into
mainfrom
automations/scheduled-parent-workspace
Oct 24, 2026
Merged

jalehman merged 6 commits into
mainfrom
automations/scheduled-parent-workspace

Conversation

@jalehman

@jalehman jalehman commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Builds on #178933, #179834, #178965, #179011 and #179062 (all merged).

Related: #178812
Related: #178811

What Problem This Solves

Fixes: a scheduled child of a conversation runs in the agent's default workspace, not the workspace, working directory or managed worktree its parent conversation is bound to. A child of a sandboxed conversation can also run without a sandbox.

User Impact

User impact: an automation created from a conversation that is bound to a workspace, working directory or managed worktree now runs its child sessions there, with that conversation's ownership checks.

  • If the parent conversation requires a sandbox, the child does too, including when the job's cron session already existed before this change. A child never runs looser than its parent.
  • If the parent is reset (/new) or removed while the child runs in its workspace, the run ends: the child's next OpenClaw tool effect is refused, and a CLI backend's process is stopped so its own file tools cannot keep writing there. It never keeps working in the former conversation's workspace.
  • If the parent's bound worktree is gone, the job pauses with a notice naming the path (the feat(cron): pause automations whose creating conversation is gone #178965 pause). It never falls back to the agent workspace.
  • A parent that was already reset when the occurrence is admitted does not pause, and the child gets none of these: that occurrence runs unbound, in the run session's own workspace, as before this PR.
  • In-session (session:<key>) jobs, operator jobs and unbound jobs keep their current workspace selection.
  • File scope stays root: a child automation is limited to its own workspace and does not get its parent conversation's file scope. Josh decided this on 2026-10-21 ("Keep root."; design row 36, resolved decision 9).

Why This Change Was Made

  • One parent read. The occurrence admission from refactor(cron): admit each scheduled occurrence once #179834 already reads the parent row once per occurrence. For a child run whose parent is current and not paused, it now also returns occurrence.childParent: the parent row when it persists a workspace binding, its sandbox requirement, and assertCurrent, which fails once the parent resets or the occurrence settles. Run preparation and workspace selection use it and don't read the parent again. The parent row's workspace uses the same persisted-binding rule run preparation applies (resolveIngressWorkspaceOverrideForSessionRun).
  • Workspace. prepareCronSessionWorkspace applies the existing ownership and worktree checks to the parent's row, not the run session's row, and every workspace step checks the parent. The in-session target path is unchanged.
  • Live parent authority. When the child runs in its parent's bound workspace, the prompt executor passes the parent check as the admitted run's source assertion. Embedded tool authority runs that assertion before every tool effect, so a parent reset mid-run refuses every later read and write. A CLI backend's native file tools never reach that check, so admission also watches committed changes to the parent row while a bound child runs (parent-reset-watch.ts) and aborts a signal once the parent stops being current; the CLI run's abort signal includes it, so the process ends with the parent.
  • Sandbox. The creator-role sandbox still wins. Otherwise a parent with sandbox: "required" makes the child sandboxed. An existing cron root keeps its row and never takes creation metadata, so the CLI host-placement check also receives the occurrence's inherited requirement directly.
  • File scope. The execution context now records root for child runs, matching what runs today; only in-session runs record their session's scope. No consumer reads this field yet, so behavior is unchanged.
  • Fail-safe. If the parent read fails, the occurrence is unadmitted and carries no childParent, so the run keeps the legacy run-session workspace instead of failing, and the minted context fails closed for grants that only the parent gets.

Evidence

  • Real cron service, sessions and tools (run.session-workspace-authority.test.ts): a job created through the automations tool from a bound conversation runs through the real cron service with persisted session rows.
    • An isolated child reads its parent's workspace (plain and managed worktree).
    • After a real /new reset of the parent during the run (resetSessionEntryLifecycle), the admitted run's assertion refuses, and nothing is read from the former workspace.
    • Archived parents pause, and foreign, escaping and mismatched bindings are refused, as before.
  • Sandbox, real CLI process (run.sandbox-admission.test.ts): with an existing persisted, unstamped cron root and the agent's sandbox mode off, a child whose parent requires a sandbox fails closed before the CLI process launches; the same root with an unsandboxed parent launches the real CLI stub. Without the placement fix the first case launches the CLI on the host.
  • Admission: execution-context-admission covers removed and archived parents (pause), a reset parent (runs, no binding), a missing worktree (pause naming the path), a child getting its parent's bound row, sandbox requirement and live check (which fails after a parent reset and after the occurrence settles), an unbound parent's child getting only its sandbox requirement, an in-session job keeping its own binding, a failed read (no pause), and the notice.
  • Parent reset watch (execution-context-admission.test.ts): a bound child's signal aborts with the parent's failure on a change to the parent row, ignores other rows, stays live while the parent is current, and stops after the occurrence settles.
  • Docs: docs/automation/cron-jobs/payloads.md now describes which detached runs inherit the creating conversation's workspace and what a reset does mid-run.
  • Related suites (execution context, admission, occurrence, workspace authority, sandbox admission, fast mode, PR automation, memory audience): pass.
  • Checks: tsgo:core, tsgo:core:test and tsgo:test:src are clean; type-aware oxlint and oxfmt are clean; the line-cap and mock-export ratchets pass.
  • Autoreview (Codex, P0–P2): the two P1s from the previous review were confirmed fixed by the new commit; a stale admission-test expectation it found was updated.

Live behavior proof (real Gateway, code at head 4618fc07eb9)

A QA scenario creates conversations with sessions.create bound to a working directory (cwd) that holds a marker file, schedules child jobs from inside them, and force-runs the jobs on a real Gateway child process (mock-openai). The CLI lane uses a local fake CLI backend that reports its launch directory and writes files with its own (native) file I/O, so those writes never pass OpenClaw's tool check. The scenarios, the fake CLI and the gated probe tool are local proof tooling only, not part of this PR.

Scenario This PR main / previous head
Embedded child reads QA_PARENT_WS_MARKER.txt pass: reads PARENT-WS-MARKER from the parent's directory main (ddbf65c9215) fails: File not found: <qa-suite>/workspace/QA_PARENT_WS_MARKER.txt (agent default workspace)
CLI child launch directory pass: cwd=<parent dir> marker=PARENT-WS-MARKER —
Parent reset while an embedded child is parked mid-run pass: run ends source execution authority is no longer active; no tool result after the reset reaches the model —
Parent reset while a CLI child is mid-run (native file writes before and after a gate) pass: write before the reset lands; the CLI process is already gone right after sessions.reset; the write after the gate never happens; run ends source execution authority is no longer active previous head d1920578643 fails: process still alive after the reset, writes QA_CLI_HOLD_AFTER.txt into the parent's directory, run reports ok
CLI reset case, before and after the fix
d1920578643 (before):  before=true after=true  aliveAfterReset=true  status=ok
4618fc07eb9 (after):   before=true after=false aliveAfterReset=false status=error
                       "source execution authority is no longer active | SESSION_DELIVERY_GENERATION_REVOKED"

Upgrade proof (latest stable 2026.10.6 → this PR)

On an isolated state directory, 2026.10.6 creates a conversation bound to a working directory, a job linked to it and an unlinked job, then stops. This PR's doctor --fix runs on the same state, and this PR's Gateway starts on it.

  • Both jobs are byte-identical before and after the upgrade. The only job change is Doctor's existing conversion of the built-in heartbeat job.
  • The parent conversation's saved workspaceDir, spawnedCwd, label and session id are unchanged.
  • The pre-upgrade linked job runs in the parent's directory (cwd=<parent dir> marker=PARENT-WS-MARKER); the pre-upgrade unlinked job runs in the agent workspace (marker=missing (ENOENT)); a linked job created after the upgrade also runs in the parent's directory. All three runs use the CLI runtime.
  • A conversation's required sandbox can only be set through an identified operator's role policy, not over the token connection used here, so the live upgrade does not cover it. The stored sandbox field is read unchanged; its inheritance is covered by run.sandbox-admission.test.ts against a real CLI process.

@clawsweeper

clawsweeper Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper clawsweeper Bot added the clawsweeper:intake:feature Preliminary submission classification; full source review pending. label Oct 21, 2026
@jalehman
jalehman force-pushed the automations/scheduled-parent-memory branch from 859d601 to fac8f7f Compare October 21, 2026 19:52
@jalehman
jalehman force-pushed the automations/scheduled-parent-workspace branch from 93a19b3 to 365ccc3 Compare October 21, 2026 19:52
@jalehman
jalehman force-pushed the automations/scheduled-parent-memory branch from fac8f7f to fc8567e Compare October 21, 2026 19:56
@jalehman
jalehman force-pushed the automations/scheduled-parent-workspace branch from 365ccc3 to dc6fcd2 Compare October 21, 2026 19:56
@jalehman
jalehman force-pushed the automations/scheduled-parent-memory branch from fc8567e to 941c2b0 Compare October 21, 2026 19:59
@jalehman
jalehman force-pushed the automations/scheduled-parent-workspace branch from dc6fcd2 to 3b24d61 Compare October 21, 2026 19:59
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:feature Preliminary submission classification; full source review pending. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 21, 2026
@clawsweeper

clawsweeper Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Scheduled child sessions inherit their creating conversation’s workspace and required sandbox, with inherited workspace access ending when the parent resets.

Example: A conversation’s working directory contains QA_PARENT_WS_MARKER.txt with PARENT-WS-MARKER.

  • Before: Its scheduled child searches the agent workspace and reports File not found.
  • After: The child reads PARENT-WS-MARKER from the parent directory; resetting the parent prevents further workspace effects.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Focused implementation with meaningful authority regressions, real Gateway negative controls, latest-stable upgrade evidence, and the previous documentation finding resolved.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The supplied real Gateway scenarios exercise scheduled workspace inheritance and allowed-versus-reset effects: the embedded child reads the parent marker, while reset blocks later effects and stops the CLI before its later native write; production code is unchanged since that proof, and real-process sandbox tests cover existing unstamped roots.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Feature · Worth it: Yes · Fix scope: Complete
User problem: An automation created in a project conversation searches the agent’s default workspace and can miss its parent’s required sandbox.
Reason: The maintainer-authored direction delivers useful project continuity while preserving root file scope, existing ownership checks, and live revocation.

Merge readiness

✅ Ready for maintainer review

This PR remains useful and has no remaining actionable findings; the documentation correction resolves the previous P3, and normal CI is still running.

Priority: P2
Reviewed head: 705b9502535ec8fd3449355ece606e668cd0372d

Before merge

None.

Findings

None.

Agent review details

How this fits together

Cron admits a stored job against its parent conversation, passes workspace and sandbox facts into run preparation, and enforces current authority at embedded tool effects and CLI process execution.

flowchart TD
StoredJob --> OccurrenceAdmission
ParentConversation --> OccurrenceAdmission
OccurrenceAdmission --> WorkspacePreparation
WorkspacePreparation --> EmbeddedTools
WorkspacePreparation --> CLIProcess
ParentReset --> EmbeddedTools
ParentReset --> CLIProcess
Loading

Technical review

Best possible solution:

Land the existing focused change once the normal current-head merge gates pass.

Do we have a high-confidence way to reproduce the issue?

Current-main source establishes the default-workspace path, and supplied Gateway output independently records the missing marker before the change; this read-only review ran no target code.

Is this the best way to solve the issue?

The patch is a focused extension of occurrence admission and existing workspace, generation, sandbox, and process-lifecycle owners; the reset watcher addresses CLI-native effects that embedded tool checks cannot stop.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against d7e7e402df15.

Provenance checked

  • Persisted workspace selection and containment changes intended behavior with a stated reason (300ef39: Named-session jobs needed their saved workspace while requester ownership and managed-worktree checks prevented access to another conversation’s files.)
  • Per-occurrence parent facts and generation lifetime keeps the original intent (c730759: Admit each scheduled occurrence once before executor work and retain the validated parent generation until settlement.)
  • Child file scope changes intended behavior with a stated reason (240a90e: The execution-context foundation described scheduled resource scopes before consumers switched; this PR records the accepted root-only scope for children.)
  • CLI sandbox placement keeps the original intent (7abbf85: Host-executed CLI backends cannot honor session sandbox containment and must be rejected before launch.)
  • Session preparation and workspace lifecycle keeps the original intent (3d2f7ca: Explicit conversation jobs moved through ordinary session admission while retaining scheduled authority, delivery, and managed-worktree custody.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Josh Lehman: Raw commit c730759 adds src/cron/execution-context-admission.ts:194 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: c73075978be8; files: src/cron/execution-context-admission.ts)

PR surface

Source +167, Tests +187, Docs 0. Total +354 across 14 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 8 197 30 +167
Tests 5 198 11 +187
Docs 1 2 2 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 14 397 43 +354

Labels

Label changes:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: This improves conversation-linked scheduled workspace and sandbox behavior with a limited, established execution boundary.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (4 earlier review cycles)
  • reviewed 2026-10-21T21:43:33.876Z sha 3b24d61 :: needs real behavior proof before merge. :: [P1] Bind inherited workspace access to the live parent generation | [P1] Enforce inherited sandboxing for existing cron roots
  • reviewed 2026-10-23T23:20:07.900Z sha d192057 :: needs real behavior proof before merge. :: [P3] Update the documented detached-workspace behavior
  • reviewed 2026-10-24T02:35:09.575Z sha 4618fc0 :: needs changes before merge. :: [P3] Describe removed parents as paused instead of using a fallback workspace
  • reviewed 2026-10-24T02:42:12.091Z sha 4618fc0 :: needs changes before merge. :: [P3] Describe removed parents as paused instead of using a fallback workspace

Reviewed October 23, 2026, 10:50 PM ET / October 24, 2026, 02:50 UTC (Revision 5).

@jalehman
jalehman force-pushed the automations/scheduled-parent-memory branch 2 times, most recently from d0a6f04 to 3352363 Compare October 23, 2026 07:16
@jalehman
jalehman force-pushed the automations/scheduled-parent-workspace branch from 3b24d61 to 11ec125 Compare October 23, 2026 07:24
@clawsweeper clawsweeper Bot added status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. clawsweeper:intake:feature Preliminary submission classification; full source review pending. and removed merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. clawsweeper:intake:feature Preliminary submission classification; full source review pending. labels Oct 24, 2026
@jalehman

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Fixed the P3 at 705b9502535 (docs only): a linked job whose conversation was reset runs unbound in the agent workspace; a removed or archived conversation, or a missing bound worktree, pauses the job. No code change since 4618fc07eb9, which the live proof ran on.

@clawsweeper

clawsweeper Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:feature Preliminary submission classification; full source review pending. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. clawsweeper:intake:feature Preliminary submission classification; full source review pending. labels Oct 24, 2026
@jalehman
jalehman merged commit 603c8a7 into main Oct 24, 2026
128 checks passed
@jalehman
jalehman deleted the automations/scheduled-parent-workspace branch October 24, 2026 02:54
@jalehman

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 24, 2026
…kspace and sandbox (openclaw#179669)

* feat(cron): run scheduled children in their parent conversation's workspace and sandbox

* fix(cron): keep scheduled child runs at root file scope

Josh decided child automations stay limited to root (their own workspace), not the parent's file scope. The context now records root for every placement except in-session runs, matching what runs today.

* fix(cron): end inherited workspace access with the parent and enforce its sandbox on existing roots

A child running in its parent conversation's bound workspace now carries
the parent's generation check: workspace preparation composes it, and
the prompt executor passes it as the admitted run's source assertion, so
embedded tool authority refuses every later effect once the parent
resets. The CLI host-placement check also receives the occurrence's
inherited sandbox requirement, since an existing cron root keeps its
row and never takes creation metadata.

* fix(cron): stop a CLI child working in its parent's workspace when the parent resets

A CLI backend's native file tools never reach OpenClaw's tool check, so the
parent's live check alone let a CLI child keep writing to the inherited
workspace after the parent reset. Admission now watches committed changes to
the parent row while a bound child runs and aborts a signal once the parent
stops being current; the CLI run's abort signal includes it, so the process
ends with the parent.

* docs(cron): describe parent workspace inheritance for detached runs

* docs(cron): removed or archived parents pause linked jobs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant