Repository navigation
Commit 6124d47
authored
fix(compaction): summarize the prepared window and always restore audited identifiers (#129423)
* fix(compaction): restore omitted source identifiers
* fix: log ChatGPT stream termination reasons
* fix(compaction): summarize the prepared window and always restore audited identifiers
Two safeguard defects made auto-compaction fail closed on tool-heavy sessions:
1. When the prepared window held only tool calls/results, the safeguard replaced it
with sessionManager.getBranch() — the whole branch from root. Since #112988 made
/new a reset entry inside the same transcript, that branch spans every reset and
prior compaction (3,565 messages / 5.2 MB on the reporting session), so one
compaction became dozens of sequential model calls until the 900s watchdog fired
("Compaction timed out"). The #78390 reason for that fallback (preparation
omitting custom messages) is handled by core projectSessionEntryMessage now.
Summarize only the prepared window; decide "nothing to summarize" from the
boundary-scoped context (buildSessionContext), never the raw branch. Delete the
fallback and its sessions_send replay sanitizers, which only existed for it.
2. #122824 moved the identifier oracle to the messages before the recent-turns split,
so audited identifiers can live only in preserved turns that are capped at 600
chars/message and 8K per section. The deterministic restore added in #128968 ran
only when the artifact exceeded 16K chars; an under-budget body that omits an
identifier still failed the audit (missing_identifiers -> guard_blocked). Run the
retention plan whenever a strict identifier is missing from the body, and only
emit the truncation marker when body text was actually trimmed.
* fix(compaction): fund audit sections first and cap the identifier list
The retention plan protected the model-written "## Pending user asks" and
"## Exact identifiers" sections verbatim. Each re-distill fed the previous
summary back, so the identifier list only grew: on the reporting session it was
13,568 of a 13,953-char summary, every other section an empty heading, and the
next compaction cancelled with "required quality facts exceed finalized artifact
budget" because the protected content alone passed the 16K cap.
Protect only what the audit requires (headings, bounded latest-ask context, the
audited identifiers). Fund the two audit-bearing sections first so an oversized
earlier section cannot starve them, but cap each at 25% of the content budget;
the remainder is split across decisions, TODOs, and constraints.
* fix(ai): log only structured ChatGPT stream termination facts
projectProviderError keeps provider message/body text after credential
redaction, so logging errorMessage could persist prompt- or response-derived
content. Log timing, stop classification, the error class name, and the
projection's structured errorCode/errorType instead, and cover a provider
failure whose message must not reach the transport log.
* fix(ai): classify ChatGPT stream termination locally
Provider error code/type fields are provider-controlled text, so the transport
warning logs a fixed local failure category (timeout, caller-abort,
provider-failure, transport) plus timing instead. The failed-response test
feeds hostile code/type/message values and asserts none reach the log.
* fix(compaction): recover omitted conversation from the boundary-scoped range
Replace the deleted whole-branch fallback with the bounded safety net it was
meant to be: when the prepared window holds no real conversation, project the
branch entries the preparation covered — after the last reset/compaction
boundary, before firstKeptEntryId — through the core context builder and
summarize that range if it contains conversation the preparation dropped. It
can never reach behind a boundary, so it cannot re-read the whole session.
* fix(compaction): make the audit-section cap hard even when the summary fits
Two holes let the identifier snowball survive the 25% share cap: a summary
that still fit the 16K budget skipped the retention plan entirely, so a
13.9K identifier dump was fed unchanged into the next re-distill; and the
surplus loop handed unused budget back to the protected sections whenever
the optional sections were empty — exactly the degraded shape in production.
Rebuild whenever an audit section exceeds its cap, and return surplus to the
optional sections only.
Also classify a direct non-OK HTTP reply (CodexApiError) as a provider
failure in the stream-termination diagnostic, with a direct-400 test that
keeps provider text out of the log.
---------
Co-authored-by: VACInc <[email protected]>1 parent f1c60c7 commit 6124d47
6 files changed
Lines changed: 644 additions & 657 deletions
File tree
- config
- packages/ai/src/providers
- src/agents/agent-hooks
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1667 | 1667 | | |
1668 | 1668 | | |
1669 | 1669 | | |
1670 | | - | |
| 1670 | + | |
1671 | 1671 | | |
1672 | 1672 | | |
1673 | 1673 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
262 | 262 | | |
263 | 263 | | |
264 | 264 | | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
265 | 339 | | |
266 | 340 | | |
267 | 341 | | |
| |||
270 | 344 | | |
271 | 345 | | |
272 | 346 | | |
273 | | - | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
274 | 352 | | |
275 | 353 | | |
| 354 | + | |
| 355 | + | |
276 | 356 | | |
277 | 357 | | |
278 | 358 | | |
| |||
323 | 403 | | |
324 | 404 | | |
325 | 405 | | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
326 | 423 | | |
327 | 424 | | |
328 | 425 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
243 | 243 | | |
244 | 244 | | |
245 | 245 | | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
246 | 266 | | |
247 | 267 | | |
248 | 268 | | |
| |||
288 | 308 | | |
289 | 309 | | |
290 | 310 | | |
| 311 | + | |
291 | 312 | | |
292 | 313 | | |
293 | 314 | | |
| |||
621 | 642 | | |
622 | 643 | | |
623 | 644 | | |
624 | | - | |
| 645 | + | |
625 | 646 | | |
626 | | - | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
627 | 650 | | |
628 | 651 | | |
629 | 652 | | |
630 | 653 | | |
631 | 654 | | |
632 | 655 | | |
633 | 656 | | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
634 | 670 | | |
635 | 671 | | |
636 | 672 | | |
| |||
0 commit comments