Skip to content

fix(intercept): judge decisions were stored as unknown (prefix case mismatch) - #159

Merged
BaaRai merged 1 commit into
mainfrom
fix/intercept-decision-source-prefix
Nov 9, 2026
Merged

BaaRai merged 1 commit into
mainfrom
fix/intercept-decision-source-prefix

Conversation

@BaaRai

@BaaRai BaaRai commented Nov 9, 2026

Copy link
Copy Markdown
Owner

Fixes #156.

Cause

Since e233c02 ("Translate all Chinese text to English") the two sides of the model prefix disagree on case. The judge writer (intercept/intercept.go) prefixes its reason with lowercase "[model] ", while the three readers checked a capitalized "[Model]": interceptSource (which computes the value inserted into decision_source), the approvalDecisionSource SQL fallback (LIKE '[Model]%', case-sensitive in PostgreSQL) and the archive restore path in db/task_archives_restore.go. Every judge-decided row was therefore inserted with decision_source='unknown'. Before e233c02 both sides used [模型].

Impact

Label and filter only. The approval outcome, the audit record and the reason text were always correct; the rows simply showed as "unknown" and were missed by decision_source=model (and wrongly included by decision_source=unknown). No approval decision changes.

What changed

  • db/intercept.go: one shared constant ModelReasonPrefix = "[model]" plus isModelReason, which accepts the canonical prefix case-insensitively and the legacy [模型] prefix. interceptSource and the SQL fallback (lower(ip.reason) LIKE '[model]%' OR ip.reason LIKE '[模型]%') use it. The list filter needs nothing further: it filters on the same expression.
  • db/task_archives_restore.go: the restore reader uses isModelReason.
  • intercept/intercept.go: the writer builds its reason through JudgeReason, which uses db.ModelReasonPrefix, so writer and readers cannot drift again. The stored string is unchanged ([model] ...), so the web UI, which already expects [model], needs no change.
  • db/schema.sql: idempotent backfill next to the existing one-time migration (which only targeted decision_source=''):
    UPDATE intercept_pending SET decision_source='model' WHERE decision_source='unknown' AND rule_id IS NULL AND (reason LIKE '[model]%' OR reason LIKE '[模型]%');
    It runs on every startup like the rest of schema.sql and matches nothing once applied. In a typical install it touches every row the LLM judge decided since the upgrade to e233c02 (all of them carried unknown); installs without the judge enabled have zero matching rows. Archived tasks keep intercept rows as JSON inside the archive payload, not in a table, so the backfill does not reach them; such rows restore with whatever decision_source they were archived with.
  • Tests: server/intercept_filter_test.go is un-skipped (its [model] fixture rows failed only because of this bug; the other skipped tests from Add CI: go build/vet/tests with postgres + web typecheck and static build #9 are untouched). The db/intercept_filter_test.go fixture uses the constant instead of a hand-typed [Model]. New db/intercept_source_test.go feeds the real writer output (intercept.JudgeReason) into interceptSource and checks the legacy [模型] prefix, with no database needed (db/export_test.go exposes the pure function to the external test package).
  • .github/workflows/ci.yml: the comment listing skipped tests no longer names TestInterceptFilterHTTP.

Verified

  • go build ./..., go vet ./db/ ./server/ ./intercept/: clean.
  • gofmt -l on all changed Go files: clean (the known pre-existing formatting issue in server/server.go is left alone).
  • go test -race ./intercept/ and go test -race -run 'TestInterceptSource' ./db/: pass. The new test fails against the old reader ("[model] allow" classified as "unknown") and passes with the fix.

Not verified locally

No Postgres was available locally, so TestInterceptApprovalFilters (db) and TestInterceptFilterHTTP (server) were skipped here; CI runs both against its Postgres service. The backfill was not run against a live database.

Thanks to mwe-support for the precise report, which pointed at every affected line.

…ismatch)

Since e233c02 the judge writer prefixes its reason with "[model]" while
interceptSource, the approvalDecisionSource SQL fallback and the archive
restore checked "[Model]", so model-decided rows were inserted with
decision_source='unknown' and missed by the decision_source=model filter.

- db: add ModelReasonPrefix ("[model]") and isModelReason, which also
  accepts the pre-e233c02 "[模型]" prefix; readers compare
  case-insensitively (lower(reason) LIKE in SQL).
- intercept: the writer builds its reason through JudgeReason, using the
  shared constant.
- schema.sql: idempotent backfill of 'unknown' rows without a rule whose
  reason carries either prefix.
- tests: un-skip TestInterceptFilterHTTP (it failed only because of
  this), make the db filter fixture use the constant, and add a
  Postgres-free test pinning the writer output to interceptSource.

Fixes #156
@BaaRai
BaaRai merged commit 9c2b560 into main Nov 9, 2026
4 checks passed
@BaaRai BaaRai mentioned this pull request Nov 11, 2026
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.

intercept: model-judged approvals are recorded with decision_source=unknown ("[model]" vs "[Model]" prefix mismatch)

1 participant