fix: harden Codex hook finalization

This commit is contained in:
thanhnv
2026-07-24 13:06:23 +07:00
parent bfebfa9d39
commit 34a6b013c0
8 changed files with 79 additions and 24 deletions
@@ -116,6 +116,27 @@ METRICS=$(grep -c '"harness":"H6-agentic"' "$CASAN_STATE_ROOT/logs/cost/metrics.
[[ "$(printf '%s' "$F2" | field reason)" == "already_finalized" && "$METRICS" == "1" ]] \
&& pass "second finalize is idempotent (one metric only)" || fail "finalize not idempotent (reason=$(printf '%s' "$F2" | field reason) metrics=$METRICS)"
# ── C8b: output scan status contract is handled without finalize crashes ────
echo "===== C8b: finalize handles blocked and unavailable output scans ====="
newstate
B=$(bridge '{"op":"begin","client":"codex","project":"'"$PROJ"'","session":"c8b-block","prompt":"summarize the work","integration_mode":"project_hook"}')
AID=$(printf '%s' "$B" | field admission_id)
F=$(bridge '{"op":"finalize","admission_id":"'"$AID"'","stop_reason":"completed","assistant_summary":"API_KEY=supersecret"}')
[[ "$(printf '%s' "$F" | field decision)" == "non_certified" ]] \
&& printf '%s' "$F" | field reason | grep -q "output_flagged:h4_blocked" \
&& pass "blocked assistant output finalizes as non-certified without crashing" \
|| fail "blocked assistant output finalize contract failed ($F)"
newstate
B=$(bridge '{"op":"begin","client":"codex","project":"'"$PROJ"'","session":"c8b-unavailable","prompt":"summarize the work","integration_mode":"project_hook"}')
AID=$(printf '%s' "$B" | field admission_id)
F=$(CASAN_AGENTIC_BASH=/nonexistent/bash-xyz bridge '{"op":"finalize","admission_id":"'"$AID"'","stop_reason":"completed","assistant_summary":"completed safely"}')
[[ "$(printf '%s' "$F" | field decision)" == "non_certified" ]] \
&& [[ "$(printf '%s' "$F" | field certification_strength)" == "observed_only" ]] \
&& printf '%s' "$F" | field reason | grep -q "output_gate_unavailable" \
&& pass "unavailable output gate degrades finalize without crashing" \
|| fail "unavailable output gate finalize contract failed ($F)"
# ── C10: token/cost unavailable -> null + warning, never 0 ───────────────────
echo "===== C10: missing token/cost = null + partial warning, not zero ====="
newstate