Skip to content

feat(harness): Extend config bundle to solve leaves - #468

Merged
evaline-ju merged 4 commits into
rossoctl:mainfrom
evaline-ju:leaf-bundle
Oct 9, 2026
Merged

evaline-ju merged 4 commits into
rossoctl:mainfrom
evaline-ju:leaf-bundle

Conversation

@evaline-ju

@evaline-ju evaline-ju commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A solve leaf now runs with the session's promoted config bundle in its sandbox. Before this, a session created with mocactl run --config <digest> applied the bundle to prompt turns but ran solve turns bare of the user's skills and CLAUDE.md. An empty-or-whitespace configRef on a solve request now fails loudly instead of being silently ignored (closes the solve half of #222). Sessions that don't set configRef see no change.

Rationale: B9 (#397) acceptance item 1 — "load the bundle for converge and solve." Reuses the shared attachPromotedConfig helper and session-bound configRef delivery that #458 (ADR-0038) landed. Unblocks "implementation subagents" (clone a repo + apply a fix under the user's promoted skills) that today run bare on the solve path.

Refs: #397, #458, #378

Assisted-By: Claude (Anthropic AI) [email protected]

Addresses part of #397

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Evaline Ju <[email protected]>
@pdettori pdettori added the ready-for-ai-review Request automated AI code review from clawgenti label Oct 9, 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.

Summary

This threads the promoted config bundle into realProduceSolve and adds the empty-configRef guard to runSolveLeaf. The guard and the plumbing are fine. Moving the heartbeat ahead of converge is a good change on its own. One blocking problem: on a solve leaf, the overlay's per-leaf link path is inside the solve worktree path. Because the attach now runs before converge, converge skips git worktree add, so every non-SWE-bench solve leaf that sets configRef runs in an empty, non-git directory and then fails at diff capture. Details are inline. CI is green because nothing exercises realProduceSolve with a configRef: the new tests stop at runSolveLeaf with a fake produceSolve, and the Kind smoke doesn't send one.

Author: evaline-ju (MEMBER — maintainer)
Areas reviewed: TypeScript (harness), tests
Agent/IDE config (.claude/.vscode): none
Commits: 1 commit, all signed-off: yes (subject uses the :sparkles: feat(...) emoji form, which is fine)
CI status: passing (branch is 24 commits behind main, no merge conflicts)

Comment thread harness/src/run-leaf.ts Resolved
Comment thread harness/src/run-leaf.ts Resolved
…e applying review fixes

Catches the branch up with 40 upstream commits (last fetched @22d891e) so the
review-fix commit lands on top of current main rather than requiring a rebase +
force-push.
evaline-ju added a commit to evaline-ju/moca that referenced this pull request Oct 9, 2026
…, overlay symlink excluded from patches

The attach-before-converge order in realProduceSolve collided with the worktree:
leafConfigDir(sid) = /workspace/leaves/<sid>/.sh-config is a child of
leafWorkspaceRef(sid) = /workspace/leaves/<sid>. buildLeafBindScript's `mkdir -p
"$(dirname "$LEAF")"` created the parent dir as a side effect, which made
buildConvergeScript's `[ -d "$LEAF" ] || git worktree add` skip the worktree —
so every non-swebench solve leaf with a configRef ran in an empty non-git
directory and then failed at captureWorkspaceDiff with `diff capture failed`.

Fixes applied:
- Reorder in realProduceSolve: heartbeat → converge → attach. Attach still
  happens before Pi session construction so a resolver/overlay throw fails
  the leaf before any tokens are spent.
- buildConvergeScript now appends `.sh-config` to the main repo's
  info/exclude (inside the flock, idempotent via `grep -qxF`). Without this,
  `git add -A` in buildDiffCaptureScript would stage the overlay symlink
  into every captured solve patch.
- buildSwebenchCleanupScript also removes /workspace/leaves/<sid> so the
  dir created by buildLeafBindScript's mkdir doesn't leak on the pooled
  sandbox after a swebench solve.
- Extract emptyConfigRefFailure helper used by both runSolveLeaf and
  runPromptLeaf, replacing the duplicated empty-string guard.
- runSolveLeaf's deps now use `{ produceSolve? } & ProduceSolveDeps`
  intersection to avoid repeating the field list.

Tests:
- New run-leaf-solve-produce.test.ts: observes transport.exec script
  sequence through a fully-mocked realProduceSolve and asserts converge
  runs before the resolver (the ordering invariant the reviewer pinned).
- converge.test.ts: pins the info/exclude line is written inside the
  flock, before worktree add, with an exact-full-line idempotence check.
- swebench-setup.test.ts: pins the cleanup script removes the leaves dir
  in a single rm -rf alongside co-/venv-.
- run-leaf-solve-promoted.test.ts and run-leaf-promoted.test.ts stay
  green under the shared helper.

Verified: 607/607 harness tests pass with Redis up, typecheck + prettier clean.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Evaline Ju <[email protected]>
@evaline-ju

Copy link
Copy Markdown
Contributor Author

Thanks for the careful review @ingpaolodettori-dev. Review-fix pass pushed in 2a7eb18 (on top of a merge from main so no force-push).

Must-fix — overlay/worktree collision: reordered realProduceSolve to heartbeat → converge → attach, and buildConvergeScript now appends .sh-config to the main repo's info/exclude inside the flock, idempotently. The attach still runs before Pi session construction so a resolver/overlay throw continues to fail-closed without spending tokens.

Smaller point — swebench orphan dir: buildSwebenchCleanupScript now rm -rfs /workspace/leaves/<sid> alongside the co-/venv- dirs so the overlay's mkdir doesn't leak.

Nit — DRY: runSolveLeaf's deps are now { produceSolve? } & ProduceSolveDeps, and both leaf kinds call a shared emptyConfigRefFailure helper instead of each carrying a verbatim copy of the empty-string guard.

Tests you asked for: new run-leaf-solve-produce.test.ts runs realProduceSolve with Pi/session-backend mocked out and pins the converge-before-resolver invariant by observing the transport-exec sequence. converge.test.ts pins the info/exclude write (inside flock, before worktree add, idempotent). swebench-setup.test.ts pins the cleanup script removes the leaves dir in a single rm -rf.

607/607 harness tests pass with Redis up; tsc --noEmit clean; prettier clean.

…atches

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Evaline Ju <[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.

Follow-up review @ 62349c6

All items from our review at 05baa1b are addressed, and I checked each fix against the code:

  • must-fix (overlay link vs. solve worktree): fixed. realProduceSolve now runs heartbeat → converge → attach, so worktree add is no longer skipped, and the attach still runs before any model spend. buildConvergeScript adds .sh-config to the common-dir info/exclude (under the flock, exact-line guard), so git add -A in diff capture no longer stages the symlink.
  • SWE-bench orphan dir: fixed. The cleanup script now also removes /workspace/leaves/<sid>.
  • nit (deps type / duplicated guard): fixed with { produceSolve? } & ProduceSolveDeps and the shared emptyConfigRefFailure.

I also checked the origin/main merge (e3e60d0) with git show --remerge-diff, and it is clean. CI is fully green on this head.

Approving. I left two non-blocking test suggestions inline: the no-configRef ordering test can't fail as written, and the exclude behavior is only pinned by substring checks. There are also two small nits.

Author: evaline-ju (MEMBER — maintainer)
Areas reviewed: TypeScript (harness), shell scripts embedded in TS, tests
Agent/IDE config (.claude/.vscode): none
Commits: 3 (incl. 1 merge), non-merge commits signed-off: yes
CI status: passing

execMock.mockReset().mockImplementation(async () => {
// Any exec after convergeWorkspace (session.prompt → captureWorkspaceDiff → cleanup) would
// keep the test running against the real Pi stack; throw once converge returns to halt.
throw new Error('halt after converge');

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 test can't fail as written. execMock throws on every exec, including the converge script, so convergeWorkspace throws before realProduceSolve reaches the configRef check. The resolver is never called whether or not configRef is set, so deleting or inverting the env.configRef !== undefined guard would still pass. Return the leaf path for the converge script (as the first test does), and halt later instead, e.g. throw on the next exec or from a mocked createAgentSession. Then not.toHaveBeenCalled() actually exercises the opt-in branch.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks — fixed. Convergescript now returns the leaf path like the ordering test above; the halt moved into createAgentSession.mockImplementationOnce, which runs after the configRef branch, so deleting the opt-in guard would now fail the test. Added a sanity expect(scripts).toContain(expectedConverge) so a regression in the test's own ordering surfaces explicitly.

const evil = buildConvergeScript("https://x/r.git'; rm -rf /; '", 'main', 'leaf-1');
expect(evil).toContain(`'https://x/r.git'\\''; rm -rf /; '\\'''`);
});
it('appends `.sh-config` to the repo info/exclude so the promoted-config overlay symlink is ignored by `git add -A`', () => {

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: These two tests pin the exclude line as substrings, but not the property we care about. config-overlay.test.ts already runs the real scripts under bash with /workspace rewritten to a tmp root, so the same pattern could prove it end to end. Converge a local file:// repo → run buildLeafBindScript → write a file in the leaf → run buildDiffCaptureScript. Then assert that the leaf is a git worktree and that the patch contains the edit and no .sh-config. That would have caught the original collision, and it would catch a regression in either ordering or exclusion.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Took your suggestion. New describe block at the bottom of the file: converge a local file:// repo → bind the overlay → write a tracked-file edit → diff capture. Asserts the leaf is a git worktree, the patch contains the edit, and the patch does NOT contain .sh-config. Reuses the tmp-root + flock-stub + bash execFileSync pattern from config-overlay.test.ts. Verified: fails if the .sh-config exclude line is removed from buildConvergeScript.

Comment thread harness/src/converge.ts Outdated
// Ignore an untracked `.sh-config` under any worktree: on a solve leaf with a configRef the
// promoted-config overlay symlinks `.sh-config` into the leaf dir, and without this
// `git add -A` in buildDiffCaptureScript would stage that symlink into every captured patch.
// No-op when the entry is already present; a no-op when the overlay didn't run.

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: The comment says this is "a no-op when the overlay didn't run", but the entry is written on every converge, whether or not there's a configRef. That's harmless, but the comment should say so. Optional hardening: mkdir -p "$REPO/.git/info" before the append. git init normally creates the directory from templates, but without it, echo >> fails under set -eu and takes down every converge, configRef or not.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done. Comment rewritten (the entry is harmless-always-written, not conditional). Added mkdir -p "$REPO/.git/info" before the append — thanks for catching that set -eu + a missing templates dir would have taken down every converge.

Comment thread harness/src/swebench-setup.ts Outdated
return [
`set -u`,
`rm -rf ${sq(swebenchCheckoutDir(sessionId))} ${sq(swebenchVenvDir(sessionId))}`,
`rm -rf ${sq(swebenchCheckoutDir(sessionId))} ${sq(swebenchVenvDir(sessionId))} ${sq(`/workspace/leaves/${sessionId}`)}`,

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/leaves/${sessionId} re-spells leafWorkspaceRef(sessionId) from converge.ts (and dirname(leafConfigDir(sid))). Importing the helper would keep the three paths from drifting apart.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done. Imported leafWorkspaceRef from ./converge.js and used it in the cleanup script.

@evaline-ju
evaline-ju merged commit c64b2d7 into rossoctl:main Oct 9, 2026
14 checks passed
@evaline-ju
evaline-ju deleted the leaf-bundle branch October 9, 2026 19:52
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.

3 participants