Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
6a25941
docs(plans): add Tier 1 & Tier 2 worktree creation performance plan
sambitcreate Nov 21, 2026
fd3d875
perf(git): Phase 1 worktree creation fast path and .worktreeinclude fix
sambitcreate Nov 21, 2026
e0498ad
perf(main): Phase 2 pure-FS admission, cached global skills, Pi dirIn…
sambitcreate Nov 21, 2026
62f203c
perf(worktree): phase 3 renderer perceived speed, IPC coalescing, and…
sambitcreate Nov 21, 2026
6ee05e7
perf(worktree): phase 4 native batched CoW provision subcommand in wo…
sambitcreate Nov 21, 2026
5f88cbd
merge: origin/main and update worktree performance plan with final be…
sambitcreate Nov 21, 2026
15ac075
docs(memory): record worktree creation performance benchmarks and inv…
sambitcreate Nov 21, 2026
2b3f40f
fix(lint): avoid control-char regex in resolveWorktreeBase
sambitcreate Nov 21, 2026
2202474
merge: origin/main (reconcile KeepVisualChatContext around MessageList)
sambitcreate Nov 21, 2026
ba55fa2
fix(worktree): address Pullfrog review (provision fsync, post-hook ca…
sambitcreate Nov 21, 2026
e78f45b
fix(git): require include-free local/global/system config proof for 0…
sambitcreate Nov 22, 2026
8db88bf
fix(git): scope pure-FS admission proof to admission/create paths and…
sambitcreate Nov 22, 2026
84717cd
Merge remote-tracking branch 'origin/main' into worktree_performance_…
sambitcreate Nov 22, 2026
5a71370
fix(git): probe active Git binary for exact system config origin in p…
sambitcreate Nov 22, 2026
f26db8f
fix(git): reprobe system config origin on proof refresh and track exe…
sambitcreate Nov 22, 2026
18a8215
fix(git): require verified direct native Git binary for 0-spawn workt…
sambitcreate Nov 22, 2026
ed5d91b
Merge remote-tracking branch 'origin/main' into swarm-fix-868-worktre…
sambitcreate Nov 22, 2026
ed44327
fix(lint): avoid control-char regex in verifyDirectGitExecPath
sambitcreate Nov 23, 2026
cc5b483
fix(git): restrict 0-spawn admission proof to trusted standard Git in…
sambitcreate Nov 23, 2026
17f2884
fix(git): verify Apple codesign / root-owned Linux /usr/bin/git and S…
sambitcreate Nov 23, 2026
dc0456e
test(git): pin Apple /usr/bin/git for darwin zero-spawn admission tests
sambitcreate Nov 23, 2026
313bb98
Merge remote-tracking branch 'origin/main' into swarm-fix-868-worktre…
sambitcreate Nov 23, 2026
cdfc23d
Merge remote-tracking branch 'origin/main' into swarm-fix-868-worktre…
sambitcreate Nov 23, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .memory/worktree-creation-performance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Worktree Creation Performance Optimization

Implemented across four phases on `worktree_performance_optimization` (2026-11-21), each gated by two independent adversarial reviews. See [`docs/plans/worktree-creation-performance.md`](../docs/plans/worktree-creation-performance.md).

## Head-to-Head Measured Results (`aiden-macos`, 6,497 tracked files, Apple Silicon APFS, 5-run medians)

| Operation | Before (`origin/main`) | After | Saved | % Reduction | Speedup |
| :--- | ---: | ---: | ---: | ---: | ---: |
| Explicit Create (`createIn` + `createWorktree`) | 1,417 ms (127 git spawns) | 744 ms (8 git spawns) | −673 ms | −47.5% (−93.7% spawns) | 1.90× |
| Worktree-on-Send Backend (local base → ready for LLM) | 1,915 ms (144 git spawns) | 711 ms (12 git spawns) | −1,204 ms | −62.9% (−91.7% spawns) | 2.69× |
| Post-Create `git.info(worktreePath)` | 172.82 ms (6 spawns) | 0.77 ms (0 spawns) | −172.05 ms | −99.6% (−100% spawns) | 224× |
| Per-Op Admission (`managedWorktreeUsable`) | 15.28 ms (4 spawns) | 0.58 ms (0 spawns) | −14.70 ms | −96.2% (−100% spawns) | 26.3× |
| `.worktreeinclude` (31 files, clean repo) | 100 ms (31 spawns) | 40 ms (1 batched CoW spawn) | −60 ms | −60.0% | 2.50× |
| `.worktreeinclude` (31 files + 5,000-file `node_modules`) | Crashed (`output_limit` > 1 MiB) | 44 ms | Fixed crash | 100% crash fix | ∞ |

## Key Architecture Decisions & Safety Invariants

1. **Streaming `git check-attr --cached -z --all --stdin` (`main/services/git.ts`)**: Replaces 128-path serial `check-attr` loops (~102 spawns) with 1 streaming process parsing NUL triples on raw `Buffer` slices (O(1) memory, immune to 1 MiB `DEFAULT_MAX_BUFFER_BYTES` overflow, evaluates `info/attributes`, global config, and `includeIf`).
2. **Parallel checkout tuned to APFS (`checkout.workers = min(4, cpus)`, `checkout.thresholdForParallelism = 50`)**: Controlled A/B on Apple Silicon APFS showed `workers=4` beats `workers=8` (which exhibited tail spikes). Raw APFS `clonefile(dir)` for Git working trees was rejected because it breaks Git's inode stat cache and causes 1.2–1.8 s `git status` stalls.
3. **Authoritative inner capacity admission (`additionalAllocationBytes`)**: `createIn` passes `provisionedReserve` into `git.createWorktree`, which validates non-negative safe integers and enforces `checkoutBytes + additionalAllocationBytes` inside `enqueueMutation(repo.commonDir)` before `mkdir`/`worktree add`.
4. **Inverted `.worktreeinclude` + literal `./` pathspec neutralization**: Runs `git ls-files -z -o -i --exclude-from=.worktreeinclude --full-name`, short-circuits if empty, then filters via `git check-ignore -z --stdin` in `repo.topLevel` with `./`-prefixed paths (neutralizing `:` pathspec magic bypass/DoS).
5. **0-spawn pure-FS `managedWorktreeUsable` & display cache seeding (`main/services/git.ts`)**: Reads `<wt>/.git`, `<admin>/{aiden-owner,gitdir,commondir,HEAD}`, and loose/`packed-refs` via `O_RDONLY | O_NOFOLLOW | O_NONBLOCK`, fenced with `while (this.mutations.has(commonDir))` + `mutationEpochs` (no cross-caller stale `usableFlights` cache). Falls back to Git on `reftable` or ambiguity. Display-only `infoCache` seeding for newly created worktrees is fenced by pre/post `repoRemoteHintSignature` and `mutationEpochs`.
6. **Split global/workspace skill discovery cache, Pi `dirIndex`, and `protectLocal` gating**:
- `discoverSkillCandidatesWithCachedGlobals` caches global candidates for 5 s keyed on `[home, aidenDir, globalPluginConfigs]` (honoring workspace `.claude/settings.json` disabling global plugins); `resolveFresh()` always bypasses cache.
- `PiCompactionSessionStore` indexes `.jsonl*` files with per-file `lstat` signatures and monotonic `dirMutationVersion` concurrency fencing so brand-new chats skip migration/list scans while in-place edits and symlinks are caught.
- `portable-config-core.ts` gates `protectLocal()` on warm loads only when `ownedPaths.length === 0 && archivePublicationPaths.size === 0`, keeping `ensurePrivateDirectory(root)` live and checking `lstat` (`uid`, `mode`, `nlink === 1n`, `dev/ino/mtimeNs/ctimeNs`) on `config.json` and recorded secondary files.
7. **Renderer IPC coalescing & zero-remount promotion**:
- `FirstMessageWorktreeResult` optionally carries `workspace`; `workspaces:changed` emits `{ kind: "created", workspace }` on creation so hydrated idle caches upsert via shared `upsertCreatedWorkspaceInCache` without refetching `workspaces:list` or `chats:list`.
- `markChatRecentlyPromoted` uses subscriber refcounting + microtask-deferred cleanup (React StrictMode safe) so only the immediate draft → live `useChat` activation reuses the seeded snapshot while leaving/revisiting always re-reads.
- Pending worktree sends render inside `MessageList` (`keepForkWrapper` + `"draft-prompt"` key handoff) so the user bubble and attachments settle in place without remounting.
- `EnvironmentArtifactsContext` isolates volatile `useWorkspaceArtifacts` updates from `ChatPane`, `ChatSidebar`, `RootView`, `HistoryNavButtons`, and `DesignLayout` via `useEnvironmentPanelCore()`.
8. **Native batched CoW `provision` subcommand (`native/worktree-file-io/main.c`)**:
- Preserves `copy` and `restore` (with SHA-256) untouched for snapshots.
- Dedicated `provision` subcommand handles all `.worktreeinclude` paths in 1 spawn, uses APFS `fclonefileat(..., CLONE_NOFOLLOW | CLONE_NOOWNERCOPY)` into a random temp file when plain/same-volume/no-xattrs/no-flags/no-special-bits/owner-readable, clears `fchflags(cloned, 0)` BEFORE `fchmod(cloned, mode & 0777)`, verifies `flistxattr(cloned) == 0` + `same_provision_source` (including `st_mode`, `st_flags`, `st_ctimespec`), atomically installs via `renameatx_np(..., RENAME_EXCL)`, falls back to `read/write` on `EXDEV`/`ENOTSUP`/`EACCES`/`EPERM`, deduplicates parent `fsync`s (capped at 64 FDs), and handles `SIGTERM` gracefully while Node's `provisionManagedWorktreeFilesBatch` settles strictly on `"close"` so disk state stays 1:1 with `onProvisioned`.
1 change: 1 addition & 0 deletions docs/plans/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Research addition 2026-10-03 against `main` at `3f86d41af` (0.52.0): [all-PR inv

## Active and partial

- [Worktree creation performance (Tier 1 & Tier 2)](worktree-creation-performance.md) — Implemented, in review (2026-11-21) on `worktree_performance_optimization`. All four phases shipped and audited by two adversarial reviewers per phase. Measured head-to-head on `aiden-macos` (6,497 tracked files, APFS, 5-run medians): explicit create drops from 1,417 ms / 127 git spawns to 744 ms / 8 git spawns (−47.5%, 1.90× faster); worktree-on-send local backend drops from 1,915 ms / 144 git spawns to 711 ms / 12 git spawns (−62.9%, 2.69× faster); post-create `git.info` drops from 172.8 ms (6 spawns) to 0.77 ms (0 spawns, −99.6%); per-op `managedWorktreeUsable` admission drops from 15.3 ms (4 spawns) to 0.58 ms (0 spawns, −96.2%); `.worktreeinclude` (31 files) drops from 100 ms to 40 ms (−60.0%) and stops crashing on large `node_modules` trees (44 ms with 5,000 ignored files vs `output_limit` crash). Renderer changes add inline `workspace` return + cache seeding, `workspaces:changed` creation narrowing, StrictMode-safe one-shot promotion `useChat` freshness, frame-1 draft worktree send inside `MessageList` with zero-remount bubble handoff, `EnvironmentArtifactsContext` isolation, and frame-0 `⌥↵` base seeding.
- [iPhone Duo: list and conversation side by side](ios-iphone-duo-plan.md) — In review (PR) (2026-11-22), iOS only, no Remote revision. At regular width the Inbox, Bots and Workspaces tabs are list and detail; compact width keeps one stack; the fold keeps drafts, reading place, Search and list positions; bars are ready for the Duo's vertical rail (Xcode 27.1). Also ships the owner's quieter card lists, the iOS ink Aiden accent and underlined links. Phase 4 polish (remaining poses, the swipe-row item) is listed as remaining work in the plan.
- [Prompt cache hit rate: keep the cached prefix byte-stable](prompt-cache-hit-rate.md) — Implemented, in review (2026-11-19): phase 0 (miss attribution, the 0% cache figure and the prefix harness), phase 1 (a per-chat AGENTS.md nonce, and an MCP section fixed for the turn), phase 2 (a fixed tool list per chat, with gated tools and Bot ingress refused per call), phase 3 (hook context journaled after its prompt, frozen per-chat state with `<state_update>` tails, audience and form-fill notes in the turn tail, a follow-up's connector section kept, the owed turn's window-dependent offers declared and refused per call, and removed memory never re-sent) and phase 4 (btw and a same-model advisor review continue the chat's last request on its cached prefix, and every one-off call sends no-cache retention through one helper) and phase 5 (threshold and manual compaction summaries continue the cached prefix, an attended chat near its trigger writes the summary in the background and stores it when compaction comes due if the chat was only appended to, chats with memory facts summarize isolated, and no memory fact reaches a stored summary) and phase 6 (the warmer times Pi's lifetime for the request's retention and keeps an attended chat warm for a few idle refreshes after its reply, `aiden serve` warms only when the profile opts in and never for Bot or scheduled runs, an opt-in **Keep chat caches for an hour** on Anthropic and Amazon Bedrock, and the memory limit on cached compaction accepted) and phase 7 (screenshots cut in batches with shared thresholds for workspace chats and Bots, and the Gemini explicit cache retired for implicit caching over a stable prefix) and phase 8a (in-process Codex over WebSocket with SSE fallback, a fourth Anthropic breakpoint at the end of the stable head, a Bedrock cachePoint after the tools, and chat-ID cache routing for listed custom OpenAI-compatible endpoints; message threads, a Codex cache lifetime, deferred tool declarations, head collapse and forked-subagent prefixes recorded as not built) and phase 8b (`aiden serve` keeps a paired device's chat warm when idle and honours the hour-long cache, serve threshold and manual compactions continue the turn's cached request, the replay gate reports a recorded turn compacted on its cached prefix, and a child agent's compaction after its own reply continues the child's last request) implemented; nine phases in one PR on `feat/prompt-cache-stability`, from the 33-cause cache audit. Measurement and a two-turn prefix harness first, then a stable AGENTS.md nonce and system sections fixed for the turn, a fixed tool list, frozen per-chat state, side calls and compaction on the parent prefix, idle warming on real TTLs with `aiden serve` parity, batched screenshot trimming, and Codex, threads and provider-routing changes.
- [Settings deslop: less text, one row system](settings-deslop-plan.md) — Proposed (2026-11-18), revised after an adversarial review the same day. The proposals are not built; the Settings bugs that the review and a bug hunt found are fixed on the plan's branch. 86% of the 240 settings rows carry a description (median 15 words), and pages build their own list rows and cards (about 19 local helpers), radio cards, folds and search fields. Proposes a copy budget (labels carry meaning; a description only for a consequence, at most 12 words; state in badges), title-only page headings with row-level search, a settings kit (`SettingsRow`, `SettingsListRow`, `SettingsSheet`, `SecretField`, `SettingsNote`, `RadioCardGroup`, `settingsStatus()`), a page-by-page pass, a 30-row must-stay list of disclosures with a behavioral test each, and a lint guardrail, in six phases. Includes a read of OpenCode's desktop settings and a [before/after prototype](assets/settings-deslop-prototype.html). Seven owner decisions are open.
Expand Down
Loading
Loading