Commit 08028fd
fix: gate screen context injection to prevent irrelevant pollution
The [SCREEN CONTEXT: ...] block was being injected into every task whenever
a screenshot had been captured, even when the user's intent had nothing to
do with the screen. A saved-for-later screenshot stayed in state forever,
causing Qwen 35B to chew through 800 tokens of unrelated UI text for simple
queries like "speed test 1+1" — and in one case, rambling about Cloudflare
Access because an earlier chat window was still cached as "screen context".
Two fixes in codec.py + codec_keyboard.py:
1. Relevance gate: skip screen context for trivial intents matched by a small
regex (arithmetic, time/date, bitcoin/weather, greetings, status, ping).
2. TTL: drop captured screen context after 120s. `screen_ctx_ts` timestamp
added to state, checked on every injection attempt.
The existing one-shot behavior (use + clear) is preserved via
`_maybe_screen_context()` helper in codec.py. `codec_keyboard.py` inlines
the same logic since it doesn't import from codec.py.
Verified: 8/8 trivial patterns match, 4/4 screen-relevant phrases preserved.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>1 parent 159e67f commit 08028fd
2 files changed
+77
-9
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
140 | 140 | | |
141 | 141 | | |
142 | 142 | | |
| 143 | + | |
143 | 144 | | |
144 | 145 | | |
145 | 146 | | |
146 | 147 | | |
147 | 148 | | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 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 | + | |
| 197 | + | |
148 | 198 | | |
149 | 199 | | |
150 | 200 | | |
| |||
467 | 517 | | |
468 | 518 | | |
469 | 519 | | |
| 520 | + | |
470 | 521 | | |
471 | 522 | | |
472 | 523 | | |
473 | 524 | | |
| 525 | + | |
474 | 526 | | |
475 | 527 | | |
476 | 528 | | |
477 | 529 | | |
478 | 530 | | |
479 | | - | |
480 | | - | |
481 | | - | |
| 531 | + | |
482 | 532 | | |
483 | 533 | | |
484 | 534 | | |
| |||
536 | 586 | | |
537 | 587 | | |
538 | 588 | | |
539 | | - | |
540 | | - | |
541 | | - | |
| 589 | + | |
542 | 590 | | |
543 | 591 | | |
544 | 592 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| |||
95 | 96 | | |
96 | 97 | | |
97 | 98 | | |
98 | | - | |
99 | | - | |
100 | | - | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
101 | 121 | | |
102 | 122 | | |
103 | 123 | | |
| |||
0 commit comments