Repository navigation
fix(intercept): judge decisions were stored as unknown (prefix case mismatch) - #159
Merged
Merged
Conversation
…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
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 intodecision_source), theapprovalDecisionSourceSQL fallback (LIKE '[Model]%', case-sensitive in PostgreSQL) and the archive restore path indb/task_archives_restore.go. Every judge-decided row was therefore inserted withdecision_source='unknown'. Before e233c02 both sides used[模型].Impact
Label and filter only. The approval outcome, the audit record and the
reasontext were always correct; the rows simply showed as "unknown" and were missed bydecision_source=model(and wrongly included bydecision_source=unknown). No approval decision changes.What changed
db/intercept.go: one shared constantModelReasonPrefix = "[model]"plusisModelReason, which accepts the canonical prefix case-insensitively and the legacy[模型]prefix.interceptSourceand 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 usesisModelReason.intercept/intercept.go: the writer builds its reason throughJudgeReason, which usesdb.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 targeteddecision_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.sqland matches nothing once applied. In a typical install it touches every row the LLM judge decided since the upgrade to e233c02 (all of them carriedunknown); 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 whateverdecision_sourcethey were archived with.server/intercept_filter_test.gois un-skipped (its[model] fixturerows 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). Thedb/intercept_filter_test.gofixture uses the constant instead of a hand-typed[Model]. Newdb/intercept_source_test.gofeeds the real writer output (intercept.JudgeReason) intointerceptSourceand checks the legacy[模型]prefix, with no database needed (db/export_test.goexposes the pure function to the external test package)..github/workflows/ci.yml: the comment listing skipped tests no longer namesTestInterceptFilterHTTP.Verified
go build ./...,go vet ./db/ ./server/ ./intercept/: clean.gofmt -lon all changed Go files: clean (the known pre-existing formatting issue inserver/server.gois left alone).go test -race ./intercept/andgo 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) andTestInterceptFilterHTTP(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.