Skip to content

feat: make the PR checkout opt-in for ecr attach - #117

Draft
Kudo wants to merge 3 commits into
mainfrom
attach-opt-in-checkout
Draft

Kudo wants to merge 3 commits into
mainfrom
attach-opt-in-checkout

Conversation

@Kudo

@Kudo Kudo commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

One-sentence pitch

ecr attach no longer needs the PR head in your checkout. The PR code goes on disk only with --checkout.

Why

A pull request can come from a fork. Attach used to stop unless your checkout was at the reviewed commit, so you had to check out untrusted code before you could open a stored review. Putting that code on disk should be something you ask for.

--sha was also broken. It changed which archive the lookup found, but the SHA check still compared against your HEAD, so --sha <other> always failed on a different branch.

How

  • By default the pass opens in an empty temp directory. It sees the transcript and no code. Attach does not read or change your HEAD.
  • --checkout adds the commit recorded in the archive as a detached worktree in the attach temp directory. When the clone lacks that commit, attach fetches it from origin and names the fix if the fetch fails.
  • The clone's hooks and filters no longer run on PR content. core.hooksPath=/dev/null alone did not do that. It does not stop a hook defined in config (hook.<name>.command), and checkout still ran smudge filters. With git-lfs, a PR's .lfsconfig could make attach send a request to a host the PR picks. Attach now reads the clone's hook.* and filter.* names and turns each one off, plus core.fsmonitor and LFS smudge. The settings go in GIT_CONFIG_*, so git in the follow-up session gets them too.
  • Attach removes symlinks that point outside the worktree, as the review does.
  • Attach checks that the archive's headSha matches the head in its tag, and --sha when given.
  • Attach removes the worktree when it ends, also on SIGHUP from a closed terminal. After a kill, the next --checkout removes only attach's own stale worktrees. It does not run a clone-wide git worktree prune, which would drop your worktree on a drive that is not mounted.
  • The lookup finds the newest archive for the whole PR. --sha limits it to one head, and --run to one workflow run. --run no longer needs --sha. Attach filters tags before it makes one gh call per release.
  • The Claude note tells the model whether the working directory is the reviewed commit or empty.
  • recordedShaBlocksAttach is gone. sessionPrTagPrefix, releasesForPr, isSessionTagUnder, and sessionTagHead are new. runAtExit takes a hangup option.
  • USAGE, README, LLP 0003, and LLP 0007#session-archive describe the new behavior.

Test Plan

  • bun test: 1171 pass. typecheck, lint, fmt:check, and ./ref-check pass.
  • --checkout on a clone that lacks the commit fetches it and leaves the clone's HEAD and files alone. The clone's post-checkout hook does not run.
  • A hook defined in config and a smudge filter of the clone do not run. A PR hook does not run on a later git checkout in the worktree.
  • A symlink to a file outside the checkout is removed. A link inside it stays.
  • A stale attach worktree is removed. Your own missing worktree stays.
  • An unknown commit fails with the fix in the message and leaves no worktree.
  • Reverting any one fix makes its new test fail.
  • Under Node, on a clone with global git-lfs, a config hook, a PR .lfsconfig pointing at a local URL, and a link to /etc/hosts: no LFS request, no hook, the link was removed, and the worktree and its entry were gone after cleanup.
  • By hand, from a directory outside any git repo: ecr attach --pr 54178 --repo expo/expo --list listed archives for two heads. --run 45686644170 --list printed that archive's index.
  • Not done yet: the interactive open in Claude Code and OpenCode, with and without --checkout, and a real terminal close during a session.

🤖 Generated with Claude Code

A pull request can come from a fork. Attach used to require the PR head in
the developer's own checkout, so trying a stored review meant checking out
untrusted code first. Attach now opens the pass in an empty temp directory
with the transcript only. --checkout adds the reviewed commit as a temporary
detached worktree with git hooks off.
@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

🤖 AI code review

Decision: Ready for human review

Overall PR risk: Medium. The change modifies how ecr attach selects and opens pull request code: by default it now opens in an empty directory, and --checkout creates a temporary hardened worktree whose cleanup depends on signal handling and stale-entry removal. Developers expecting the old HEAD-based selection might open an archive for an older head, though the tag and commit are printed. The blast radius is limited to the local interactive attach command; CI paths are unaffected, and rollback via commit revert is straightforward.

🔎 Reviewer summaries (4)
  • consistency: I checked the README, the LLP 0003 and LLP 0007 text, and the attach and session-archive tests against attach.ts and the sibling tests. The docs match the new --checkout, --sha, and --run flags. I found no divergence from repo conventions. I checked the attach --checkout flag, the runAtExit hangup option, and the new session-tag helpers against sibling code. They follow the conventions of the repository. I found no consistency problems.
  • correctness: I checked the new attach tests against the exported functions in attach.ts. I also compared the README and LLP text with the checkout behavior. The tests call the current signatures, and the documents match the code. I found no defects. I reviewed the new attach flow: PR-wide archive lookup, the opt-in --checkout worktree with git hardening, cleanup of dead temp directories, and the SIGHUP cleanup option. I found no concrete correctness defect.
  • security: Reviewed the README, LLP docs, and tests for the opt-in attach checkout. The docs match the code: GIT_ATTR_SOURCE, core.symlinks, the hangup cleanup, and the lsp/formatter settings. The tests use only temp paths. I found no security issue. I reviewed the new attach --checkout worktree path, the git env scrubbing, and the stale temp cleanup. The fetched SHA is validated as 40 hex digits, and hooks, filters, and symlinks are off. I found no concrete exploit path.
  • cross-cutting: Checked the changed attach flow across attach.ts, exec.ts, and session-archive.ts: the tag helpers, the runAtExit hangup option, the env passed to child processes, and the removed recordedShaBlocksAttach. No cross-file defect found.

🔗 Review setup:

  • This PR changes code the reviewer prompts cite (src/tests, src/core/exec.ts). Check that the guidance quoting it is still correct.

No findings.


This review is advisory — it never blocks a merge and never auto-approves.

Kudo added 2 commits November 26, 2026 21:12
core.hooksPath did not stop hooks defined in config, and checkout still
ran the clone's smudge filters. With git-lfs, a PR's .lfsconfig could
make attach send a request to a host the PR picks.

Attach now turns off every hook and filter the clone defines, through
GIT_CONFIG_* so git in the follow-up session gets the same settings. It
removes symlinks that point outside the worktree, checks the archive's
head against its tag and --sha, and cleans up on SIGHUP. It removes only
its own stale worktrees instead of running a clone-wide prune.
An inherited GIT_DIR made the cleanup delete the git directory of
another worktree. Git sets it for an alias that runs inside a linked
worktree. GIT_CONFIG_PARAMETERS from `git -c` turned hooks back on. A
PR's .gitattributes could still select a diff driver of the clone, a
later `git restore` put removed symlinks back, and a SIGKILL left the
checkout and the transcript on disk for good.

Attach now drops the repository-local git variables, reads no
attributes from the PR (GIT_ATTR_SOURCE), and checks symlinks out as
plain files (core.symlinks=false). The exit cleanup is registered
before the worktree is added and deletes only the entry that names it.
Each attach writes its PID, so the next run removes what a killed one
left. The fetch leaves FETCH_HEAD alone, attach prints the archive it
opens, and the OpenCode follow-up runs with lsp and formatter off.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant