Skip to content

pr-sandbox: tooling for stale PRs (make pr-merge, pr-push, DEPS=merge-base) - #683

Open
seperman wants to merge 2 commits into
devfrom
pr-sandbox-deps-from-merge-base
Open

seperman wants to merge 2 commits into
devfrom
pr-sandbox-deps-from-merge-base

Conversation

@seperman

@seperman seperman commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Problem

Old PRs (e.g. #618) can't be tested in the sandbox: their deepdiff/ still imports cachebox, which #681 dropped, and they conflict with dev. Their contributors won't rebase after this long.

make pr-merge PR=<N>: merge dev into the PR and test that

Six numbered steps, each saying what it does and what it needs from you:

  1. Fetch into refs/pr-sandbox/ (no checkout).
  2. Merge in memory with git merge-tree. None of the PR's files ever land in a working tree. It's a merge rather than a rebase, so the contributor's commits stay as they are and the result can be pushed to their branch as a fast-forward.
  3. Resolve conflicts with a locked-down agent. Only copies of the conflicted files are given to it, renamed to conflicts/NN.txt so they can't be loaded as CLAUDE.md/.claude config, plus each side's diff. It runs as claude -p --restricted --tools Read,Edit,Write,Glob,Grep --strict-mcp-config: no shell, web or MCP connectors, and user/project settings are ignored. The merge-guard.py hook confines reads to the scratch dir and writes to conflicts/* and notes.md. Before using the result, merge-pr.py checks the session's reported tools, MCP servers and mode, and that the guard saw every tool call. Otherwise it stops.
  4. Review. Each conflict is shown as PR side / dev side / resolution, with the agent's notes. Flagged: leftover markers, edits outside conflict blocks, and UNCERTAIN:/SUSPICIOUS: notes. Choices: accept, edit ($EDITOR, vim modelines off), diff, or quit. Nothing is committed before you accept.
  5. Commit via commit-tree to refs/pr-sandbox/<N>-merge (PR head is the first parent). It's reused on later runs until either side moves.
  6. Sandbox it with sandbox-pr.sh --ref (new): the usual triage and confirmation, then the tests with the current uv.lock.

Then:

  • make pr-review also reads the conflict resolution (git show --cc) when the report is for a merge. report/source.txt records what was tested.
  • make pr-push pushes the merge to the PR branch after asking. If maintainers can't push there, it offers to open a new PR instead.

Options: AGENT=0 (resolve in the editor), REDO=1, COMMIT=<sha> (for conflicts it can't handle, such as rename/delete or binary; it prints worktree instructions for those). A uv.lock conflict takes dev's lockfile, with a warning.

DEPS=merge-base (first commit)

make pr-sandbox PR=<N> DEPS=merge-base tests a stale PR as written, using uv.lock/pyproject.toml from its merge-base with dev. That commit is still in our own history, never the PR's. Old lockfiles may need OPTS="--python 3.14".

Testing

None of these ran the PR's code:

  • Agent lockdown probe: the session reported exactly the 5 file tools, no MCP servers and dontAsk. It had no shell, the guard blocked a read of /etc/hostname, and every call was logged.
  • End to end on a throwaway copy of Add t1_name/t2_name to rename t1/t2 labels in tree view repr #618's refs (--no-test): the agent resolved all 4 conflicts in 71s ($0.42), and its resolutions match the manual ones. The commit's parents are the PR head and dev, no markers are left in the tree, model.py parses, and the diff against dev is exactly the PR's 8 files.
  • Other paths: clean merge, reusing an accepted merge, and the editor path (markers left → accept refused → quit → nothing committed).
  • Unit checks: guard hook decisions (10 cases) and conflict parsing/location.
  • sandbox-pr.sh --ref: accepts the merge and shows the triage, then stops at the confirmation prompt (no TTY).
  • Lint and types: flake8 (max line length 120) and pyright are clean on the new scripts.

Not tested:

  • the full make pr-merge PR=618 with the sandbox run
  • a real pr-push
  • pr-review's merge prompt
  • the zsh wrapper that switches users (I ran as ai_agent directly)

Old PRs carry a deepdiff/ tree that can still import dependencies the
current dev has dropped (e.g. cachebox), so their tests fail at import
in the sandbox, which installs from the current uv.lock.

- sandbox-pr.sh: --deps-from checkout|merge-base. With merge-base,
  uv.lock and pyproject.toml come from the merge-base of the PR with
  BASE. That commit is in BASE's history, so the lockfile is still the
  maintainer's, never the PR's.
- run-sandboxed.sh: --deps-dir DIR to take uv.lock/pyproject.toml from
  DIR; a hint to try an older --python when the install fails (old
  lockfiles may lack wheels for the default 3.15).
- Makefile: DEPS=merge-base shorthand. README: document both.
@codecov

codecov Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.22%. Comparing base (f9affc5) to head (9def012).

Additional details and impacted files
@@           Coverage Diff           @@
##              dev     #683   +/-   ##
=======================================
  Coverage   95.22%   95.22%           
=======================================
  Files          19       19           
  Lines        5070     5070           
=======================================
  Hits         4828     4828           
  Misses        242      242           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

For PRs whose contributors won't rebase: merge BASE into the PR, resolve
conflicts with a locked-down Claude agent, let the maintainer review,
then sandbox-test the merge with the current dependencies.

- merge-pr.py merge: fetches, merges in memory with `git merge-tree`
  (nothing is checked out), copies only the conflicted files (renamed
  to conflicts/NN.txt) plus each side's diff to a scratch dir, and runs
  `claude -p --restricted --tools Read,Edit,Write,Glob,Grep
  --strict-mcp-config` there. merge-pr.py verifies the session's tools,
  MCP servers and permission mode, and that the guard hook saw every
  tool call, before using the result. The review shows each conflict's
  PR side, base side and resolution, and flags leftover markers, edits
  outside conflict blocks and UNCERTAIN/SUSPICIOUS notes. The accepted
  merge is written with commit-tree to refs/pr-sandbox/<N>-merge (PR
  head first parent), then tested via sandbox-pr.sh --ref.
- merge-pr.py push: fast-forward push of the merge to the PR branch
  after confirmation, or a new PR when maintainers can't push there.
- merge-guard.py: PreToolUse hook confining the agent's reads to the
  scratch dir and its writes to conflicts/* and notes.md.
- sandbox-pr.sh --ref: test a merge commit (validated against the PR
  head and BASE); the report records what was tested (source.txt), so
  `make pr-review` adds the conflict resolution to its prompt.
- Makefile, README: pr-merge (AGENT=0, REDO=1, COMMIT=<sha>), pr-push.
@seperman seperman changed the title pr-sandbox: install deps from the PR's merge-base for stale PRs pr-sandbox: tooling for stale PRs (make pr-merge, pr-push, DEPS=merge-base) Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant