Repository navigation
Take the unknown-capacity compaction assumption from the host - #11
Merged
Merged
Conversation
The automatic-compaction trigger for a model without catalogue capacity used a core-owned constant, DEFAULT_ASSUMED_CONTEXT_WINDOW (128,000). That number is consumer policy. The planner now receives the resolved model's host-supplied Model.contextWindow as a separate assumedContextWindow field and uses it only to schedule automatic compaction; it is still never a capacity or admission limit. Real capacity keeps flowing through contextWindow as before. Breaking: DEFAULT_ASSUMED_CONTEXT_WINDOW is no longer exported. Hosts define their own fallback and supply it as Model.contextWindow. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JqbJBBoCXgqyyFZaYn5Co4
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.
What leaked
When a model has no catalogue capacity,
@qduc/agent-corescheduled automatic compaction atDEFAULT_ASSUMED_CONTEXT_WINDOW × compactThreshold, whereDEFAULT_ASSUMED_CONTEXT_WINDOW(128_000) was a constant owned and exported by the core. Which window to assume for an unknown model is the consumer's policy, not the harness's. (#7 raised that constant to a consumer's figure; #10 reverted it. This PR removes the core-side number instead of changing it.)What the host now supplies
The host already sets a required
Model.contextWindowon every model: catalogue capacity when known, otherwise its own fallback. The compaction planner now receives that value as a separate field,assumedContextWindow, distinct from the existingcontextWindowfield that carries real capacity only.packages/core/src/engine/recovery-compaction.ts:DirectCompactionInputgains requiredassumedContextWindow: number; the unknown-capacitysoftTriggeruses it where the constant was. Nothing else reads it. When it would be used (automatic compaction, unknown capacity), a non-positive or non-integer value throws aRangeError, like the existingcontextWindowvalidation, so a bad host value cannot silently compact on every boundary.packages/core/src/engine/turn-model-compaction.ts: the only call site ofcompactDirectHistorypassesassumedContextWindow: model.contextWindow(the resolved model). The real-capacity argument is unchanged (deps.compaction.contextWindow ?? model.catalogContextWindow).packages/core/src/model/index.ts: constant and its export removed;Model.contextWindowdocumented as a host-supplied window that only schedules maintenance when capacity is unknown.packages/core/README.md(public-interface doc): new section on capacity versus the host's assumption, plus the migration note.Unchanged: known catalogue capacities, explicit
maxRequestInputTokensceilings, rawcompactThresholdTokens, manual compaction (ignores the assumption), and admission (enforceDirectInputLimitstill only sees real capacity or the explicit ceiling, so the assumption is never a hard limit).Breaking change
DEFAULT_ASSUMED_CONTEXT_WINDOWis no longer exported. The package is a prerelease and its one consumer is Term2, so this is a deliberate breaking removal. Consumers that imported it must define their own fallback and set it asModel.contextWindowfor uncatalogued models.package.jsonversion is unchanged;packages/wireis untouched.Verification
Ran on Node 24.22.1 / pnpm 11.7.0 at the head commit:
pnpm install --frozen-lockfile,pnpm build,pnpm typecheck,pnpm test(8/8),node scripts/agent-package-smoke.mjs, andpnpm smoke:checkoutafter committing. All passed.A temporary probe (not committed) called
compactDirectHistoryfrom the builtdistof this branch and oforigin/main, ratio 0.8, local mode. "Needed" means the planner went past the trigger into an attempt (the probe history has nothing to summarise, so it endsblocked:no_complete_cold_turn); "not needed" isnot_needed.compactThresholdTokens50,000: 49,999 / 50,000maxRequestInputTokens60,000: 44,999 / 45,000End to end through
startTurn, a model with no catalogue capacity and host window 128,000 received a request of roughly a million estimated tokens: the turn completed and the model saw the large request on both builds (admitted, not rejected). Control: withmaxRequestInputTokens200,000 the same turn failed before dispatch on both builds.Not verified
Generated by Claude Code