Skip to content

fix(offload): imply block_fallback under debug logging, WARN on ask failure - #401

Merged
amiddavid merged 1 commit into
mainfrom
feat/sweep-debug-block-fallback
Oct 6, 2026
Merged

amiddavid merged 1 commit into
mainfrom
feat/sweep-debug-block-fallback

Conversation

@amiddavid

@amiddavid amiddavid commented Oct 6, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

extract_llm_sweep's prefix ask can fail (sweep_ask_failed), and the provider's
error text was only ever recorded in r.rec.Rejection when block_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 see
why a call did what it did.

  • effectiveBlockFallback(c) on ExtractSweep: an explicit block_fallback
    (either value) always wins; left unset, the effective value now follows
    logging.Debugging(c.Ctx) — i.e. debug behaves as block_fallback: true.
    Explicit-vs-unset is detected via the same YAML probe newExtractSweep already
    builds to reject banned keys, since the field's Go zero value can't otherwise be
    told apart from an explicit false.
  • Every genuine prefix-ask failure is now also logged at WARN with session and
    gate, regardless of block_fallback, so the cause is never visible only
    inside a rejection string the default (fallback) path never writes.
  • Updated the block_fallback field doc comment, its components.RegisterFields
    hint, and docs/components/advanced-offload.md to describe the debug behavior.

A decision worth calling out

The WARN is added only on the genuine sweep_ask_failed branch, not on
sweep_no_prefix (components.ErrNoPrefix). A first turn with nothing stashed
yet 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

  • Added TestSweepDebugImpliesBlockFallbackUnlessExplicit (debug+unset blocks and
    preserves the provider's error in the published Rejection; debug+explicit
    block_fallback: false still falls back; non-debug+unset falls back as before).
  • Added TestSweepAskFailureIsLoggedAtWarn (WARN line carries level/gate/session,
    checked both when it falls back and when it's blocked).
  • Ran on the shared eval box (laptop has no Go toolchain):
    • go build ./... — ok
    • go vet ./components/offload/... — ok
    • gofmt -l on the changed .go files — empty
    • CGO_ENABLED=1 go test ./components/offload/... — ok (12.7s)
    • CGO_ENABLED=1 go test -race ./components/offload/... ./internal/logging/... — ok (148.9s / 1.0s)

…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
amiddavid merged commit 3bf3f19 into main Oct 6, 2026
7 checks passed
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]>
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]>
@amiddavid
amiddavid deleted the feat/sweep-debug-block-fallback branch October 8, 2026 11:12
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant