Skip to content

feat: save-more config — every shipped preset, priced and checked against history - #538

Merged
amiddavid merged 3 commits into
mainfrom
feat/save-more-config
Oct 15, 2026
Merged

amiddavid merged 3 commits into
mainfrom
feat/save-more-config

Conversation

@OsherElhadad

Copy link
Copy Markdown
Collaborator

Stacked on #528 (base feat/adapt-compaction). Backend for /context-guru:save-more config; the command and its rendering are in the plugin PR.

What it does

GET /api/adapt/compaction (also GET /api/save-more/config):

  • Every shipped preset is an option (ids are the preset names, from config.PresetNames()), plus current, default and none. Each is replayed on the account's stored requests with the same engine and pricing as before: gross per request, cache reads and writes at the tier billed, re-sends and prefix busts, sessions read from their start, the expand declaration, and the expand round trips an option with no offloader avoids.
  • Model components are not replayed. A preset that contains one (extract_llm, its sweep, the summarizers) is marked class: "estimate", its not_replayed lists them, and detail says so.
  • Ranges. range_usd brackets each figure: the low end keeps every conservative assumption, the high end refunds the unseen-saving charge and scales any gain over the current configuration by how much of the current configuration's booked saving the replay reproduces.
  • custom=1 adds the bounded search over which deterministic components run, their order and two thresholds (as in feat: adapt compaction report and apply (hosted and local) #528), on top of the presets.
  • to_date / observed: the savings to date with the current configuration, from the request rows on every priced request in the window (booked token counts re-priced at the gateway rates the replay uses).
  • Accuracy check. reproduction compares the replay of the CURRENT configuration (before any unseen-saving charge) with what the rows booked for it on the same covered requests. If they differ by more than 15% (and more than $0.05), the figures are shown and nothing is recommended.
  • The recommendation adds gain_usd, gain_range_usd, gain_window_usd_est (scaled to the window, labelled an estimate) and per_week_usd.

POST /api/adapt/compaction/apply (also /api/save-more/config/apply): a preset option stores preset: <name> without an explicit pipeline and keeps the rest of the document; custom options as in #528. Revert, identity, offers and limits are #528's.

Tests

  • One subtest per shipped preset (TestSaveMorePricesEveryShippedPreset): present, priced, range brackets the figure, model components listed and the class set, applying it switches to the preset, a preset with format saves on JSON content and a preset with nothing replayable saves nothing.
  • Custom search order (TestSaveMoreCustomSearchOrder): only candidates move, neighbouring candidates swap, a non-candidate keeps its place, and custom adds to the presets.
  • Reproduction (TestSaveMoreReproductionGatesTheRecommendation): a faithful history reproduces; the same history booked at ten times its real saving does not, and nothing is recommended.
  • Tenant scoping: both report routes, user / manager default / manager naming an account, offers bound to the account; preset apply and revert on the hosted control plane (TestSaveMoreAppliesAPresetAndRevertsIt).
  • go test ./dash/ ./proxy/ ./components/... ./cmd/... ./tenant/ ./config/ passes.

@OsherElhadad OsherElhadad 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.

Review: REQUEST CHANGES at 7102c2c (one blocker). (Posted as a comment: GitHub does not let the author account request changes.)

Blocker: a preset option is priced on a different config than the one apply stores.

  • The preset arms are built from adaptSpecFromDoc("preset: " + name + "\n"), so the replay runs the preset's own tuned blocks.
  • adaptPresetDoc, the apply path, keeps the account's existing components: blocks and only sets preset and drops pipeline. The loader lets those user blocks override the preset's.
  • I checked this with config.LoadBytes: preset: house gives extract.min_tokens 400, while preset: house plus a user extract: {min_tokens: 9999} gives 9999.
  • So for any account with a tuned block for a component in the chosen preset, the option's price, range and recommendation describe something other than what gets applied.
  • Fix: build each preset arm from the same document apply will store, i.e. curDoc with preset: <name> set and pipeline removed (share adaptPresetDoc's transform). Alternatively, have apply drop the user blocks for components the preset tunes. Add a round-trip test: apply, load, and require the same effective pipeline and settings as the replayed arm.

What I checked and found correct:

  1. The reproduction check is not circular. run.replay is the raw replay, cached in pop.raw. The declaration, expand and unseen charges are added only in eval. ObservedUSD sums r.observed over exactly the covered requests in pop.sessions, so both sides share one denominator and one pricing. With replay swapped for eval (which includes the unseen charge), TestSaveMoreReproductionGatesTheRecommendation fails.
  2. range_usd. The low end is the net. The high end is the net plus the refunded unseen charge, plus any gain over current scaled by the share of current's booked savings the replay sees, clamped at no less than 0.2. That is bounded, and documented on the field.
  3. Preset replay. A preset plus an explicit pipeline keeps the preset's tuned blocks (house's extract.min_tokens 400 survives). Model components are listed in not_replayed, and such options are class estimate. TestSaveMorePricesEveryShippedPreset pins both.
  4. neighbours() swaps only adjacent candidates, and never across a non-candidate the account runs. TestSaveMoreCustomSearchOrder pins it.
  5. Stale user blocks for components outside the new preset's pipeline load harmlessly. The apply stores preset: with no pipeline key and leaves mode and the rest of the document intact. The cache block is untouched, and the per-kind revert works.
  • Expand credit. An arm with no offloader is credited the recorded expand round trips at the repeat rate, as a negative delta. The sign is right and it is labelled in the method text.
  • Checks. go vet is clean. The dash Adapt|SaveMore tests and the proxy Adapt|SaveMore tests pass, and CI is green. The commit is signed off with no AI attribution, and the PR text has no experiment figures.

On the flaky TestKeepAliveStrategyControlRoutesResolveLiveWithNoRestart, the bug is in main's test, not in the product. The fixture's "all-day" window is 00:00–23:59. Window.contains treats End as exclusive, and the default TZ is Asia/Jerusalem (UTC+3 in October). So at 20:59 UTC, which is 23:59 local, the window does not match. The product documents 24:00 as the end of the day; the fixture should use "end":"24:00".

@OsherElhadad OsherElhadad 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.

Re-review: APPROVE at 9837078 (8003752 + 9837078 on top of 7102c2c). (Posted as a comment: GitHub does not let the author account approve.)

  • The blocker is fixed. Pricing and apply now go through one function, dash.AdaptPresetDocWith. A preset arm is priced on exactly the document apply stores: the current config with preset set, pipeline removed, and the account's blocks kept. Removing that sharing breaks tests:
    • Pricing the bare preset: <name> again makes TestSaveMorePricesThePresetDocumentApplyStores and TestSaveMoreOffersThePresetWithoutTheAccountsOverrides fail.
    • Applying with the overrides kept makes TestSaveMoreAppliesThePresetWithoutOverrides fail.
  • " without your overrides". This arm is offered only when the account's blocks change that preset. It drops only the account's blocks for components the preset runs that are replayable. The tool removal list, model components, components outside the preset and every other top-level key, cache settings included, are kept. It is priced on its own stored document, its option detail and recommendation say which settings it removes, and it goes through the normal offer, basis and revert path.
  • No regressions. The reproduction check, range_usd and the expand credit are unchanged since 7102c2c.
  • gofmt and go vet are clean, and the dash and proxy SaveMore/Adapt tests and ./config pass. CI is green, both commits are signed off with no AI attribution, and the PR text carries only the product's own thresholds.

Approved. This approval covers 9837078.

Osher-Elhadad added 3 commits October 15, 2026 13:07
…lay against history

The compaction report now prices every shipped preset as an option (ids
are the preset names), adds the bounded custom search with custom=1, and
returns the savings to date with the current configuration, observed from
the request rows on every priced request in the window.

Before anything is recommended, the replay of the current configuration
must reproduce what the rows booked for it on the same covered requests
within 15% (or $0.05); otherwise the figures are shown and nothing is
recommended. Each option carries a range that refunds what the replay is
known to miss, its model components (excluded, class "estimate"), and the
expand round trips it avoids. Applying a preset stores `preset: <name>`
and keeps the rest of the document. GET /api/save-more/config and
POST /api/save-more/config/apply serve the same report and offers.

Signed-off-by: Osher-Elhadad <[email protected]>
@amiddavid
amiddavid changed the base branch from feat/adapt-compaction to main October 15, 2026 10:07
@amiddavid
amiddavid force-pushed the feat/save-more-config branch from 9837078 to f6965f0 Compare October 15, 2026 10:10
@amiddavid
amiddavid merged commit c82ae31 into main Oct 15, 2026
4 checks passed
@github-project-automation github-project-automation Bot moved this from New/ToDo to Done in Rossoctl Issue Prioritization Oct 15, 2026
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.

2 participants