Skip to content

refactor(#674): driver-tagged ResumeHandle with cwd-bound resume - #680

Merged
admarble merged 2 commits into
mainfrom
feature/674-refactor-normalize-agent-driver-resume-semantics-o
May 31, 2026
Merged

admarble merged 2 commits into
mainfrom
feature/674-refactor-normalize-agent-driver-resume-semantics-o

Conversation

@admarble

Copy link
Copy Markdown
Contributor

Summary

  • Replaces opaque sessionId + global sessionId && !worktreePath guard at phase-executor.ts:660 with ResumeHandle { driver, token, originCwd } and driver-owned canResume(handle, targetCwd).
  • ClaudeCodeDriver: accepts byte-equal cwd match only; on mismatch transparently starts a fresh session (avoids the SDK's recoverable error_during_execution). AiderDriver declines all resume.
  • Unblocks same-worktree resume across phases (regression fix).

Pre-PR AC Verification

AC Source Description Status Evidence
AC-1 Original ResumeHandle { driver, token, originCwd } on AgentExecutionConfig + AgentPhaseResult; sessionId kept as @deprecated mirror ✅ Implemented src/lib/workflow/drivers/agent-driver.ts:9-77
AC-2 Original ClaudeCodeDriver populates originCwd from config.cwd; returns it on result ✅ Implemented src/lib/workflow/drivers/claude-code.ts:153-160, 230-237
AC-3 Original Driver-owned canResume(handle, targetCwd); remove !worktreePath guard ✅ Implemented src/lib/workflow/drivers/agent-driver.ts:97-113; src/lib/workflow/phase-executor.ts:655-669
AC-4 Original ClaudeCodeDriver: resume only when originCwd === cwd; transparent fallback on mismatch ✅ Implemented src/lib/workflow/drivers/claude-code.ts:42-45, 72-89
AC-5 Original CodexDriver same rule, enforced in driver 🔄 Deferred to #497 CodexDriver not present yet; .skip placeholders in fixture test
AC-6 Original Resume works across phases within same worktree ✅ Implemented src/lib/workflow/phase-executor.ts:655-669; regression test in phase-executor.test.ts:678-705
AC-7 Original AGENTS.md parity precondition for Codex 🔄 Deferred to #497 Gated on CodexDriver
AC-8 Original Fixture test — cross-worktree rejected for both drivers; same-worktree succeeds; Codex it.skip; preserved/advisory/skipped annotation ✅ Implemented src/lib/workflow/drivers/resume-semantics.test.ts (10 passed, 2 skipped)
AC-9 Original Reconcile phase-executor.ts:653 comment ✅ Done in #675 Spec marked this as already-complete

Test plan

  • npm run build — clean
  • npm run lint — clean
  • npx vitest run src/lib/workflow/ — 171 passed, 2 skipped (Codex deferred)
  • Manual review: phase-executor.ts:655-669 replaces the prior heuristic with driver.canResume() — same-worktree resume now threads through
  • After feat: add OpenAI Codex CLI agent driver #497 lands, drop .skip on the two CodexDriver fixture cases

Notes

  • IssueState.sessionId kept as @deprecated mirror of resumeHandle.token for one release so in-flight .sequant/state.json records load cleanly. Legacy entries without originCwd are intentionally inert under the new fail-safe (driver-owned canResume() declines without originCwd proof).
  • Pre-existing test failures in prompt-wait.test.ts and relay-hook.integration.test.ts confirmed unrelated to this PR (reproduce on the base branch).

Closes #674

🤖 Generated with Claude Code

Replaces the opaque `sessionId` string + global `sessionId && !worktreePath`
guard at phase-executor.ts:660 with a `ResumeHandle { driver, token,
originCwd }` and a driver-owned `canResume(handle, targetCwd)` method.

ClaudeCodeDriver accepts only byte-equal cwd matches (matches the SDK's
cwd-namespaced storage at ~/.claude/projects/<encoded-cwd>/); on mismatch
it transparently falls back to a fresh session rather than triggering the
SDK's recoverable error_during_execution. AiderDriver declines all resume.

Unblocks same-worktree resume across phases (the prior heuristic disabled
all worktree resume). State files gain a `resumeHandle` field; the legacy
`sessionId` is retained as a one-release @deprecated mirror so in-flight
.sequant/state.json records load cleanly (legacy entries without
originCwd are intentionally inert under the new fail-safe).

AC-5 (CodexDriver same-cwd rule) and AC-7 (Codex AGENTS.md parity) are
gated on #497 landing CodexDriver; placeholder `.skip` tests in
resume-semantics.test.ts light up when that work lands.

Entire-Checkpoint: 879293b67de6
Add the missing direct unit test for the new updateResumeHandle method:
writes the driver-tagged handle, mirrors the token into the deprecated
sessionId field, bumps lastActivity, and throws on an unknown issue.

Closes the one closeable gap flagged in QA for PR #680.
@admarble
admarble merged commit 31dd93c into main May 31, 2026
5 checks passed
admarble added a commit that referenced this pull request Sep 9, 2026
Add the missing direct unit test for the new updateResumeHandle method:
writes the driver-tagged handle, mirrors the token into the deprecated
sessionId field, bumps lastActivity, and throws on an unknown issue.

Closes the one closeable gap flagged in QA for PR #680.
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.

refactor: normalize agent-driver resume semantics (origin-cwd-bound ResumeHandle, driver-owned validation)

1 participant