feat(8141): a rule holding the finished reply is recorded as a gate stop too
CI & Build / Python lint (push) Successful in 2s
CI & Build / Plugin hooks (push) Successful in 14s
CI & Build / TypeScript typecheck (push) Successful in 34s
CI & Build / Python tests (push) Failing after 1m49s
CI & Build / integration (push) Successful in 2m4s
CI & Build / Build & push image (push) Skipped

The end-of-turn reply hold was the one gate the gate_stops table left out.
The server applies the per-session cap before anything holds and the Stop
hook blocks on every reason it is given, so the hook reports each held rule
after blocking, as the tool-call gates do: gate `reply`, tool `reply`, and
where the rule was reached (`rule_at`, new beside `rule_ids` in the
/reply-rules answer: the moment it is mounted on, or `reply_rule` for the
backstop). A section hold names no rule and stays counted by report_check.
Opening the rule clears the stop, and rule_misfired marks it, unchanged.

The readout, the telemetry docstring and the Settings panel name the new gate.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-27 14:32:46 -05:00
co-authored by Claude Opus 5.5
parent 9b781d57de
commit 82ffd9a235
11 changed files with 85 additions and 18 deletions
+39
View File
@@ -23,6 +23,7 @@ FENCE = HOOKS / "grimoire_project_fence.sh"
FENCE_RAN = HOOKS / "grimoire_fence_ran.sh"
STOP = "/api/plugin/gate-stop"
RAN = "/api/plugin/gate-ran"
REPLY_CHECK = HOOKS / "grimoire_reply_check.sh"
TOOLS = {"/api/plugin/moment-tools": b'{"tools":["bash"]}'}
@@ -194,3 +195,41 @@ def test_the_after_call_hook_is_registered_only_after_calls_and_on_the_fenced_to
for h in m["hooks"] if "grimoire_project_fence.sh" in h["command"]]
assert matchers("PreToolUse") == []
assert matchers("PostToolUse") == fence_pre
# ── the reply hold ───────────────────────────────────────────────────────
def _transcript(tmp_path, reply):
lines = [
{"type": "user", "message": {"role": "user", "content": "is it finished?"}},
{"type": "assistant", "message": {"content": [{"type": "text", "text": reply}]}},
]
path = tmp_path / "t.jsonl"
path.write_text("\n".join(json.dumps(x, separators=(",", ":")) for x in lines) + "\n")
return path
def _stop(tmp_path, transcript):
return {"session_id": "s-gate", "transcript_path": str(transcript), "cwd": str(tmp_path),
"hook_event_name": "Stop", "stop_hook_active": False}
def test_each_rule_that_holds_a_reply_is_reported_with_where_it_was_reached(tmp_path):
held = json.dumps({"reason": "Held for one read.", "rule_ids": [11, 40],
"rule_at": ["reply.report", "reply_rule"],
"moments": ["reply.report"]}).encode()
with http_sink(by_path={"/api/plugin/reply-rules": held}) as (port, seen):
out = _run(REPLY_CHECK, tmp_path, port, _stop(tmp_path, _transcript(tmp_path, "All done.")))
assert json.loads(out)["decision"] == "block"
assert [(s["gate"], s["outcome"], s["tool"], s["rule_id"], s["at"]) for s in _stops(seen)] == [
("reply", "stopped", "reply", 11, "reply.report"),
("reply", "stopped", "reply", 40, "reply_rule"),
]
def test_a_section_hold_names_no_rule_and_reports_no_gate_stop(tmp_path):
"""The completion-section check has its own record (`report_check`)."""
sections = b'{"reason":"Add the sections.","rule_ids":[],"moments":[],"report_check":"blocked"}'
with http_sink(by_path={"/api/plugin/reply-rules": sections}) as (port, seen):
_run(REPLY_CHECK, tmp_path, port, _stop(tmp_path, _transcript(tmp_path, "All done.")))
assert _stops(seen) == []
+8 -4
View File
@@ -123,6 +123,9 @@ async def test_the_semantic_backstop_holds_and_never_names_a_mounted_rule_twice(
arm, _surfaced, _lookup, stack = _stubs(mounted=[(DONE, "reply.report")], checkpoint=cp)
out = await _hold(stack)
assert out["rule_ids"] == [11, 40]
# Where each was reached, for the hook's gate report: a mount names its
# moment, the backstop names its arm.
assert out["rule_at"] == ["reply.report", rp.REPLY_RULE.source]
assert "scores 0.84 against this reply" in out["reason"]
spec, moment = arm.await_args.args
assert spec is rp.REPLY_RULE
@@ -207,7 +210,7 @@ async def test_the_route_passes_the_reply_and_all_three_ledgers():
with patch.object(routes.moment_delivery_svc, "reply_hold", hold):
resp = await routes.reply_rules.__wrapped__()
body = await resp.get_json()
assert body == {"reason": "Held.", "rule_ids": [11], "moments": ["reply.report"],
assert body == {"reason": "Held.", "rule_ids": [11], "rule_at": [], "moments": ["reply.report"],
"report_check": ""}
assert hold.await_args.args == (7, "done")
assert hold.await_args.kwargs == {
@@ -304,11 +307,12 @@ def test_the_hook_blocks_in_the_servers_words_and_records_the_hold(tmp_path):
out = json.loads(_run(tmp_path, port, t))
_run(tmp_path, port, t)
assert out == {"decision": "block", "reason": "Held for one read: get_rule(11)."}
sent = json.loads(seen[0]["_body"])
asks = [e for e in seen if e["_path"] == "/api/plugin/reply-rules"]
sent = json.loads(asks[0]["_body"])
assert sent["reply"] == "All done.\nLet me know if it works on your end?"
# The second turn tells the server what already held.
assert seen[1]["stopped_rule_ids"] == ["11"]
assert seen[1]["exclude_rule_ids"] == ["11"]
assert asks[1]["stopped_rule_ids"] == ["11"]
assert asks[1]["exclude_rule_ids"] == ["11"]
def _closing_transcript(tmp_path, *replies):