Reject ambiguous spans consistently across repair modes

This commit is contained in:
2026-11-17 04:20:25 +00:00
parent 9ad79ce13b
commit 2d93e8ae7c
3 changed files with 42 additions and 1 deletions

View File

@@ -142,6 +142,11 @@ func (p *fixtureProvider) serve(w http.ResponseWriter, r *http.Request) {
content = `{"corrections":[{"id":1,"original_text":" ","corrected_text":" "}]}`
case "span-negative":
content = `{"corrections":[{"id":1,"original_text":"not ","corrected_text":""}]}`
case "span-ambiguous":
content = `{"corrections":[{"id":1,"original_text":"Mage Armor","corrected_text":"ward"}]}`
if _, repair := request.ResponseFormat.JSONSchema.Schema.Properties["proposal_ref"]; repair {
content = `{"proposal_ref":1,"decision":{"action":"withdraw","correction":null}}`
}
}
if validation {
if p.mode == "span-clean" || p.mode == "span-filter" {
@@ -718,6 +723,37 @@ func TestSubprocessAppliesWhitespaceOnlySpan(t *testing.T) {
f.assertNoStructuralRepairs(t, 3)
}
func TestSubprocessRejectsAmbiguousSpanAtTheSameBoundaryWithOrWithoutRepair(t *testing.T) {
for _, budget := range []int{0, 1} {
t.Run(fmt.Sprint(budget), func(t *testing.T) {
f := newProcessFixture(t, "span-ambiguous", "[grammar]")
f.setSegments(t, "Mage Armor and Mage Armor")
raw, err := os.ReadFile(f.config)
if err != nil {
t.Fatal(err)
}
cfg := strings.Replace(string(raw), "correction_repair_attempts: 0", fmt.Sprintf("correction_repair_attempts: %d", budget), 1)
cfg += "protected_terms: [spells]\nglossary_collections:\n spells:\n entries:\n - {id: armor, name: Mage Armor, category: spell}\n"
if err := os.WriteFile(f.config, []byte(cfg), 0600); err != nil {
t.Fatal(err)
}
if code, _, stderr := f.run(t, true, "--debug"); code != 0 {
t.Fatalf("exit %d: %s", code, stderr)
}
_, ledger := f.debugArtifacts(t)
if len(ledger) != 1 || !ledgerHasDecision(t, ledger[0], "deterministic_validator_decisions", "original_text_presence", false) ||
ledgerHasDecision(t, ledger[0], "deterministic_validator_decisions", "protected_terms", true) {
t.Fatalf("unexpected evidence: %+v", ledger)
}
if text := f.readTranscript(t, f.output).Segments[0].Text; text != "Mage Armor and Mage Armor" {
t.Errorf("ambiguous proposal changed segment to %q", text)
}
f.assertNoStructuralRepairs(t, 1+budget)
})
}
}
func TestSubprocessFiltersBlankResultAlongsideApprovedCorrections(t *testing.T) {
f := newProcessFixture(t, "span-filter", "[spoken_word]")
f.setSegments(t, "uh hello", "I I think", "uh")

View File

@@ -261,6 +261,11 @@ operational acquisition failure and malformed YAML. Check status 1 and status
### R8 — Use the Same Span Applicability With and Without Repair (P3)
**Complete.** The original-text validator rejects ambiguous require-unique
spans at either budget. A built CLI regression verifies local attribution,
no protection approval or model validation for the span, and repair only
at the positive budget. Whitespace and blank-result tests also passed.
**Affected plan:** Stages 8 and 9, with ledger projection in Stage 17.
**Evidence:** The [original-text validator](../../internal/framework/validators/deterministic.go#L38)

View File

@@ -50,7 +50,7 @@ func (v OriginalTextPresenceValidator) Validate(_ context.Context, req Request)
decisions = append(decisions, rejection(c.ProposalIndex, ReasonMissingOriginalText, "original_text was not found in current segment text"))
continue
}
if req.IndependentEvidence && req.Preview(c).SkipReason == proposals.SkipReasonAmbiguousOriginal {
if req.ReplacementPolicy == proposals.ReplacementPolicyRequireUnique && req.Preview(c).SkipReason == proposals.SkipReasonAmbiguousOriginal {
decisions = append(decisions, rejection(c.ProposalIndex, string(proposals.SkipReasonAmbiguousOriginal), "original_text matches multiple locations in the target segment"))
continue
}