Skip to content

fix(plugin): the preset picker restarts the proxy after a yes, and the status shows a pending preset (#887) - #889

Merged
amiddavid merged 3 commits into
mainfrom
feat/picker-restart-887
Nov 4, 2026
Merged

amiddavid merged 3 commits into
mainfrom
feat/picker-restart-887

Conversation

@amiddavid

@amiddavid amiddavid commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

Behavior change (needs a human developer's yes)

  • Who: plugin users who pick a preset with /context-guru:preset-picker.
  • Old: the picker saved the preset. The running proxy kept the old one until the next session start. It sent the ultrahigh probe to that old proxy.
  • New: when the running preset differs, the picker says a restart costs one cache rewrite in every open session on the port, and asks for a yes. On yes, preset restart restarts the proxy. It sends the ultrahigh probe to the restarted proxy only. The status screen and status line show preset: xhigh (ultrahigh after a restart) while the two differ.
  • Turn off: answer no. The old preset then runs until the next session start. The picker never restarts without a yes.

Summary

Additive /stats field

  • /stats gains a preset key (the preset the proxy started with, single-tenant only, like pipeline).
  • Added to the golden contract and to the Prometheus exempt list.

Owner decisions

  • The preset gap shows in every status line layout, on by default. No opt-in flag.
  • When another project owns the proxy, preset restart leaves it alone and reports not_applied.

Data dependence

None. Nothing new is stored. No row in docs/data-dependence.md changes.

What changed

  • context-guru-plugin/scripts/settings.py: saved_preset, running_preset, preset_gap_note, preset restart. No probe goes to a stale proxy.
  • context-guru-plugin/scripts/statusline.py: new preset element, shown only on a gap, in every layout.
  • context-guru-plugin/scripts/cg.py (and the Codex copy): a gap line on the home screen.
  • Skills: preset-picker and status text.
  • metrics/metrics.go, proxy/proxy.go: the preset field.

How it was tested

On box 2, with -race:

  • go test -race ./context-guru-plugin/ passes (364 s).
  • go test -race ./proxy/... ./metrics/... ./cmd/... passes, after the Prometheus exempt entry for Preset.
  • New tests: stale proxy gives restart_needed=true and no probe; matching proxy gives the probe; preset restart replaces the proxy through start-proxy.sh and the probe reaches the restarted one; unrouted directory refuses; status line shows the gap and stays quiet when equal or unknown; /stats reports the preset.
  • Mutation: sending the probe to the old proxy in preset set made TestPresetSetWithAStaleProxyAsksForARestartAndSendsNoProbe fail. Restored.
  • Not run: any restart of a real proxy on this laptop.

Technical notes

  • preset restart passes --unrouted --no-update-check --port --preset (and the configured upstream and idle_exit) to start-proxy.sh, because plugin options do not reach a Bash call.
  • A proxy owned by another project is left alone by the starter. Then /stats still shows the old preset and the result is not_applied.
  • A proxy from before this field reports no preset. The gap stays hidden then, not guessed.

🤖 Generated with Claude Code

…e status shows a pending preset (#887)

`preset set` saved the preset but the running proxy kept the old one until
the next session start, and nothing showed the gap.

- `preset set` reads the running preset from /stats. If it differs, it
  says a restart costs one cache rewrite per open session and asks for a
  yes. It sends no probe to the old proxy.
- New `preset restart --name X` runs start-proxy.sh (strategy sync,
  fingerprint compare, stop by pidfile, start), checks /stats, then sends
  the ultrahigh probe to the restarted proxy.
- /stats gains an additive `preset` key.
- `cg.py home` and the status line show "preset: xhigh (ultrahigh after a
  restart)" when saved and running presets differ.

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 1 (bob, user of @amiddavid) IBM Bob Shell 1.0.3 offload-review skill, @amiddavid's session fresh 1 of 2 1 of 2 2ecd56737eb9 blocking

Verdict: blocking

Findings

  1. PR description — Missing behavior change disclosure required by CLAUDE.md

    • What fails: Users with tool search on Chat Completions (GPT models, ultrahigh preset) lose streaming. The PR removes the splice path for Chat Completions and moves it to a fully buffered path. This is a behavior change that affects real users.
    • Proof: CLAUDE.md states "No behavior change for an edge case without a human developer's permission. A fix that changes what the proxy or the library does for users or for other cases (a default, a time limit, what gets cached, offloaded or shown) needs a human developer's yes before it merges. This holds even when the change looks like a side effect of a narrow fix. Name the change at the top of the PR: who it affects, the old and the new behavior, and how to turn it off." The diff shows: (1) Line 2118 removes Chat Completions from the splice case, (2) Lines 2171-2180 add a new buffered case for searchOn, (3) The comment says "The client loses its stream for the requests of a thread with deferred tools; see #825". The PR description must state: who (users with tool search on GPT models), old behavior (streamed with splice), new behavior (fully buffered), and how to turn it off (disable tool search or use a different preset).
    • Fix: Add the behavior change disclosure to the PR description and get approval from a human developer before merge.
  2. proxy/proxy.go:2133 — Condition change from !sp.opened() to sp.blocks == 0 needs verification

    • What fails: The condition that determines if a response is buffered changed. The old opened() method checked sp.said || sp.blocks > 0 for Chat Completions. The new check is only sp.blocks == 0. If sp.said was tracking something sp.blocks does not, this could misclassify responses.
    • Proof: In the removed code (ssepeek_chat_test.go), opened() returned true when the client held text OR tool calls. The new code only checks blocks. For Anthropic-only streams, this is correct because Anthropic streams always start with a role chunk before content, so sp.blocks > 0 implies content was sent. But the change should be verified: does any Anthropic stream path set sp.said without incrementing sp.blocks?
    • Fix: Verify that for Anthropic streams, sp.blocks > 0 is equivalent to the old opened() check. If not, restore the opened() method for Anthropic-only use.
  3. proxy/proxy.go:1818 — Removed counter for tooldefer.ClientSearchName in countLeak

    • What fails: When a client search call leaks (is handed back to the client), it is no longer counted. The comment says "Counted where it is decided: mixed_searches, or kept for the next request." But if the call leaks due to a failed splice or other error, it should still be counted somewhere.
    • Proof: Lines 1818-1821 were removed. The switch now only handles adjudicate.ToolName and expand.ToolName. If tooldefer.ClientSearchName appears in the called slice passed to countLeak, it will hit the default case and only be logged, not counted. The old code had a case for it with a comment explaining why it was counted elsewhere. The new code removes that case entirely.
    • Fix: Either restore the counter for leaked client search calls, or verify that the "counted where it is decided" path covers all leak scenarios. If mixed searches are the only leak case and they are counted elsewhere, document this in a comment.

Non-blocking

  • The preset field addition to /stats is correct and has a test (TestStatsReportsTheRunningPreset). The single-tenant check matches the pipeline field's logic.
  • The fail-open paths are preserved: buffering a stream instead of splicing it is a degradation, not a failure. The client still gets a complete response.
  • The removal of Chat Completions streaming tests is consistent with removing the feature. No orphaned test code remains.

What I checked

  • Read CLAUDE.md and docs/design.md for repo rules
  • Read the full diff (proxy/proxy.go, proxy/ssepeek.go, proxy/ssepeek_chat_test.go, proxy/stats_golden_test.go, proxy/tooldefer_search_test.go)
  • Verified the behavior change: Chat Completions with tool search moves from streamed (spliced) to fully buffered
  • Checked that CLAUDE.md requires behavior changes to be disclosed and approved
  • Verified the sp.blocks == 0 condition change is correct for Anthropic-only streams
  • Checked the countLeak function for missing counters
  • Verified the preset field addition to /stats has a test and correct logic
  • Confirmed fail-open paths are preserved (buffering is a degradation, not a failure)
  • Checked that no orphaned test code or references to removed functions remain

@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 (bob, user of @amiddavid) IBM Bob Shell 1.0.3 offload-review skill, @amiddavid's session fresh 2 of 2 1 of 2 2ecd56737eb9 blocking

Verdict: blocking

Findings

  1. proxy/proxy.go:2171-2179 — Behavior change lacks required human approval documentation

    • What fails: Users with deferred tools on Chat Completions lose streaming. The PR removes the streaming splice added in #879 and buffers the entire response instead.
    • Proof: Lines 2171-2179 show isSSE && searchOn now buffers with io.ReadAll(resp.Body). The comment states "The client loses its stream for the requests of a thread with deferred tools; see #825." This is a behavior change affecting users, but the PR description does not document it per CLAUDE.md requirements.
    • Fix: Add to PR description: who is affected (Chat Completions users with deferred tools), old behavior (streaming with splice), new behavior (buffered), and how to turn it off (disable tool deferral or use a preset below ultrahigh). Get human developer approval before merge per CLAUDE.md line 44-48.
  2. proxy/proxy.go:1748 — Comment claims non-Anthropic dialects are not inspected, but searchOn path inspects them

    • What fails: The comment at line 1748 states "Non-Anthropic dialects are not inspected at all" but lines 2171-2179 show Chat Completions streams ARE inspected when searchOn is true - they are buffered and passed to expand.AggregateSSE.
    • Proof: Line 1748 comment vs lines 2171-2179 implementation. The searchOn path buffers and processes Chat Completions streams, contradicting the "not inspected at all" claim.
    • Fix: Update comment to: "Non-Anthropic dialects are not inspected at all, except Chat Completions with our search tool which is buffered (see searchOn path below)."
  3. proxy/stats_golden_test.go:347-360 — Unrelated preset reporting test in streaming removal PR

    • What fails: The test TestStatsReportsTheRunningPreset and the preset reporting code (proxy.go:2788-2792) appear unrelated to removing Chat Completions streaming. This violates the single-purpose PR principle.
    • Proof: The test and implementation add preset reporting to /stats, but the PR is about removing streaming support. No connection is explained.
    • Fix: Move preset reporting to a separate PR, or explain in the PR description why it belongs with this change.
  4. proxy/tooldefer_search_test.go — Missing test coverage for buffered searchOn behavior

    • What fails: The PR removes 3 streaming tests (TestClientSearchStreamsAndSplicesInBand, TestClientSearchStreamTextPassesThrough, TestClientSearchStreamMixedCall) but adds no tests for the new buffered behavior on the searchOn path.
    • Proof: Lines deleted in proxy/tooldefer_search_test.go show streaming tests removed. The remaining tests (TestClientSearchInBand, TestClientSearchMixedCall) test the non-streaming path but do not verify the buffered stream behavior.
    • Fix: Add a test that verifies: (1) a Chat Completions stream with searchOn is buffered, (2) the client receives the complete response after the in-band answer, (3) the response is valid JSON (not a partial stream).

Non-blocking

  • The countLeak function at proxy.go:1811-1825 no longer needs to handle tooldefer.ClientSearchName since that case was removed from the switch at line 1820. The default case with the warning will catch it, which is correct behavior.
  • The preset reporting addition (proxy.go:2788-2792) uses the same single-tenant check as the pipeline reporting above it, which is consistent.

What I checked

  • Read CLAUDE.md and docs/design.md for repo rules
  • Read the full diff (proxy/proxy.go, proxy/ssepeek.go, proxy/ssepeek_chat_test.go deleted, proxy/tooldefer_search_test.go, proxy/stats_golden_test.go)
  • Verified the behavior change: Chat Completions with searchOn now buffers instead of streaming
  • Checked that fail-open is maintained: the buffered path still processes responses correctly
  • Verified comment accuracy against implementation
  • Checked test coverage for the new buffered behavior
  • Confirmed the preset reporting addition is unrelated to the main change

The first commit was built from a tree older than #883. It removed the
Chat streaming splicer, its tests and a countLeak case. This commit sets
every file back to origin/main, so the only proxy changes left are the
additive /stats `preset` field, its golden test and the Prometheus
exemption.

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

Copy link
Copy Markdown
Collaborator Author

R1#1, R1#2, R1#3, R2#1, R2#2 and R2#4 came from an accidental revert of #883. I built the first commit from a tree older than #883. Commit 3dd5dd8 sets every file back to origin/main. Head 82591e9 also merges the current origin/main. The diff against origin/main now has no change in proxy/ssepeek.go, proxy/ssepeek_chat_test.go, proxy/tooldefer_search_test.go, or the other proxy/proxy.go hunks. These are fixed.

R2#3 (the preset field is unrelated): rejected. The /stats preset field is the running preset. Part 2 of #887 (the status gap) cannot work without it. The PR body names it under "Additive /stats field".

@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 (bob, user of @amiddavid) IBM Bob Shell 1.0.3 offload-review skill, @amiddavid's session resumed 1 of 2 2 of 2 82591e9f9b3d approve

Verdict: approve

Status of round 1 findings

All three findings from round 1 are fixed:

  1. R1#1 (behavior change disclosure) — Fixed. The accidental revert of #883 removed Chat Completions streaming. Commit 3dd5dd8 restored it. The streaming code is back in proxy/ssepeek.go and proxy/proxy.go.

  2. R1#2 (condition change sp.opened()) — Fixed. The opened() method is restored at proxy/ssepeek.go:147-153. The condition at proxy/proxy.go:2189 uses !sp.opened() again.

  3. R1#3 (missing countLeak counter) — Fixed. The tooldefer.ClientSearchName case is restored at proxy/proxy.go:1858-1861 with its original comment.

New commits reviewed

  • Commit 3dd5dd8: Restores all files to origin/main, undoing the accidental revert of #883
  • Commit 0c0e9ff (merged from origin/main): Adds accountant library integration (#768)
  • Commit 82591e9: Merge commit

What changed since round 1

The diff between 2ecd567 (round 1 head) and 82591e9 (round 2 head) shows:

  1. Chat Completions streaming restored: proxy/ssepeek.go adds back newChatSSESplicer(), opened(), rewriteChat(), terminateChat(), and chatProxyToolCallName(). The 308-line test file proxy/ssepeek_chat_test.go is restored.

  2. Streaming path restored: proxy/proxy.go:2160-2220 restores the splice path for Chat Completions with searchOn. The buffered-only path is removed.

  3. countLeak case restored: proxy/proxy.go:1858-1861 restores the tooldefer.ClientSearchName case with its comment.

  4. Streaming tests restored: proxy/tooldefer_search_test.go adds back the three streaming tests (TestClientSearchStreamsAndSplicesInBand, TestClientSearchStreamTextPassesThrough, TestClientSearchStreamMixedCall).

  5. Accountant integration: The merge with origin/main brings in the accountant library changes from #768. This is a separate feature, reviewed and approved in that PR.

  6. Preset field remains: The /stats preset field addition stays. The author states it is needed for #887 part 2 (the status gap). It has a test and is documented in the PR body.

Findings

None. All round 1 findings are fixed.

Non-blocking

  • The accountant library integration from the merge is a large change, but it was reviewed in PR #768 and approved there. It is not part of this PR's scope.
  • The preset field addition is small, tested, and documented. The author's reason (needed for #887 part 2) is valid.

What I checked

  • Last review: round 1, 2ecd567, 2026-11-04T11:06:44Z
  • New commits read: 2 (3dd5dd8 "fix(plugin): restore the files #889 reverted by accident", 82591e9 merge with origin/main)
  • Read in full: 2 reviews, 1 comment, 0 inline comments (from the three files)
  • New items since my last review: One comment by amiddavid at 2026-11-04T11:33:36Z explaining the accidental revert and the fix
  • Verified all round 1 findings are fixed by reading the restored code
  • Checked the diff between round 1 head and round 2 head shows the revert is undone
  • Verified the Chat Completions streaming code is back (proxy/ssepeek.go, proxy/proxy.go)
  • Verified the streaming tests are back (proxy/ssepeek_chat_test.go, proxy/tooldefer_search_test.go)
  • Verified the countLeak case for tooldefer.ClientSearchName is restored
  • Verified the sp.opened() method is restored and used correctly
  • Confirmed the preset field addition is the only remaining change from the original PR
  • Checked that the accountant library integration is from the merge with origin/main, not this 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 2 (bob, user of @amiddavid) IBM Bob Shell 1.0.3 offload-review skill, @amiddavid's session resumed 2 of 2 2 of 2 82591e9f9b3d approve

Verdict: approve

Findings

None. All round 1 findings are fixed.

Status of round 1 findings

My findings (Reviewer 2, round 1)

  1. R2#1 (proxy/proxy.go:2171-2179) — Behavior change lacks required human approval: Fixed. The code that removed streaming for Chat Completions with searchOn is gone. Commit 3dd5dd8 restored proxy/proxy.go to origin/main. The current diff shows Chat Completions with searchOn now uses the splice path (lines 2163-2189), not a buffered path. The behavior change no longer exists.

  2. R2#2 (proxy/proxy.go:1748) — Comment claims non-Anthropic dialects are not inspected: Fixed. The comment at line 1785 now correctly states "Of the other dialects, only a Chat Completions stream that declares our own tool search is spliced (#879)." This matches the implementation.

  3. R2#3 (proxy/stats_golden_test.go:347-360) — Unrelated preset reporting test: Rejected by author, and I accept the rejection. The author states the preset field is needed for part 2 of #887 (the status gap). The PR body names it under "Additive /stats field". The test at lines 347-360 verifies the field reports the running preset correctly, which is necessary for the plugin to detect restarts. This is not unrelated; it is a prerequisite for #887 part 2.

  4. R2#4 (proxy/tooldefer_search_test.go) — Missing test coverage for buffered searchOn behavior: Fixed. The three streaming tests (TestClientSearchStreamsAndSplicesInBand, TestClientSearchStreamTextPassesThrough, TestClientSearchStreamMixedCall) are restored at lines 401-482. They verify the spliced behavior, not a buffered one, which is correct for the current implementation.

Reviewer 1 findings (round 1)

  1. R1#1 (PR description) — Missing behavior change disclosure: Fixed. The behavior change (Chat Completions losing streaming) no longer exists. The current implementation splices Chat Completions streams when searchOn is true, preserving streaming.

  2. R1#2 (proxy/proxy.go:2133) — Condition change from !sp.opened() to sp.blocks == 0: Fixed. Line 2189 now uses !sp.opened(), not sp.blocks == 0. The opened() method (ssepeek.go:150-156) correctly checks sp.said || sp.blocks > 0 for Chat Completions and sp.blocks > 0 for Anthropic.

  3. R1#3 (proxy/proxy.go:1818) — Removed counter for tooldefer.ClientSearchName: Fixed. Lines 1858-1861 restore the case for tooldefer.ClientSearchName with the comment explaining why it is counted elsewhere.

Non-blocking

  • The Chat Completions splice implementation (proxy/ssepeek.go:505-641, proxy/ssepeek_chat_test.go) is comprehensive and correct. It handles: text streaming, call detection, index renumbering across rounds, mixed responses, truncation, and gateways that omit [DONE].
  • The preset field addition to /stats (proxy/proxy.go:2788-2792, proxy/stats_golden_test.go:347-360) is correct and necessary for #887 part 2.
  • Fail-open is preserved: the splice degrades to a hand-back when the retain bound is exceeded or a rebuild fails, and the client still gets a complete response.

What I checked

  • Last review: round 1, 2ecd567, 2026-11-04T11:09:30Z
  • New commits read: 2 (3dd5dd8 "fix(plugin): restore the files #889 reverted by accident", 82591e9 "merge origin/main")
  • Read in full: 2 reviews, 1 comment, 0 inline comments (from the three files)
  • New items since my last review:
    • Author comment at 2026-11-04T11:33:36Z: explains that R1#1, R1#2, R1#3, R2#1, R2#2, R2#4 were from an accidental revert of #883, fixed by commit 3dd5dd8. Rejects R2#3 with a valid reason (preset field is needed for #887 part 2). Verified the explanation against the diff.
  • Read the full diff from 2ecd567..HEAD (git diff output, 8448 insertions, 929 deletions)
  • Verified each round 1 finding is fixed:
    • R2#1: proxy/proxy.go lines 2163-2189 show Chat Completions with searchOn now uses the splice path, not buffered
    • R2#2: proxy/proxy.go line 1785 comment is correct
    • R2#3: author's rejection is valid; preset field is necessary for #887 part 2
    • R2#4: proxy/tooldefer_search_test.go lines 401-482 restore the three streaming tests
    • R1#1: behavior change no longer exists
    • R1#2: proxy/proxy.go line 2189 uses !sp.opened(); ssepeek.go lines 150-156 implement opened() correctly
    • R1#3: proxy/proxy.go lines 1858-1861 restore the tooldefer.ClientSearchName case
  • Read proxy/ssepeek.go lines 500-641 (Chat Completions splice implementation)
  • Read proxy/ssepeek_chat_test.go lines 1-100 (test coverage for Chat Completions splice)
  • Verified the preset field implementation (proxy/proxy.go:2788-2792) and its test (proxy/stats_golden_test.go:347-360)
  • Confirmed fail-open paths are preserved in the splice implementation

@amiddavid
amiddavid merged commit 0f0d2d8 into main Nov 4, 2026
5 checks passed
@github-project-automation github-project-automation Bot moved this from New/ToDo to Done in Rossoctl Issue Prioritization Nov 4, 2026
amiddavid added a commit that referenced this pull request Nov 4, 2026
…0.2.11) (#921)

Claude Code plugin 0.6.6 -> 0.6.7:
- #889: the preset picker restarts the proxy after a yes, and the status shows a pending preset.
- #891: insights and the status show tool deferral as its own saving lever.
- #877, #885: save-more tools (keep, unkeep, defer, undefer, search on/off, revert).
- #882: ultrahigh is marked experimental in the picker.

Codex plugin 0.2.10 -> 0.2.11:
- #889, #891: the same cg.py changes (vendored copy).
- #882: ultrahigh is marked experimental in the picker.


Signed-off-by: DAVID AMID <[email protected]>
Assisted-By: Claude Opus 5.5 <[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.

fix(plugin): the preset picker does not apply the preset until the next session, and nothing shows it

1 participant