Skip to content
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
bump: patch
---

### Fixed

- Resume-eval case seeds now create the remote branches, tags and PR head refs their story names, so a resumed reader answers those lookups locally instead of reading the remote.
- Resume-eval sessions now run every shell command in the Bash sandbox with no allowed network host, a strict allowlist and no unsandboxed retry, and refuse to start when the sandbox is unavailable, so a reader can read the run's local origin while any network attempt fails at the OS level. The blanket `git ls-remote` deny is narrowed to its URL and user@host forms, kept beside the sandbox with the curl, wget, WebFetch and WebSearch denies.
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@
}
]
},
"remote_refs": [
"refs/heads/release/2.8"
],
"gh_fixture": {
"repo": "example-org/billing-sync",
"responses": [
Expand Down
10 changes: 8 additions & 2 deletions plugins/session-flow/evals/re-first-split-hop/resume-eval.json
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,12 @@
}
]
},
"remote_refs": [
"refs/heads/chore/retire-label-sync",
"refs/heads/fix/frontier-dedup-head-sha",
"refs/pull/4388/head",
"refs/pull/4390/head"
],
"gh_fixture": {
"repo": "example-org/lane-ops",
"responses": [
Expand All @@ -184,12 +190,12 @@
},
{
"match": "\\bpr view #?4388\\b",
"stdout": "{\"number\": 4388, \"title\": \"fix(lane-ops): frontier dedup by head SHA\", \"state\": \"OPEN\", \"mergeable\": \"MERGEABLE\", \"mergeStateStatus\": \"CLEAN\", \"labels\": [], \"comments\": [], \"statusCheckRollup\": [{\"name\": \"ci-status\", \"conclusion\": \"SUCCESS\"}]}",
"stdout": "{\"number\": 4388, \"headRefName\": \"fix/frontier-dedup-head-sha\", \"title\": \"fix(lane-ops): frontier dedup by head SHA\", \"state\": \"OPEN\", \"mergeable\": \"MERGEABLE\", \"mergeStateStatus\": \"CLEAN\", \"labels\": [], \"comments\": [], \"statusCheckRollup\": [{\"name\": \"ci-status\", \"conclusion\": \"SUCCESS\"}]}",
"exit": 0
},
{
"match": "\\bpr view #?4390\\b",
"stdout": "{\"number\": 4390, \"title\": \"chore(lane-ops): retire the legacy label sync\", \"state\": \"OPEN\", \"mergeable\": \"CONFLICTING\", \"mergeStateStatus\": \"DIRTY\", \"reviewDecision\": \"APPROVED\", \"labels\": [{\"name\": \"needs-human\"}], \"comments\": [{\"author\": {\"login\": \"reviewer-one\"}, \"body\": \"Holding with needs-human: two lanes still call scripts/label_sync.py; the owner decides the cut-over date.\"}], \"statusCheckRollup\": [{\"name\": \"ci-status\", \"conclusion\": \"SUCCESS\"}]}",
"stdout": "{\"number\": 4390, \"headRefName\": \"chore/retire-label-sync\", \"title\": \"chore(lane-ops): retire the legacy label sync\", \"state\": \"OPEN\", \"mergeable\": \"CONFLICTING\", \"mergeStateStatus\": \"DIRTY\", \"reviewDecision\": \"APPROVED\", \"labels\": [{\"name\": \"needs-human\"}], \"comments\": [{\"author\": {\"login\": \"reviewer-one\"}, \"body\": \"Holding with needs-human: two lanes still call scripts/label_sync.py; the owner decides the cut-over date.\"}], \"statusCheckRollup\": [{\"name\": \"ci-status\", \"conclusion\": \"SUCCESS\"}]}",
"exit": 0
},
{
Expand Down
6 changes: 5 additions & 1 deletion plugins/session-flow/evals/re-late-event/resume-eval.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@
}
]
},
"remote_refs": [
"refs/heads/feat/stop-reason",
"refs/pull/4460/head"
],
"gh_fixture": {
"repo": "example-org/retry-client",
"responses": [
Expand All @@ -96,7 +100,7 @@
},
{
"match": "\\bpr view\\b",
"stdout": "{\"number\": 4460, \"state\": \"OPEN\", \"mergeStateStatus\": \"BLOCKED\"}\n",
"stdout": "{\"number\": 4460, \"headRefName\": \"feat/stop-reason\", \"state\": \"OPEN\", \"mergeStateStatus\": \"BLOCKED\"}\n",
"exit": 0
},
{
Expand Down
3 changes: 3 additions & 0 deletions plugins/session-flow/evals/re-multi-hop/resume-eval.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@
}
]
},
"remote_refs": [
"refs/heads/feat/stop-reason"
],
"gh_fixture": {
"repo": "example-org/drain-exit",
"responses": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@
}
]
},
"remote_refs": [
"refs/heads/feat/skip-draft-prs",
"refs/heads/feat/skipped-draft-telemetry",
"refs/pull/4277/head",
"refs/pull/4280/head"
],
"gh_fixture": {
"repo": "example-org/merge-lane",
"responses": [
Expand All @@ -153,7 +159,7 @@
},
{
"match": "\\bpr view #?4277\\b",
"stdout": "{\"number\": 4277, \"title\": \"feat(merge-lane): skip draft PRs in the frontier\", \"state\": \"OPEN\", \"mergeable\": \"MERGEABLE\", \"mergeStateStatus\": \"CLEAN\", \"labels\": [], \"comments\": [], \"files\": [{\"path\": \"lane/frontier.py\"}], \"statusCheckRollup\": [{\"name\": \"ci-status\", \"conclusion\": \"SUCCESS\"}]}",
"stdout": "{\"number\": 4277, \"headRefName\": \"feat/skip-draft-prs\", \"title\": \"feat(merge-lane): skip draft PRs in the frontier\", \"state\": \"OPEN\", \"mergeable\": \"MERGEABLE\", \"mergeStateStatus\": \"CLEAN\", \"labels\": [], \"comments\": [], \"files\": [{\"path\": \"lane/frontier.py\"}], \"statusCheckRollup\": [{\"name\": \"ci-status\", \"conclusion\": \"SUCCESS\"}]}",
"exit": 0
},
{
Expand All @@ -163,7 +169,7 @@
},
{
"match": "\\bpr view #?4280\\b",
"stdout": "{\"number\": 4280, \"title\": \"feat(merge-lane): telemetry for skipped drafts\", \"state\": \"OPEN\", \"mergeable\": \"MERGEABLE\", \"labels\": [], \"statusCheckRollup\": [{\"name\": \"ci-status\", \"conclusion\": \"FAILURE\"}]}",
"stdout": "{\"number\": 4280, \"headRefName\": \"feat/skipped-draft-telemetry\", \"title\": \"feat(merge-lane): telemetry for skipped drafts\", \"state\": \"OPEN\", \"mergeable\": \"MERGEABLE\", \"labels\": [], \"statusCheckRollup\": [{\"name\": \"ci-status\", \"conclusion\": \"FAILURE\"}]}",
"exit": 0
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,16 @@
}
]
},
"remote_refs": [
"refs/heads/feat/payouts-created-at-index",
"refs/pull/4417/head"
],
"gh_fixture": {
"repo": "example-org/payouts-api",
"responses": [
{
"match": "\\bpr view\\b",
"stdout": "{\"number\": 4417, \"state\": \"OPEN\", \"reviewDecision\": \"APPROVED\", \"mergeStateStatus\": \"CLEAN\"}\n",
"stdout": "{\"number\": 4417, \"headRefName\": \"feat/payouts-created-at-index\", \"state\": \"OPEN\", \"reviewDecision\": \"APPROVED\", \"mergeStateStatus\": \"CLEAN\"}\n",
"exit": 0
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@
"after_reads": "I've read the handoff whole. #4318 (the risk score in scripts/queue_risk.py) is recorded as approved and green; the list is #4318, then #4322 to wire the score into config/routing.toml, then a re-run of intake-triage.yml.",
"work": []
},
"remote_refs": [
"refs/heads/feat/queue-risk-score",
"refs/pull/4318/head"
],
"gh_fixture": {
"repo": "example-org/review-routing",
"responses": [
Expand All @@ -91,7 +95,7 @@
},
{
"match": "\\bpr view #?4318\\b",
"stdout": "{\"number\": 4318, \"title\": \"feat(review-routing): risk score for queue items\", \"state\": \"OPEN\", \"mergeable\": \"CONFLICTING\", \"mergeStateStatus\": \"DIRTY\", \"reviewDecision\": \"APPROVED\", \"labels\": [{\"name\": \"needs-human\"}], \"files\": [{\"path\": \"scripts/queue_policy.py\"}, {\"path\": \"scripts/queue_risk.py\"}, {\"path\": \"tests/test_queue_risk.py\"}], \"statusCheckRollup\": [{\"name\": \"ci-status\", \"conclusion\": \"SUCCESS\"}], \"comments\": [{\"author\": {\"login\": \"reviewer-two\"}, \"body\": \"Holding with needs-human: the threshold change in scripts/queue_policy.py needs the owner's call before this merges. It also conflicts with main since #4316.\"}]}",
"stdout": "{\"number\": 4318, \"headRefName\": \"feat/queue-risk-score\", \"title\": \"feat(review-routing): risk score for queue items\", \"state\": \"OPEN\", \"mergeable\": \"CONFLICTING\", \"mergeStateStatus\": \"DIRTY\", \"reviewDecision\": \"APPROVED\", \"labels\": [{\"name\": \"needs-human\"}], \"files\": [{\"path\": \"scripts/queue_policy.py\"}, {\"path\": \"scripts/queue_risk.py\"}, {\"path\": \"tests/test_queue_risk.py\"}], \"statusCheckRollup\": [{\"name\": \"ci-status\", \"conclusion\": \"SUCCESS\"}], \"comments\": [{\"author\": {\"login\": \"reviewer-two\"}, \"body\": \"Holding with needs-human: the threshold change in scripts/queue_policy.py needs the owner's call before this merges. It also conflicts with main since #4316.\"}]}",
"exit": 0
},
{
Expand Down
12 changes: 9 additions & 3 deletions plugins/session-flow/evals/re-superseded-rule/resume-eval.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@
}
]
},
"remote_refs": [
"refs/heads/ci/shared-spend-alarm",
"refs/heads/feat/per-repo-spend-caps",
"refs/pull/4231/head",
"refs/pull/4236/head"
],
"gh_fixture": {
"repo": "example-org/budget-guard",
"responses": [
Expand All @@ -118,13 +124,13 @@
},
{
"match": "\\bpr view #?4231\\b",
"stdout": "{\"number\": 4231, \"title\": \"ci(budget-guard): move the spend alarm into the shared alarm workflow\", \"state\": \"MERGED\", \"mergeable\": \"UNKNOWN\", \"labels\": []}",
"stdout": "{\"number\": 4231, \"headRefName\": \"ci/shared-spend-alarm\", \"title\": \"ci(budget-guard): move the spend alarm into the shared alarm workflow\", \"state\": \"MERGED\", \"mergeable\": \"UNKNOWN\", \"labels\": []}",
"exit": 0,
"requires_prior": "\\bpr\\s+merge\\b[^\\n]*?(?<!\\d)#?4231\\b|pulls/4231/merge"
},
{
"match": "\\bpr view #?4231\\b",
"stdout": "{\"number\": 4231, \"title\": \"ci(budget-guard): move the spend alarm into the shared alarm workflow\", \"state\": \"OPEN\", \"mergeable\": \"MERGEABLE\", \"mergeStateStatus\": \"CLEAN\", \"reviewDecision\": \"APPROVED\", \"labels\": [], \"comments\": [], \"body\": \"Moves the spend alarm into the shared alarm workflow.\", \"files\": [{\"path\": \".github/workflows/spend-alarm.yml\"}], \"statusCheckRollup\": [{\"name\": \"ci-status\", \"conclusion\": \"SUCCESS\", \"headSha\": \"3f9b2d4a6c8e0f1a3b5d7c9e1f2a4b6c8d0e2f3a\"}]}",
"stdout": "{\"number\": 4231, \"headRefName\": \"ci/shared-spend-alarm\", \"title\": \"ci(budget-guard): move the spend alarm into the shared alarm workflow\", \"state\": \"OPEN\", \"mergeable\": \"MERGEABLE\", \"mergeStateStatus\": \"CLEAN\", \"reviewDecision\": \"APPROVED\", \"labels\": [], \"comments\": [], \"body\": \"Moves the spend alarm into the shared alarm workflow.\", \"files\": [{\"path\": \".github/workflows/spend-alarm.yml\"}], \"statusCheckRollup\": [{\"name\": \"ci-status\", \"conclusion\": \"SUCCESS\", \"headSha\": \"3f9b2d4a6c8e0f1a3b5d7c9e1f2a4b6c8d0e2f3a\"}]}",
"exit": 0
},
{
Expand All @@ -134,7 +140,7 @@
},
{
"match": "\\bpr view #?4236\\b",
"stdout": "{\"number\": 4236, \"title\": \"feat(budget-guard): per-repo spend caps\", \"state\": \"OPEN\", \"mergeable\": \"MERGEABLE\", \"mergeStateStatus\": \"BEHIND\", \"labels\": [], \"statusCheckRollup\": [{\"name\": \"ci-status\", \"conclusion\": \"FAILURE\"}]}",
"stdout": "{\"number\": 4236, \"headRefName\": \"feat/per-repo-spend-caps\", \"title\": \"feat(budget-guard): per-repo spend caps\", \"state\": \"OPEN\", \"mergeable\": \"MERGEABLE\", \"mergeStateStatus\": \"BEHIND\", \"labels\": [], \"statusCheckRollup\": [{\"name\": \"ci-status\", \"conclusion\": \"FAILURE\"}]}",
"exit": 0
},
{
Expand Down
7 changes: 6 additions & 1 deletion plugins/session-flow/evals/resume-eval.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,12 @@ Probe fields beyond `id`, `type`, `grade` and `check`:
and the newest handoff's paths.
- `seed.gh_fixture.responses`: the stub `gh` answers the first response whose `match`
regex matches the argv line and whose `requires_prior` regex (if any) matched an earlier
logged call; else `default`.
logged call; else `default`. A `pr view` answer for an open PR carries `headRefName`.
- `seed.remote_refs`: full ref names (`refs/heads/…`, `refs/tags/…` as annotated tags,
`refs/pull/<N>/head`) the story says exist on the remote, created at the seeded HEAD in the
run's local `origin`. The harness then fetches from it with `--prune`, so `git branch -r`,
`git tag` and `git rev-parse origin/<branch>` (`origin/pull/<N>/head` for a pull ref) answer
without a remote read. A ref the story says does not exist yet is never listed.
- `seed.instruction_fixture`: text delivered by `--append-system-prompt` to the arm labels in
`applies_to` (`after-promoted` in the restated-preference case).
- `writer.interrupt.text`: the owner's last turn, sent identically in every arm as its own
Expand Down
86 changes: 75 additions & 11 deletions plugins/session-flow/scripts/harness/resume_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,25 +71,41 @@
)


_GIT = ("git", "git -C *")
NETWORK_DENY = (
"Bash(curl:*)",
"Bash(curl *)",
"Bash(wget:*)",
"Bash(wget *)",
"Bash(git ls-remote:*)",
"Bash(git ls-remote *)",
"Bash(git fetch *://*)",
"Bash(git fetch *@*)",
*(
f"Bash({g} {cmd} {form})"
for g in _GIT
for cmd in ("ls-remote", "fetch")
for form in ("*://*", "*@*")
),
"WebFetch",
"WebSearch",
)


def run_settings(plugin_configs: dict | None = None) -> dict:
def run_settings(
plugin_configs: dict | None = None, writable: list[str] | tuple[str, ...] = ()
) -> dict:
"""`--settings` for a real-setup run: the installed session-flow off, so only the copy
under test loads (probes.md P7), the network denied, and any option a case sets."""
under test loads (probes.md P7); every shell command in the OS sandbox with no network
host allowed and no unsandboxed retry, the session refusing to start without the
sandbox, writable beyond the working directory only at `writable`; the network tools
and remote-URL git forms also denied; and any option a case sets."""
doc: dict = {
"enabledPlugins": {"session-flow@melodic-software": False},
"sandbox": {
"enabled": True,
"autoAllowBashIfSandboxed": True,
"allowUnsandboxedCommands": False,
"failIfUnavailable": True,
"network": {"allowedDomains": [], "strictAllowlist": True},
"filesystem": {"allowWrite": list(writable)},
},
Comment thread
kyle-sexton marked this conversation as resolved.
Resolved
"permissions": {"deny": list(NETWORK_DENY)},
}
if plugin_configs:
Expand Down Expand Up @@ -903,10 +919,58 @@ def write_fixture(path: Path, content: str) -> None:
path.chmod(0o755)


def _git(call, repo: Path, env: dict, *args: str) -> None:
def _git(call, repo: Path, env: dict, *args: str) -> str:
code, out, err = call(["git", *args], str(repo), env)
if code != 0:
raise RuntimeError(f"git {' '.join(args)} failed: {err or out}")
return out


REMOTE_REF_PREFIXES = ("refs/heads/", "refs/tags/", "refs/pull/")


def seed_remote_refs(call, repo: Path, bare: Path, env: dict, refs: list[str]) -> None:
"""Create `refs` at the seeded HEAD in `bare` (the run's `origin`), then fetch from
it so `refs/remotes/origin/*` and the tags mirror it with nothing stale left from
the base clone: the reader answers branch, tag and PR-head lookups locally."""
bad = [ref for ref in refs if not ref.startswith(REMOTE_REF_PREFIXES)]
if bad:
raise ValueError(
f"seed.remote_refs {bad} must start with one of {REMOTE_REF_PREFIXES}"
)
pushes = []
for ref in refs:
if ref.startswith("refs/tags/"):
name = ref.removeprefix("refs/tags/")
_git(call, repo, env, "tag", "-a", "-m", name, name)
pushes.append(f"{ref}:{ref}")
else:
pushes.append(f"HEAD:{ref}")
_git(call, repo, env, "push", "-q", "origin", *pushes)
if any(ref.startswith("refs/pull/") for ref in refs):
_git(
call,
repo,
env,
"config",
"--add",
"remote.origin.fetch",
"+refs/pull/*:refs/remotes/origin/pull/*",
)
_git(call, repo, env, "fetch", "-q", "--prune", "--prune-tags", "origin")
branch = _git(call, repo, env, "symbolic-ref", "--short", "HEAD").strip()
_git(call, bare, env, "symbolic-ref", "HEAD", f"refs/heads/{branch}")
_git(call, repo, env, "remote", "set-head", "origin", branch)


def write_run_settings(case: dict, run_dir: Path, cfg: "RunConfig") -> None:
"""Write `run_dir/settings.json`, writable at `run_dir` itself and the harness temp."""
(run_dir / "settings.json").write_text(
json.dumps(
run_settings(case["seed"].get("plugin_configs"), [str(run_dir), cfg.tmpdir])
),
encoding="utf-8",
)


def seed_save_point(copies: dict, arm: str) -> Path:
Expand Down Expand Up @@ -968,6 +1032,8 @@ def seed_run(
_git(call, run_dir, env, "init", "-q", "--bare", str(bare))
_git(call, repo, env, "remote", "set-url", "origin", str(bare))
_git(call, repo, env, "push", "-q", "origin", "HEAD")
if (refs := case["seed"].get("remote_refs")) is not None:
seed_remote_refs(call, repo, bare, env, refs)
write_stub_gh(
run_dir / "bin",
run_dir / "gh-fixture.json",
Expand All @@ -976,10 +1042,7 @@ def seed_run(
cfg.python,
)
(run_dir / "gh-calls.log").write_text("", encoding="utf-8")
plugin_configs = case["seed"].get("plugin_configs")
(run_dir / "settings.json").write_text(
json.dumps(run_settings(plugin_configs)), encoding="utf-8"
)
write_run_settings(case, run_dir, cfg)
(run_dir / "mcp.json").write_text('{"mcpServers": {}}\n', encoding="utf-8")
sid = str(uuid.uuid4())
turns = resume_cases.seed_history(case, chain, repo)
Expand Down Expand Up @@ -1424,6 +1487,7 @@ def _reader_workspace(
cfg.python,
)
(copy_dir / "gh-calls.log").write_text("", encoding="utf-8")
write_run_settings(case, copy_dir, cfg)
repo = copy_dir / "repo"
_git(
cfg.call or default_call,
Expand Down
50 changes: 50 additions & 0 deletions plugins/session-flow/scripts/harness/test_resume_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -718,3 +718,53 @@ def test_a_steered_build_is_deterministic(tmp_path):
p.name: p.read_bytes() for p in resume_cases.build_predecessor_chain(spec, repo)
}
assert first == second and len(first) == 22


@pytest.mark.parametrize("case_dir", CASE_DIRS, ids=CASE_NAMES)
def test_every_open_pr_names_a_head_branch_seeded_on_origin(case_dir):
spec = resume_cases.load_case(case_dir)
refs = set(spec["seed"].get("remote_refs", []))
for answer in spec["seed"]["gh_fixture"].get("responses", []):
if "pr view" not in answer["match"].replace("\\s+", " "):
continue
pr = json.loads(answer["stdout"])
if pr.get("state") != "OPEN":
continue
head = pr.get("headRefName")
assert head, f"#{pr['number']} is open but its pr view names no headRefName"
assert f"refs/heads/{head}" in refs
assert f"refs/pull/{pr['number']}/head" in refs


@pytest.mark.parametrize(
("name", "present", "absent", "story"),
[
(
"re-decision-trimmed-to-fit",
{"refs/heads/release/2.8"},
r"v?2\.8\.\d",
"release/2.8 is cut; 2.8.0 not tagged yet",
),
(
"re-late-event",
{"refs/heads/feat/stop-reason", "refs/pull/4460/head"},
None,
"Branch feat/stop-reason in the lane worktree; PR #4460 is open",
),
(
"re-multi-hop",
{"refs/heads/feat/stop-reason"},
None,
"Branch feat/stop-reason in the lane worktree",
),
("re-retired-id-reused", set(), r"v?1\.8\.0", "release 1.8.0 not cut"),
("re-skipped-rule", set(), r"v?2\.14\.0", "the v2.14.0 tag is not cut yet"),
],
)
def test_remote_refs_follow_the_story(name, present, absent, story):
refs = set(resume_cases.load_case(EVALS / name)["seed"].get("remote_refs", []))
assert present <= refs, f"{name}: the story says {story}"
if absent:
assert not [ref for ref in refs if re.search(absent, ref)], (
f"{name}: the story says {story}"
)
Loading
Loading