Skip to content

perf(worktree): retain composer drafts and prepare agent shells - #18842

Closed
nwparker wants to merge 39 commits into
nwparker/worktree-create-technicalfrom
nwparker/faster-worktree-create-ASTRA-astronaut
Closed

nwparker wants to merge 39 commits into
nwparker/worktree-create-technicalfrom
nwparker/faster-worktree-create-ASTRA-astronaut

Conversation

@nwparker

@nwparker nwparker commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Superseded by #18876, stacked directly on #18793. That approach retains immediate editable prompts while omitting the early real-workspace/deferred-shell lifecycle. This PR is closed; its branch and earlier trial release remain available for comparison.

Problem and behavior

Create currently waits for checkout, shell startup and first terminal rendering. Opening the composer now prepares a real workspace and, on eligible native local hosts, its shell. Create adopts that exact workspace and releases the selected agent command. Canceling or editing preserves the existing draft as an accessible workspace.

Stacked on #18793. Current head: bb75b4c6a72, containing A and B atop main af82126058de.

Implementation

  • Retain an immutable request and execution owner; quick submit joins the in-flight creation.
  • Bound and serialize checkout preparation for the active native target, with per-window leases.
  • Capability-gate deferred agent startup. The daemon retains the original environment and holds the command until Create authorizes its exact operation/incarnation.
  • Retire undelivered startup after manual use or a signal; reconnect, retry and restored drafts cannot replay it into another session.
  • Preserve startup identity and context through completion, while applying current terminal/chat presentation preferences.
  • Render the already-preloaded terminal component directly on its first mount. Keep its component type stable thereafter; the cold path retains existing lazy-load retry/recovery.

Performance evidence

Fresh-profile comparison using the real Create button after preparation, the same signed A+B main process, and a production renderer build with only the preload fix:

Renderer Create → selection Create → first terminal
Released 15b770c0605 control 19 ms 384 ms
With preload fix 18 ms 105 ms

The control started its terminal mounting work about 330 ms after Create; the changed renderer started promptly. This is a local controlled renderer comparison, not a benchmark of a newly published installer. No experimental WebGL changes were included. Screenshots were inspected, Codex accepted keyboard input, and terminal readback preserved the unsent draft. Codex's existing update menu was skipped explicitly; no task was submitted.

Cold creation remains variable: an earlier optimized immediate-click trial showed pending feedback in 29 ms, terminal availability in 4.16 seconds, and agent prompt/input in 5.38/5.42 seconds. Checkout dominated that run. These changes do not establish universally near-instant creation or full MCP/tool readiness. SSH, folder, paired-runtime, VM and structured-chat paths do not all receive identical acceleration.

Validation and review

  • Latest preload change: 47 tests across loader, startup-routing and lazy retry suites; renderer typecheck; lint/format; production build; independent correctness/elegance review; real rendered control/change comparison and unsent-input proof.
  • Existing deferral work: integrated creation/deferral, protocol, owner-routing and compatibility tests; full typecheck; native rendered adoption/cancellation and normal/forced app-process restart checks with original terminal identity.
  • Signal retirement: 110 daemon tests and a real daemon probe covering both readiness-marker and timeout delivery, with manual shell input remaining usable.
  • Prior 15b770c0605 CI and exact-head review passed. All current-head CI checks passed, including packaging, eight unit-test shards and SSH E2E. Exact-head Pullfrog review also found no new issues.
  • Latest change adds no persisted state or mobile-facing wire surface. Cold-load recovery is retained, and the cache holds one already-imported component. No new proven readiness issue was found.

Merge risk and negative trade-offs

Merge risk: moderate, due to the broader preparation/retained-session lifecycle and incomplete live coverage across supported topologies. The isolated preload fix is low risk.

Introduced user-facing trade-offs:

  • Hooks and shell profiles can have side effects before Create.
  • Canceled or edited drafts retain workspace and shell resources that may need cleanup.
  • Unused speculative preparation consumes CPU, disk and memory.

No additional negative trade-off was identified for the preload fix.

Trial release

Latest A+B trial at bb75b4c6a72, including the preload fix. macOS Intel/ARM artifacts are published; the downloaded Apple Silicon ZIP passed SHA-512/size, archive-integrity and deep/strict code-signature verification. Bundled build metadata confirms bb75b4c6a72d. The macOS notarization staple also validates. Windows is published and its installer passed SHA-512/size verification; Windows builds are unsigned. Both jobs in 33981313200 completed successfully.

Earlier lifecycle visual proof

Prepared composer

Retained draft after restart

Draft restored after forced app-process crash

# Conflicts:
#	src/shared/child-process/process-tree-termination.test.ts
@greptile-apps

greptile-apps Bot commented Sep 5, 2026 •

Copy link
Copy Markdown

Too many files changed for review (170 files, 100 file limit).

Bypass the limit by tagging @greptile-apps to review.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes — reviewed the full 169-file diff at head 5da5700 (35 commits) implementing retained composer drafts and owner-fenced deferred agent-shell startup.

  • Retained composer drafts — the quick composer prepares a real workspace (checkout + shell) in the background; Create adopts it, cancel/edits keep it as a normal workspace.
  • Owner-fenced deferred startup — the daemon holds the agent command until releaseStartupCommand, gated on workspace + PTY incarnation + operation; manual input retires it.
  • Protocol v36→v38 — new releaseStartupCommand RPC (capability-gated ≥37) and deferred-state-on-reattach (v38), preserving v37 release for already-held commands.
  • Runtime/renderer release plumbing — worktree.background-startup.v1-gated preparation, worktrees:releaseStartup, and crash-safe retry via deferredStartupRecovery.
  • Standby checkout pool — bounded, serialized per-window standby with hold/replenish-after-finalize and stale-cleanup rescheduling.

I independently traced the two highest-stakes invariants — exactly-once command release on the daemon, and adoption identity / no-duplicate-create on the renderer — plus the run-process.ts termination-barrier change. All hold: SessionDeferredStartup.release sets state = 'accepted' and nulls submission before writing; SessionStartupInput.deliver re-checks liveness inside the queued closure and clearPendingWrites() drops it on exit; createRetainedWorktreeCreation.take retires on any snapshot/identity divergence and forces ordinary Create; releasePreparedWorktreeStartup binds release to the exact retained incarnationId/operationId.

ℹ️ Nitpicks

  • viewMode (native-chat vs terminal) is baked into the backend startup by resolveBackendDraftStartup at prepare time from experimentalNativeChat/openAgentTabsInChatByDefault, but it is not part of the serialized adoption identity in retained-worktree-creation.ts. Toggling either setting between opening the composer and Create adopts the workspace with a stale agent-tab view mode. Cosmetic, draft-prompt launches only.
  • SessionDeferredStartup.release() returns 'accepted' even when deliver() only queues the write behind the shell-ready gate; if the session exits before the flush, the command is silently dropped while release reported success. At-most-once is preserved and this matches the reliability-gate invariant, but 'accepted' can overstate delivery (only a throwing write reaches 'unverifiable').
  • Session.signal() calls input.retire(), but retire() only transitions pending → retired; a command already accepted (queued but unflushed) survives a signal, so a release immediately followed by a signal can still flush into a signaled shell. exit/dispose fence correctly; signal does not.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes — reviewed the delta since the prior pullfrog review (head 5da5700 → 0fad065), a single test-only follow-up commit.

  • macOS Crashpad teardown — cleanupE2ECrashpad enumerates macOS processes and SIGTERMs the test profile's reparented Chrome crash handler so Playwright is not held open; re-reads the PID's command line to confirm ownership before killing, guards pid <= 1, and is macOS-only (no-op elsewhere).

The change is E2E test-harness only — product source is unchanged from the released 2aa499b9412 build. The ownership recheck (ps -p <pid> -o command=) before process.kill correctly fences PID-reuse races, and the unit test covers exact-profile matching, changed-ownership no-signal, and non-macOS no-ops. No product or wire impact.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes — reviewed the delta since the prior pullfrog review (head 0fad065 → 15b770c), a single daemon fix commit.

  • Signal retires a queued accepted command — SessionStartupInput now tracks an awaitingDelivery flag, and SessionDeferredStartup.retire(acceptedButUndelivered) transitions accepted → retired when a signal lands after Create authorization but before the queued write flushes; the flush closure re-checks the flag and drops the write, so neither the readiness marker nor its timeout can launch the command.

I traced the state machine end-to-end (session-deferred-startup.ts, session-startup-input.ts, session-shell-ready-barrier.ts, session.ts). deliver() sets awaitingDelivery before enqueueing the write closure and the closure clears it only when it actually writes, so a synchronous signal interleaving cannot misfire. The two new tests assert exact behavior (retire-before-marker/timeout leaves written empty and returns retired on retry; an already-delivered command is neither revoked nor repeated) and both fail against the pre-fix code. This cleanly resolves the prior review's signal-retirement nitpick.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes — reviewed the delta since the prior pullfrog review (head 15b770c → bb75b4c), a single renderer-only commit.

  • Synchronous preloaded-terminal mount — terminal-component-loader.ts now caches the resolved module.default in a module-level loadedTerminal and exposes a PreloadedTerminal that captures loadedTerminal ?? LazyTerminal once via useState and renders it through createElement. AppWorkspaceShell consumes PreloadedTerminal as Terminal.

I traced the behavior across both paths. When NewWorkspaceComposerCard has already preloaded the chunk (loadedTerminal set), the first workspace creation paints the real terminal synchronously instead of throwing a Suspense fallback — this is the bug the commit fixes, since React.lazy suspends once even when the module is cached. When the mount is cold, PreloadedTerminal falls back to lazyWithRetry, preserving the existing chunk-recovery semantics, and the useState initializer keeps the component type stable so a mid-flight preload completion cannot remount the terminal and drop unsent input. The new terminal-component-loader.test.tsx asserts exactly these three behaviors (cold suspend-then-paint, input preservation with mounts === 1, and no suspend after warm preload), and the app-startup-routing.test.ts ratchet was updated to match.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

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