Skip to content

fix(run): a spec-phase SPEC_DIVERGENCE marker is dropped because the skill's shape has no timestamp, so the run never halts #1691

Closed

Description

@admarble

Epic: graph-2026-11-simplify (found executing #1688) Tier: mechanical Execution: sequant_run Blocked by: #1688 (both edit phase-executor.ts)

Problem

A spec phase that declares SPEC_DIVERGENCE never halts the run. parseSpecDivergence (src/lib/workflow/phase-executor.ts:1142) reads markers through parsePhaseMarkers (phase-detection.ts:72). That function validates each one against PhaseMarkerSchema (state-schema.ts:74), which requires timestamp: z.string().datetime(), and drops a marker that fails validation without a word.

The spec skill tells the agent to end with a bare marker carrying "status":"failed", "outcome":"SPEC_DIVERGENCE", "divergenceAcs":"AC-N" and an "error" (.claude/skills/spec/SKILL.md:311). It doesn't mention timestamp. So a spec agent that follows its skill emits a marker the parser discards.

Observed: sequant #1688's spec (2026-11-16, run log in the owner's graph-run folder) ended with:

<!-- SEQUANT_PHASE: {"phase":"spec","status":"failed","outcome":"SPEC_DIVERGENCE","divergenceAcs":"AC-3","error":"AC-3 pins the per-site qa wrap …; owner must amend AC-3 or choose option B."} -->

The run printed ✔ #1688 spec and went on to exec, which picked one of the two options the spec had left to the owner. With npx tsx against main, parseSpecDivergence(<that line>) returns undefined. Add "timestamp":"2026-11-16T03:33:00Z" and the same line returns {"acs":"AC-3", …}.

Prior fixes / producers

Acceptance Criteria

  • AC-1: A SPEC_DIVERGENCE marker with no timestamp is returned by parseSpecDivergence, while a marker in a fenced code block still is not. Evidence: npx vitest run src/lib/workflow/phase-executor.test.ts -t "divergence without timestamp" → ≥ 2 passed, 0 failed
  • AC-2: A spec phase whose output ends with a marker shaped like the one above stops the run before exec. Evidence: npx vitest run src/lib/workflow/batch-executor.test.ts -t "spec divergence without timestamp" → ≥ 1 passed, 0 failed
  • AC-3: Phase detection still orders markers by timestamp. Evidence: npx vitest run src/lib/workflow/phase-detection.test.ts → 0 failed (constraint)

Non-Goals

  • Skill text (frozen).
  • What happens after the halt (ladder-halt bundle, resume).

Done when

A spec or exec agent that declares the spec impossible, in the shape its skill describes, stops the run.

Activity

  1. added
    graph-2026-11-simplify
    on Nov 16, 2026
  2. admarble commented on Nov 16, 2026

    @admarble
    ContributorAuthor

    Runner context, 2026-11-16

  3. admarble commented on Nov 16, 2026

    @admarble
    ContributorAuthor

    Complexity: Simple (3 ACs, 2 directories)

    AC Quality Check

    All three ACs are single-line with Evidence:. The -t filters match no test today, so AC-1 and AC-2 fail on main and cannot be vacuous. AC-2 needs care: batch-executor tests mock specDivergence directly (batch-executor.test.ts:3778), so a test that only sets that field would skip the parser and pass without the fix. See Plan step 3.

    Scope Assessment

    Non-Goals: present (skill text, post-halt behaviour). Verdict: ✅ SCOPE_OK

    Acceptance Criteria

    AC-1: Timestamp-less SPEC_DIVERGENCE marker is read; fenced one is not

    Verification: Unit Test
    Scenario: Given output ending with the #1688 line (no timestamp) → When parseSpecDivergence runs → Then {acs:"AC-3", message}. Same marker in a fenced block → undefined.
    Assumptions: exec's shape (with timestamp) keeps working.

    AC-2: Spec output ending in that marker halts before exec

    Verification: Integration Test
    Scenario: Given a spec phase whose raw output ends with the timestamp-less marker, run through mapAgentSuccessToPhaseResult and the batch loop → Then exec never runs and the #995 bundle prints.

    AC-3: Phase detection still orders by timestamp

    Verification: Unit Test (constraint, existing suite)

    Implementation Plan

    Decision (the issue asks the spec to pick): lenient reader used only by the escape hatch; the shared schema stays unchanged. Making timestamp optional would leak undefined into new Date(b.timestamp) at phase-detection.ts:111,141,262. Those would sort as NaN, and a timestamp-less marker could be picked as the "latest" phase, which changes behaviour AC-3 doesn't cover. A separate reader keeps detection untouched.

    1. phase-detection.ts: extract the regex scan from parsePhaseMarkers into a shared internal scanMarkerJson(body) (same code-block stripping, same regex, JSON.parse). parsePhaseMarkers keeps schema-validating the result. Behaviour is unchanged.
    2. phase-executor.ts:1142 parseSpecDivergence: read via the scanner and validate with PhaseMarkerSchema.partial({ timestamp: true }), or the .omit({timestamp:true}) equivalent. This accepts markers with or without a timestamp. Last divergence marker still wins. Update the doc comment, which currently says parsePhaseMarkers is reused verbatim.
    3. Tests (written in the worktree): phase-executor.test.ts "divergence without timestamp" has ≥2 cases (spec shape without timestamp parses; fenced does not; add the exec shape with timestamp). batch-executor.test.ts "spec divergence without timestamp": feed raw output through the real mapAgentSuccessToPhaseResult and not a mocked specDivergence, then assert exec is not invoked.
    4. Mutation-verify per CLAUDE.md: revert step 2 to parsePhaseMarkers, confirm exactly the new tests fail, restore, and record Mutation-verified: markers in the PR body. Run vitest only in the worktree.

    Design Review

    1. Where: reader side (parseSpecDivergence); the eight producing skills are frozen.
    2. Simplest: a lenient schema in the one consumer. Rejected: optional timestamp in the shared schema (the sort hazard above). Also rejected: editing the skill to add a timestamp (frozen, and the agent can't know the time).
    3. Pattern / recurrence: the reuse-parsePhaseMarkers pattern from feat(run): SPEC_DIVERGENCE escape hatch, ladder halts with evidence bundles, docs, rigged real run (#971 part B) #995. git log -S parseSpecDivergence shows no later fixes, so this is the first fix and there is no re-patch class.
    4. Reviewer challenge: "why not make timestamp optional?" Answer: step 2 above.
    5. Producers/consumers: the producer is the spec skill (SKILL.md:311); the exec skill's divergence marker has the same shape. Consumers of parsePhaseMarkers are the three detection sites plus this hatch. Only the hatch changes.

    Open Questions

    None blocking. Note that the same timestamp-less drop applies to any other consumer that needs a marker the skill emits without a timestamp. None is in scope.

    Recommended Workflow

    Phases: exec → qa
    Quality Loop: disabled
    Reasoning: a small, localised reader fix with unit and integration ACs. testgen is skipped because the tests are small enough for exec to write.

    Label Review

    Current: graph-2026-11-simplify. Recommended: add planned.

  4. added
    planned
    on Nov 16, 2026
  5. admarble commented on Nov 16, 2026

    @admarble
    ContributorAuthor

    QA Verdict: NEEDS_VERIFICATION

    Needs human review:

    • Required CI checks still pending; re-run QA after they report

    Reviewed in a separate session by claude-code (claude-opus-5-5); the change was written by claude-code (claude-sonnet-5-5).

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

    graph-2026-11-simplifyplanned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions