Skip to content

feat(save-more): flag a small model that rejects the free auto-mode check (#680) - #681

Merged
amiddavid merged 1 commit into
mainfrom
feat/small-model-check
Oct 23, 2026
Merged

amiddavid merged 1 commit into
mainfrom
feat/small-model-check

Conversation

@amiddavid

Copy link
Copy Markdown
Collaborator

Summary

  • Adds a third check to the save-more "Settings that cost you money" card: small-model-rejects-server-check.
  • It flags a small model older than Haiku 5.5. That model can get a 400 invalid beta flag on Bedrock gateways. Claude Code can then send billed classifier requests.
  • The fix sets ANTHROPIC_SMALL_FAST_MODEL and ANTHROPIC_DEFAULT_HAIKU_MODEL to claude-haiku-5-5, after a yes.

Refs #680, #615.

What changed

  • Detection. New detect kind model_unsupported. It reads the effective value of both keys (highest-precedence settings file, else the process env). It fires when a value names a Haiku below 5.5.
  • Version parser. haiku_version() reads claude-haiku-4-5, dated ids, aws/ and us.anthropic. prefixes, claude-3-5-haiku-..., claude-haiku-5-5[1m]. Non-Haiku, unset and unreadable ids never fire.
  • Fix. New fix kind set_env. It changes each key in each editable file that holds an old Haiku. One record per (file, key). Revert restores each key exactly and refuses after an outside change.
  • Card text. Notes whether check 1 also fires: "This matters after you remove the betas setting above." or "The betas setting is off, so the small model can cause billed classifier requests now."
  • Pricing. CostlyShape gets Status and SessionHas. The check sums the classifier rows (Sonnet, 0 tools, max_tokens 64, no stream) in sessions that also have a Haiku row with status 400. The cost line says "(also counted under the betas setting while it is on)".
  • Gateway check. None. The plugin does not call the gateway. The risk line says to check the gateway serves claude-haiku-5-5.
  • Docs: docs/plugin/save-more.md, docs/data-dependence.md. The Codex copies of cg.py, costly.py and costly_settings.json stay byte-identical.

Data dependence

  • Off: the plugin still finds the settings. Cost shows "not measured yet".
  • Metadata only: works. It reads the model, status, tools, max_tokens, stream, session id, tenant and time columns. It stores nothing new.
  • Everything: same as metadata only. It reads no request text.
  • The plugin reads 2 more named keys from the user's own settings, on the user's machine. It sends none to the proxy.

How it was tested

  • python3 -I context-guru-plugin/scripts/test_costly.py: 47 tests, OK.
  • go test -race ./dash/...: ok (474 s).
  • go test -race ./context-guru-plugin/...: only the 2 known box failures (TestInstallRefusesAnUnverifiedDownload, TestInstallReportsPATHFromTheSourceFallbackToo). A first run also failed one install test. It passed on the rerun.
  • go vet, gofmt -l, go mod verify: clean. go.mod and go.sum unchanged.
  • New Go test: classifier rows count only in a session with a Haiku 400. The 400 row never counts. Other tenant, a 400 outside the window, and a row outside the window do not count.
  • Existing goldens unchanged. The test harness sets no Haiku key.

Open questions

  • Should a later change ask the proxy for its model list, to offer the fix only when the gateway serves claude-haiku-5-5? No cheap proxy endpoint lists models today.
  • A process-env-only value is reported but cannot be applied. Same as check 1.

Technical notes

  • SessionHas renders as EXISTS (SELECT 1 FROM requests x ...) on the same session. The inner row gets the same tenant, time and keep-alive scope as the outer row. All values are bound parameters. Column names are fixed.
  • Rows with an empty session id never match.
  • When several files set a key, the highest-precedence file decides whether the check fires. The fix also changes lower files that hold an old Haiku.

🤖 Generated with Claude Code

…heck (#680)

Add the check small-model-rejects-server-check to the "Settings that
cost you money" card.

- Fires when ANTHROPIC_SMALL_FAST_MODEL or ANTHROPIC_DEFAULT_HAIKU_MODEL
  names a Haiku older than 5.5, at its effective value.
- The fix sets each such key to claude-haiku-5-5. Apply and revert keep
  one record per file and key.
- The proxy prices classifier rows in sessions that also have a Haiku
  request with status 400. CostlyShape gets Status and SessionHas.

Refs #680, #615.

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 89740669b6d3 approve

Verdict: approve

Findings

None. The PR adds a new costly settings check for small model versions that reject server-side checks. The implementation is correct and well-tested.

Non-blocking

  • codex-marketplace/plugins/context-guru/scripts/costly.py:134 — The regex _HAIKU_NEW uses (?!\d) negative lookahead twice. This is correct but dense. The comment helps.
  • codex-marketplace/plugins/context-guru/scripts/costly.py:366 — _target() returns fix["names"][0] as fallback when loc has no "name". This assumes fix["names"] is non-empty for set_env fixes. The JSON schema guarantees this, but a defensive check would make the code more robust.
  • dash/costlysettings.go:122 — The sessionHasWhere() function duplicates filter conditions from the outer query. This is correct for SQL semantics but creates maintenance coupling. A comment noting this would help future readers.

What I checked

  • New check definition: The small-model-rejects-server-check check in both JSON files is identical and correctly structured. The detect.kind is model_unsupported, fix.kind is set_env, and the price shape uses session_has with a Haiku 400 status filter.
  • Haiku version parsing: The haiku_version() function handles both new format (claude-haiku-4-5) and old format (claude-3-5-haiku-20241022) correctly. The regex patterns use proper negative lookaheads to avoid matching partial numbers. Test coverage includes edge cases like claude-haiku-5, claude-haiku-4.5, and non-Haiku models.
  • Detection logic: The detect() function for model_unsupported correctly uses effective_value() to get the winning value across file precedence, then checks each file that sets an old Haiku. The logic handles process env, multiple files, and precedence correctly.
  • Apply/revert for multiple keys: The refactored apply() and revert() functions now group entries by file path, then process all keys in each file together. This creates one backup per file even when fixing multiple keys. The todo list in apply() deduplicates keys within a file. The revert() validation checks each key before restoring any.
  • SQL query logic: The sessionHasWhere() function builds an EXISTS subquery that correctly filters by session, tenant, time window, and the inner shape. The shapeWhere() function now takes an alias parameter to support both outer and inner queries. The test TestCostlySmallModelCountsClassifiersOnlyInSessionsWithAHaiku400 verifies the query logic with 16 test cases covering tenant isolation, time windows, status codes, and session matching.
  • Data dependence: The docs/data-dependence.md update correctly notes that the check now reads ANTHROPIC_SMALL_FAST_MODEL and ANTHROPIC_DEFAULT_HAIKU_MODEL in addition to the existing keys, and that one check uses upstream status (400).
  • Documentation: The docs/plugin/save-more.md table correctly describes the new check, its detection condition, fix, and cost measurement. The note about the double-count with the betas setting is clear.
  • Test coverage: Python tests cover detection across all sources (user, project, project-local, managed, process env), file precedence, version parsing edge cases, apply/revert with multiple keys in one file, and the card rendering. Go tests verify the SQL query logic with comprehensive session/tenant/time/status combinations.
  • Fail-open: This is a read-only check. It does not modify requests. The plugin reads only named keys from the user's own settings files and sends none to the proxy.
  • JSON schema consistency: The Go test TestCostlyChecksMatchThePluginList verifies that the Go CostlyChecks slice matches the plugin's JSON file. The test now handles the new Status and SessionHas fields.
  • Edge cases: The code handles unset keys (not judged), non-Haiku models (no fire), version strings it cannot parse (no fire), and Haiku 5.5 or newer (no fire). The apply refuses when the setting is in managed settings or process env only.

@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 89740669b6d3 approve

Verdict: approve

Findings

None.

Non-blocking

  • codex-marketplace and context-guru-plugin costly.py duplication: The same costly.py file exists in two locations with identical changes. This is intentional for the two plugin distributions, but consider whether a shared import or symlink could reduce maintenance burden in future changes.

What I checked

  • New check logic: The small-model-rejects-server-check detects Haiku models below 5.5 using regex patterns that handle both new (claude-haiku-4-5) and old (claude-3-5-haiku-20241022) naming conventions. The haiku_version() parser correctly extracts major and minor versions and returns None for non-Haiku models or unparseable versions.

  • Multi-key fix handling: The new set_env fix kind with names array allows one fix to update multiple environment keys (ANTHROPIC_SMALL_FAST_MODEL and ANTHROPIC_DEFAULT_HAIKU_MODEL). The apply logic groups locations by file path, processes all keys in each file together, creates one backup per file, and records separate entries for each key. The revert logic correctly restores all keys in each file and validates that each key still holds the written value before reverting.

  • SessionHas filter: The Go sessionHasWhere() function builds an EXISTS subquery that filters rows by whether the same session has another row matching an inner shape. It correctly applies the same tenant and time window constraints to both the outer and inner queries. The condition r.session_id <> '' ensures the filter only applies when the outer row has a non-empty session ID.

  • Test coverage: Python tests cover detection across all sources (user, project, project-local, managed, process env), precedence rules, version parsing edge cases, apply/revert with multiple keys in one file and across files, and refusal when settings are not editable. Go test seeds 16 scenarios covering session matching, tenant isolation, time window boundaries, status code filtering, and the interaction between the outer classifier shape and inner Haiku 400 shape.

  • Metadata-only: Confirmed in docs/data-dependence.md line 226. The check uses only request columns (model, tools, max_tokens, stream, status) and session_id. No request text is read. The plugin reads only the named env keys from local settings files and sends none to the proxy.

  • Fail-open: This is a settings check, not a request-path component. It does not affect request forwarding. The check fires independently of the betas setting and displays conditional text based on whether that setting is also on.

  • Sync between plugin files: The costly_settings.json schema is the single source of truth. The Go test TestCostlyChecksMatchThePluginList compares the Go CostlyChecks shapes against the JSON file, including the new status and session_has fields. Both plugin distributions (codex-marketplace and context-guru-plugin) have identical changes.

  • Edge cases: The detect logic handles files that override each other (higher precedence wins), process env vs file settings (file wins), and keys set in multiple files (all editable files get the fix). The apply logic refuses when settings are managed-only or process-only. The revert logic refuses if any key was changed outside the apply. The backup naming includes a timestamp, so multiple applies create separate backups, but only the most recent apply is revertable (the record is overwritten).

  • Documentation: docs/plugin/save-more.md updated to describe the new check, its detection logic, fix behavior, cost measurement (classifier requests in sessions with a Haiku 400), and the note that it fires with or without the betas setting. docs/data-dependence.md updated to list the new env keys the plugin reads.

@amiddavid
amiddavid merged commit d722488 into main Oct 23, 2026
9 of 10 checks passed
@github-project-automation github-project-automation Bot moved this from New/ToDo to Done in Rossoctl Issue Prioritization Oct 23, 2026
amiddavid added a commit that referenced this pull request Oct 23, 2026
…l back (#682)

fix(review): say why a backend was skipped, and flag a round that fell back

On #681 the whole round went to Bob, and the script said only
"glm (not set up)". The real cause: the session started before the user
added GLM_KEY_FILE to the shell profile, so it never saw the variable.
The reviewer took "not set up" as a fact about the machine.

- backend_ready may print a reason. glm's names the exact cause: no
  claude on PATH, GLM_KEY_FILE unset, set in the profile but not in this
  session, a file that is missing, or no gateway URL in it.
- The "Tried first" line shows that reason.
- When a reviewer did not use the first backend, the script ends with a
  Note line that says to tell the user before accepting the round.
- SKILL.md: check GLM_KEY_FILE in this session before the run, and
  report the skip reason; do not read "not set up" as a fact about the
  machine.

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

fix(review): flag only a fallback in this round, and make the profile probe robust

From both GLM reviewers of #682, round 1 (the same 2 findings each).

- The Note fired on a normal round-2 resume of an earlier fallback
  backend, and pointed at "Tried first" lines that were never printed.
  run_reviewer now leaves a marker only when it fell back in this
  round, and the Note reads that marker.
- The profile probe needed the shell's whole stdout to be "set", so a
  profile that prints a line read as "not set". It also used -ic, which
  skips .zprofile and .bash_profile. It now prints a CGPROBE: marker,
  matches it anywhere, and runs -lic.

Assisted-By: Claude
Signed-off-by: DAVID AMID <[email protected]>
amiddavid added a commit that referenced this pull request Oct 23, 2026
Resolve the conflicts with #681 by keeping both sides: main's new
small-model check (its title, cost note and Note line, its Go shape and
its docs row), plus this branch's "Saves:" line for the recap, which
replaces only the Cost line for a check with price kind avoided_call.

Assisted-By: Claude Opus 5.5
Signed-off-by: DAVID AMID <[email protected]>
OsherElhadad pushed a commit that referenced this pull request Oct 25, 2026
…0.2.5)

Both plugins changed in this release, so installed plugins must update.

- Claude Code plugin: 0.6.0 was set in #694. No change here.
- Codex plugin: 0.2.4 to 0.2.5. The vendored cg.py and costly.py
  and one skill changed in #512, #681, #683, #691, #694 and #698.

Assisted-By: Claude Sonnet 5.5 <[email protected]>
Signed-off-by: Osher Elhadad <[email protected]>
amiddavid pushed a commit that referenced this pull request Oct 26, 2026
…0.2.5) (#701)

chore(plugin): bump the plugins for v0.6.0 (Claude Code 0.6.0, Codex 0.2.5)

Both plugins changed in this release, so installed plugins must update.

- Claude Code plugin: 0.6.0 was set in #694. No change here.
- Codex plugin: 0.2.4 to 0.2.5. The vendored cg.py and costly.py
  and one skill changed in #512, #681, #683, #691, #694 and #698.

Assisted-By: Claude Sonnet 5.5 <[email protected]>
Signed-off-by: Osher Elhadad <[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