Repository navigation
fix(offload): imply block_fallback under debug logging, WARN on ask failure - #401
Merged
Merged
Conversation
…ailure extract_llm_sweep's prefix ask can fail (sweep_ask_failed), and the provider's error text was only recorded in r.rec.Rejection when block_fallback: true. On the default (unset -> false) path the ask failure was silently folded into a fresh-priced fallback and the cause was lost -- including under CG_LOG_LEVEL=debug, the one mode an operator reaches for specifically to see why a call did what it did. Make the unset case defer to the process log level: at debug, effectiveBlockFallback() behaves as if block_fallback: true, unless the operator wrote the key explicitly (either value), which always wins. Detected via the same YAML probe newExtractSweep already uses to reject banned keys, since the field's zero value cannot otherwise be told apart from an explicit `false`. Also log every prefix-ask failure at WARN with session and gate, regardless of block_fallback, so the cause is never visible only inside a rejection string the default path never writes. Updates the block_fallback field hint and docs/components/advanced-offload.md to describe the debug behavior. Assisted-By: Claude Sonnet 5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
amiddavid
added a commit
that referenced
this pull request
Oct 6, 2026
…efixAsk The trigger/cache_state/cold-ordering/keep-alive work from the previous commit was correctly implemented but inert on the deployment's own traffic: cache_aware_summarizer requires components.MessagesModel, and on Anthropic incoming-model requests the host wraps the client as internal/cheapmodel.Anthropic, which implements only Complete (#275 part 2). Add a second call path through components.PrefixAsker (Ctx.PrefixAsk) — the same "stored request plus one appended question" shape extract_llm_sweep already uses on this traffic, reading the previous turn's actually-sent body rather than rebuilding a prompt. Both paths converge on one summaryCaller closure built once in Offload, so the detached async path, the cold-turn deferral and the keep-alive substitute all carry it opaquely; PrefixAsker.Ask's underlying CompletePrefixed/CompletePrefixedResponses already records usage into the same ambient sink CompleteMessages does, so no extra accounting was needed. PrefixAsker always sends its question as a trailing USER message, so a pinned instruction_role: system is refused loudly (system_role_unsupported_via_prefix_ask) rather than silently sent as user. components.ErrNoPrefix (nothing stashed yet) is counted apart from a real failure; a real failure is now WARN-logged with the provider's error on every path that can hit one, matching the fix already shipped for extract_llm_sweep's sweep_ask_failed (#401). Also fixes a timing bug found while wiring the keep-alive substitute's cache_state: pre_expiry check: the keeper's own ping-due timing is a different question from whether a candidate's configured pre-expiry window is actually live, and by the time a ping fires sweep has already overwritten the entry's startedAt with the ping's own not-yet-sent start — so the check now reads the entry's PREVIOUS startedAt (captured in sweep before the overwrite) rather than computing against a value that always reads back as "nearly the full TTL remaining". Closes #275 (both the inert cache_state and the Anthropic MessagesModel gap). Assisted-By: Claude Sonnet 5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
This was referenced Oct 6, 2026
amiddavid
added a commit
that referenced
this pull request
Oct 7, 2026
A prefix ask can still run out of its reply budget on the capped branch added for the ceiling bug. The provider marks this with stop_reason: "max_tokens", not a 400. CompletePrefixed now treats that as an error. A clipped JSON array must not parse as a clean "nothing was spent" verdict. The failure takes the normal path: sweep_ask_failed, the WARN added in #401, then fallback or decline. Usage is still billed, since the tokens were spent either way. Added one more table case: thinking.type "enabled" with budget_tokens missing computes 0 + reply. The API would reject such a body on its own, so this just states the choice instead of leaving it unexplained. Assisted-By: Claude Sonnet 5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
amiddavid
added a commit
that referenced
this pull request
Oct 8, 2026
…efixAsk The trigger/cache_state/cold-ordering/keep-alive work from the previous commit was correctly implemented but inert on the deployment's own traffic: cache_aware_summarizer requires components.MessagesModel, and on Anthropic incoming-model requests the host wraps the client as internal/cheapmodel.Anthropic, which implements only Complete (#275 part 2). Add a second call path through components.PrefixAsker (Ctx.PrefixAsk) — the same "stored request plus one appended question" shape extract_llm_sweep already uses on this traffic, reading the previous turn's actually-sent body rather than rebuilding a prompt. Both paths converge on one summaryCaller closure built once in Offload, so the detached async path, the cold-turn deferral and the keep-alive substitute all carry it opaquely; PrefixAsker.Ask's underlying CompletePrefixed/CompletePrefixedResponses already records usage into the same ambient sink CompleteMessages does, so no extra accounting was needed. PrefixAsker always sends its question as a trailing USER message, so a pinned instruction_role: system is refused loudly (system_role_unsupported_via_prefix_ask) rather than silently sent as user. components.ErrNoPrefix (nothing stashed yet) is counted apart from a real failure; a real failure is now WARN-logged with the provider's error on every path that can hit one, matching the fix already shipped for extract_llm_sweep's sweep_ask_failed (#401). Also fixes a timing bug found while wiring the keep-alive substitute's cache_state: pre_expiry check: the keeper's own ping-due timing is a different question from whether a candidate's configured pre-expiry window is actually live, and by the time a ping fires sweep has already overwritten the entry's startedAt with the ping's own not-yet-sent start — so the check now reads the entry's PREVIOUS startedAt (captured in sweep before the overwrite) rather than computing against a value that always reads back as "nearly the full TTL remaining". Closes #275 (both the inert cache_state and the Anthropic MessagesModel gap). Assisted-By: Claude Sonnet 5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
AIMikav
pushed a commit
to AIMikav/context-guru
that referenced
this pull request
Oct 8, 2026
…fix asks CompletePrefixed (the Anthropic Messages leg of a prefix ask) overwrote the stored request body's max_tokens with the fixed PrefixAskMaxTokens (16000) without looking at thinking.budget_tokens already on that body. Claude Code sends max_tokens=32000 with thinking.budget_tokens=31999, so every prefix ask on such a session 400'd: "max_tokens must be greater than thinking.budget_tokens". This broke cache_aware_summarizer on the Anthropic route and is very likely the unrecorded cause of two prior sweep_ask_failed fires, since extract_llm_sweep's adjudication call goes through the same path. The thinking block itself must stay byte-identical: per Anthropic's prompt-caching docs, changing thinking parameters (including the budget) invalidates the cached message prefix, which would defeat the entire point of a prefix ask (proxy/keepalive.go already relies on the same fact to justify refusing to ping a thinking-enabled session). So the fix reads the existing budget rather than editing it: with thinking.type == "enabled", the outbound max_tokens becomes budget_tokens + the existing reply allowance, which clears the invariant while leaving room for the actual answer. "adaptive", "disabled", and no thinking block at all are unaffected, since only "enabled" ties max_tokens to a budget this call doesn't otherwise know. Checked openai_prefixed.go (the Responses leg): the Responses API's reasoning control is a qualitative effort level, not a token budget, so no equivalent fix applies there -- documented why in a comment at the call site. Also checked that extract_llm_sweep and rossoctl#401 reference PrefixAskMaxTokens by name rather than its literal value, so this change does not affect them. Assisted-By: Claude Sonnet 5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
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
extract_llm_sweep's prefix ask can fail (sweep_ask_failed), and the provider'serror text was only ever recorded in
r.rec.Rejectionwhenblock_fallback: true.On the default (unset → false) path the failure was silently folded into a
fresh-priced fallback and the cause was lost — including under
CG_LOG_LEVEL=debug, which is precisely the mode an operator reaches for to seewhy a call did what it did.
effectiveBlockFallback(c)onExtractSweep: an explicitblock_fallback(either value) always wins; left unset, the effective value now follows
logging.Debugging(c.Ctx)— i.e. debug behaves asblock_fallback: true.Explicit-vs-unset is detected via the same YAML probe
newExtractSweepalreadybuilds to reject banned keys, since the field's Go zero value can't otherwise be
told apart from an explicit
false.sessionandgate, regardless ofblock_fallback, so the cause is never visible onlyinside a rejection string the default (fallback) path never writes.
block_fallbackfield doc comment, itscomponents.RegisterFieldshint, and
docs/components/advanced-offload.mdto describe the debug behavior.A decision worth calling out
The WARN is added only on the genuine
sweep_ask_failedbranch, not onsweep_no_prefix(components.ErrNoPrefix). A first turn with nothing stashedyet is expected and happens once per session; the existing code comment at that
branch already draws this line ("one is 'there was nothing to read yet' ... and
the other is 'the read failed', which does"). Logging a WARN on every session's
first turn would be noise, not evidence, so only the real failure case gets one.
Test plan
TestSweepDebugImpliesBlockFallbackUnlessExplicit(debug+unset blocks andpreserves the provider's error in the published
Rejection; debug+explicitblock_fallback: falsestill falls back; non-debug+unset falls back as before).TestSweepAskFailureIsLoggedAtWarn(WARN line carries level/gate/session,checked both when it falls back and when it's blocked).
go build ./...— okgo vet ./components/offload/...— okgofmt -lon the changed.gofiles — emptyCGO_ENABLED=1 go test ./components/offload/...— ok (12.7s)CGO_ENABLED=1 go test -race ./components/offload/... ./internal/logging/...— ok (148.9s / 1.0s)