Repository navigation
Conversation
UX Review (Opus 5.5, fork) — ⏭️ skippedRevision |
Design Review (Opus 5.5, fork) — ✅ PASSDesign-level review of Design-Verdict: PASS The reuse rule in Suggestions
[DESIGN-REVIEWED] f82e888 Description read[DESCRIPTION-READ] 31d13331ca1728a330721fe80643169e4916f47677ab3e54375cf61bc0b9fde5 That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
GPT 6.1 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings. |
First Principles Review (Opus 5.5, fork) — 🟡 CONCERNSPremise-level review of First-Principles-Verdict: CONCERNS The new Not justified as shipped
What this change shipsInventory (5 items) — 4 justifiedIntent: stop "Start in new worktree" from opening a session on a worktree whose
[FIRST-PRINCIPLES-REVIEWED] f82e888 Description read[DESCRIPTION-READ] 60a21823a0a8a429a82d0cd12bbd4107875921453ce5721d71ff13460808d325 That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings that block the merge. FINDING — src/kiro_crew/dashboard/handlers/worktree.py:106 — git writes the lock reason through gettext ( [OPUS-REVIEWED] f82e888 |
|
Thanks, the finding holds. Fixed in a second commit, 66a3a7c, on top of 85c489c.
Runs on 66a3a7c:
|
66a3a7c to
ad3a4f5
Compare
ad3a4f5 to
d98490a
Compare
`git worktree add` registers the worktree and sets its lock to
"initializing" before it checks files out, clearing the lock only once
the checkout finishes. When the add is killed in between (a gateway stop
or restart kills its control group), the entry is left registered,
partly checked out and locked "initializing". The create endpoint's
reuse path read only the path and branch, not the lock, so a retry
returned 200 {"reused": true} for that half-made tree. A session then
opened on a tree missing most of its files, and its first commit would
record them as deletions.
Parse the porcelain `locked` reason (new `_worktree_entries`, which
`_worktree_branches` now projects from). The reuse path refuses a
destination locked "initializing" with 409 `worktree_unfinished`
whatever its branch line says (a killed add may still be detached). A
completed worktree on the requested branch is still reused, whether it
is unlocked or locked for another reason.
A request that finds the winner's finished worktree is a legitimate reuse and also answers 200, so counting 200s depended on timing. The race now asserts exactly one response that created the worktree (reused false), and keeps the file and worktree-count checks.
d98490a to
f82e888
Compare
|
Thanks, the finding holds. Fixed by amending the first commit, now ebc86c2; the second, f82e888, is unchanged, and both are still on main 843abe3. |
|
Closing this as already covered by #19013. Once #19013 landed, a worktree whose The one behaviour left is cosmetic: for a half-finished add specifically, a dedicated |
Problem / Motivation
Goal: A worktree whose
git worktree addnever finished, which git leaveslocked initializing, is never handed back as a ready, reused worktree.The "Start in new worktree" endpoint (
POST /api/worktree/create,src/kiro_crew/dashboard/handlers/worktree.py) decides a destination is a ready worktree to reuse by reading only its registered path and branch. The root cause:git worktree addregisters the worktree, sets its HEAD and writes alocked= "initializing" marker BEFORE it checks files out, and clears the marker only once the checkout finishes. If the add is killed in between — a gateway stop or restart kills its control group — the entry is left registered, partly or not at all checked out, and stilllocked initializing. The reuse path in_create_worktree_sync(worktree.py) matched that entry and returned200 {"reused": true}, so a session opened on a tree missing most of its files.Why it matters
An agent that opens in that worktree sees most of the repository's files as absent. Its first
git add -Aand commit record them as deleted on the new branch — a data-loss footgun from a routine restart. A realgit worktree addof a 20,000-file tree, killed mid-checkout, leaves 214 files present and the entrylocked initializing; the retry then reported it ready.Not a goal
git worktree addwrites the lock reason through gettext, and_run_git(dashboard/handlers/worktree.py) does not pin the locale, so under a German locale the reason readsinitialisiere. An add interrupted under such a locale is not refused when its branch line is already recorded: it is reused, as on main. Detached, it gets theDirectory already exists409, also as on main. PinningLC_ALL=Cfor git, asapps/registry_pipeline/subprocess_env.pydoes, would close that case; it changes the environment of every git call inworktree.py, so it is a separate change.What changed (motivation → approach → change)
_worktree_entries(root)parsesgit worktree list --porcelain -zintopath -> (branch, locked_reason), including thelockedline git already emits._worktree_branchesbecomes a thin projection of it topath -> branch, so its other caller (_cleanup_partial) is unchanged._create_worktree_syncnow reads the entry at the destination:initializing→409withcode: "worktree_unfinished", whatever the branch line says (a killed add may still be detached, with no branch recorded yet);200), whether it is unlocked or locked for another reason.git worktree lockonly keeps git from pruning, moving or removing a tree, so a completed tree that someone locked is still usable.The hot path is unchanged: a first-time create still claims the branch and the directory and runs
worktree add; only the reuse branch reads one extra field from a listing it already fetched.Every path that decides a worktree is "ready"
_create_worktree_synchas exactly one reuse decision — theif os.path.exists(dest):block. After this change it is the only place that returnsreused: true, and it returns it only whenentries.get(_norm_path(dest))is present, on this branch, and not lockedinitializing. The two other_worktree_branchescall sites are in_cleanup_partial, which decides what to delete, not what is ready; they are unchanged. No other function returnsreused.Backwards compatibility
Compatible: no persisted format or route change. A completed worktree is reused exactly as before, locked or not. The one new outcome is a
409withcode: "worktree_unfinished"for a destination whose add never finished, which main answered with a wrong200 {"reused": true}.Removes nothing: no endpoint, response field or error code is removed.
Tests
test/test_worktree_reuse_initializing.py(new) drives the real_create_worktree_syncagainst a scratch repository undertmp_path; the OS-sandbox wrapper is replaced by a plaingitcall so it runs on any host, and the root is realpath'd so the handler's lexical dest keying agrees with git's canonicalized worktree path. The repository's base commit holds 4,000 files, so each realgit worktree addin the two race tests checks out long enough to overlap the other requests. The fixture builds that commit with onegit fast-import, as a single pack, so it writes no working-tree files and no loose objects; the tree is the same onegit add -Aof those files gives. Nothing reads the repository's own working tree: the handler reads its refs, config and worktree list. Writing the 4,000 files and runninggit add -Atook longer than pytest's 180 s per-test limit on a Windows runner, with three of these fixtures running at once. Here the fixture's setup takes 0.15-0.25 s per test, down from 0.98-1.28 s.Red on main (
test_a_retry_after_an_interrupted_add_is_refused_not_reused): the test leaves the state a killed add leaves, directly and every time. It runsgit worktree add --no-checkouton the branch, thengit worktree lock --reason initializing, which writes the same marker git's add writes before its checkout. The entry is registered, on its branch,locked initializing, with 0 of 4000 files. On the currentmain(843abe3) with only the test file added, 1 failed and 4 passed in each of 3 runs. The retry returns200 reused=Truewith 0 files, and the test fails witha retry reported a worktree whose add never finished as ready: status 200, reused=True, 0 of 4000 files, git lists it 'locked initializing'. On the fix the retry returns409 worktree_unfinished, and the entry is left registered and still locked.Controls, green on the fix:
git worktree lock --reason) is still reused (200) and stays locked and complete, as on main;_race(test/test_worktree_reuse_initializing.py:149-184), which bounds every wait: a worker waits at most 60 s at the barrier, a failedThread.start()aborts the barrier so the workers already waiting stop, and every started worker is joined against one deadline, failing the test by name if it is still alive.Green: the three changed test files give 222 passed in each of 3 serial runs, on this branch rebased onto that
main. The 7 test files that use the worktree handler, run with this file first: 409 passed, 8 skipped.Two existing fixtures retargeted. Both mocked the list helper
_worktree_branches; each now also mocks the create path's new seam,_worktree_entries, with the same trees, unlocked:test_worktree_create.py(list failure →503);sync_envfixture intest_dashboard_worktree_coverage.py.Their intent is unchanged.
Manual verification
Not run against a live gateway.
Related Issues
Two open PRs touch
worktree.py. #17628 (switch branches from the Git panel) does not conflict with origin/main in this file, butgit merge-treeshows this change adds a conflict there; whichever lands second resolves it. #17169 (Set-repo-path on the follow-up card) already conflicts with origin/main in this file, so its conflict is its own staleness, not caused by this change. No open PR already fixes the unfinished-worktree reuse.A separate change, not yet opened as a PR, also edits this reuse branch of
_create_worktree_sync: it refuses to hand back a worktree that another session is using. The two touch the same lines, so whichever lands second keeps both checks, the in-use check inside the same-branch case.Pattern harvest
Rule candidate: when code decides a resource is ready for reuse from a listing, it must read the listing's own "not ready" marker (here git's
locked initializing), not just the resource's identity. A half-created resource that advertises its own incompleteness should never be read as complete.