Commit c2522fc
fix(chat): memory-injection hygiene + degenerate-loop circuit breaker (#232)
Root-caused the 2026-07-10 01:13 "nonsense loop" on a pasted movie-trailer
transcript. Three compounding problems, all fixed:
1. FALSE MEMORY TRIGGER: the pasted trailer DIALOGUE contained "I remembered
something" and "human history" — substring-matching fired the 'remember' +
'history' memory triggers, so a creative-writing question was treated as a
memory-recall question. Triggers now match on word boundaries and only scan
the first 300 chars (the user's intent lives at the front of the message,
not inside pasted content).
2. MEMORY POLLUTION: the targeted qchat lookup (LIKE %first-80-chars%) matched
the user's OWN message, so the model received its question echoed back 3-4x
wrapped in [MEMORY] tags, plus agent-status chrome ("running Agent
started...", "Plan approved...") replayed as "recent conversation". New
_mem_noise filter drops self-echo rows and agent-status noise from all
memory blocks; blocks that end up empty are not injected at all. Verified
against the actual trailer message: injected context shrank ~2000 -> 760
chars with zero echo and zero agent noise.
3. NO RUNAWAY GUARD: when the 4-bit model does collapse into repetition, the
stream would grind toward the 28k-token cap in front of the user. New
_degenerate_tail breaker in the SSE loop (checked every ~40 deltas) cuts
the stream and says honestly that the model glitched and to re-ask.
Unit-tested: trips on a repeating movie-list loop, does NOT trip on the
real (clean) 4k-char reply reproduced from the incident prompt, nor on
varied enumerations.
Frontend hardening: if a cut/degenerate stream leaves an UNCLOSED <thinking>
block, the fallback no longer dumps the raw reasoning into the chat bubble —
reasoning stays in the reveal panel with an honest glitch notice (both stream
handlers).
Note: reproducing the exact incident prompt against the live model produced a
clean, high-quality analysis — the collapse was transient model behavior; these
fixes remove the confusion fuel (echo/noise/false trigger) and guarantee any
future collapse is cut short with an honest message instead of minutes of
garbage.
Verified: full suite 2469 passed, ruff clean, node --check on inline JS,
enrichment re-simulated on the real incident message.
Co-authored-by: Mickael Farina <farina.mickael@gmail.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>1 parent 24b441f commit c2522fc
2 files changed
Lines changed: 105 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
672 | 672 | | |
673 | 673 | | |
674 | 674 | | |
675 | | - | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
676 | 681 | | |
677 | 682 | | |
678 | 683 | | |
| |||
1433 | 1438 | | |
1434 | 1439 | | |
1435 | 1440 | | |
1436 | | - | |
| 1441 | + | |
| 1442 | + | |
| 1443 | + | |
| 1444 | + | |
1437 | 1445 | | |
1438 | 1446 | | |
1439 | 1447 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
34 | 35 | | |
35 | 36 | | |
36 | 37 | | |
| |||
150 | 151 | | |
151 | 152 | | |
152 | 153 | | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
153 | 197 | | |
154 | 198 | | |
155 | 199 | | |
| |||
188 | 232 | | |
189 | 233 | | |
190 | 234 | | |
191 | | - | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
192 | 246 | | |
193 | 247 | | |
194 | 248 | | |
| |||
203 | 257 | | |
204 | 258 | | |
205 | 259 | | |
| 260 | + | |
| 261 | + | |
206 | 262 | | |
207 | 263 | | |
208 | 264 | | |
209 | | - | |
210 | | - | |
211 | | - | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
212 | 269 | | |
213 | 270 | | |
214 | 271 | | |
| |||
225 | 282 | | |
226 | 283 | | |
227 | 284 | | |
| 285 | + | |
| 286 | + | |
228 | 287 | | |
229 | 288 | | |
230 | 289 | | |
231 | | - | |
232 | | - | |
233 | | - | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
234 | 294 | | |
235 | 295 | | |
236 | 296 | | |
237 | 297 | | |
238 | 298 | | |
239 | 299 | | |
240 | 300 | | |
| 301 | + | |
| 302 | + | |
241 | 303 | | |
242 | 304 | | |
243 | 305 | | |
244 | | - | |
245 | | - | |
246 | | - | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
247 | 310 | | |
248 | 311 | | |
249 | 312 | | |
| |||
903 | 966 | | |
904 | 967 | | |
905 | 968 | | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
906 | 974 | | |
907 | 975 | | |
908 | 976 | | |
| |||
921 | 989 | | |
922 | 990 | | |
923 | 991 | | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
924 | 1002 | | |
925 | 1003 | | |
926 | 1004 | | |
927 | 1005 | | |
928 | 1006 | | |
929 | 1007 | | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
930 | 1015 | | |
931 | 1016 | | |
932 | 1017 | | |
| |||
0 commit comments