fix(agent): gadfly round 1 — the hyphen made "above-board" a back-reference
CI / Tidy (pull_request) Successful in 9m25s
CI / Build & Test (pull_request) Successful in 10m43s

Three of four reviewers independently found the same defect: `\b` holds
between "above" and "-", so the literal hyphen in aboveRefRe's terminator
class made every hyphenated compound clause-final. "above-average",
"above-board", "above-ground" all read as deictic pointers, putting a
legitimate short closer at risk of being discarded. My own test used the
SPACE-separated "above average" — it tested the neighbour, not the named
path, which is exactly why the class survived a round of review. Hyphen
dropped from the class; the four compounds are now table cases.

Two more findings, both real:

- backRefHeadChars and weakFinalMaxChars were two unlinked 120 literals
  that the comment called "the same guard". Now defined by reference,
  with a test pinning the identity.
- isBackRef claimed to be the shared extension point for both shapes but
  had a single caller — isSummaryCloser deliberately uses pointsAbove
  directly, because backRefRe's fixed phrases match ANYWHERE and are only
  safe under the 120-byte weak cap. Folding the two together for
  tidiness would widen the gate, not deduplicate it. Helper deleted, the
  doc moved onto pointsAbove where the real sharing is, and it now says
  why backRefRe is not shared.

Also shared the front-loaded-analysis fixture between the table and the
end-to-end test (kimi), and de-hollowed the offset-bound cases: they were
sized as backRefHeadChars±n, so they moved with the constant they were
meant to pin — a break-check that widened the bound to 100000 sailed
through. Literal lengths now, plus an explicit identity assertion.

Break-check: six mutations, each killed by a named test; control survives.
This commit is contained in:
2026-08-21 23:41:46 -04:00
parent bcba9667bd
commit f97c2b78c2
2 changed files with 64 additions and 25 deletions
+37 -7
View File
@@ -51,6 +51,13 @@ func TestIsWeakFinal(t *testing.T) {
// that had never been posted.
const closer1611 = "Done — that's the full chain above. Short version: it's not one incident, it's the confluence of the Iran war, the Epstein files, and three ex-allies now openly plotting a third-party movement that finally set him off."
// analysis1611 stands in for that run's front-loaded analysis: long enough to
// dwarf closer1611 (>3x its 220 bytes). Shared by the finalOutput table and
// the end-to-end Run test so the two cannot drift apart.
func analysis1611() string {
return strings.TrimSpace(strings.Repeat("The break was the Iran strikes, then the Epstein files. ", 12))
}
func TestPointsAbove(t *testing.T) {
cases := []struct {
name string
@@ -72,13 +79,24 @@ func TestPointsAbove(t *testing.T) {
{"above-all", "Above all, keep the deploy green.", false},
{"above-average", "Turnout was above average in three counties.", false},
// Hyphenated compounds. \b holds between "above" and "-", so a literal
// '-' in the terminator class made all of these read as deictic — the
// space-separated cases above did NOT cover it (gadfly, 3 models).
{"hyphen-above-average", "Turnout was above-average in three counties.", false},
{"hyphen-above-board", "The deal was above-board from the start.", false},
{"hyphen-above-ground", "Run the above-ground cable along the fence.", false},
{"hyphen-above-mentioned", "The above-mentioned findings are attached.", false},
{"no-above-at-all", "42", false},
{"empty", "", false},
// Offset bound: past backRefHeadChars there IS enough text before the
// reference for it to be pointing inside this same message.
{"late-reference-not-a-pointer", strings.Repeat("x", backRefHeadChars+1) + " as shown above.", false},
{"reference-at-the-bound", strings.Repeat("x", backRefHeadChars-6) + " above.", true},
// reference for it to be pointing inside this same message. The
// lengths are LITERALS, not backRefHeadChars +/- n: a case sized from
// the constant it is meant to pin moves with it, and a break-check
// that widened the bound to 100000 sailed straight through.
{"late-reference-not-a-pointer", strings.Repeat("x", 200) + " as shown above.", false},
{"reference-at-the-bound", strings.Repeat("x", 100) + " above.", true},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
@@ -87,6 +105,18 @@ func TestPointsAbove(t *testing.T) {
}
})
}
// The two bounds are ONE guard expressed two ways (see backRefHeadChars).
// Pinned here so decoupling them is a test failure, not a silent drift.
if backRefHeadChars != weakFinalMaxChars {
t.Errorf("backRefHeadChars = %d, weakFinalMaxChars = %d: the offset bound and the "+
"weak-final cap are the same guard and must stay equal",
backRefHeadChars, weakFinalMaxChars)
}
if weakFinalMaxChars != 120 {
t.Errorf("weakFinalMaxChars = %d, want 120: the literal-length cases in this table "+
"pin the bound at 120 and must be resized with it", weakFinalMaxChars)
}
}
func TestIsCitationsOnly(t *testing.T) {
@@ -208,7 +238,7 @@ func TestFinalOutput(t *testing.T) {
// and long enough (>~92 bytes) that longAnswer would fail the summary bar.
bothMatchCloser := "Citations are logged. As I mentioned above, the full detail on the money sources is in my earlier message."
// The #1611 pair: a front-loaded analysis that dwarfs its 220-byte closer.
analysis1611 := strings.TrimSpace(strings.Repeat("The break was the Iran strikes, then the Epstein files. ", 12)) // >3x closer1611
analysis := analysis1611()
// A terminal using "above" as a PREPOSITION — not a back-reference, so it
// must survive verbatim next to a dwarfing prior turn.
prepositionalTerminal := "Anything above 100 degrees boils off, which is exactly why the sample evaporated overnight in the unsealed tray."
@@ -460,12 +490,12 @@ func TestFinalOutput(t *testing.T) {
name: "above-pointer closer discarded when the front-loaded answer dwarfs it",
msgs: []llm.Message{
llm.UserText("what set off the Truth Social rant?"),
asst(analysis1611, cite...),
asst(analysis, cite...),
llm.ToolResultsMessage(llm.ToolResult{ID: "c1", Name: "cite", Content: "ok"}),
asst(closer1611),
},
terminal: closer1611,
want: analysis1611,
want: analysis,
},
{
// The dwarf ratio governs the new opener too: a prior turn that is
@@ -652,7 +682,7 @@ func TestRun_RecoversFrontLoadedAnswerWithCitations(t *testing.T) {
// compression. The delivered output must be the front-loaded analysis, with no
// extra model call.
func TestRun_RecoversFrontLoadedAnswerOverAboveRefCloser(t *testing.T) {
analysis := strings.TrimSpace(strings.Repeat("The break was the Iran strikes, then the Epstein files. ", 12))
analysis := analysis1611()
fp := fake.New("fp")
fp.Enqueue("test-model",
fake.ReplyWith(llm.Response{