Skip to content

feat(executor): turn-boundary snapshot/rollback (Phase 3b) - #152

Merged
dahai80 merged 1 commit into
mainfrom
feat/executor-turn-snapshot
Aug 27, 2026
Merged

dahai80 merged 1 commit into
mainfrom
feat/executor-turn-snapshot

Conversation

@dahai80

@dahai80 dahai80 commented Aug 27, 2026

Copy link
Copy Markdown
Owner

Summary

Implements PR #1 (M1) of the fusion-code enhance ar-plan (architecture/fusion-code-enhance-ar-plan-0827.md §1 P0): caller-owned turn-boundary git snapshot + /rollback manual command.

Complementary to the in-band auto-rollback landed in PR #139:

  • in-band (PR feat(executor): Phase 2 diagnostics slicing + Phase 3 git snapshot/rollback #139) = single-call self-contained snapshot/rollback, opt-in FUSION_CODE_EXECUTOR_AUTO_ROLLBACK. Reverts within one bash call.
  • turn-boundary (this PR) = caller owns the snapshot at submitMessage entry; the model/user decides to /rollback to revert the working tree to before the turn. Manual, not automatic — safer for the edit-test-fail coding loop where auto-rollback would revert legit edits on test failure.

Changes

  • src/services/executor/types.ts — SnapshotResult / RollbackResult wire types
  • src/services/executor/ExecutorClient.ts — snapshotCreate / rollback client methods (UDS NDJSON-RPC: executor.snapshot_create / executor.rollback)
  • src/services/executor/ExecutorInstance.ts — methods with ensureStarted + health gate; rollback short-circuits empty snapshot_id
  • src/services/executor/executorDriver.ts — ExecutorClientLike test seam extended with the two methods
  • src/services/executor/turnSnapshot.ts (new) — turn-boundary manager:
    • takeTurnSnapshot(turnId) — fail-soft; non-repo cwd (executor returns "") is a no-op; ring of last 5 turns
    • recordTurnFailure() — counts same-turn is_error tool results; at threshold 3 stages a /rollback hint (idempotent per turn)
    • lastHint() — read + clear staged hint
    • rollbackToTurn(turnId?) — defaults to most recent; drops rolled-back + newer turns from ring
  • src/QueryEngine.ts — takeTurnSnapshot at submitMessage entry; case "user" scans tool_result is_error blocks + injects the staged hint as a user-role note for the next ask()
  • src/commands/rollback/ (new) — /rollback [turnId] local-jsx command
  • src/__tests__/services/executor/turnSnapshot.test.ts (new) — 21 unit tests

Gate

Default off, env FUSION_CODE_EXECUTOR_TURN_SNAPSHOT=1 (strict truthy). Byte-identical when env unset: takeTurnSnapshot is a no-op (returns null, no client calls, no ring entry, no hint). Double-gate with FUSION_CODE_EXECUTOR_ENABLED (executor must be on).

Upstream wire (cross-repo read-only, verified fusion-executor/crates/fe-ipc/src/lib.rs):

  • executor.snapshot_create {cwd} → {"snapshot_id": id} (empty when non-repo)
  • executor.rollback {snapshot_id, cwd} → {"ok": true}

Verification (4 gates)

  • bun run typecheck — 0 errors
  • bun test src/__tests__/ — 537 pass (21 new + 516 existing)
  • bun run lint — new/edited files clean (repo-wide pre-existing warnings untouched)
  • bun run build:dev — pass

Co-Authored-By: Claude Fable 5 [email protected]

Caller-owned turn-level git snapshot at submitMessage entry + /rollback
manual command. Complementary to in-band auto-rollback (PR #139):
in-band = single-call self-contained + opt-in; turn-boundary = caller
owns the snapshot, model/user decides to /rollback — safer for the
edit-test-fail coding loop.

- types.ts: SnapshotResult/RollbackResult wire types
- ExecutorClient.ts: snapshotCreate/rollback client methods (UDS RPC)
- ExecutorInstance.ts: methods with ensureStarted health gate
- executorDriver.ts: ExecutorClientLike test seam extended
- turnSnapshot.ts (new): turn-boundary manager — takeTurnSnapshot
  (fail-soft, non-repo no-op), recordTurnFailure (counter, threshold 3),
  lastHint (staged hint drain), rollbackToTurn, ring of 5
- QueryEngine.ts: takeTurnSnapshot at submitMessage entry; case 'user'
  is_error scan + hint injection to mutableMessages
- commands/rollback/ (new): /rollback [turnId] local-jsx command
- tests: 21 unit tests (fake client: take/rollback, failure counter,
  non-repo no-op, ring bounds, default-off byte-identical)

Gate: default off, FUSION_CODE_EXECUTOR_TURN_SNAPSHOT=1 (strict truthy).
Byte-identical when env unset — takeTurnSnapshot no-op returns null,
no client calls, no ring entry, no hint. Double-gate with
FUSION_CODE_EXECUTOR_ENABLED (executor must be on too).

Co-Authored-By: Claude Fable 5 <[email protected]>
@dahai80
dahai80 merged commit 3cd016e into main Aug 27, 2026
1 check passed
@dahai80
dahai80 deleted the feat/executor-turn-snapshot branch August 27, 2026 05:05
dahai80 added a commit that referenced this pull request Aug 27, 2026
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