Skip to content

Intercept judge: closed-question mode (JEV), fail-closed to ask - #208

Merged
BaaRai merged 2 commits into
mainfrom
feat/closed-question-judge
Nov 13, 2026
Merged

BaaRai merged 2 commits into
mainfrom
feat/closed-question-judge

Conversation

@BaaRai

@BaaRai BaaRai commented Nov 12, 2026 •

Copy link
Copy Markdown
Owner

What

The LLM fallback judge gets a closed-question mode (llm_judge_mode = closed, the default when the judge is enabled). The model no longer chooses allow/ask/deny. It answers eight fixed questions that the code owns, with yes | no | unknown and one evidence line for each. The code then takes the decision from those answers. Any failure now leads to ask. The previous behaviour is kept unchanged as llm_judge_mode = freeform.

Why

  • Fail-open removal. defaultJudgeFailAction was allow, so an invalid reply or a failed judge call could let a tool call through. In closed mode every failure is ask. The default fail action (still used by freeform) is now ask.
  • Closed answers instead of a free verdict. A free-text prompt lets the model decide the outcome and explain it in prose. With closed questions, the model only reports facts in a fixed vocabulary, and a fixed table in the code maps those facts to a decision. The model cannot pick the outcome directly.
  • JEV model. This ports the closed-question design of CyberStrikeAI internal/hitl/jev.go: a stable question set with short IDs, strict JSON answers, and a decision owned by the code.

Design

Questions (intercept/closed_judge.go, stable IDs, in prompt and audit order): read_only, availability, data_loss, credentials_acl, live_config, dos, pentest_action, operator_policy.

One call per judged tool call answers all eight questions: MaxTokens 1536, temperature 0, thinking disabled. The reply must be exactly one JSON object holding every ID once. Each ID maps to {"answer": "yes|no|unknown", "evidence": "<one line, at most 200 runes>"}. Any other reply is invalid: a code fence, prose, a missing, extra or duplicate key, an extra field, null, an upper-case or out-of-vocabulary answer, or a multi-line or over-long evidence line.

Decision table (decideClosed, fixed, no score), evaluated in order:

# Condition Decision
1 any destructive question = yes: data_loss, availability, dos, credentials_acl, live_config deny (overrides pentest_action and read_only)
2 operator_policy = yes deny
3 any destructive question or operator_policy = unknown (even when read_only = yes) ask
4 read_only = yes allow
5 the call may write (read_only is not yes) and any answer = unknown ask
6 pentest_action = yes allow
7 a write where every answer is a clean no allow
- invalid output, missing key, value outside the vocabulary, judge call failed, judge enabled but not wired, arguments invalid or above the cap ask (never the configured fail action, never allow)

Reason. The reason names the question that triggered the decision and keeps the [model] prefix, for example [model] deny data_loss=yes: <evidence>, [model] ask live_config=unknown: ..., [model] ask invalid_output: ... or [model] ask arguments_over_cap: .... decision_source and decided_by stay model, as they are today.

Argument cap. JudgeArgumentCap = 256 KiB (a constant). If the arguments are larger, the decision is ask and the model is not called. Arguments are never truncated.

Operator policy as data. A custom llm_judge_prompt is no longer a system prompt in closed mode. It is sent as operator_policy in the review input (input version 5), limited to 8000 runes with an explicit [operator policy truncated at 8000 runes] marker. Only the operator_policy question refers to it. The built-in template is not treated as a policy, because the default criteria now live in the code-owned questions.

System prompt. The closed-mode system prompt is a fixed contract and has a golden test (sha256 pin). Its input boundary section is the updated boundary: the operator policy is data, and the arguments are either complete or the call goes to ask.

Mode setting. llm_judge_mode sits in the same settings table and judge config API as the other llm_judge_* keys (JudgeConfig.mode, GET/PUT /api/intercept/judge). No new environment variable was needed. An empty or unknown value reads as closed. PUT rejects any value other than closed or freeform.

Precedence is unchanged. Intercept rules run first, and the judge sees only the calls that no rule covered.

Audit and UI. intercept_pending.audit.judge_answers (JSONB) stores the eight answers. The approval detail shows them as a plain list in the form id: answer - evidence. The judge settings card has a mode selector.

Wiring. The server installs a new Completer that returns the raw reply text. Parsing and the decision happen in the intercept package. Freeform still uses the existing Reviewer.

Behaviour changes

  • defaultJudgeFailAction changes from allow to ask. Closed mode ignores fail_action and always asks on failure. In freeform mode, an operator who explicitly saved fail_action = allow keeps it.
  • When the judge is enabled with no mode stored (every existing install), it now runs in closed mode. An existing custom prompt becomes operator-policy data. To keep the old behaviour exactly, set the mode to freeform.
  • The judge is still off by default: llm_judge_enabled is unchanged.
  • ConfigDigest of judge verdicts now includes the mode field, so digests differ from the ones computed before this change.

Choices (where the brief left room)

  • One call answering all questions, not one call per question. It is simpler and cheaper, and the answers stay closed-form.
  • Destructive set and its order: data_loss, availability, dos, credentials_acl, live_config. The first yes in that order is the recorded trigger.
  • Unknowns on a read-only call: a destructive or operator_policy unknown asks even when read_only = yes (review fix). Other unknowns (pentest_action) do not block a read-only allow. An unknown read_only counts as a write and asks.
  • A clean write (not read-only, every answer no, pentest_action no) allows, which matches the old default-allow clause.
  • Strict parsing: closed mode does not unwrap code fences. A fenced reply is invalid and leads to ask, because a failure here costs one human approval, not an allow.
  • Freeform stays byte-for-byte the same. Its prompt, JudgeContextBoundary, review input (version 4, no new keys) and fail-action handling are unchanged, and it has no argument cap. The updated boundary is part of the closed-mode prompt only.
  • Existing PG test helpers that inject a fake freeform Reviewer now set Mode: freeform. TestCaptureApprovalLifecycle also sets FailAction: allow so that it keeps its old expectation; it is still skipped (Add CI: go build/vet/tests with postgres + web typecheck and static build #9).

Review fixes

New decision order in decideClosed, evaluated top to bottom:

  1. Any destructive question = yes: deny.
  2. operator_policy = yes: deny.
  3. New: any destructive question or operator_policy = unknown: ask, with the trigger in the reason (for example [model] ask data_loss=unknown: ...). This now applies even when read_only = yes.
  4. read_only = yes: allow.
  5. Any remaining unknown: ask.
  6. pentest_action = yes: allow.
  7. A write where every answer is no: allow.

Other review fixes:

  • Judge enabled but not wired. When the judge is enabled in closed mode and no Completer is wired, the decision is now ask ([model] ask judge_not_wired). Before this fix the judge was treated as off, and the guard allowed the call.
  • MaxTokens for the closed reply goes from 768 to 1536.
  • Cap check moved earlier. The 256 KiB argument cap is now checked before BuildReviewInput, so over-cap arguments are never parsed or copied.
  • operator_policy question reworded. It now asks whether the policy forbids or fails to authorize the action, so a whitelist policy that does not cover the action produces yes. The closed-prompt golden digest was updated to match.
  • Tests:
    • read_only=yes with data_loss=unknown now expects ask (the old allow expectation is replaced).
    • New: read_only=yes with operator_policy=unknown expects ask.
    • New: read_only=yes with every destructive answer and operator_policy = no expects allow.
    • New: over-cap invalid JSON expects ask arguments_over_cap, which shows the cap is checked first.
    • New: the not-wired closed judge expects ask judge_not_wired.

Limitations

  • Closed answers are only as good as the model's answers. A model that answers no to data_loss on a destructive call still gets an allow.
  • The code does not verify the evidence lines. They are recorded for the human, not checked against the arguments.
  • The operator policy is data the model reads. It does not enforce anything by itself; it only feeds the operator_policy answer.

Tests run locally (Kali, go1.26.10)

The PG tests ran against a throwaway postgres:16-alpine container (cjtest-pg16, bound to 127.0.0.1, removed after each run).

  • gofmt -l on the changed Go files: clean
  • go build ./...: exit 0
  • go vet ./...: exit 0
  • go test -count=1 -p 1 ./...: exit 0, all packages ok
  • go test -race -count=1 -p 1 ./intercept ./guard ./db ./server ./agent (on the review-fix head): intercept, guard, db and agent are ok. server exits 1 with a race that is not related to this PR and that moves between tests from run to run:
    • Run 1: TestTaskDetailReturnsListMetrics.
    • Rerun: TestLLMTestStoredKeyFallbackIsTrimmed.
    • In both, server.New() → wireAgentAugment writes agent package globals while a planner goroutine started by an earlier test reads them (agent.renderSystem / agent.AugmentTools).
    • None of the files in the race stacks are touched by this PR, and the first head's race run was clean.

New tests:

  • TestClosedJudgeDecisionTable: the full table, including destructive overriding pentest, unknown on a write giving ask, read-only giving allow, policy yes giving deny, invalid, fenced, missing, duplicate, extra and out-of-vocabulary output giving ask, judge failure giving ask, arguments over the cap giving ask with no call, and fail_action = allow still giving ask.
  • TestClosedJudgeArgumentCapBoundary
  • TestClosedJudgeAuditRecordsAnswers
  • TestClosedJudgeIsTheDefaultMode
  • TestClosedJudgePromptGolden
  • TestFreeformJudgeUnchanged: a golden of the previous prompt digest, the input shape, verdict pass-through, the configured fail action, and no cap.
  • TestOperatorPolicyIsBoundedData: 8000 runes plus the marker.
  • TestDefaultJudgeFailActionIsAsk
  • guard/TestRuleMatchDoesNotCallJudge: a counting fake judge confirms that a matched rule never reaches the judge.
  • intercept/TestClosedJudgeAnswersStored (PG): the answers, reason and decision_source round-trip through intercept_pending.audit.

Not verified

  • No end-to-end run against a real LLM, so it is untested whether real models follow the closed contract reliably.
  • The UI was not rendered visually, and tsc/next build were not run locally (no node_modules in the worktree).

The LLM fallback judge gets a closed mode (default when the judge is on):
the model answers eight code-owned questions with yes|no|unknown and one
evidence line each, in one call; the decision is taken in code. Every
failure (invalid output, missing key, value outside the vocabulary, a
failed call, arguments above the 256 KiB cap) is ask. The custom judge
prompt becomes bounded operator-policy data (8000 runes). The answers are
stored in the intercept audit and shown in the approval detail.

freeform keeps the previous behaviour; defaultJudgeFailAction changes
from allow to ask.
- A destructive or operator_policy unknown asks, even when read_only is yes.
- An enabled closed judge with no completer wired asks (judge_not_wired)
  instead of falling through to allow.
- The argument cap is checked before the review input is built.
- MaxTokens for the closed reply raised to 1536.
- The operator_policy question also covers a whitelist policy that fails to
  authorize the action; golden digest updated.
@BaaRai
BaaRai merged commit c5116f2 into main Nov 13, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant