Skip to content

feat: workload runs start in their context - #534

Merged
moonlight16 merged 3 commits into
rossoctl:mainfrom
moonlight16:feat/workload-run-cwd
Oct 15, 2026
Merged

moonlight16 merged 3 commits into
rossoctl:mainfrom
moonlight16:feat/workload-run-cwd

Conversation

@moonlight16

Copy link
Copy Markdown
Member

Fixes a gap found while moving a demo off kubectl cp onto workloads (#517, seed sandbox files before a leaf runs): after mocactl spawn --workload, the agent started in an empty directory and had to search for its files.

What changes

  • Working directory. A workload run now starts in its context view (read-only) or its writable copy (--writable, feat: writable per-run copy of a workload's context #532), so pwd and ls show the project immediately. This mirrors how solve runs start in their cloned repo.
  • workspace/ root. When a revision has a workspace/ folder, which contextctl ctx pack produces (feat: workspace bundles and contextctl ctx pack context-service#56, workspace bundles), the view and the writable copy point at it, so files appear exactly as in the source folder (src/greet.py, not workspace/src/greet.py). Bundles without workspace/ work as before. A workspace symlink inside a bundle is ignored, so a view never points outside the cache.
  • Prompt note. Read-only runs are told the session directory is writable scratch space; writable runs are told the copy is discarded and to return their changes.
  • Docs and mocactl hints now use contextctl ctx pack <dir> --type workspace -o FILE, which needs a Context Service with feat: workspace bundles and contextctl ctx pack context-service#56.

Checked in a real ubi9-minimal container as the sandbox user, for bundles with and without workspace/, read-only and writable: the working directory lists src directly, writes are refused read-only and allowed in the writable copy, and cleanup leaves nothing behind.

🤖 Generated with Claude Code

A workload run's working directory is now its context view (or writable copy), so pwd and ls show the project at once. When a revision has a workspace/ root (contextctl ctx pack), the view and the copy point at it, so files appear as in the source folder. The prompt names the session directory as scratch space for read-only runs. Docs and mocactl hints use contextctl ctx pack.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Jeremy Cohn <[email protected]>
@moonlight16
moonlight16 requested a review from pdettori as a code owner October 14, 2026 22:34
@pdettori pdettori added the ready-for-ai-review Request automated AI code review from clawgenti label Oct 14, 2026

@ingpaolodettori-dev ingpaolodettori-dev left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Starting a workload run in its context, and rooting the view at workspace/, is a clean change. It reuses the solve leaf's podCwd override. The [ ! -L ] guard keeps a bundled workspace link from re-rooting a view outside the cache. Cleanup and the sweep are unaffected, because they never resolve the link target. The worker creates the scratch directory on every Exec (WorkspaceRunner.Run MkdirAll), so the note's podCwd always exists.

Blocking: the check job (Test step) is red on this head. Main is green at the base and after it. The new real-shell populate test stubs sha256sum with a function that doesn't read stdin, which races printf into SIGPIPE under pipefail. That is the likely cause; see the inline comment. Please fix it and re-run CI.

Non-blocking: sibling bundle roots are hidden when workspace/ exists, the docs/hints depend on the unmerged rossoctl/context-service#56, and the scratch path wording is container-tier only.

Author: moonlight16 (MEMBER — maintainer)
Areas reviewed: TypeScript (harness overlay scripts, prompt leaf), tests, Docs, mocactl CLI text
Agent/IDE config (.claude/.vscode): none
Commits: 1 commit, all signed-off: yes
CI status: failing (check → Test step); all other checks pass

Comment thread harness/test/context-overlay.test.ts Outdated
// No flock(1) on macOS, and its sha256sum lacks --status; neither is under test here.
execFileSync('bash', [
'-c',
'flock() { :; }\nsha256sum() { :; }\n' +

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

must-fix — this stub makes the test flaky, and it is the most likely cause of the red check job (Test step) on this head.

The populate script runs printf '%s %s\n' … "$ARCHIVE" | sha256sum -c --status under set -euo pipefail. sha256sum() { :; } exits without reading stdin. When it exits before printf writes, printf gets SIGPIPE (exit 141), pipefail makes the pipeline fail, set -e aborts the script, and execFileSync throws. The same pipeline on GNU bash 5.2 failed 23 of 300 runs here.

Main is green before and after this PR's base, and every other ci.yml run today passed. The 29 tests in the two changed files also passed once in an isolated rerun, which is what you'd expect from an intermittent failure.

Suggested fix: drain stdin in the stub:

'flock() { :; }\nsha256sum() { cat >/dev/null; }\n' +

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 367474a: the stub now drains stdin (sha256sum() { cat >/dev/null; }). That test passed 25 runs in a row locally.

Comment thread harness/src/context-overlay.ts Outdated
* the cache.
*/
const VIEW_SOURCE =
'SRC="$CACHE"; if [ -d "$CACHE/workspace" ] && [ ! -L "$CACHE/workspace" ]; then SRC="$CACHE/workspace"; fi';

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion — when a revision has workspace/ and other top-level roots, the view now hides those roots. The agent can no longer reach the revision root at all: the prompt names only the view, and the view is cache/<rev>/workspace.

rossoctl/context-service#56 documents bundle content under harnesses/, memory/, knowledge/, artifacts/, or workspace/. ctx pack writes only workspace/ (plus manifest/checksums), but a bundle that mixes workspace/ with memory/ or knowledge/ would silently lose them. Options:

  • re-root only when workspace/ is the only content root, or
  • when siblings exist, add the revision root's path to the prompt note.

At minimum, the "Runs" docs should say that a revision's other roots aren't visible when it has workspace/.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 367474a: the view re-roots at workspace/ only when it is the revision's only content root. With harnesses/, memory/, knowledge/ or artifacts/ present, the view is the whole revision, so nothing is hidden. Added a real-shell test for the mixed case and documented it under Runs.

Comment thread docs/context-service.md Outdated
`contextctl ctx pack` puts a directory's files, the view shows that directory, so `src/` sits at the
root of the working directory. Otherwise the view shows the whole revision. Only a real directory
counts: a `workspace` link in the bundle is ignored. The prompt tells the agent its working
directory and, for a read-only run, that the session's own directory, `/workspace/<session>`, is

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit — /workspace/<session> is the scratch directory only on container workers that advertise workspace-subdir (sessionPodCwd, select-sandbox.ts:398). The microVM tier and older workers keep podCwd at /workspace, so there the note points at /workspace. The code is right, since the note uses the lease's actual podCwd. Consider "the session's own working directory (/workspace/<session> on container workers)" here and in packages/mocactl/README.md:188.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 367474a: "the session's own working directory (/workspace/<session> on container workers)" in both docs.

Comment thread packages/mocactl/src/workloads.ts Outdated
} catch {
io.err(
`--context ${opts.contextPath} does not exist (build one with \`contextctl ctx export\`)`,
`--context ${opts.contextPath} does not exist (build one with \`contextctl ctx pack DIR --type workspace -o FILE\`)`,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion — this hint and the docs (README.md:177/185, docs/context-service.md:34-36) now point users only at contextctl ctx pack, which exists only in the still-open rossoctl/context-service#56. A Context Service without #56 also rejects bundles containing workspace/. Until #56 merges and ships, a user following these instructions has no command that works.

Either merge after #56 ships, or keep ctx export as the fallback here. Also, "coming in a Context Service PR" should link rossoctl/context-service#56 directly in both docs. Minor: --type workspace is #56's default and only accepted value, so the hint could drop it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 367474a: both docs link rossoctl/context-service#56 directly, and --type workspace is dropped from the hint and docs. I'll merge this after #56 ships.

- Drain stdin in the populate test's sha256sum stub, so printf never hits SIGPIPE under pipefail (the flaky check job).
- Root the view at workspace/ only when it is the revision's only content root, so harnesses/, memory/, knowledge/ and artifacts/ are never hidden.
- Describe the scratch directory as the session's own working directory (/workspace/<session> on container workers).
- Link rossoctl/context-service#56 for ctx pack and drop the redundant --type workspace.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Jeremy Cohn <[email protected]>

@ingpaolodettori-dev ingpaolodettori-dev left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All four items from the b707c71 review are fixed in 367474a, and CI is green on this head, including check.

  • must-fix (flaky test): the sha256sum stub now drains stdin (cat >/dev/null), so printf can no longer hit SIGPIPE under pipefail. check passes.
  • sibling roots hidden: VIEW_SOURCE now re-roots at workspace/ only when none of harnesses/, memory/, knowledge/ or artifacts/ exist. This one string still drives acquire (hit path), populate and writable, so the paths can't drift apart. A new real-shell test covers a mixed bundle on both the read-only and writable paths, plus cleanup. The [ ! -L ] guard is unchanged. [ ! -e ] follows links, so a dangling memory link still re-roots at workspace/. That's harmless because nothing escapes the cache.
  • scratch wording: both docs now say "(/workspace/<session> on container workers)".
  • context-service#56: linked from both docs, and --type workspace is dropped. #56 merged at 2026-10-15 18:28 UTC, but context-service's latest release is still v0.1.0 (2026-09-16). The author said they'd merge after #56 ships, so that's a merge-timing call, not a review blocker.

Base 324e202 is behind main. Since then, main only touched harness/src/run-leaf.ts (leafTurnConfig in runPromptLeaf, right next to this PR's contextNote line). mergeable_state is blocked (reviews), not dirty, so it merges cleanly.

Author: moonlight16 (MEMBER — maintainer)
Areas reviewed: TypeScript (harness overlay script), tests, Docs, mocactl CLI text
Agent/IDE config (.claude/.vscode): none
Commits: 2 commits, all signed-off: yes
CI status: passing (all 15 checks)

Comment thread packages/mocactl/README.md Outdated
`ctx pack` puts the directory's files under the bundle's `workspace/` directory. It needs a Context
Service with [rossoctl/context-service#56](https://github.com/rossoctl/context-service/pull/56) (workspace bundles). A run starts in its context: the agent's working directory shows the
bundle's `workspace/` directory (`src/`, not `workspace/src/`), or the whole bundle when it has
other content too. A read-only run gets the session's own working directory (`/workspace/<session>`

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: "or the whole bundle when it has other content too" no longer covers a bundle without a workspace/ directory, which also shows the whole bundle. Suggest: "or the whole bundle when it has no workspace/ directory or has other content too".

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 74f0edb, and rewrapped the paragraph.

…l#534 review)

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Jeremy Cohn <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-ai-review Request automated AI code review from clawgenti

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No way to seed sandbox files before a leaf starts running

3 participants