decompose phase loops on coverage-mapping discovery after repeated successful haiku_discovery_complete { ok: true }
Versions
- MCP / plugin: 4.5.6 (both)
- Studio / stage:
software/product - Intent:
location-timesheet-summary
Symptom
After a per-stage reset of the product stage and a fresh run-through, the workflow engine emits a decompose prompt whose body contains the Discovery Fan-Out section listing coverage-mapping as the one outstanding discovery artifact — even though haiku_discovery_complete has returned { ok: true } for that template on three separate attempts.
Each haiku_run_next tick re-emits the same Discovery Fan-Out prompt asking for coverage-mapping. The decomposition phase is never reached.
Reproduction
- Reset the
productstage:haiku_stage_reset { intent: "location-timesheet-summary", stage: "product" }. - Tick to elaborate; record elaboration; verify; pass.
- Tick to decompose. Engine fans out 4 discovery subagents (
acceptance-criteria,behavioral-spec,coverage-mapping,data-contracts). - 3 of 4 merge cleanly.
coverage-mappinghitsdiscovery_merge_conflictonproduct/DATA-CONTRACTS.md+stages/product/elaboration.md(sibling-owned files). - Run
haiku_run_next→ engine emits a new decompose prompt asking only forcoverage-mapping. Spawn the retry agent. - Retry agent resolves the merge conflicts via
--theirson sibling files, commits, callshaiku_discovery_complete { template: \"coverage-mapping\" }. Receives{ ok: true, message: \"merged haiku/<intent>/discovery-product-coverage-mapping → haiku/<intent>/product\" }. - Run
haiku_run_next→ engine emits the same decompose prompt asking forcoverage-mappingagain. - Spawn a 3rd attempt: working tree clean, artifact already committed,
haiku_discovery_completereturns{ ok: true }again. - Run
haiku_run_next→ engine emits the same decompose prompt asking forcoverage-mappinga 4th time.
Expected
After haiku_discovery_complete { ok: true } for all 4 templates (acceptance-criteria, behavioral-spec, coverage-mapping, data-contracts), the next haiku_run_next tick should advance past the Discovery Fan-Out section and emit the actual unit-decomposition instructions.
Evidence
All four discovery artifacts are physically present and committed on the stage branch haiku/location-timesheet-summary/product:
``` .haiku/intents/location-timesheet-summary/product/ACCEPTANCE-CRITERIA.md (53,892 bytes) .haiku/intents/location-timesheet-summary/product/DATA-CONTRACTS.md (44,496 bytes) .haiku/intents/location-timesheet-summary/knowledge/COVERAGE-MAPPING.md (42,638 bytes) .haiku/intents/location-timesheet-summary/features/*.feature (24 files) ```
Latest commit on the coverage-mapping isolation worktree: `3c027b4b4b9 haiku: merge discovery coverage-mapping into product`.
`haiku_stage_get { field: "discovery_complete" }` and `{ field: "discovery" }` both return `{ found: false, value: null }`, so there doesn't appear to be a `state.json` field tracking discovery completion.
Suspected cause
The engine's per-tick "needed discoveries" computation does not appear to credit a prior `haiku_discovery_complete { ok: true }` response — possibly because the completion marker is keyed off a state field (or git note / tag) that isn't being written on the merge path, or because the conflict-recovery path on the first attempt left a flag inconsistent with the final merged state.
Repro environment
- macOS 25.3.0 (Darwin)
- Claude Code (Opus 4.7, 1M context)
- Project: `gigsmart/projects/monorepo` (mainline `dev`)
- Branch at time of repro: `haiku/location-timesheet-summary/product`
Workaround used (so far)
None — looping with re-spawn each time. Considering `/haiku:repair` next.
Fix landed in PR #355, commit `4682f42fb`.
Root cause confirmed from the session logs: the coverage-mapping subagent wrote COVERAGE-MAPPING.md to knowledge/ (carrying over the design-stage convention) instead of the template's declared product/ location:
``` plugin/studios/software/stages/product/discovery/COVERAGE-MAPPING.md: location: .haiku/intents/{intent-slug}/product/COVERAGE-MAPPING.md ```
Actual on-disk state from the repro: ``` knowledge/COVERAGE-MAPPING.md ← where the subagent wrote it product/ ← where the cursor looked (ACCEPTANCE-CRITERIA.md, DATA-CONTRACTS.md only) ```
haiku_discovery_complete ff-merged the wrong-path commit and returned { ok: true }. The cursor's existence check on every subsequent tick then looked at product/COVERAGE-MAPPING.md, found it missing, and re-emitted the Discovery Fan-Out prompt asking for the same template. Three successive "fixes" all wrote to the same wrong directory and got the same lying success.
The fix is three coordinated changes:
-
haiku_discovery_completenow verifies the artifact exists at the template's resolvedlocation:inside the isolation worktree BEFORE merging. On miss it returns a new error codediscovery_artifact_missingwithexpected_path,location, and a message naming the exact absolute path + git invocation + re-call to retry. The worktree is NOT reaped on this error so the subagent can fix the write location and retry without redispatch. -
The subagent's initial prompt now states the EXACT absolute artifact path under a dedicated "Required artifact path (EXACT)" section, computed from the template's
location:resolved against the isolation worktree. Replaces the old vague guidance ("under the worktree'sknowledge/dir per the template'slocation:") that let this kind of drift happen. -
The error message itself echoes the same path so a parent agent reading just the failure response sees the same fix path as the subagent — initial prompt and failure prompt agree.
Test coverage in packages/haiku/test/haiku-discovery-complete.test.mjs pins the new gate (subagent calls with a wrong-path commit → tool returns discovery_artifact_missing with expected_path inside the worktree → worktree NOT reaped).
After this lands, the repro case will fail-loud on the first wrong-path attempt instead of looping silently. The agent will see the expected path and write to the right place on retry.
Re-tested on 5.0.1 after the 4.0.0 → 5.x migration ran cleanly via #358's fix.
haiku_run_next advances past migrated → emits the same decompose prompt with the Discovery Fan-Out section listing coverage-mapping as the one outstanding artifact:
## Discovery Fan-Out (REQUIRED)
This stage produces 1 discovery artifact: `coverage-mapping`.
All four discovery artifacts remain physically present on the stage branch:
.haiku/intents/location-timesheet-summary/product/ACCEPTANCE-CRITERIA.md (53,892 bytes)
.haiku/intents/location-timesheet-summary/product/DATA-CONTRACTS.md (44,496 bytes)
.haiku/intents/location-timesheet-summary/knowledge/COVERAGE-MAPPING.md (42,638 bytes)
.haiku/intents/location-timesheet-summary/features/*.feature (24 files)
So the migration cleared #358, but the underlying state-tracking miss on coverage-mapping is intact in 5.0.1. Not spawning a 4th retry — we already established haiku_discovery_complete returns ok: true and the engine still re-asks on the next tick.
@pgarza98 — addressed in PR #360, commit `7732cd915`.
You're right that PR #355 only prevented the NEW occurrence (the engine no longer ff-merges a wrong-path subagent write). The file landed at `knowledge/COVERAGE-MAPPING.md` on the pre-fix engine, so the artifact-presence gate has nothing to gate on — the merge already happened.
The follow-up fix (in PR #360) self-heals that historical bad state. In `decompose.ts`, before the existence-check filter that drives re-emission, the engine now scans each artifact's declared `outputPath`. If the declared path is empty AND a same-name file exists at the legacy `knowledge/
- Source must exist at `knowledge/
.md`. - Destination must be empty (no overwrite).
- The legacy path must NOT equal the declared outputPath (no self-move for templates that legitimately declare `knowledge/
.md`).
Console-logs both the success and any error so operators see what happened.
For your `location-timesheet-summary` intent, on the next `haiku_run_next` tick after PR #360 ships, the engine will move `.haiku/intents/location-timesheet-summary/knowledge/COVERAGE-MAPPING.md` → `.haiku/intents/location-timesheet-summary/product/COVERAGE-MAPPING.md` automatically. The existence check then passes and decompose advances.
If you want to unblock NOW without waiting for the release, the manual move is: ```bash mv .haiku/intents/location-timesheet-summary/knowledge/COVERAGE-MAPPING.md \ .haiku/intents/location-timesheet-summary/product/COVERAGE-MAPPING.md git add -A && git commit -m "relocate misplaced coverage-mapping artifact" ```
Test coverage in PR #360: `discovery-relocate-misplaced.test.mjs` (3 cases) pins the relocation contract, the skip-when-empty-source path, and the skip-when-destination-exists path.