forked from mosaicstack/stack
Completes the promotion path: the client landed in the previous commit, but nothing drove step 2 — the model emitting the receipt. This wires it. LAZY, not at session start. Promotion costs an entire model turn, because the receipt must be the whole message (hmac.compare_digest, "not a transcript substring"). Minting at session start would collide with the Constitution's first-response mode declaration — the two cannot share a message, so requiring both would be unsatisfiable. Deferring to the first DENIED MUTATOR means the mode declaration happens first and the receipt gets its own later turn, so no governance change is needed. A read-only session never pays for promotion at all. Mechanism: on a MUTATOR_UNVERIFIED denial the tool_call hook mints a challenge and returns the receipt in the block `reason`, which pi feeds back to the model as the tool result — the existing injection path already used by lease-lifecycle.ts. The model emits the receipt as its next message, message_end ships it to the observer, and the extension then calls observe_receipt + promote_lease. Only MUTATOR_UNVERIFIED triggers minting. Other denials (GATE_UNAVAILABLE, STALE_GENERATION, LEASE_EXPIRED, ANCESTRY_MISMATCH) describe conditions a receipt cannot fix, and begin_verification revokes before it mints, so minting there would thrash the broker. Completion is gated on an EXACT text match against the minted receipt. This is load-bearing, not defensive: message_end also fires for the message that CONTAINED the blocked tool call — one turn BEFORE the model answers. An earlier version completed there, so observe_receipt compared against the wrong text, failed, and burned the challenge before the model ever emitted it. Matching the text mirrors the broker's own compare_digest semantics and waits for the right turn. Confirmed by instrumenting message_end and watching it fire with pending=yes one message too early. It never posts the receipt itself. receipt-observer-client.py accepts any string, so self-posting would satisfy the broker while proving nothing — the whole point is that a live model echoes a challenge it was given. Bounded by MAX_PROMOTION_ATTEMPTS: model compliance is not guaranteed (observed a run where the model retried the command instead of emitting the receipt), so a non-complying model degrades to today's behaviour — denied mutators — rather than looping. Verified with a live model on sb-it-1-dt: receipt emitted verbatim as a whole message, and the broker token was minted AND consumed, i.e. observe_receipt and promote_lease both succeeded and the lease reached VERIFIED. Known limitation: under `pi -p`, the receipt is a text-only turn, which ends the one-shot loop — so promotion completes but the blocked tool is not retried in that same invocation. Interactive and durable fleet sessions continue and retry normally.