Repository navigation
Let the model provider compact long conversations - #1907
Merged
Merged
Conversation
fazxes
force-pushed
the
fazxes/provider-written-compaction
branch
2 times, most recently
from
November 12, 2026 22:59
d72e656 to
cff4c8f
Compare
fazxes
force-pushed
the
fazxes/provider-written-compaction
branch
2 times, most recently
from
November 23, 2026 03:47
e0517b3 to
629e366
Compare
fazxes
marked this pull request as ready for review
November 23, 2026 05:34
- On models whose provider can compact a conversation, fx asks the provider to compact it, and later requests send the provider's block, then the newest 4 turns unchanged with their reasoning. - If the provider's compaction fails, fx writes its own summary and keeps no turns after it. - After a model switch, the earlier model's kept steps are sent as text. - Models without provider compaction keep fx's own compactor. - Stopping a compaction while the provider writes its block leaves the conversation as it was. - A session killed after the block is saved resumes with the block and the kept turns. - A running turn that doesn't fit is compacted whole, and only its message follows the block. - A request the provider refuses for its size is compacted with fx's summary and sent again. - `/compact` on these models runs right before the next message is sent. - Resuming a session compacted in the middle of a turn no longer drops the steps saved after the compaction.
… dropped /compact
main's fx-core.wasm was already at 99.8% of its budget. Provider compaction adds about 20 KB of shared compactor, session and gateway code to it, which puts it over. The budget goes back to about 10% above the measured size, as when it was set.
A fork of a session that holds a provider's block resumes with the block first on the model that wrote it, and with fx's text summary of the same turns on another model.
fazxes
force-pushed
the
fazxes/provider-written-compaction
branch
from
November 25, 2026 03:07
629e366 to
3a380d6
Compare
fx-term.wasm also carries the compactor, session and gateway code that provider compaction adds, about 21 KB, which put it over its budget. Set both wasm budgets just above the sizes CI measured, as main raises them. The recorded compaction replies held the gateway's client session fingerprint; replace it with zeros, which the tests never read.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
/compacton these models runs right before the next message is sent.Why
Before and after
/compacton these models now shows "Context will be compacted before your next message." and compacts right before that message is sent, the one request the provider can compact exactly as it was sent.Tests
tests/e2e/provider-compaction.test.tsdrives the built binary through a fake AI Gateway: both providers' blocks, each fallback (error statuses, no block, an answer, empty, cut and oversized replies), a model switch,/compact, a stopped compaction, a kill and resume, 30-turn sessions, a running turn compacted whole, a request refused for its size, and a fork of a compacted session, which sends the block to the model that wrote it and fx's text to another model.compaction-policy.test.tsnow counts the provider's compaction request.tests/tla/compaction/ProviderCompaction.tlamodels the cut, the block, the fallback and the kept turns.check.shruns TLC on it, shows that the old behavior breaksNoDroppedReasoning, and checks that four planted bugs each break a property.tests/tla/drivers/compaction/walks the built binary along the model.Size
fx-core.wasmand tofx-term.wasm, which would put both over the budgetsmainsets (mainmeasures 2,471,087 of 2,475,000 and 4,270,750 of 4,276,000 bytes). Their budgets insdk/tests/package-size-budgets.jsongo just above the measured sizes, asmainraises them:fx-core.wasmto 2,505,000 bytes (2,491,219 measured) andfx-term.wasmto 4,310,000 bytes (4,292,140 measured). SDK agents keep fx's own compactor: their model connection sets no compaction hooks.Notes on the checks
TLA+ models that cover changed files and stay unchanged:
agent_runtime/: the provider's compaction request is not an agent step, and the step loop's empty-reply nudge is untouched.auth/: a provider compaction rejected with 401 renews through the samerenewCredentialpath as fx's own summary request, once per compaction.configured_provider/: custom model connections never turn provider compaction on (only the AI Gateway provider sets the hooks,src/builtins/gateway.zig), and the fields they send do not change.compaction_progress/: the provider's request uses the same ask step as a summary request, so the row earns its waiting share; if fx then writes its own summary, that request asks again, as the model allows.gateway_open/: the compaction request opens its connection through the samestreamModelCompletionpath.saved_turn/: the order of a turn's messages at each step boundary does not change; the block is a checkpoint message before the turns. In the turns a block kept, another model's reasoning goes as text (seesession/below).session/: how a turn streams and is written again after a compaction cut does not change, and that is what this model covers. Two other parts of the session code change. Restore no longer trims a turn written again, since it already starts after the cut. And a checkpoint's provider block now goes to the model that wrote it, with another model's reasoning in the turns kept after it sent as text;tests/tla/compaction/ProviderCompaction.tlamodels that projection (Wire,KeptAfterBlock, checked byReadableandNoDroppedReasoning).toolbox/: the compaction request sends the conversation as it was sent, toolbox menu included;compaction-policy.test.tschecks the menu across compactions.subagent/: the compaction call in the step loop reads no subagent message queue, stop, or close, soSteerQueueandStopMessagestill hold.Other notes:
tests/e2e/provider-compaction.test.ts,tests/tla/drivers/compaction/provider.test.ts). They wait on the child's exit; the timer only stops a hang.src/core/compactor/model.zig). The tests' SIGINT and SIGKILL go to the fx child process.