Skip to content

refactor(offload): one helper for the role and opening of an appended question - #507

Merged
amiddavid merged 5 commits into
mainfrom
refactor/ask-instruction-role
Oct 25, 2026
Merged

amiddavid merged 5 commits into
mainfrom
refactor/ask-instruction-role

Conversation

@amiddavid

@amiddavid amiddavid commented Oct 13, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • The rule for the role and opening of an appended question now lives in one helper: resolveAsk in components/offload/ask_role.go.
  • The summarizer uses it. Its behavior does not change.
  • The sweep question now starts with the summarizer's opening line.

What changed

  • New resolveAsk(systemModels, modelID, channel):
    • askViaMessages: role is system only if the model is in system_models. Otherwise user.
    • askViaPrefix: always user. The prefix-ask path can only append a user message.
    • askStandalone: user, no opening line. There is no transcript to disclaim.
    • A user question gets the opening line [OPERATOR INSTRUCTION — this is not a task request from the user].
  • summarizerProfiles.roleFor and the prefix-ask role override in cache_aware_summarizer.go call the helper. The yaml keys (instruction_role, system_models, profiles) work as before.
  • The thinking guard moved into the helper: askStripsThinking(lastTurnOnlyModels, modelID, msgs), and askStripsThinkingShipped(modelID, msgs) for a caller with no profiles. The summarizer calls it with the same inputs. The sweep does not call it in this PR. PR A will (extract_llm_sweep fires at the wrong moment and loses money; ask at the keep-alive ping and apply when cold #404 point 11).
  • The bridge rule is named in the helper: askBridge(lastRole). It is backed by cheapmodel.AskBridge, which insertAskMessage now uses. The helper cannot own the rule alone, because cheapmodel cannot import offload. The summarizer's message-array path is unchanged.
  • extract_sweep.go: one line changes, at the BuildPrefixAsk call. This keeps the merge with PR A small.

How it was tested

On the eval box:

  • go vet ./components/...: clean. gofmt -l: empty.
  • go test -race ./components/... ./internal/... ./config/... ./apply/...: all pass. The existing summarizer role tests pass unchanged.
  • New tests (ask_role_test.go):
    • table test per model family (Opus, Sonnet, Haiku, Fable, open model, unknown, empty id, promoted, prefix, standalone)
    • summarizer roleFor uses the helper
    • the summarizer yaml user prompt starts with the shared line
    • the sweep question starts with the shared line, then the contract
    • the thinking guard (7 cells) and the bridge rule
  • Mutations run (each one made a test fail; then restored):
    1. roleFor ignores the helper: 2 tests fail.
    2. Allow-list never matches: 3 tests fail.
    3. Prefix channel may send system: table test fails.
    4. Sweep skips the opening line: sweep test fails.
    5. Opening line text changes: yaml-link test fails.
    6. Summarizer prefix path keeps a stale role: prefix-ask test fails.
    7. Guard ignores the model list: 2 tests fail.
    8. Guard ignores the messages: 2 tests fail.
    9. Summarizer skips the guard: its decline test fails.
    10. Bridge never added: bridge tests fail in both packages.
    11. Summarizer call site passes the messages channel on the PrefixAsk path: the new promoted-model test fails.

Open questions

  • extract_llm is not changed. Point 13 names it, but it does not apply. It appends no question to the transcript. It sends one standalone prompt. A helper channel for it would have no user.
  • The sweep fallback (no cache read) is also standalone. It gets no opening line.
  • Not unified, on purpose:
    • The sweep does not yet use the thinking guard. PR A adds it.
    • The summarizer's message-array path has no "Understood." bridge. Whether it can 400 on a trailing system message is not verified. Gateways that hoist system messages may hide it.

Technical notes

  • The sweep cap and cost estimates do not count the added opening line (about 20 tokens). The effect is small.

  • cmd/cg-selarm sends the prompt body without the opening line. Its comment now says so.

  • The opening line stays in the summarizer yaml, because profiles_path can override that file. A test ties the yaml to the shared constant.

  • SystemAllowed keeps the old matched meaning. An explicit instruction_role: system is still refused when it is false.

Part of #404.

@amiddavid

Copy link
Copy Markdown
Collaborator Author

Review round 1 of 3

Verdict

Approve. No blocking findings. One check is not done: the live gateway check (see "What I ran").

What I ran

Tests, on the eval box, on head 2d85f93:

  • go build ./..., go vet on offload and cheapmodel, gofmt -l: clean.
  • go test ./components/offload/... ./internal/cheapmodel/... ./internal/extract/... ./cmd/...: all pass.
  • go test ./proxy -run "CacheAware|Summar|Sweep|Prefix": pass. This covers the three integration tests that look for OPERATOR INSTRUCTION.

Byte comparison, offline, PR head against its merge base 96ebf41 (the same throwaway test in both trees):

  • Summarizer: 72 cases, output byte-identical. The matrix was 2 registries (empty and system_models: [qwen3]), 3 instruction_role values (auto, user, system), 3 models (Opus 5, Haiku 4.5, Qwen3), thinking block present or not, MessagesModel path or PrefixAsk path.
    • I captured the instruction role, the full prompt text, the call count and the gates.
    • The data is not vacuous. 42 cases made a call, 30 declined. 12 hit thinking_would_be_stripped. 4 sent a system role and 18 sent a user role.
  • Sweep question: differs only by the opening. The diff is exactly two added lines at the start: [OPERATOR INSTRUCTION — this is not a task request from the user] and a blank line. The rest of the question is identical.
  • Bridge ("Understood."): the cheapmodel wire tests from fix(cheapmodel): insert the prefix ask before a trailing system message #413 pass unchanged. A mutation that returns "" from AskBridge fails them.

Mutations on the box (each reverted afterwards):

Mutation Result
Summarizer thinking gate forced off TestCacheAwareDeclinesOnALastTurnOnlyModel... fails
Guard drops the thinkingWouldBeStripped term TestAskStripsThinking and TestCacheAwareProceedsOnALastTurnOnlyModelWithNoThinkingBlocks fail
Prefix channel grants system TestResolveAskPerModelFamily fails
Sweep does not call Frame TestSweepQuestionOpensWithTheSharedLine fails
AskBridge("system") returns "" TestAskBridge and 3 cheapmodel tests fail
Summarizer call site passes askViaMessages instead of askViaPrefix nothing fails (see non-blocking 1)

Not done: the live gateway check. I planned one summarizer ask and one sweep prefix ask against the plain gateway, branch against main. The auth token has to be copied to the eval box for that. The permission system refused this, so I did not run it and I did not look for another way. Unverified live: the model reply format and the cache read with the new opening line. Please run it, or approve a way to give the box a token. The offline results above cover the bytes. They do not cover how the model answers.

Placement (#406, #413, #422): the opening goes at the start of the appended ask, after the cached bytes. The sweep stays on the append-last path. Cached bytes do not change. The Understood. rule keeps its position after a trailing system message (#413). The thinking guard is defined, tested, and not yet called by the sweep, as agreed (#422 is for PR #508).

Blocking findings

None.

Non-blocking

  1. Test gap at the summarizer call site. cache_aware_summarizer.go:797 passes askViaPrefix. No test fails if it passes askViaMessages. The helper test covers the rule, but not the call. The effect is only visible when a model is added to system_models, which the shipped registry leaves empty. Add one test: a promoted model on the PrefixAsk path must send the user prompt.
  2. cmd/cg-selarm/main.go:146,175 calls extract.BuildPrefixAsk and says "THE SHIPPED PROMPT". That is no longer true. Production now sends the opening line first. Arm results from this tool will differ from production by that line. Apply Frame there, or fix the comment.
  3. Unused wrappers. askBridge and askStripsThinkingShipped in ask_role.go have no production caller. Tests use them. This is fine if feat(sweep): ask at the keep-alive ping, hold the answer, recheck, shadow mode #508 uses them. If not, remove them.
  4. The sweep cap and cost estimates do not count the added opening (about 20 tokens). The effect is small, but note it in the PR text.

@amiddavid

Copy link
Copy Markdown
Collaborator Author

Review round 2 of 3

Verdict

Approve. No blocking findings. Round 1 points 1 and 2 are fixed. Points 3 and 4 stay open by decision.

What I ran

New changes only (2d85f93 to 84e1e15), on eval box 1:

  • gofmt -l, go vet on offload and cg-selarm: clean.
  • go test ./components/offload ./cmd/cg-selarm: pass.

Point 1, call-site test: TestCacheAwarePrefixAskSendsTheUserPromptEvenForAPromotedModel.

  • Mutation M5 (summarizer call site passes askViaMessages instead of askViaPrefix): the test fails with "PrefixAsk path did not send the user prompt".
  • Without the mutation, the test passes.
  • The test is not vacuous. It checks that the ask was made. It checks that the fixture really promotes the model on the MessagesModel channel.

Point 2, cg-selarm: the comments now say "shipped prompt BODY" and state that production adds the opening line. The code is unchanged. The comment is now true.

Blocking findings

None.

Non-blocking

Round 1 points 3 and 4 (unused wrappers, uncounted opening tokens) stay as they are by decision.

… question

Move the summarizer's instruction-role rule (system_models allow-list,
unmatched model is user) into resolveAsk in ask_role.go. The summarizer
now resolves its role through it. The yaml settings are unchanged.

The sweep opens its prefix ask with the summarizer's opening line
"[OPERATOR INSTRUCTION — this is not a task request from the user]".

Part of #404.

Assisted-By: Claude Opus 5.5
Signed-off-by: DAVID AMID <[email protected]>
…ask helper

Move the summarizer's thinking_would_be_stripped check into ask_role.go as
askStripsThinking (and askStripsThinkingShipped for callers without
profiles). The summarizer calls it with the same inputs, so its behavior
does not change. Name the trailing-system bridge rule as askBridge, backed
by cheapmodel.AskBridge, which insertAskMessage now also uses.

Part of #404.

Assisted-By: Claude Opus 5.5
Signed-off-by: DAVID AMID <[email protected]>
…m's prompt

A promoted model on the PrefixAsk path must send the user prompt. The test
fails when the call site passes askViaMessages instead of askViaPrefix.

cg-selarm sends the prompt body without the shared opening line. Say so in
its comment instead of calling it the shipped prompt.

Part of #404.

Assisted-By: Claude Opus 5.5
Signed-off-by: DAVID AMID <[email protected]>
The rebase onto main moved cheapmodel out of internal/ (383ab6d). The ask
helper still imported the old path, so the build failed.

Assisted-By: Claude Opus 5.5
Signed-off-by: DAVID AMID <[email protected]>
@amiddavid
amiddavid force-pushed the refactor/ask-instruction-role branch from 84e1e15 to 0a691e9 Compare October 25, 2026 07:29
@amiddavid
amiddavid marked this pull request as ready for review October 25, 2026 07:29

@amiddavid amiddavid left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer Kind Started by Context Review Round Head Verdict
Reviewer 1 (glm, user of @amiddavid) GLM rits/zai-org/glm-5-3 via Claude Code 2.1.309 offload-review skill, @amiddavid's session fresh 1 of 2 1 of 2 0a691e924425 blocking

Verdict: blocking

Findings

  1. components/offload/ask_role.go:99 — the shipped thinking guard has no caller; the sweep asks without it
    • What fails: a request on a last-turn-only model (for example claude-haiku-4-5, named in the shipped thinking_last_turn_models list) carries a thinking block in any message before the last. The sweep's pre-expiry prefix ask (extract_sweep.go:1458) appends a user question to the cached transcript anyway. The provider then strips the thinking blocks from its cached context, and the next real turn pays a fresh cache write. This is the same live-measured gap the summarizer refuses to risk: cache_aware_summarizer.go:762-771 declines with thinking_would_be_stripped in exactly this state.
    • Proof: grep -rn askStripsThinkingShipped over components/, cmd/, proxy/ finds only its definition (ask_role.go:99) and its test (ask_role_test.go:152). No production code calls it. Its own comment says it exists "for a caller that has no profiles of its own (the sweep)" — but extract_sweep.go contains no reference to thinking at all. Commit 30f11ea also says the helper is "for callers without profiles". So the PR ships the guard, claims the sweep is its caller, and never wires it. A reader auditing cache safety would believe the sweep is protected. It is not.
    • Fix: in ExtractSweep.adjudicate, before the prefix ask, check askStripsThinkingShipped(c.ModelName, req.Input) (the same input the summarizer's guard uses). When it fires, gate (for example sweep_thinking_would_be_stripped) and take the fallback path, as the summarizer does. Or delete the helper and rewrite its comment to say it has no caller yet.

Non-blocking

  • components/offload/ask_role.go:112 — askBridge is also test-only dead code. Its comment says the rule is "named here so every channel reads one answer", but no offload channel calls it. The wire path (cheapmodel.insertAskMessage) applies the rule itself. The MessagesModel summarizer path builds [conversation..., instruction] with no bridge, but no Anthropic MessagesModel client exists today (cheapmodel's Anthropic client implements Complete only), so no reachable channel needs it. Either drop the wrapper or fix the comment.
  • cmd/cg-selarm/main.go:148 — the arm tool now differs from production by the opening line. The comment documents this (~20 tokens, identical in every arm), so arm comparisons stay internally valid. Absolute keep-rates may shift a little versus production. Acceptable as documented.
  • components/offload/cache_aware_summarizer.go:241 — thinkingLastTurnOnly now has no production caller (the guard calls askStripsThinking directly). It is still exercised by the registry-documentation test in cache_aware_trigger_test.go, so it is not fully dead. Fine to keep.

What I checked

  • Read the full diff (4 commits) and the code around every change.
  • Refactor equivalence, summarizer. roleFor → resolveAsk(..., askViaMessages): same allow-list match, same case-insensitive substring rule, same return values. thinkingLastTurnOnly → matchesModelList: same rule. The PrefixAsk role override at line 798: resolveAsk(..., askViaPrefix).Role is always user, because only askViaMessages can grant system — identical to the old hard-coded user. The moved hasThinkingBlock/thinkingWouldBeStripped bodies are unchanged.
  • Refactor equivalence, cheapmodel. insertAskMessage: AskBridge(role) != "" fires only for role == "system", and the inserted text is AskBridge("system") = "Understood.". Behavior identical to the old inline check.
  • Sweep prompt change. The opening line is prepended only on the prefix-ask path (askViaPrefix always yields role user, so Opening is always set). newSweepAskDump records the framed prompt, so the dump stays "as sent". Existing sweep tests assert with Contains, so the added line breaks none; the labelAsker regex \[(\d+)\] cannot match the opening line (no digits in its brackets).
  • Opening-line consistency. askOpeningLine matches the first line of the yaml user prompt character for character (em-dash included), and TestSummarizerUserPromptOpensWithTheSharedLine pins that link.
  • New tests. Verified every helper they use exists with matching signatures (labelAsker, newSweepSmall, sweepReqStocked, preExpiryCtx, fakePrefixAsker, caWriteProfiles, caCtxNoModel, caFixture, WaitForSummaryForTest). The promoted-model PrefixAsk test checks its own preconditions (ask happened, registry promotes) so it cannot pass vacuously.
  • Import cycle. components/offload → cheapmodel is safe: cheapmodel imports components, dispatch, internal/adjudicate, internal/logging; none imports offload.
  • Fail open. askStripsThinkingShipped fails open to false on an unreadable registry. The registry is embedded, so the error path is theoretical. No new error or panic path touches the request body.
  • Data dependence. No feature changes what it stores or reads. No docs/data-dependence.md update needed.
  • Live tests were not run (not approved). All findings above are from reading the code.

amiddavid added a commit that referenced this pull request Oct 25, 2026
…adow mode

Part A of #404 (the cold path). The sweep asks its question in place of
the keep-alive ping and holds the answer per thread. Nothing applies a
held answer yet: it changes no request.

- Ask at the ping, no timer of its own. The time-window trigger and
  pre_expiry_seconds are removed (the key is refused with the reason).
- Ask with one candidate or more. min_inventory defaults to 1.
- Hold per thread in the Store (cg:swh:, pinned), with tool_use_id and a
  SpanHash of the agent's message for each judged output, the judged
  length and the wait cause (#453). Stored only; nothing decides on it.
- recheckHeld drops a verdict when the conversation is shorter, the
  output is gone or changed, a later turn referenced it (coref), or the
  agent expanded it. PR C calls it on the cold request.
- shadow: true (off, in no preset) reports asked, proposed, still valid
  at the cold request, and the reasons, as request_components events and
  a cg.sweep.shadow log line.
- evidence is on by default.
- Plain ping, counted as sweep_model_declined, where the question breaks
  the cache (#422).
- Ask only when shadow is on, until the cold apply exists (PR C). Counted
  as sweep_ask_needs_shadow.
- Remove econ_trigger, the in-request ask and the full-price fallback.
  The keys econ_trigger, econ_ignore_ask_cost, reward_premium,
  min_pressure and block_fallback are ignored with a warning and a count,
  so an old config still loads.
- extract.Ask composes the question from lists, so #490 and #485 can add
  theirs. An output in two lists is judged once.
- Recover from a panic in the ping question: the ping stays plain, the
  panic is counted, and the next ping is plain too. Check the concurrency
  bound before collecting candidates.

- Rebased onto #507. Point 11 now uses askStripsThinkingShipped. The keeper
  changes live in package keepalive (main moved the keeper there); the
  wait cause reaches it through Options.OpenTasks and Record.ToolUseNames.
  The question is framed with the shared opening line (resolveAsk.Frame)
  and asked through AskCovered when the asker supports it.

Assisted-By: Claude Opus 5.5
Signed-off-by: DAVID AMID <[email protected]>

@amiddavid amiddavid left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer Kind Started by Context Review Round Head Verdict
Reviewer 2 (glm, user of @amiddavid) GLM rits/zai-org/glm-5-3 via Claude Code 2.1.309 offload-review skill, @amiddavid's session fresh 2 of 2 1 of 2 0a691e924425 blocking

Verdict: blocking

Findings

  1. components/offload/ask_role.go:99 — askStripsThinkingShipped has no caller; the sweep it was written for is not wired to it.
    • What fails: The helper's comment says it exists "for a caller that has no profiles of its own (the sweep)". No such caller exists. grep over all non-test Go files finds askStripsThinkingShipped only at its definition (ask_role.go:99) and in ask_role_test.go:159. The sweep's prefix-ask branch (extract_sweep.go:1452-1485) never checks it. So the sweep still asks over the cached prefix on a last-turn-only model with earlier thinking blocks. That ask strips those blocks from the provider's cached context — the same damage the summarizer declines on at cache_aware_summarizer.go:765, measured live at ~2,100-2,150 tokens short on claude-haiku-4-5. The sweep's econ trigger fires while the cache is still valuable, so the damage is not confined to the pre-expiry window. The exposure is pre-existing, but this PR ships a guard for it and does not connect it, while the commit message and the comment both say the sweep is the caller.
    • Proof: grep -rn "askStripsThinkingShipped" --include="*.go" returns only ask_role.go (definition) and ask_role_test.go. grep -n "thinking" components/offload/extract_sweep.go returns nothing. The summarizer's own gate (cache_aware_summarizer.go:765) covers only its own instruction, not the sweep's ask, in the same pipeline.
    • Fix: Either wire the guard into adjudicate's prefix-ask branch — before attemptedPrefixAsk = true, decline the prefix ask and take the existing fallback when askStripsThinkingShipped(c.ModelName, msgs) is true, with its own gate name so the counters separate it — or drop the helper and reword the comment so it no longer names the sweep. If the wiring is planned for a later PR in #404, say so in the comment; as shipped, the comment misstates the code.

Non-blocking

  • components/offload/ask_role.go:112 — askBridge has no production caller either. Only the test reads it. Same class as the finding above, smaller: dead wrapper around cheapmodel.AskBridge. Drop it or wire it.
  • cheapmodel/anthropic.go:434-435 — the guard and the content read different inputs. The condition reads AskBridge(lastRole); the inserted text hardcodes AskBridge("system"). Today the two are identical, because only "system" returns non-empty. If AskBridge ever gains a second role, the guard fires but the wrong text is inserted. Capture the role's answer once and reuse it.
  • cmd/cg-selarm/main.go:148-151 — the tool's prompt now differs from production by the opening line. The divergence is documented and identical in every arm, so comparative arm results hold. Note the cause: askOpeningLine is unexported, so cmd/ cannot reuse it. If absolute fidelity to the shipped prompt matters for the tool, export the line (for example from internal/extract) and frame there too.
  • components/offload/ask_role.go:31 — askStandalone is never passed by production code. Only tests use it. It documents the fallback channel's semantics, which is defensible; noting it so it does not silently rot.

What I checked

  • Read CLAUDE.md, docs/design.md, the full diff, and all four commits one by one.
  • Traced the refactor for behavior equality against base 1731483: roleFor and thinkingLastTurnOnly now delegate to resolveAsk/matchesModelList with the same trim, lowercase, and substring rules; the line-798 PrefixAsk role override still resolves to user; askStripsThinking at line 765 is the same conjunction the base used. No behavior change in the summarizer.
  • Checked the sweep framing change: BuildPrefixAsk carries no opening line of its own, so Frame does not duplicate it; the dump records the framed prompt, so "as sent" still holds; the labelAsker regex needs digits in brackets, so the new "[OPERATOR INSTRUCTION ...]" line cannot forge a label; existing ask-text assertions all use Contains, so none break.
  • Verified the yaml user prompt opens with the same line character-for-character (em dash included), which is what the new PrefixAsk test and TestSummarizerUserPromptOpensWithTheSharedLine rely on.
  • Checked the new tests for vacuity: TestCacheAwarePrefixAskSendsTheUserPromptEvenForAPromotedModel fails if the call site passes askViaMessages (the system prompt lacks the line), and its fixture really promotes qwen3; TestSweepQuestionOpensWithTheSharedLine fatals when no ask was made.
  • Checked the import direction: components/offload → cheapmodel is legal (cheapmodel imports the components root, not offload; no cycle). The rebase fix in 0a691e9 points at the moved public path.
  • Data dependence: unchanged — the PR changes prompt text and code structure only, stores nothing new. docs/data-dependence.md needs no new row; no new component is registered.
  • No live tests were run (not approved). All claims above come from reading the code.

…king

Both round-1 reviewers found that askStripsThinkingShipped had no caller,
while its comment named the sweep as one. The sweep's prefix ask now
declines on it, gates sweep_thinking_would_be_stripped, and takes the
fallback, the same rule the summarizer uses (#422).

askBridge in offload had no caller either. It is removed. insertAskMessage
now reads the bridge text once, from the last message's role.

Assisted-By: Claude Opus 5.5
Signed-off-by: DAVID AMID <[email protected]>
@amiddavid

Copy link
Copy Markdown
Collaborator Author

Replies to round 1 (both reviewers), fixed in e118ae2

Finding 1 (both reviewers): askStripsThinkingShipped has no caller. Fixed.

  • The sweep's prefix ask now checks it, in ExtractSweep.adjudicate, before it asks. When the check fires, the sweep does not ask over the cached transcript. It gates sweep_thinking_would_be_stripped and takes the fallback. This is the same rule the summarizer uses (extract_llm_sweep: the prefix ask re-writes the cache on Haiku 4.5 with thinking #422).
  • New test: TestSweepDeclinesThePrefixAskWhenItWouldStripThinking. On claude-haiku-4-5 with an earlier thinking block, the sweep makes 0 prefix asks and gates the case. On claude-sonnet-5, the same request asks once, so the test cannot pass by never asking.
  • Mutation: the check set to false. The new test fails.
  • The comment on askStripsThinkingShipped now names its real caller. The gate is added to the docs list.
  • Note: feat(sweep): ask at the keep-alive ping, hold the answer, recheck, shadow mode #508 replaces this ask path with a question at the keep-alive ping, and already calls the same helper there.

Non-blocking: askBridge has no caller. Removed, with its test. cheapmodel.AskBridge stays as the one rule, and insertAskMessage uses it.

Non-blocking (reviewer 2): the bridge check and the inserted text read different inputs. Fixed. insertAskMessage now reads the bridge text once, from the last message's role (lastBridge), and uses that same text.

Not changed:

  • cmd/cg-selarm: the comment documents the one-line difference, and both reviewers accept it.
  • thinkingLastTurnOnly: a registry test still uses it.
  • askStandalone: it documents the fallback channel.

Tests on the eval box: go vet and gofmt are clean. go test -race passes for components/offload and cheapmodel. These packages pass: components, internal, cmd, config, apply, proxy, cheapmodel, keepalive.

For the GLM record: in round 1, reviewer 2's first run did not finish. After 46 normal tool calls, the model repeated one word until it reached the 32,000-token output limit, 4 turns in a row, at about 21 minutes per turn. I stopped it after 75 minutes. A fresh run posted the review above. This is the first GLM run that failed. A script fix follows in its own PR.

@amiddavid amiddavid left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer Kind Started by Context Review Round Head Verdict
Reviewer 1 (glm, user of @amiddavid) GLM rits/zai-org/glm-5-3 via Claude Code 2.1.309 offload-review skill, @amiddavid's session resumed 1 of 2 2 of 2 e118ae2adc32 approve

Verdict: approve

Findings

None. The round-1 blocking finding is fixed correctly, and the fix introduces no new defect.

Earlier findings, resolved

  1. Mine, round 1: askStripsThinkingShipped had no caller; the sweep asked without the thinking guard. Fixed in e118ae2.
    • ExtractSweep.adjudicate now computes thinkingStripped := usePrefixAsk && !stalePrefix && askStripsThinkingShipped(c.ModelName, req.Input) (extract_sweep.go:1432) and routes that case into the existing fallback fork, with its own gate sweep_thinking_would_be_stripped and its own block_fallback rejection text. This is the same rule and the same input the summarizer uses at cache_aware_summarizer.go:765.
    • The gate priority is right: thinkingStripped requires !stalePrefix, so the two gates cannot both fire, and a stale prefix still reports as stale.
    • The fallback is safe: it is a self-contained prompt on a fresh prefix, so it cannot touch the cached transcript the guard protects.
    • The helper's comment now names its real caller. The gate is added to the docs list (docs/components/advanced-offload.md).
    • New test TestSweepDeclinesThePrefixAskWhenItWouldStripThinking is not vacuous: the claude-sonnet-5 arm makes exactly 1 ask on the same fixture, and the haiku arm must show the named gate, so a decline for any other reason fails the test.
  2. Reviewer 2, round 1, finding 1 — same defect. Fixed by the same change. I checked it myself; the proof above is mine. Nothing to add.
  3. Mine, round 1, non-blocking: askBridge in offload was test-only dead code. Fixed: removed with its test. cheapmodel.AskBridge stays as the one rule.
  4. Reviewer 2, round 1, non-blocking: the bridge condition and inserted text read different inputs. Fixed: lastBridge(msgs) reads the last message's role once, and insertAskMessage uses that one answer for both the condition and the content. Behavior is unchanged today (only system returns non-empty), and the future divergence reviewer 2 described is gone.
  5. Kept by the author, with reasons I accept:
    • cmd/cg-selarm still omits the opening line. The comment documents the one-line difference, and both round-1 reviews accepted it.
    • thinkingLastTurnOnly keeps its test-only caller (the registry-documentation test). Agreed.
    • askStandalone stays as documentation of the fallback channel. Agreed.

Non-blocking

  • extract_sweep.go:1428-1431 — comment placement. The new thinking comment sits between the "One arming point for all four exits" comment and the defer foldFallback() it describes. A reader can attach the wrong comment to the wrong line. Cosmetic only.

What I checked

  • Last review: round 1, 0a691e9, 2026-10-25T07:37:23Z.
  • New commits read: 1 — e118ae2 "fix(offload): decline the sweep's prefix ask when it would strip thinking". Read the full diff and the changed files around every hunk (extract_sweep.go adjudicate, ask_role.go, ask_role_test.go, cheapmodel/anthropic.go, docs/components/advanced-offload.md).
  • Read in full: 2 reviews, 3 comments, 0 inline comments (from .review-in-reviews.txt, .review-in-comments.txt, .review-in-inline.txt).
  • New items since my last review:
    • Reviewer 2's round-1 review (08:59:50Z) — same core finding as mine; checked its non-blocking bridge-input point, now fixed by lastBridge.
    • Author's reply comment (09:08:28Z) — describes the fix; I verified each claim in the code. The claimed eval-box test runs (vet, gofmt, -race) I cannot repeat; I take them as reported.
    • Two older comments from 2026-10-13 (human review rounds 1 and 2 of 3) — predate my round 1; their open points (call-site test, cg-selarm comment) were already fixed in 83e06d6, and the unused-wrapper point is now resolved by this commit.
  • The fix, verified in code: the guard runs before the ask fork; gates reach rep.Gates through the existing call.gates merge at extract_sweep.go:1040, which also runs on the return nil, r blocked path (the same path the already-tested sweep_fallback_blocked gate takes).
  • No regression in existing tests: sweep fixtures use claude-sonnet-5 (a keep-all model) and carry no thinking blocks, so the new guard stays false there; the ask tests keep their one ask.
  • Refactor safety: lastBridge is behavior-identical to the old inline check. ask_role.go drops its cheapmodel import with askBridge; nothing else in that file needs it. No import cycle, no new fail-open path, no data-dependence change.
  • Live tests were not run (not approved). All claims above come from reading the code.

@amiddavid amiddavid left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer Kind Started by Context Review Round Head Verdict
Reviewer 2 (glm, user of @amiddavid) GLM rits/zai-org/glm-5-3 via Claude Code 2.1.309 offload-review skill, @amiddavid's session resumed 2 of 2 2 of 2 e118ae2adc32 approve

Verdict: approve

Findings

None. My round-1 finding is fixed correctly, and the new commit introduces no defect I can show.

Status of earlier findings

  1. askStripsThinkingShipped had no caller (mine, and reviewer 1's same finding) — fixed in e118ae2. Verified myself:
    • The guard now runs at extract_sweep.go:1431, before the prefix-ask fork, gated on usePrefixAsk && !stalePrefix. The fork takes the existing fallback, so no ask goes over the cached transcript in that state. Fail open holds: the request forwards unchanged, and with block_fallback the decline is loud (gate plus rejection text).
    • The switch order is right: thinkingStripped implies !stalePrefix, so the two gates cannot mask each other.
    • The new test is not vacuous. The haiku row proves the fork was reached (the gate fires only there); the sonnet row proves the ask path still runs on a keep-all model. I checked the fixture: thinkingAsst() lands at index 1 of a longer transcript, the shipped registry names claude-haiku-4-5 and not claude-sonnet-5, and the sweep's other tests use sonnet with no thinking blocks, so none of them change meaning.
    • The helper's comment now names its real caller, and the gate is in docs/components/advanced-offload.md's list.
    • Agree with reviewer 1, finding 1 — same defect, same fix, checked independently.
  2. askBridge dead wrapper (my non-blocking) — fixed. Removed with its test. The offload package no longer imports cheapmodel from ask_role.go; no other reference remains.
  3. insertAskMessage guard and content read different inputs (my non-blocking) — fixed. lastBridge reads the last message's role once and inserts that same text (cheapmodel/anthropic.go:434-437, 449-454).
  4. cg-selarm differs from production by the opening line — not changed, as accepted. Both round-1 reviews accepted the documented divergence. Fine.
  5. askStandalone unused in production — not changed, by decision. It documents the fallback channel's semantics. Accepted.
  6. The author's Oct 13 log, points 3 and 4 (unused wrappers, ~20 uncounted tokens). Point 3 is now resolved by the wiring and the removal. Point 4 stays open by decision; the effect is bounded and stated in the PR text.

Non-blocking

  • extract_sweep.go:1431 — the guard reads req.Input, but the ask appends to the stashed body. The stash ends before this turn's new tail. A thinking block that sits after the stash boundary (the newest assistant turn, not yet forwarded) is counted as at-risk, though the ask never touches it. On a haiku thinking session whose only pre-last thinking block is that newest turn, the sweep declines a prefix ask that would have been safe. Cost only, never cache damage; the summarizer's use of the same input is exact there because its ask carries the whole current conversation. A precise fix needs the stash boundary (MaxCachedIdx or PrefixCoverage); the conservative direction is defensible as shipped.
  • The live gateway check is still open. The author's own Oct 13 log flagged it: the model's reply shape and the cache read under the new opening line are unmeasured live. The offline byte comparison and the eval-box tests cover the code. Worth running before the next reward measurement, not before merge.
  • extract_sweep.go:1425-1431 — the thinking comment merges into the "One arming point" comment block. The two now read as one paragraph. Cosmetic.

What I checked

  • Last review: round 1, 0a691e9, 2026-10-25T08:59:50Z
  • New commits read: 1 — e118ae2 "fix(offload): decline the sweep's prefix ask when it would strip thinking"
  • Read in full: 2 reviews, 3 comments, 0 inline comments (from the three files)
  • New items since my last review:
    • Author reply at 2026-10-25T09:08:28Z. Checked every claim against the code: the wiring, the gate name, the rejection text, the new test, the comment fix, the docs row, the askBridge removal, the lastBridge fix. All verified true.
    • The same reply's process note about a failed GLM run in round 1. Read; no action for this review.
  • Read the new commit's full diff and the code around each change: adjudicate's fork and switch, ask_role.go after the removals, cheapmodel's lastBridge, the new test's fixture and helpers.
  • Confirmed scope and ordering in adjudicate: usePrefixAsk and stalePrefix are both computed above line 1431; thinkingStripped cannot be true when stalePrefix is; attemptedPrefixAsk stays false on the new path, so foldFallback reports the row as "fallback", which is what ran.
  • Confirmed the shipped registry (summarizer_model_profiles.yaml:180-188) matches haiku-4-5 and not sonnet-5, which the new test's two rows depend on.
  • Confirmed no remaining askBridge reference in the offload package and no leftover cheapmodel import in ask_role.go.
  • The author reports vet, gofmt, and go test -race pass on the eval box for the touched packages. I could not run them here (live tests not approved); nothing in the diff suggests a failure.

@amiddavid
amiddavid merged commit 1953b47 into main Oct 25, 2026
6 checks passed
@github-project-automation github-project-automation Bot moved this from New/ToDo to Done in Rossoctl Issue Prioritization Oct 25, 2026
amiddavid added a commit that referenced this pull request Oct 25, 2026
…adow mode

Part A of #404 (the cold path). The sweep asks its question in place of
the keep-alive ping and holds the answer per thread. Nothing applies a
held answer yet: it changes no request.

- Ask at the ping, no timer of its own. The time-window trigger and
  pre_expiry_seconds are removed (the key is refused with the reason).
- Ask with one candidate or more. min_inventory defaults to 1.
- Hold per thread in the Store (cg:swh:, pinned), with tool_use_id and a
  SpanHash of the agent's message for each judged output, the judged
  length and the wait cause (#453). Stored only; nothing decides on it.
- recheckHeld drops a verdict when the conversation is shorter, the
  output is gone or changed, a later turn referenced it (coref), or the
  agent expanded it. PR C calls it on the cold request.
- shadow: true (off, in no preset) reports asked, proposed, still valid
  at the cold request, and the reasons, as request_components events and
  a cg.sweep.shadow log line.
- evidence is on by default.
- Plain ping, counted as sweep_model_declined, where the question breaks
  the cache (#422).
- Ask only when shadow is on, until the cold apply exists (PR C). Counted
  as sweep_ask_needs_shadow.
- Remove econ_trigger, the in-request ask and the full-price fallback.
  The keys econ_trigger, econ_ignore_ask_cost, reward_premium,
  min_pressure and block_fallback are ignored with a warning and a count,
  so an old config still loads.
- extract.Ask composes the question from lists, so #490 and #485 can add
  theirs. An output in two lists is judged once.
- Recover from a panic in the ping question: the ping stays plain, the
  panic is counted, and the next ping is plain too. Check the concurrency
  bound before collecting candidates.

- Rebased onto #507. Point 11 now uses askStripsThinkingShipped. The keeper
  changes live in package keepalive (main moved the keeper there); the
  wait cause reaches it through Options.OpenTasks and Record.ToolUseNames.
  The question is framed with the shared opening line (resolveAsk.Frame)
  and asked through AskCovered when the asker supports it.

Assisted-By: Claude Opus 5.5
Signed-off-by: DAVID AMID <[email protected]>
amiddavid added a commit that referenced this pull request Oct 25, 2026
…adow mode

Part A of #404 (the cold path). The sweep asks its question in place of
the keep-alive ping and holds the answer per thread. Nothing applies a
held answer yet: it changes no request.

- Ask at the ping, no timer of its own. The time-window trigger and
  pre_expiry_seconds are removed (the key is refused with the reason).
- Ask with one candidate or more. min_inventory defaults to 1.
- Hold per thread in the Store (cg:swh:, pinned), with tool_use_id and a
  SpanHash of the agent's message for each judged output, the judged
  length and the wait cause (#453). Stored only; nothing decides on it.
- recheckHeld drops a verdict when the conversation is shorter, the
  output is gone or changed, a later turn referenced it (coref), or the
  agent expanded it. PR C calls it on the cold request.
- shadow: true (off, in no preset) reports asked, proposed, still valid
  at the cold request, and the reasons, as request_components events and
  a cg.sweep.shadow log line.
- evidence is on by default.
- Plain ping, counted as sweep_model_declined, where the question breaks
  the cache (#422).
- Ask only when shadow is on, until the cold apply exists (PR C). Counted
  as sweep_ask_needs_shadow.
- Remove econ_trigger, the in-request ask and the full-price fallback.
  The keys econ_trigger, econ_ignore_ask_cost, reward_premium,
  min_pressure and block_fallback are ignored with a warning and a count,
  so an old config still loads.
- extract.Ask composes the question from lists, so #490 and #485 can add
  theirs. An output in two lists is judged once.
- Recover from a panic in the ping question: the ping stays plain, the
  panic is counted, and the next ping is plain too. Check the concurrency
  bound before collecting candidates.

- Rebased onto #507. Point 11 now uses askStripsThinkingShipped. The keeper
  changes live in package keepalive (main moved the keeper there); the
  wait cause reaches it through Options.OpenTasks and Record.ToolUseNames.
  The question is framed with the shared opening line (resolveAsk.Frame)
  and asked through AskCovered when the asker supports it.

Assisted-By: Claude Opus 5.5
Signed-off-by: DAVID AMID <[email protected]>
amiddavid added a commit that referenced this pull request Oct 25, 2026
…adow mode

Part A of #404 (the cold path). The sweep asks its question in place of
the keep-alive ping and holds the answer per thread. Nothing applies a
held answer yet: it changes no request.

- Ask at the ping, no timer of its own. The time-window trigger and
  pre_expiry_seconds are removed (the key is refused with the reason).
- Ask with one candidate or more. min_inventory defaults to 1.
- Hold per thread in the Store (cg:swh:, pinned), with tool_use_id and a
  SpanHash of the agent's message for each judged output, the judged
  length and the wait cause (#453). Stored only; nothing decides on it.
- recheckHeld drops a verdict when the conversation is shorter, the
  output is gone or changed, a later turn referenced it (coref), or the
  agent expanded it. PR C calls it on the cold request.
- shadow: true (off, in no preset) reports asked, proposed, still valid
  at the cold request, and the reasons, as request_components events and
  a cg.sweep.shadow log line.
- evidence is on by default.
- Plain ping, counted as sweep_model_declined, where the question breaks
  the cache (#422).
- Ask only when shadow is on, until the cold apply exists (PR C). Counted
  as sweep_ask_needs_shadow.
- Remove econ_trigger, the in-request ask and the full-price fallback.
  The keys econ_trigger, econ_ignore_ask_cost, reward_premium,
  min_pressure and block_fallback are ignored with a warning and a count,
  so an old config still loads.
- extract.Ask composes the question from lists, so #490 and #485 can add
  theirs. An output in two lists is judged once.
- Recover from a panic in the ping question: the ping stays plain, the
  panic is counted, and the next ping is plain too. Check the concurrency
  bound before collecting candidates.

- Rebased onto #507. Point 11 now uses askStripsThinkingShipped. The keeper
  changes live in package keepalive (main moved the keeper there); the
  wait cause reaches it through Options.OpenTasks and Record.ToolUseNames.
  The question is framed with the shared opening line (resolveAsk.Frame)
  and asked through AskCovered when the asker supports it.

- Review round 1: keep the conversation copies only for a thread the
  keep-alive can ping (Ctx.CanKeepAlive). Take the collection slot before
  collecting and release it on every exit. Count the result-cache miss in
  collect, and count sweep_concurrency_full. Report the shadow ask and the
  cold recheck once, under a mutex. Rewrite the sweep rows of
  docs/data-dependence.md and drop the stale counters and prose from
  advanced-offload.md.

Assisted-By: Claude Opus 5.5
Signed-off-by: DAVID AMID <[email protected]>
amiddavid added a commit that referenced this pull request Oct 25, 2026
…adow mode (#508)

feat(sweep): ask at the keep-alive ping, hold the answer, recheck, shadow mode

Part A of #404 (the cold path). The sweep asks its question in place of
the keep-alive ping and holds the answer per thread. Nothing applies a
held answer yet: it changes no request.

- Ask at the ping, no timer of its own. The time-window trigger and
  pre_expiry_seconds are removed (the key is refused with the reason).
- Ask with one candidate or more. min_inventory defaults to 1.
- Hold per thread in the Store (cg:swh:, pinned), with tool_use_id and a
  SpanHash of the agent's message for each judged output, the judged
  length and the wait cause (#453). Stored only; nothing decides on it.
- recheckHeld drops a verdict when the conversation is shorter, the
  output is gone or changed, a later turn referenced it (coref), or the
  agent expanded it. PR C calls it on the cold request.
- shadow: true (off, in no preset) reports asked, proposed, still valid
  at the cold request, and the reasons, as request_components events and
  a cg.sweep.shadow log line.
- evidence is on by default.
- Plain ping, counted as sweep_model_declined, where the question breaks
  the cache (#422).
- Ask only when shadow is on, until the cold apply exists (PR C). Counted
  as sweep_ask_needs_shadow.
- Remove econ_trigger, the in-request ask and the full-price fallback.
  The keys econ_trigger, econ_ignore_ask_cost, reward_premium,
  min_pressure and block_fallback are ignored with a warning and a count,
  so an old config still loads.
- extract.Ask composes the question from lists, so #490 and #485 can add
  theirs. An output in two lists is judged once.
- Recover from a panic in the ping question: the ping stays plain, the
  panic is counted, and the next ping is plain too. Check the concurrency
  bound before collecting candidates.

- Rebased onto #507. Point 11 now uses askStripsThinkingShipped. The keeper
  changes live in package keepalive (main moved the keeper there); the
  wait cause reaches it through Options.OpenTasks and Record.ToolUseNames.
  The question is framed with the shared opening line (resolveAsk.Frame)
  and asked through AskCovered when the asker supports it.

- Review round 1: keep the conversation copies only for a thread the
  keep-alive can ping (Ctx.CanKeepAlive). Take the collection slot before
  collecting and release it on every exit. Count the result-cache miss in
  collect, and count sweep_concurrency_full. Report the shadow ask and the
  cold recheck once, under a mutex. Rewrite the sweep rows of
  docs/data-dependence.md and drop the stale counters and prose from
  advanced-offload.md.

Assisted-By: Claude Opus 5.5
Signed-off-by: DAVID AMID <[email protected]>

docs(data-dependence): record David's approval of the sweep change (#508)

The ping-time question and the held answer in cg:swh: (metadata only)
are approved, with the two in-memory conversation copies per thread
kept only while the keep-alive can ping the thread, for at most 256
threads and 30 minutes.

Assisted-By: Claude Opus 5.5
Signed-off-by: DAVID AMID <[email protected]>
amiddavid added a commit that referenced this pull request Oct 25, 2026
…ed run (#697)

fix(review): stop a reviewer that never ends, and never resume a failed run

On #507 a GLM reviewer repeated one word up to the 32k output limit, 4
turns in a row, about 21 minutes each. Nothing stopped it, and a later
round would have resumed that same session.

- Each reviewer run now has a wall-clock limit, OFFLOAD_REVIEW_TIMEOUT
  (default 1800 s, 0 = off). Past it, the script stops the run's whole
  process group and falls back to the next backend, unless the review is
  already on the PR. It does not limit tokens.
- A run that ends without posting drops its saved session
  (backend_forget_session, or backend_cleanup), so the next round starts
  fresh.
- Any .review-in-*.txt in a reviewer's own folder is allowed. A reviewer
  that also saved the PR body (.review-in-prbody.txt, #508) made the
  round exit 1 although both reviews posted.

Assisted-By: Claude Opus 5.5
Signed-off-by: DAVID AMID <[email protected]>

fix(review): forget a session only after the backend ran

Round-1 review fixes for #697.

- Forget a saved session only when the backend started. A failure before
  it (worktree lock, prompt) keeps the session for the next round.
- Check OFFLOAD_REVIEW_TIMEOUT once at startup, before any worktree exists.
- Mark a stopped run with a file, not exit code 124. A backend that exits
  124 by itself is no longer labelled a timeout.
- Append to review.log, so an earlier diagnostic stays.
- claude: forgetting a session also removes its transcript.
- Fix the function counts in the backend headers and SKILL.md.

Assisted-By: Claude Opus 5.5
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