Skip to content

feat(worktrees): create threads in git worktrees - #74

Merged
nixuuu merged 1 commit into
devfrom
feat/worktrees-1
Nov 4, 2026
Merged

nixuuu merged 1 commit into
devfrom
feat/worktrees-1

Conversation

@nixuuu

@nixuuu nixuuu commented Nov 4, 2026

Copy link
Copy Markdown
Member

Stage 1 of git worktree support (modelled on T3 Code).

  • Settings → Worktrees (Code section) with scopes "Applying settings for [All projects | a project] across [All computers | a computer]": worktree location (empty = Canopy-managed folder in the worker's data dir), start from remote, advanced options, branch naming (prefix or a semantic prefix chosen by the text-generation model), default workspace for new threads. Settings live in the gateway DB, inheritance shown per field.
  • Composer: Workspace picker (Current checkout / New worktree / Previous worktrees) and a base ref picker with search and default/current markers.
  • Git runs on the worker that owns the workspace, with argv only (no shell), path containment, serialized creation; owner and workspace placement enforced in the gateway. Threads show their worktree branch.
  • Threads on linked computers get an explicit refusal for now.
  • Migration 0064_worktrees. Design and stage plan: docs/worktrees.md.

Next stages: cleanup policies; status/open/remove actions; worktrees for agent spawning, bots and schedules; linked-computer support.

Checks: install, gen:check, typecheck, lint, format:check, check:tmp (954 pass, 152 skip, 0 fail; 15 worktree integration scenarios), web build. Browser checked light/dark at desktop and phone widths.

Draft until the whole stack is done.

@nixuuu
nixuuu marked this pull request as ready for review November 4, 2026 19:02
@nixuuu
nixuuu merged commit 7e93f13 into dev Nov 4, 2026
10 checks passed
@nixuuu
nixuuu deleted the feat/worktrees-1 branch November 4, 2026 19:02
nixuuu added a commit that referenced this pull request Nov 4, 2026
…ead (#82)

Stage 2 of git worktree support (on top of #74).

- Cleanup policies in Settings → Worktrees with the stage 1 scopes: with
deleted threads, merged branches (git ancestry after fetch), inactive
for N days, settled threads, only unchanged worktrees vs. keeping those
with local changes. Dirty or unpushed worktrees are never removed
without explicit confirmation.
- Cleanup engine on the gateway schedule, executed on the owning worker;
dry-run preview in Settings; every removal audited; durable retries when
the worker is offline; path containment (never the main checkout or
anything outside worktree roots).
- Per-worktree status (branch, ahead/behind, dirty files, last activity)
and actions (copy path / reveal, remove) from the thread and a Worktrees
list in Settings.
- Composer picker row now wraps as a group with aligned controls at
desktop and phone widths.
- Migration `0065` (both worktree migrations will be renumbered after
#75's `0064` before the stack merges).

Known gap: squash-merged branches are not detected as merged by git
ancestry; handled in the next stage.

Checks: install, gen:check, typecheck, lint, format:check, check:tmp
(972 pass, 152 skip, 0 fail), web build. Browser checked light/dark at
desktop and phone widths.

Draft until the whole stack is done.
nixuuu added a commit that referenced this pull request Nov 4, 2026
…109)

Settings → Worktrees: changing **Branch naming** and pressing **Reset**
showed `cannot encode enum canopy.ui.v1.BranchNaming to JSON: expected
number, got undefined`.

Reset sends `undefined` to inherit a field. That works for the
`optional` fields, but `branch_naming` and `default_mode` are plain
proto enums: inheriting means their unspecified value (0), and
`undefined` can't be serialised. Resets of these two fields are now
written as `UNSPECIFIED`; every other field is unchanged. No other
settings page uses this reset pattern.

Checks: web typecheck, lint, format.

Fixes: #74
nixuuu added a commit that referenced this pull request Nov 6, 2026
Stage 3 of 4, mobile parity round 2: where a thread runs.

**Changed**
- **Linked computers:** the overview state keeps `computers` and handles
`computer`, `computer_removed` and `computer_snapshot`. The phone's
snapshot already carries the linked computers' workers, projects and
threads.
- **Worker picker** of a new thread, as on the web:
- workers grouped by computer: "This computer" first, then linked
computers by name;
- a worker on a linked computer this one cannot reach is greyed out with
its status ("Unreachable") and reason ("Studio Mac is unreachable since
6:45 AM.");
- the worker pill shows "worker · computer" for a linked one, and the
blocker uses the same reason.
- The presence rules (`computerName`, `sharesThreads`, `awayReason`, …)
move from the web to `@canopy/domain/computer-presence`, and the web
imports them from there. The web formats times with its own clock
settings.
- **Worktrees** (as #74, #82, #90): when the worker offers worktrees and
the folder is a git repository (`ListGitRefs`), the new thread shows:
- a workspace pill: Current checkout, New worktree, or a previous
worktree;
- the branch: read-only for the checkout and earlier worktrees, a base
ref picker (Branches, Remote branches) for a new worktree.
- The worktree settings' default mode applies until you pick.
`CreateThread` gets `workspace_mode`, `base_ref` and `worktree_id`.

**Checked**
- Gates clean, as in stage 1. Web typecheck covers the moved presence
rules.
- Android emulator, light and dark, unfolded and phone width:
- workspace and base ref pickers with a long branch name, against a
scripted worker that lists refs;
- the worker picker grouped by computer, with one reachable and one
unreachable linked computer. These came from overview data injected
locally for the check; no real link between two gateways.
- **Not checked on the device:** creating a thread in a new worktree end
to end (the scripted worker reports no agents for new threads).

**Copy audit (§8)**
- "This computer", "Unreachable" and the reasons ("‹Name› is unreachable
since 7:42 PM."): the web's text.
- "Workspace", "Current checkout", "Works in the project's directory",
"New worktree", "A new branch in its own directory", "Previous
worktrees", "Created 2 days ago", "Base ref", "Branches", "Remote
branches", "Default", "Current": from the web pickers.
nixuuu added a commit that referenced this pull request Nov 17, 2026
## Change

Creating a thread with a new worktree can fail with “git exceeded its
time or output limit” when checking out a large repository, especially
on Windows. Give `git worktree add` a dedicated 60-second limit instead
of the 15-second limit for Git metadata reads. Quiet mode suppresses
progress output while preserving errors.

The optional fetch keeps its 20-second limit, within the gateway's
existing 90-second wait. Update the worktrees documentation and add a
real gateway–worker regression test with a 16-second checkout hook that
verifies the resulting thread, files, and HEAD.

## Verification

- `bun run check:tmp ./tests/integration/worktrees.test.ts`: 16 passed,
including the slow checkout; no temporary files left. Used a separate
temporary directory because the system temporary directory reached its
quota.
- `bun run lint -- apps/worker/src/git/worktrees.ts
tests/integration/worktrees.test.ts`: passed.
- Edited TypeScript files formatted; `git diff --check`: passed.
- Local verification ran on Linux. Windows confirmation and the full
verification gate remain with CI.
- No UI text changed; copy audit does not apply.

Fixes: #74
nixuuu added a commit that referenced this pull request Nov 18, 2026
## What changed

- Report Git timeouts, output-limit failures and nonzero checkout exits
separately. Keep raw command output out of the new checkout errors and
map worker and link failures to fixed messages in `spawn_thread`.
- Mark the new branch and the temporary Git worktree lock with the same
attempt ID. After a failed checkout, remove only a matching worktree and
the unchanged, unused branch created by this attempt. Preserve the
original failure and report when cleanup is incomplete.
- Verify that rollback waits for the process to close and for the
attempt to stop its descendants to finish. Keep the 60 s checkout and 90
s gateway budgets. A gateway deadline or disconnect can still leave the
outcome unconfirmed, so the agent prompts the caller to check before
retrying.

The report involved a Windows 11 checkout of about 58,000 tracked files
with CRLF conversion and Git LFS. Both reported nightly.70 and the
edited report's nightly.74 already include the 60 s checkout limit. The
original error alone cannot distinguish elapsed time from excess output.
The fixtures reproduce those failure paths with real Git on Linux. The
original Windows checkout and its initiating cause remain unverified. A
longer checkout budget would need corresponding worker, gateway and
client deadline changes based on that evidence.

## Verification

- Verified PR head `dc73d853` on `nix-pc` (Linux, Bun 1.4.4, Git
2.56.0). Ran `check:tmp` on the worker worktree tests and five
integration files covering worktrees, creation progress, creation
failures, automation and the process governor. Also ran the worker's
device preview key tests. In all, 51 passed, zero failed, and no
temporary test files were left.
- The tests exercise a checkout filter that times out before completing,
a hook that exceeds output capture, a hook that exits nonzero, a
successful retry with the same branch name, a ref modified during
checkout, preservation of pre-existing worktrees and refs, both gRPC
callers, and an older worker that reports the two limits under one code.
- A generated 58,000-file CRLF checkout completed and unlocked in 2.14 s
on Linux. The fixture used small files and had no LFS filters.
- The prior CI run failed in [Tests
(6/8)](https://github.com/itsoltech/canopy/actions/runs/44361247730/job/135003276782)
because device preview depended on the shared process error text. The
runner now preserves that text and exposes the precise reason to Git.
The existing device preview assertions passed locally.
- Affected worker, gateway and process-governor typechecks, edited-file
lint and formatting, and `git diff --check` passed. Full verification
runs in CI.
- Copy audit (§8). The ambiguous limit message now identifies time or
output, checkout failure names Git settings and filters, and an
incomplete rollback tells the user what to check. New messages use
static sentence-case text without dynamic paths or names. The creation
step and retry were tested through the UI's gRPC API. No browser or
Windows runtime verification.

Fixes: #74
Fixes: #90
Fixes: #124
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