Skip to content

docs(#604): chain-mode 29% success rate — failure forensics - #621

Merged
admarble merged 4 commits into
mainfrom
feature/604-investigate-metrics-chain-mode-29-success-rate-vs-
May 10, 2026
Merged

admarble merged 4 commits into
mainfrom
feature/604-investigate-metrics-chain-mode-29-success-rate-vs-

Conversation

@admarble

Copy link
Copy Markdown
Contributor

Summary

Investigation of why chain mode (--chain) shows 29% success vs 80% single-issue. Mirrors the #437 data-driven pattern — analysis first, no code changes until findings drive them.

  • Signal confirmed: 7 chain runs in .sequant/metrics.json, 28.6% whole-chain success vs 80% single-issue (spec+exec+qa).
  • Length matters: length-2 = 1/1, length-3 = 1/4 (25%), length-4 = 0/2 (0%).
  • Per-issue rate (61.5%) closer to single-issue baseline (80%) than the 29% headline suggests — whole-chain accounting marks all downstream issues as failed when issue 1 fails.
  • Verdict: RESTRICT to length=2; warn for length≥3. No chain-specific root causes; failures are pre-existing modes (rate limits, QA saturation, AC_MET_BUT_NOT_A_PLUS retry-loop) amplified by halt-on-failure semantics.

Files changed

  • docs/reference/chain-mode-analysis-2026-05.md (new) — full forensic doc with run-by-run classification.
  • docs/features/parallel-execution.md — refresh stale 50% n=4 table.
  • docs/reference/run-command.md — refresh stale ~50% performance warning.

AC Coverage

AC Status Evidence
AC-1 confirm signal across full history ✅ 7 chain runs, 62 total; analysis doc §"Headline"
AC-2 segment by length and failure position ✅ analysis doc §"Segmentation by chain length"
AC-3 classify each failed chain run ✅ analysis doc §"Phase B" — table maps each run to root cause
AC-4 chain-specific vs incidental ✅ analysis doc §"Chain-attributable rate" — 0/5 chain-specific causes
AC-5 top-3 failure modes + verdict ✅ analysis doc §"Top-3 failure modes" + §"Phase C — Recommendation"
AC-6 sync /assess rule across mirrors 🔄 Deferred 2 user docs done; runtime + 6 skill mirrors deferred (small sample, mirror-drift risk)

Test plan

  • Read docs/reference/chain-mode-analysis-2026-05.md for forensic conclusions.
  • Confirm two stale "50% n=4 / ~50%" references are now updated with current data.
  • Decide whether to file a follow-up issue for the AC-6 runtime + skill-mirror rule change.

Closes #604

Forensic analysis of 7 chain runs in .sequant/metrics.json + run logs.
Confirms 29% chain-mode success rate vs 80% single-issue (spec+exec+qa).

Key findings:
- Length-3+ chain success: 1/6 = 17% (vs length-2: 1/1)
- Per-issue success when chain reaches the issue: 8/13 = 61.5%
  (much closer to single-issue baseline than the 29% headline suggests)
- Top failure mode (3/5): first-issue retry exhaustion halts entire chain
- 0/5 failures had chain-specific root causes — chain mode amplifies
  pre-existing failure modes (rate limits, QA saturation, AC_MET_BUT_NOT_A_PLUS
  retry-loop bug) rather than introducing new ones.

Verdict: RESTRICT chain to length=2; warn for length>=3.

This commit covers AC-1..AC-5:
- docs/reference/chain-mode-analysis-2026-05.md (new) — full analysis
- docs/features/parallel-execution.md — refresh stale 50% n=4 success table
- docs/reference/run-command.md — refresh stale "~50%" performance warning

AC-6 (runtime + skill mirrors) deferred — see analysis doc for the proposed
change. Per spec note "update in lockstep or skip entirely", the 9-touchpoint
runtime+mirror change is deferred to a follow-up given the small sample (n=7).
admarble added 3 commits May 9, 2026 23:31
…rate at length≥3

Closes the AC-6 gap from the QA review on PR #621. The original PR refreshed
the two user-facing docs (parallel-execution.md, run-command.md) but skipped
the runtime + 3 skill-mirror touchpoints — the spec said update in lockstep
or skip entirely, and partial update was the path it told us not to take.

Annotation (per QA's lower-risk recommendation; alternative was a threshold flip):

  Chain: npx sequant run … --chain --qa-gate -q   # alternative — N issues modify <path> (chain length≥3 historically 1/6 = 17%; see docs/reference/chain-mode-analysis-2026-05.md)

Touchpoints:
- src/lib/assess-collision-detect.ts: append historical rate to suggestion (length≥3 only)
- 3 mirrors of predicted-collision-detection.md: prose updated to match runtime
- Test added for the annotation; existing 'emits Chain:' test unchanged (regex still matches prefix)

Also fix two minor findings from the QA:
- chain-mode-analysis-2026-05.md L110: stale 50% n=4 reference pointed to git-workflows.md:126; actually was parallel-execution.md:126 (already refreshed in this PR)
- Add bridge note explaining the 92% (issue body, sequant stats snapshot at filing time) vs 80% (this analysis, spec+exec+qa filter, larger 62-run snapshot) single-issue gap; sequant stats counts every issues.length===1 run regardless of phases (src/commands/stats.ts:422)
… annotation-route rationale

Addresses three gaps surfaced during /qa adversarial re-read on dc59f78:

1. CHANGELOG [Unreleased]/Changed entry for #604 (verdict-blocker per §10a + §7).
   Single Keep-a-Changelog entry covers both branch commits: the runtime
   annotation in src/lib/assess-collision-detect.ts, the 3 skill mirrors,
   the new unit test, and the doc refreshes.

2. Strict-success filter footnote in chain-mode-analysis-2026-05.md after the
   "1/6 = 17%" segmentation table. Defines that "success" means
   outcome === "success" in metrics.json — the 2 length-3 partial chains are
   counted with failures, not successes. Under partial-counts framing the
   length≥3 rate would be 3/6 = 50% rather than 1/6 = 17%; we use the strict
   definition consistently so the headline (28.6%), the segmentation, and the
   runtime annotation all align.

3. §"Suggested /assess collision-detect change" updated to reflect the
   implemented annotation route (rather than the threshold-flip option the
   doc previously listed as one of two recommendations). Includes the
   why-not-threshold-flip rationale (n=7 too small to hard-restrict;
   surface the rate inline so users can weigh chain vs parallel) and the
   re-evaluate trigger (n≥20).
…te-metrics-chain-mode-29-success-rate-vs-

# Conflicts:
#	CHANGELOG.md
@admarble
admarble merged commit df6277c into main May 10, 2026
8 checks passed
@admarble
admarble deleted the feature/604-investigate-metrics-chain-mode-29-success-rate-vs- branch May 10, 2026 06:50
admarble added a commit that referenced this pull request May 11, 2026
Gap 1 — §6c precondition greps diff hunks, not file content.

The first cut of this section's precondition shelled out to
`xargs grep -lE ...` against the *current* skill-md file content. All
19 sequant SKILL.md files mention `grep|awk|jq|sed` in unrelated
example code, so the gate triggered on 100% of skill-md PRs and the
cost-saving intent of #608 / #609 evaporated. The fix iterates the
diffed skill-md files and only triggers §6c when the **added lines**
contain the patterns. On 6 historical merged PRs (#623 #620 #621 #617
#622 #547) the new gate skips §6c on 4/6 (67%) — vs 0/6 under the old
content-grep gate. Mirrored across `.claude/skills/`,
`templates/skills/`, `skills/`.

Gap 2 — `extractIdentifiersFromDiff` skips indented locals.

`content = line.slice(1).trimStart()` defeated the comment's claim of
"no nested-block decls" by stripping the indent that distinguishes
top-level from function-body declarations. The dogfood run on #609
surfaced 24 identifiers (17 of them local `const lines = …` /
`let inFence = …` style variables). Dropping `.trimStart()` brings
the surface to top-level decls only. New test asserts indented
`+  const local = …` is skipped while `+const topLevel = …` matches.

Gap 3 — Empirical 5-PR replay for AC-5 / AC-6.

New `--base-sha` / `--head-sha` CLI flags let `precheck.ts` replay
against historical merged PRs. SHAs validated with `/^[0-9a-f]{4,40}$/`
to avoid shell injection. Ran replay against 6 PRs (5 recent +
#547 for AC-6 demo): aggregate ≈ −1,002 tok/PR under the new gate;
PR #620's replay surfaced `acLiteralDiff.missingInPR.length = 8` —
a real catch the inline §1 prose was supposed to make but #608's
data shows §1 surfaced silently for years. Investigation doc
appended with per-PR table + correction to the prior
"true on 0 PRs" calibration claim.

Test count: 27 → 30 (indented-skip + 2 parseArgs flag tests).
`scripts/check-skill-sync.ts` reports qa/SKILL.md synced 3/3.
admarble added a commit that referenced this pull request May 11, 2026
…628)

* feat(#609): extract deterministic QA gap-checks into precheck script

New `scripts/qa/precheck.ts` runs three deterministic gap-checks before
the QA agent and emits `.sequant/gap-precheck.json`:

  - fixtures      — verbatim motivating-example extraction from issue body
                    (feeds §6d Q1 / §6c Step 4)
  - siblingGrep   — changed-identifier scan for cross-file sibling sites
                    (feeds §5)
  - acLiteralDiff — AC checkbox IDs in issue body vs PR body (feeds §1)

`qa/SKILL.md` gains Phase 0c that runs the precheck inline and consumes
its findings. §6c becomes a file-glob hard precondition (no skill-md
diff → emit nothing). §6c Step 4 prefers precheck `fixtures` over the
inline `awk` extractor when available. §6d trims to a single
adversarial paragraph (per #608's 9/14 / 0-actioned signal).

Inline fallback preserved on missing/error/`not_applicable` output.
Mirrored across all three `qa/SKILL.md` copies. Exit code always 0.

Investigation doc at `docs/investigations/qa-precheck-extraction.md`
covers AC-1 (22-row gate classification), AC-2 (per-PR run frequency),
AC-5 (section-size delta calibration via #608's 50-PR window:
~−1,585 tok/invoke window-typical), and AC-6 (regression-coverage
methodology against PR #547 / PR #533 shapes).

Builds on #608's signal-to-noise data which informed Phase A scope.

* fix(#609): close three gaps surfaced in post-commit QA

Gap 1 — §6c precondition greps diff hunks, not file content.

The first cut of this section's precondition shelled out to
`xargs grep -lE ...` against the *current* skill-md file content. All
19 sequant SKILL.md files mention `grep|awk|jq|sed` in unrelated
example code, so the gate triggered on 100% of skill-md PRs and the
cost-saving intent of #608 / #609 evaporated. The fix iterates the
diffed skill-md files and only triggers §6c when the **added lines**
contain the patterns. On 6 historical merged PRs (#623 #620 #621 #617
#622 #547) the new gate skips §6c on 4/6 (67%) — vs 0/6 under the old
content-grep gate. Mirrored across `.claude/skills/`,
`templates/skills/`, `skills/`.

Gap 2 — `extractIdentifiersFromDiff` skips indented locals.

`content = line.slice(1).trimStart()` defeated the comment's claim of
"no nested-block decls" by stripping the indent that distinguishes
top-level from function-body declarations. The dogfood run on #609
surfaced 24 identifiers (17 of them local `const lines = …` /
`let inFence = …` style variables). Dropping `.trimStart()` brings
the surface to top-level decls only. New test asserts indented
`+  const local = …` is skipped while `+const topLevel = …` matches.

Gap 3 — Empirical 5-PR replay for AC-5 / AC-6.

New `--base-sha` / `--head-sha` CLI flags let `precheck.ts` replay
against historical merged PRs. SHAs validated with `/^[0-9a-f]{4,40}$/`
to avoid shell injection. Ran replay against 6 PRs (5 recent +
#547 for AC-6 demo): aggregate ≈ −1,002 tok/PR under the new gate;
PR #620's replay surfaced `acLiteralDiff.missingInPR.length = 8` —
a real catch the inline §1 prose was supposed to make but #608's
data shows §1 surfaced silently for years. Investigation doc
appended with per-PR table + correction to the prior
"true on 0 PRs" calibration claim.

Test count: 27 → 30 (indented-skip + 2 parseArgs flag tests).
`scripts/check-skill-sync.ts` reports qa/SKILL.md synced 3/3.
admarble added a commit that referenced this pull request May 11, 2026
…ssions (#626)

* feat(#625): per-issue concurrency lock prevents concurrent sequant sessions

New src/lib/locks/ module with LockManager that claims
.sequant/locks/<issue>.lock via open(O_CREAT|O_EXCL) when sequant run
starts. A second session attempting the same issue is skipped with a
clear error message; the rest of the batch continues.

- Stale detection: same-host PID-dead clears immediately (covers
  SIGKILL); cross-host clears by 2h age fallback.
- --force takes over the lock; --force --signal-other also SIGTERMs the
  prior PID (same-host alive only).
- Read-only commands (status, merge) warn but proceed.
- New sequant locks list/clear subcommands.
- SEQUANT_ORCHESTRATOR env var no-ops the entire mechanism (MCP path).
- SEQUANT_LOCKS_DIR env var overrides the directory for test isolation.

Lock cleanup wired through ShutdownManager and process.on('exit') for
uncaught-exception coverage; SIGKILL recovery happens on the next run.

27 unit tests cover the stale-detection matrix, atomic acquire, force
semantics, orchestrator no-op, error format, and list/clear. Integration
tests spawn real child processes to verify O_EXCL atomicity and
SIGKILL stale-recovery.

Addresses one of the failure modes behind the 29% chain-mode failure
rate documented in #604 / #621.

* feat(#625): wire /fullsolve and /assess to concurrency lock; close AC-16/AC-18

Addresses the QA AC_NOT_MET gaps on PR #626. The lock primitive shipped
in the prior commit was solid for the CLI path but didn't reach the
motivating example (npx sequant run vs /fullsolve collision) because
the /fullsolve skill never claimed it.

- LockFile schema: add optional skipPidCheck flag. classifyStaleness
  now skips the same-host PID probe when set, falling back to age-only
  (2h). Required because skill shells exit immediately after `locks
  acquire`, leaving the lock's PID dead between acquire and release.
- LockManager: new releaseExternal() releases same-host skipPidCheck
  locks from any PID (the next skill shell's PID, not the original).
- CLI: new `sequant locks acquire/release/check <issue>` subcommands.
- Skills: /fullsolve SKILL.md Phase 0.3 acquires with --skip-pid-check;
  Phase 5.5 releases. /assess Step 1 probes via `locks check --json`
  and surfaces a dashboard warning when held. Mirrored across all
  three skill dirs (.claude/skills, templates/skills, skills).
- Tests: 8 new unit tests for skipPidCheck + releaseExternal,
  1 RunOrchestrator lockedResults flow test (AC-18), 1 SIGINT integration
  test verifying ShutdownManager.gracefulShutdown → releaseAll (AC-16).
  Total: 36 unit + 3 integration = 39 (was 29).
- README §Concurrency and CHANGELOG entry document skill wiring +
  --skip-pid-check rationale (2h orphan window if skill crashes).

QA verdict reference: AC-2 + AC-4 now MET (skill wiring); AC-16
covered by SIGINT integration test; AC-18 covered by orchestrator
lockedResults unit test.

* test(#625): assert buildLockedResult shape for AC-18 end-to-end coverage

Closes the literal AC-18 gap: prior test exercised the orchestrator's
per-issue acquire loop but didn't verify that buildLockedResult produces
the IssueResult shape the summary depends on (abortReason + locked
metadata flowing into run-display.ts:100). 40 lock tests now pass.

* feat(#625): close 5 lock-design gaps — skill TTL, /assess wiring, cleanup obligations

Addresses gaps surfaced post-QA review:

1. Skill-shell locks now use a SEPARATE 6h TTL (DEFAULT_SKILL_LOCK_TTL_MS)
   instead of inheriting the 2h cross-host staleAgeMs — long /fullsolve runs
   with multi-iteration QA loops no longer risk self-expiring their own
   lock. SEQUANT_SKILL_LOCK_TTL_MS env override.
2. New `sequant locks check-batch <issues...>` subcommand. Text mode emits
   one canonical ⚠ warning line per held issue (ready to paste into the
   /assess dashboard); JSON mode emits structured output. /assess SKILL.md
   updated to use the single batch call instead of per-issue probes.
3. New `locks-cli.integration.test.ts` exercises dist/bin/cli.js for the
   actual SKILL.md contract: acquire→block→release→check sequence,
   check-batch text/JSON/empty/orchestrator modes, and --force --signal-other
   --skip-pid-check skill-lock takeover (Gap 4).
4. /fullsolve SKILL.md now releases the lock on every halt branch (Phase
   1.3 spec failure, Phase 2.3 exec exhausted, Error Recovery section) and
   includes an explicit "release contract" at Phase 0.3 listing all known
   abort branches. Aborted runs no longer wait for the 6h TTL.

Tests: +19 (8 unit for skillLockTtlMs boundary cases + resolveSkillLockTtlMs
env parse; 13 CLI integration tests; minor: 1 SIGINT integration; AC-18
buildLockedResult). Full suite: 3067/3067.

Orchestrator-mode release JSON gains an `issue` field for shape consistency
with the non-orchestrator path.
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.

investigate(metrics): chain mode 29% success rate vs 92% single-issue — failure forensics

1 participant