fix(gate): auto-finalize session after last phase approval

The model sometimes stops after receiving 'Fase approvata' without calling
`tht session finalize`, leaving the session open. Now the gate itself calls
finalize after advancing the max phase (F8), making session closure
deterministic regardless of model behavior.

- reviewer_confirm kind:phase: after phase advance at max_phase, gate calls
  `tht session finalize <session>` (best-effort with recovery message)
- SKILL.md updated: model no longer needs to call finalize itself
- Tests: 2 new JS tests (auto-finalize at max phase; no-finalize at non-max)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-07-07 18:47:19 +02:00
co-authored by Claude Opus 4.6
parent ade6838182
commit 893ad99594
3 changed files with 101 additions and 8 deletions
+17
View File
@@ -957,6 +957,23 @@ export default function (pi) {
PHASE_RECOVERY,
);
if (err) return err;
// Auto-finalize after advancing the LAST phase: the model may not
// follow through (token budget, turn end) leaving the session open.
const meta = phaseMeta(ctx);
if (curNum >= meta.max_phase) {
const fErr = relayIfThtFails(
ctx,
["session", "finalize", session],
"Fase approvata ma finalizzazione fallita: esegui manualmente " +
`\`tht session finalize ${session}\`.`,
);
if (fErr) return fErr;
lockActive = false;
lastSteered = false;
return textResult(
`Fase ${curNum} approvata e sessione finalizzata (${session}).`,
);
}
return textResult(`Fase approvata (sessione ${session}).`);
}
if (kind === "cte_plan") {