Skip to content

feat(worktrees): use worktrees for agents, bots and schedules - #90

Merged
nixuuu merged 1 commit into
feat/worktrees-2from
feat/worktrees-3
Nov 4, 2026
Merged

nixuuu merged 1 commit into
feat/worktrees-2from
feat/worktrees-3

Conversation

@nixuuu

@nixuuu nixuuu commented Nov 4, 2026

Copy link
Copy Markdown
Member

Stage 3 (final for now) of git worktree support, on top of #82.

  • Squash-merge detection for the "merged" cleanup policy and status: a branch counts as merged when its PR is merged (owner-scoped GitHub connector, checked in the gateway, no credentials on the worker) or, without a connector, when all its commits are patch-equivalent to the base or its changes are fully contained in the base after fetch. Covers squash-merged and rebased branches; partially merged ones stay.
  • Worktrees for automation: agent-spawned threads (spawn_thread), bots running code tasks and scheduled tasks follow the scoped worktree settings, with an explicit option (current checkout / new worktree / inherit). Side threads inherit their parent's worktree by default. Cleanup policies cover them.
  • Linked-computer threads keep a clear refusal (linked computers are desktop-only, feat(computers): offer linked computers only in the desktop app #88); worktrees across linked computers are a later, separate change.
  • Migration 0068_worktree_automation. The whole stack was rebased onto current dev with migrations 0066–0068.

Known limitation: if thread creation fails after its worktree was created, the worktree stays on disk until cleanup.

Checks per stage: install, gen:check, typecheck, lint, format:check, shard check. Top: check:tmp (1,035 pass, 153 skip, 0 fail), web build; composer and Settings → Worktrees checked in light/dark at desktop and phone widths.

@nixuuu
nixuuu added this pull request to stack #83 November 4, 2026 18:59
@nixuuu
nixuuu marked this pull request as ready for review November 4, 2026 19:02
@nixuuu
nixuuu merged commit 431b8fd into dev Nov 4, 2026
9 checks passed
@nixuuu
nixuuu deleted the feat/worktrees-3 branch November 4, 2026 19:02
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 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