Commit 2ed8478
fix: address review — anchor the shrink budget to the payload, not the ceiling
Six issues from review, one of which partly defeated the original fix.
1. The budget was seeded from `maxChars` rather than from the text being sent,
so `truncate` (which only cuts when length > budget) made the first halvings
byte-identical resends. A document below maxChars/2^4 — 1,875 chars at the
default — could never shrink at all: five identical rejected calls and then
the same permanent index hole this change exists to close, at 5x the cost.
The budget now starts at min(maxChars, longest input).
2. The batch comment claimed one oversized member "cannot cost the short ones
any content". Untrue: the budget is per-request, so a halving forced by one
text also trims every other member above the new budget. The comment now
says so, and seeds from the longest member. Also notes that a provider may
reject on the request's aggregate token count, where trimming members is the
right lever but the floor may arrive before the batch fits.
3. Intermediate attempts ran through `attempt(..., mayFailOpen=false)`, whose
`handleFailure` logs before it rethrows — so every successful shrink emitted
"Embedding failed" with a stack trace for a call that then succeeded, and a
terminal failure logged twice with contradictory failOpen values. The retry
loop is now `attemptOrThrow`, with logging left to the single terminal
`handleFailure`.
4. The 4-arg `attempt` overload became unreachable once both callers moved to
`embedWithShrink`; removed.
5. `givesUpAfterTheShrinkFloor...` asserted the attempt cap, not the floor —
at a 30,000 ceiling the cap is always reached first. Renamed to say what it
tests, and a real floor test added at a 1,500 ceiling.
6. The shrink log printed the budget as though it were the payload size, which
would mislead exactly the person debugging (1).
New tests: shrinksRelativeToTheInputNotTheConfiguredCeiling (regression for 1,
fails on the previous commit) and stopsAtTheCharacterFloorRatherThanEmbedding
ATokenOfContent (coverage for 5).
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>1 parent f93f483 commit 2ed8478
2 files changed
Lines changed: 104 additions & 18 deletions
File tree
- backend/src
- main/java/com/dbaagent/service
- test/java/com/dbaagent/service
Lines changed: 52 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
118 | 118 | | |
119 | 119 | | |
120 | 120 | | |
121 | | - | |
| 121 | + | |
| 122 | + | |
122 | 123 | | |
123 | 124 | | |
124 | 125 | | |
| |||
140 | 141 | | |
141 | 142 | | |
142 | 143 | | |
143 | | - | |
144 | | - | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
145 | 152 | | |
146 | 153 | | |
147 | 154 | | |
148 | | - | |
149 | | - | |
150 | | - | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
151 | 160 | | |
152 | 161 | | |
153 | 162 | | |
154 | 163 | | |
155 | 164 | | |
156 | 165 | | |
157 | | - | |
| 166 | + | |
| 167 | + | |
158 | 168 | | |
159 | 169 | | |
160 | 170 | | |
161 | | - | |
| 171 | + | |
162 | 172 | | |
163 | 173 | | |
164 | 174 | | |
| |||
172 | 182 | | |
173 | 183 | | |
174 | 184 | | |
175 | | - | |
176 | | - | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
177 | 197 | | |
178 | 198 | | |
179 | 199 | | |
180 | | - | |
| 200 | + | |
| 201 | + | |
181 | 202 | | |
182 | 203 | | |
183 | 204 | | |
| |||
230 | 251 | | |
231 | 252 | | |
232 | 253 | | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | | - | |
237 | 254 | | |
238 | 255 | | |
239 | 256 | | |
| |||
244 | 261 | | |
245 | 262 | | |
246 | 263 | | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
247 | 283 | | |
248 | 284 | | |
249 | 285 | | |
250 | 286 | | |
251 | 287 | | |
252 | 288 | | |
253 | 289 | | |
254 | | - | |
| 290 | + | |
255 | 291 | | |
256 | 292 | | |
257 | 293 | | |
| |||
Lines changed: 52 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
509 | 509 | | |
510 | 510 | | |
511 | 511 | | |
512 | | - | |
| 512 | + | |
513 | 513 | | |
514 | 514 | | |
515 | 515 | | |
| |||
522 | 522 | | |
523 | 523 | | |
524 | 524 | | |
525 | | - | |
| 525 | + | |
| 526 | + | |
526 | 527 | | |
527 | 528 | | |
528 | 529 | | |
| |||
545 | 546 | | |
546 | 547 | | |
547 | 548 | | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
548 | 598 | | |
0 commit comments