Skip to content

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

Closed

Description

@admarble

Parent: #497

Problem

AgentPhaseResult.sessionId / AgentExecutionConfig.sessionId are opaque strings with no record of the cwd the session was created in. The only safety net is canResume = sessionId && !worktreePath (phase-executor.ts:650), which disables resume whenever a worktree is active — correctness-preserving, but it means Claude Code resume never fires in normal operation, and it can't express the real constraint.

Claude Code and Codex resume are asymmetric:

Collapsing both into one sessionId + one global boolean hides this. The moment Codex's thread_id is wired into sessionId and the guard relaxed to make resume useful, Codex silently runs a resumed phase in the wrong worktree against the wrong AGENTS.md while Claude Code self-protects. The AGENTS.md double-load question in #497 is the same root cause, not a separate one.

Credit: @m13v in #497.

Recommended solution

Normalize resume semantics in the driver layer, keyed on actual cwd equality — not a single opaque id plus a global !worktreePath heuristic.

Acceptance Criteria

  • Introduce ResumeHandle { driver: string; token: string; originCwd: string }; carry it on AgentExecutionConfig and AgentPhaseResult (keep sessionId as a deprecated alias for one release).
  • ClaudeCodeDriver populates originCwd from config.cwd at session creation and returns it.
  • Add a driver-owned canResume(handle, targetCwd) contract; move resume-eligibility out of the !worktreePath heuristic in phase-executor.ts.
  • ClaudeCodeDriver: resume only when handle.originCwd === cwd; otherwise start fresh.
  • CodexDriver (when added in feat: add OpenAI Codex CLI agent driver #497): same rule, enforced in the driver — never pass resume <thread-id> when cwd differs.
  • Resume works across phases within the same worktree (regression fix — currently blocked by !worktreePath).
  • AGENTS.md parity as a Codex resume precondition: divergent/missing AGENTS.md stack in the target cwd ⇒ no-resume (folds in feat: add OpenAI Codex CLI agent driver #497 open-question docs: Add pre-release checklist #2).
  • Fixture test: a phase resumed against a different worktree is rejected for both drivers; a same-worktree resume succeeds; assert Codex cannot run in a mismatched cwd. Record per-behavior "preserved / advisory / skipped" so harness drift is visible, not silent.
  • Verify empirically whether the Claude Code SDK crashes (exit 1) or silently resumes-in-place on cwd mismatch; reconcile the phase-executor.ts:653 comment with observed behavior.

Activity

  1. admarble commented on May 30, 2026

    @admarble
    ContributorAuthor

    Empirical verification — Claude Code SDK cwd-mismatch resume

    Ran a direct probe against @anthropic-ai/[email protected]: created a session in dirA, then resumed it (resume: <sessionId>) with cwd: dirB.

    Result — it does NOT crash, and does NOT silently resume-in-place. It fails to find the session:

    subtype: error_during_execution
    error:   "Claude Code returned an error result:
              No conversation found with session ID: 2348f08c-..."
    

    Mechanism (confirmed on disk): Claude Code namespaces session storage by the encoded cwd —
    ~/.claude/projects/<encoded-cwd>/<session-id>.jsonl. The session was written under
    -private-tmp-seq-resume-probe-dirA/; resuming from dirB makes the SDK look under dirB's
    project dir, where the session doesn't exist → "No conversation found." No dirB project dir was
    even created.

    Reconciliation

    • The phase-executor.ts:653 comment ("Resuming from a different cwd crashes the SDK (exit code 1)") is imprecise. It's not a process crash — it's a recoverable, structured error_during_execution with a clear "No conversation found" message. Net effect is still a failed phase, so the guard's intent stands, but the framing should be corrected.
    • The "silently resumes in place" behavior noted in Anthropic's docs refers to the interactive /resume picker selecting a session from another worktree — a different code path from the SDK resume: option. Not applicable here.

    Design impact (sharpens the ACs above)

    Because a cwd-mismatched Claude Code resume is a detectable, non-fatal error (not a crash), the driver-owned canResume(handle, cwd) check should do more than refuse — on handle.originCwd !== cwd it can transparently fall back to a fresh session instead of failing the phase. Two AC refinements:

    • Update the phase-executor.ts:653 comment: cwd-mismatch yields error_during_execution / "No conversation found", not an exit-1 crash (storage is cwd-namespaced under ~/.claude/projects/<encoded-cwd>/).
    • ClaudeCodeDriver.canResume: on cwd mismatch, start a fresh session (don't pass resume) rather than erroring — the failure mode is recoverable.

    Verified 2026-05-30 with a throwaway probe; no repo changes.

  2. added a commit that references this issue on May 30, 2026
  3. admarble commented on May 30, 2026

    @admarble
    ContributorAuthor

    → PROCEED — Normalize agent-driver resume semantics (origin-cwd-bound ResumeHandle, driver-owned validation)

    Workflow: spec → exec → qa (-Q)

    Verified against codebase:

    • Guard lives at phase-executor.ts:660 (const canResume = sessionId && !worktreePath), not :650/:653 as the body states — line drift only, scope unchanged.
    • No ResumeHandle / originCwd type exists yet; sessionId is the only resume token threaded through.

    ⚠ Two ACs (CodexDriver same-cwd rule, Codex AGENTS.md parity) are gated on #497 adding CodexDriver, which is not yet present. The Claude-Code-side ResumeHandle + driver-owned canResume + same-worktree resume regression-fix all ship now; the Codex ACs become live once #497 lands.
    ⚠ The final AC ("reconcile the :653 comment with observed behavior") is already satisfied by merged PR #675 (f6b8e40). Spec should mark it done rather than redo it; the empirical verification comment above documents the recoverable-error finding.

    This is the foundational refactor #497 builds on, so PROCEED rather than PARK.

  4. admarble commented on May 30, 2026

    @admarble
    ContributorAuthor

    Spec — Plan vs Acceptance Criteria

    Tier: Complex (9 ACs, 1 primary directory). Workflow: spec → exec → qa with quality loop. Scope: SCOPE_WARNING (6 in-flight ACs after deferrals/done).

    AC status

    Implementation plan (compact)

    1. Types — add ResumeHandle, extend AgentExecutionConfig + AgentPhaseResult, add canResume to AgentDriver.
    2. ClaudeCodeDriver — populate originCwd on init, canResume returns originCwd === cwd, drop resume: silently on mismatch (transparent fallback).
    3. AiderDriver — canResume returns false (explicit, no session-resume concept).
    4. phase-executor.ts line 660 — swap sessionId && !worktreePath for handle && driver.canResume(handle, cwd).
    5. State — add optional resumeHandle to IssueStateSchema; keep sessionId for one release; old state without originCwd → resume disabled (fail-safe).
    6. Tests — unit tests for canResume truth table + driver behavior; integration fixture (AC-8); regression test for same-worktree resume (AC-6).

    Key decisions

    • Transparent fallback over error: SDK's cwd-mismatch is recoverable (docs(#674): correct resume cwd-mismatch comment (recoverable error, not exit-1 crash) #675 empirical verification), so start fresh silently rather than surface error_during_execution.
    • Byte-equal cwd comparison, not normalized: matches the SDK's storage-key behavior (~/.claude/projects/<encoded-cwd>/); normalizing risks false-positive resumes.
    • Keep sessionId for one release: avoids orphaning in-flight .sequant/state.json records across upgrade.
    • canResume on the driver, not free function: Codex's future AGENTS.md hash check is driver-specific; free function can't reach driver state.

    Open questions

    1. ResumeHandle.token as plain string vs driver-tagged union → recommend string; driver discriminates via handle.driver. Cosmetic if wrong.
    2. agentsMdHash on ResumeHandle (shared optional) vs Codex-internal → recommend shared optional. Minor field bloat if wrong.
    3. Delete legacy sessionId this release? → no; one-release deprecation window to keep in-flight state migrating cleanly.

    Deferrals

    Out-of-scope (non-goals, implicit)

    This refactor does not add new resume call sites, change phase ordering, change worktree lifecycle, or rename the on-disk sessionId field in .sequant/state.json.

  5. added
    planned
    refactor
    complex
    on May 30, 2026
  6. admarble commented on May 30, 2026

    @admarble
    ContributorAuthor

    /exec progress — PR #680 opened

    Branch: feature/674-refactor-normalize-agent-driver-resume-semantics-o
    PR: #680

    AC coverage

    AC Status Notes
    AC-1 — ResumeHandle on configs + @deprecated sessionId mirror ✅ Implemented agent-driver.ts:9-77
    AC-2 — ClaudeCodeDriver populates originCwd ✅ Implemented claude-code.ts:153-160, 230-237
    AC-3 — Driver-owned canResume; remove !worktreePath guard ✅ Implemented agent-driver.ts:97-113; phase-executor.ts:655-669
    AC-4 — Same-cwd resume only; transparent fallback on mismatch ✅ Implemented claude-code.ts:42-45, 72-89
    AC-5 — CodexDriver same-cwd rule 🔄 Deferred to #497 .skip placeholder in fixture
    AC-6 — Same-worktree resume works across phases ✅ Implemented Regression fix; new test in phase-executor.test.ts
    AC-7 — Codex AGENTS.md parity 🔄 Deferred to #497 Gated on CodexDriver
    AC-8 — Fixture test (cross-worktree rejected; Codex it.skip; preserved/advisory/skipped annotation) ✅ Implemented resume-semantics.test.ts (10 passed, 2 skipped)
    AC-9 — phase-executor.ts:653 comment ✅ Done in #675 Per spec

    Key files changed

    • src/lib/workflow/drivers/agent-driver.ts — new ResumeHandle type; canResume on the interface
    • src/lib/workflow/drivers/claude-code.ts — byte-equal cwd gate; transparent fallback
    • src/lib/workflow/drivers/aider.ts — canResume returns false
    • src/lib/workflow/phase-executor.ts — replaced sessionId && !worktreePath with driver-owned check
    • src/lib/workflow/batch-executor.ts — threads ResumeHandle across phases
    • src/lib/workflow/state-schema.ts + state-manager.ts — new optional resumeHandle field; updateResumeHandle()
    • src/lib/workflow/drivers/resume-semantics.test.ts (new) — AC-8 fixture
    • CHANGELOG.md — [Unreleased] entry under ### Changed

    Checks

    Known gaps

    • AC-5 / AC-7 remain unchecked on the issue; both are gated on feat: add OpenAI Codex CLI agent driver #497 landing CodexDriver. The fixture test has two it.skip cases ready to flip once CodexDriver exists.
    • Legacy IssueState.sessionId is @deprecated-mirrored for one release. Plan: remove in the release after this one once in-flight state files have aged out. Not tracked as a separate issue — flagged in the state-schema.ts and state-manager.ts docstrings.
  7. admarble commented on May 30, 2026

    @admarble
    ContributorAuthor

    QA Review for Issue #674

    AC Coverage

    AC Source Description Status Notes
    AC-1 Original ResumeHandle { driver, token, originCwd } on AgentExecutionConfig + AgentPhaseResult; sessionId as @deprecated mirror MET agent-driver.ts:17-24, 44-46, 62-68; deprecation JSDoc explicit; both fields populated by ClaudeCodeDriver (claude-code.ts:153-157, 164-165).
    AC-2 Original ClaudeCodeDriver populates originCwd from config.cwd MET claude-code.ts:234-240 (buildResumeHandle(token, originCwd)) called with config.cwd on every result branch (success, error, exception).
    AC-3 Original Driver-owned canResume(handle, targetCwd); remove !worktreePath guard at phase-executor.ts:660 MET Interface contract at agent-driver.ts:98-112; old sessionId && !worktreePath heuristic deleted (phase-executor.ts:655-669), replaced with driver.canResume(resumeHandle, cwd) gate.
    AC-4 Original Resume only when originCwd === cwd; transparent fallback on mismatch MET claude-code.ts:42-45 byte-equal check, including handle.driver === this.name cross-driver guard; claude-code.ts:79-89 silently drops resume: on mismatch (verified by resume-semantics.test.ts:111-121). Comment cites #675 empirical finding.
    AC-5 Original CodexDriver same-cwd rule N/A Explicitly deferred to #497 per spec; fixture has .skip placeholder (resume-semantics.test.ts:183-190).
    AC-6 Original Same-worktree resume works across phases (regression fix) MET Old guard blocked all worktree resume; new gate accepts handles where originCwd === cwd. Regression test at phase-executor.test.ts:680-705 asserts handle propagates to executePhase (4th arg).
    AC-7 Original Codex AGENTS.md parity precondition N/A Deferred to #497 (gated on CodexDriver).
    AC-8 Original Fixture test: cross-worktree rejected for both drivers, same-worktree succeeds, Codex .skip; preserved/advisory/skipped annotations MET resume-semantics.test.ts covers canResume truth table (3 tests), executePhase resume gating (4 tests including legacy sessionId-only fail-safe), Aider rejection (2 tests), Codex .skip × 2. Each test prefixed with PRESERVED/ADVISORY/SKIPPED comment. 10 passed, 2 skipped.
    AC-9 Original Reconcile phase-executor.ts:653 comment MET Done in merged PR #675 (f6b8e40); new comment at phase-executor.ts:655-661 re-cites #675 finding.

    Coverage: 7/7 in-flight AC items met; AC-5 and AC-7 deferred to #497.


    Precheck Findings

    Precheck Findings: unavailable — inline fallback used (.sequant/gap-precheck.json not present).


    CI Status

    Check State Bucket Impact
    validate-skills SUCCESS pass ✅ MET
    typecheck SUCCESS pass ✅ MET
    validate-plugin SUCCESS pass ✅ MET
    build (20.x) IN_PROGRESS pending ⏳ PENDING
    build (22.x) IN_PROGRESS pending ⏳ PENDING

    CI Summary: 3 passed, 2 pending, 0 failed
    Markdown-only relaxation: Not applicable (.ts files dominate the diff — 10/11 files are TypeScript). Pending build matrix checks remain gating.


    Quality Metrics

    Metric Value Status
    Type issues (any) 0 added OK
    Deleted tests 0 OK
    Files changed 11 OK
    Lines added +464 -
    Lines deleted -53 -

    Test Coverage Analysis

    Changed File Tier Has Tests? Test File
    src/lib/workflow/drivers/agent-driver.ts Standard ✅ Yes resume-semantics.test.ts (interface contract)
    src/lib/workflow/drivers/claude-code.ts Standard ✅ Yes resume-semantics.test.ts
    src/lib/workflow/drivers/aider.ts Standard ✅ Yes resume-semantics.test.ts
    src/lib/workflow/phase-executor.ts Standard ✅ Yes phase-executor.test.ts (AC-6 regression)
    src/lib/workflow/batch-executor.ts Standard ⚠️ Indirect batch-executor.test.ts covers other paths; resume-handle threading not separately asserted
    src/lib/workflow/state-schema.ts Standard ⚠️ No Schema field addition; zod-validated at runtime
    src/lib/workflow/state-manager.ts Standard ⚠️ No updateResumeHandle lacks a unit test
    src/lib/workflow/drivers/index.ts Optional ✅ Yes Re-export only

    Coverage: Core driver logic and phase-executor handoff covered; batch-executor wiring and updateResumeHandle rely on integration testing.


    Code Review

    Strengths:

    Issues:

    • None blocking.

    Suggestions:

    • state-manager.ts:497-519 keeps updateSessionId as a deprecated entry point but adds no test that legacy callers writing through it produce a fail-safe-inert state record. A one-line test on the existing state-manager suite would lock in the documented contract.
    • phase-executor.ts:680 writes both resumeHandle: eligibleHandle and sessionId: eligibleHandle?.token into the agent config. The driver only ever consumes the handle when both are present (claude-code.ts:80-84), so the sessionId mirror at this hop is dead — only the state-schema.ts-level mirror matters for migration. Worth a comment, or drop the line.

    Test Quality Review

    Category Status Notes
    Behavior vs Implementation ✅ OK Tests assert on queryCalls[0].options.resume (the boundary), not internal state.
    Coverage Depth ✅ OK Truth table (3 cases) + executePhase routing (4 cases) + Aider unconditional false (2 cases) + cross-driver guard.
    Mock Hygiene ✅ OK Only @anthropic-ai/claude-agent-sdk mocked — the external boundary.
    Test Reliability ✅ OK No timing; async generator yields synchronously. queryCalls.length = 0 reset per test prevents bleed.

    Anti-Pattern Detection

    Dependency Audit

    N/A — No package.json changes.

    Code Patterns

    No critical or warning patterns detected in changed files. No new any casts, no hardcoded secrets, no await inside loops, no empty catches.


    Call-Site Review

    New exported functions/types detected: ResumeHandle type, canResume method on AgentDriver, updateResumeHandle on StateManager, buildResumeHandle (private) on ClaudeCodeDriver.

    Symbol Call Sites Loop? Conditions AC Match
    ResumeHandle type agent-driver.ts, claude-code.ts, aider.ts, phase-executor.ts, batch-executor.ts, state-manager.ts, state-schema.ts, plus re-export N/A N/A ✅ Threaded through every relevant boundary.
    driver.canResume(handle, cwd) phase-executor.ts:667 No resumeHandle && … ✅ Matches AC-3 (driver-owned eligibility).
    stateManager.updateResumeHandle batch-executor.ts:569 (spec), batch-executor.ts:838 (general phase) No if (result.resumeHandle) ✅ Matches AC-1 (persists handle, not bare sessionId).
    buildResumeHandle All 4 return paths in claude-code.ts (success, error, no-result, catch) No if (!token) return undefined ✅ Originating cwd captured on every termination.

    Findings: No call-site mismatches.


    Execution Evidence

    N/A — No scripts/ or CLI files changed.


    Skill Command Verification

    N/A — No .claude/skills/**/*.md files changed.


    Detection Pattern Verification

    Precondition false (no skill markdown changes) — section omitted per §6c.


    CLI Registration Verification

    N/A — No RunOptions or bin/cli.ts changes.


    Smoke Test

    Not Required — Internal type refactor; behavior covered by 887-test workflow suite (all passing).


    Manual Test ACs

    N/A — Spec plan does not flag any AC as Manual Test; all are Unit Test or Integration Test.


    CHANGELOG Verification

    Check Status
    CHANGELOG.md exists ✅ Found
    User-facing changes ✅ Yes (refactor: commit detected)
    [Unreleased] entry ✅ Present (### Changed, cites #674)
    Entry format ✅ Valid (includes issue number, explains regression fix and deprecation)

    Result: CHANGELOG requirements met.


    Risk Assessment

    • Likely failure mode: A future driver author forgets to verify handle.driver === this.name in canResume, letting a Claude Code handle activate on (e.g.) a Codex path. Mitigated by the interface contract docstring, but not enforced at compile time.
    • Not tested: batch-executor.ts's handle threading across phases (spec → exec → qa) and the persistence round-trip through state-manager.updateResumeHandle. The unit tests verify the driver and the phase-executor argument, but the integration test that proves a resumed worktree phase actually reuses the session lives only as a fixture-mocked test — there is no end-to-end test against a real worktree.
    • Sibling sites considered: Scanned all sessionId/resumeHandle/canResume references across src/. Only the documented call sites touch resume logic: state-hook.ts retains its updateSessionId(sessionId: string) skill-side API by design (writes legacy-only state which the new fail-safe correctly declines). No cross-file sibling code with the same root cause.
    • Sibling-line audit: Single-call-site gate replacement at phase-executor.ts:655-669; no adjacent intra-file resume logic carries the old !worktreePath heuristic.

    Adversarial Re-Read

    Findings: No gaps found because: (1) verbatim motivating-example fixture from issue body (Claude Code SDK cwd-mismatch returns "No conversation found", verified in #675's empirical comment) is encoded in resume-semantics.test.ts:111-121 and the corresponding production code at claude-code.ts:79-89 matches the fixture; (2) evidence claims in the exec PR comment (171 workflow tests passing, build clean, lint clean) were re-validated locally — 887 workflow tests pass, build is clean, no surviving !worktreePath resume heuristic; (3) process state is clean (worktree on branch HEAD, no uncommitted changes, 0 commits behind origin/main); (4) sibling sites scanned via grep on sessionId|resumeHandle|canResume — only state-hook.ts retains a legacy entry point, which by design writes inert state under the new fail-safe; (5) Non-Goals from issue body (no new resume call sites, no phase ordering changes, no worktree lifecycle changes, no rename of on-disk sessionId) all held — the deprecated sessionId field is still present in state-schema.ts:271 as a one-release mirror.

    Status: Clean


    Behavior-Rule Survival Check

    AC Triggered? Survivors Status
    AC-3 Yes — "remove the !worktreePath guard" is a behavior rule None found. Grep for !worktreePath in phase-executor.ts returns only the unrelated worktree-isolation passthrough at function signatures. The old const canResume = sessionId && !worktreePath is gone. Clean

    Status: Clean


    Verdict: NEEDS_VERIFICATION

    All in-flight ACs (AC-1 through AC-4, AC-6, AC-8, AC-9) are MET. AC-5 and AC-7 are explicitly deferred to #497 (N/A). Implementation quality is high: driver-tagged handles, byte-equal cwd guard, cross-driver rejection, transparent fallback on mismatch, fail-safe for legacy sessionId-only state, and PRESERVED/ADVISORY/SKIPPED test annotations per AC-8.

    The verdict is NEEDS_VERIFICATION rather than READY_FOR_MERGE solely because the build (20.x) and build (22.x) CI checks are still IN_PROGRESS. The diff is not markdown-only (10/11 files are TypeScript), so the markdown-only build-matrix relaxation does not apply. Locally, npm run build is clean and npx vitest run src/lib/workflow/ passes 887/887 (2 .skip are the Codex placeholders gated on #497). Once the CI build matrix completes green, re-running /qa 674 will short-circuit to READY_FOR_MERGE.

    Documentation

    • CHANGELOG entry added (### Changed under [Unreleased])
    • README/docs — N/A (internal refactor; no user-facing surface)
    • Run /docs 674 before merge if anything user-facing is reconsidered

    Next Steps

    1. Wait for build (20.x) and build (22.x) CI checks to complete.
    2. Re-run /qa 674 once CI is green → verdict will promote to READY_FOR_MERGE.
    3. Merge PR refactor(#674): driver-tagged ResumeHandle with cwd-bound resume #680; feat: add OpenAI Codex CLI agent driver #497 inherits the now-defined ResumeHandle + canResume contract and will fill in AC-5, AC-7, and the Codex half of AC-8.
    4. Optional follow-ups (non-blocking, see "Suggestions"): unit test for updateSessionId fail-safe behavior; clarify or drop the dual-write of sessionId mirror at phase-executor.ts:680.
  8. admarble commented on May 30, 2026

    @admarble
    ContributorAuthor

    QA Review for Issue #674 (PR #680)

    AC Coverage

    AC Description Status Notes
    AC-1 Introduce ResumeHandle{driver,token,originCwd}; carry on config + result; keep sessionId as deprecated alias MET agent-driver.ts: interface added; both AgentExecutionConfig and AgentPhaseResult carry resumeHandle; sessionId kept + JSDoc @deprecated. Schema + state-manager mirror the token.
    AC-2 ClaudeCodeDriver populates originCwd from config.cwd and returns it MET buildResumeHandle(token, config.cwd) called at all 4 return sites (success / error-result / no-result / catch).
    AC-3 Driver-owned canResume(handle, targetCwd); move eligibility out of !worktreePath heuristic MET Interface method added; phase-executor.ts now resolves driver first and gates on driver.canResume(resumeHandle, cwd). Old sessionId && !worktreePath removed.
    AC-4 Claude Code resumes only when originCwd === cwd, else fresh MET Byte-equal compare + handle.driver === this.name guard; mismatch silently drops resume: and starts fresh.
    AC-5 CodexDriver same rule, driver-enforced N/A CodexDriver lands in #497 (AC text: "when added in #497"). canResume contract documents the Codex rule; .skip placeholder test gates on #497.
    AC-6 Resume works across phases within the same worktree (regression fix) MET canResume allows same-cwd; phase-executor.test.ts AC-6 test asserts resumeHandle threads into executePhase.
    AC-7 AGENTS.md parity as Codex resume precondition N/A Folds into #497 (no CodexDriver yet). Documented in the canResume contract.
    AC-8 Fixture test: cross-worktree rejected for both drivers; same-worktree succeeds; per-behavior preserved/advisory/skipped MET resume-semantics.test.ts: Claude + Aider cross-worktree rejection, same-worktree token pass-through, legacy-sessionId-no-resume, handle round-trip. PRESERVED/ADVISORY/SKIPPED annotations present; Codex assertion is .skip (can't assert a non-existent driver).
    AC-9 Verify empirically whether SDK crashes vs resumes-in-place on cwd mismatch; reconcile phase-executor.ts comment MET Comment now states recoverable error_during_execution ("No conversation found"), not exit-1 crash (the #675 docs precursor). New driver/comment text consistent against @anthropic-ai/[email protected].

    Coverage: 7/7 applicable ACs MET; AC-5 & AC-7 correctly deferred to #497 (Codex).


    Quality Metrics

    Metric Value Status
    Type issues (any) 0 added OK
    Deleted tests 0 OK
    Files changed 11 OK
    Lines +464 / -53 OK
    Build (tsc) pass OK

    CI Status

    Check State Impact
    build (20.x) SUCCESS MET
    build (22.x) SUCCESS MET
    typecheck SUCCESS MET
    validate-plugin SUCCESS MET
    validate-skills SUCCESS MET

    CI Summary: 5 passed, 0 pending, 0 failed.


    Test Coverage Analysis

    Changed File Has Tests? Test File
    drivers/agent-driver.ts (interface) ✅ resume-semantics.test.ts
    drivers/claude-code.ts ✅ resume-semantics.test.ts (canResume + executePhase gating)
    drivers/aider.ts ✅ resume-semantics.test.ts (always-false)
    phase-executor.ts ✅ phase-executor.test.ts (AC-6 threading)
    batch-executor.ts ⚠️ indirect sessionId→resumeHandle rename; covered by existing flow tests
    state-manager.ts (updateResumeHandle) ⚠️ No direct test mirrors updateSessionId pattern
    state-schema.ts ✅ implicit zod schema exercised via state-manager tests

    Targeted run: 187 passed, 2 skipped (the 2 skips are the Codex .skip placeholders).


    Code Review

    Strengths:

    • Clean separation of concerns: resume eligibility is now driver-owned (canResume) instead of a leaky !worktreePath heuristic in the orchestrator. This is the correct abstraction and directly unblocks the AC-6 same-worktree regression.
    • Byte-equal cwd comparison (not normalized) is the right call and is explicitly justified — it preserves parity with the SDK's literal-cwd storage key, avoiding false-positive resumes that would then miss on disk.
    • Fail-safe back-compat: legacy bare sessionId (no originCwd) is treated as inert rather than blindly resumed. Documented in code, schema, state-manager, and CHANGELOG.
    • buildResumeHandle applied uniformly across all 4 driver return paths — no return site leaks a result without the handle.
    • Cross-driver guard (handle.driver === this.name) prevents a Codex handle from being honored by Claude Code once feat: add OpenAI Codex CLI agent driver #497 lands.
    • Test annotations (PRESERVED / ADVISORY / SKIPPED) make harness drift visible — converting a SKIPPED Codex test without feat: add OpenAI Codex CLI agent driver #497 becomes a review signal.

    Issues: None blocking.

    Suggestions (non-blocking):

    • StateManager.updateResumeHandle has no direct unit test. It's a 15-line mirror of the tested updateSessionId, but a small test asserting it writes resumeHandle + mirrors sessionId + bumps lastActivity (and throws on unknown issue) would close the gap.
    • Minor redundancy: phase-executor.ts sets sessionId: eligibleHandle?.token alongside resumeHandle. Harmless (driver prefers resumeHandle), but the duplicate could be dropped once the deprecation window closes.

    Risk Assessment

    • Likely failure mode: A future phase registered without requiresWorktree could change cwd between phases; since canResume is byte-equal on cwd, this fails safe to a fresh session (never a wrong-cwd resume). The deprecation of sessionId is the main temporal risk — if a downstream consumer outside this repo reads result.sessionId for resume it still works (mirror retained).
    • Not tested: updateResumeHandle (direct); cross-process resume seeding from state.json — but note that path was never wired (the in-memory resumeHandle starts undefined and state.resumeHandle is write-only, identical to the prior sessionId behavior — no regression introduced here).
    • Sibling sites considered: Cross-file driver siblings — AiderDriver handled (declines all resume); CodexDriver is feat: add OpenAI Codex CLI agent driver #497. No other AgentDriver implementers (build would have failed the interface otherwise).
    • Sibling-line audit: Intra-file — buildResumeHandle is invoked at every ClaudeCodeDriver.executePhase return site (success/error/no-result/catch); all pass config.cwd consistently. No adjacent return path leaks a result without a handle.

    Adversarial Re-Read

    Findings: Walked the diff against all 9 ACs, ran build + targeted suite (187 passed), traced resumeHandle from driver return → mapAgentSuccessToPhaseResult → executePhase → executePhaseWithRetry → batch-executor threading + state persistence. Two non-blocking gaps surfaced: (1) updateResumeHandle lacks a direct test; (2) state-persisted resumeHandle is write-only (pre-existing parity, not a regression). No verbatim motivating-example fixture was left unrun; no "evidence" claim is a bug-repro; process state is clean (worktree intact, 0 behind main, mergeable). Codex ACs (5, 7) match their literal "when added in #497" text — not silent scope expansion.

    Status: Gaps Found (non-blocking)


    Verdict: AC_MET_BUT_NOT_A_PLUS

    All 7 applicable ACs are MET; the two Codex ACs are correctly scoped to #497 per their own text. Build and all 5 CI checks pass; core resume logic is well-tested with clear behavior annotations. This is a borderline-A+ refactor held just short of READY_FOR_MERGE by one closeable gap: StateManager.updateResumeHandle (a new public method) has no direct unit test. Add a short test for it and this is A+.

    Documentation

    Next Steps

    1. Add a unit test for StateManager.updateResumeHandle (writes resumeHandle, mirrors sessionId, bumps lastActivity, throws on unknown issue).
    2. (Optional) Run /docs 674 before merge if you want the resume-semantics contract documented for maintainers.
  9. added a commit that references this issue on May 31, 2026
  10. admarble commented on May 31, 2026

    @admarble
    ContributorAuthor

    QA Update — Issue #674 (PR #680)

    The one closeable gap from the prior QA is now resolved.

    Added ([1f24c30]): a direct unit test for StateManager.updateResumeHandle — asserts it writes the driver-tagged resumeHandle, mirrors the token into the deprecated sessionId, bumps lastActivity, and throws on an unknown issue. state-manager.test.ts: 69 passed (+4).

    All 7 applicable ACs MET (AC-5/AC-7 deferred to #497 per their text). Build + 5 CI checks green. With updateResumeHandle now directly covered, the prior AC_MET_BUT_NOT_A_PLUS blocker is cleared.

    Verdict: READY_FOR_MERGE

    Documentation: optionally run /docs 674 before merge to document the resume-semantics contract for maintainers.

  11. added a commit that references this issue on May 31, 2026
  12. added 3 commits that reference this issue on Sep 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    complexplannedrefactor

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions