Closes #3770, closes #3773.
phase_complete now REFUSES to complete a phase while any planned task in it is unfinished (status is neither completed nor closed — the readiness predicate shared with Epic phase-readiness; blocked refuses, matching Epic's wave-close semantics). The refusal names the unfinished task IDs (capped at 20, then a count) and returns a structured update_task_status recovery. The check runs early (before any state-mutating step, so a refused call leaves .swarm/ byte-identical and never creates plan.md) and again as an always-applicable re-read at the commit boundary — Turbo does NOT bypass it (the turbo enable disclosure now says so). It reads the authoritative plan state observationally (ledger peek with file/SQLite authority resolution; the plan.json projection only when no ledger authority exists), and a ledger authority that exists but cannot be trusted — a torn ledger tail, a resetting crash marker, an unreadable ledger, or duplicate phase ids — REFUSES with PLANNED_TASKS_UNKNOWN rather than completing over an unreadable authority. phase_complete.enabled: false remains the documented operator bypass of completion enforcement.
- The
phase_complete core event is now exactly-once (#3770's pinned preserving failure): a normal completion records a durable phase_completed ledger event (parity with the close-terminal path; savePlan gained completedPhaseIds), and the core event is appended through the authority-key dedupe keyed by (ledger root digest, phase, transition seq). Duplicate calls and crash-between-save-and-append retries collapse to one record; a re-rooted plan's new completion gets a distinct identity; concurrent double-calls write one event (the second call returns immediately with the retryable PHASE_COMMIT_LOCKED result before any append — the dedupe additionally guards the sequential duplicate path).
getProjectDb now REFUSES writable open with a typed schema_newer_than_supported ProjectDbError naming the recorded and supported versions when a database's schema_migrations records a newer schema than this client knows (#3773); the global-rules store, the memory sqlite provider, and the memory-family merge destination make the same refusal with an untyped Error carrying the same version-bearing message (typed open errors remain scoped to the project swarm.db). In every case schema and rows are preserved, getGlobalDb closes its raw handle on the refusal, and the /swarm close sqlite archive opens its VACUUM INTO source read-only; the read-only diagnostic open (withProjectDbReadOnly) is exposed for the project swarm.db store, which is also the store whose refusal is typed. Current and supported-older schemas keep opening/migrating exactly as before. Public type surface: ProjectDbErrorCategory gains schema_newer_than_supported (additive).
Bug Fixes
- tools,db: refuse phase_complete with unfinished planned tasks and newer-schema sqlite opens (#3770, #3773) (64605a9)
- tools: feedback round 3 — degraded ledger authorities refuse, duplicate phase ids refuse, normal flow records phase_completed (5bb912f)
- tools: Stage B reviewer fixes — commit re-read before the close intent, fixture type, second stale name, fragment contract wording (52fcf84)