Repository navigation
feat(config): house/housellm defaults, and stop the expand tool moving the tools array - #97
Merged
Merged
Conversation
…LLM variant
Two named configs replace "codesmart minus extract_llm" as the service default:
house format, dedup, toon, cmdfilter, searchfold, textclean,
extract, cachesplit, toolfilter
housellm the same, with extract_llm before extract
house becomes tenant.DefaultConfigYAML and the standalone proxy's --preset
default, so it is what an account runs unless it says otherwise. housellm is
applied per account on request, because its model calls spend the caller's
money and that is a consent decision rather than a default.
housellm's extract_llm block is the one this service has actually run and
measured, and DefaultExtractLLMForm now offers the same values instead of a
second opinion about them. Three matter, and each was once the silent reason a
fully configured component did nothing:
allow_on_caching_backend: true - false makes the economic gate hard-decline
every prompt-cached candidate, which on Claude Code against Anthropic is
the entire workload. economic_gate stays on, so this buys "spend when it
pays", not "spend on size".
trigger.min_request_tokens: 20000, context_messages: 2 - a higher pressure
bar so most turns still make no call, and a shorter window per call.
llm_max_per_session: 0 - UNLIMITED, by operator decision. The bounds that
remain are llm_max_per_request 4, the pressure trigger and the gate.
toolfilter ships in the default with an EMPTY removal list, so it is a no-op
until an account names a tool, MCP server or skill to stop sending. It is in
the default so that naming one is a settings change rather than a pipeline
change.
Two departures from this file's own rules, recorded rather than quietly made:
The lossless trio no longer leads - dedup and cmdfilter run ahead of
searchfold and textclean. The consequence is confined to attribution: two
offloaders have already edited the messages by the time the folds count
theirs, so the per-component split in /stats is less honest than general's.
Totals are unaffected, and all three folds verify-then-adopt in any order.
toon runs, against its retirement measurement (0 acts in 5,752 requests, 0
convertible candidates in 11.67M tokens). It is a Reformat, so what it costs
is latency - 1.53 ms and one TextTokens call per tool message - never
content. TestToonIsInNoPreset now exempts exactly these two presets and
fails on a stale exemption, so adding toon to a third still has to be a
decision somebody makes.
linecap is absent, and that is the omission worth re-measuring rather than
either of the above: it took 20.3% of all shipped tokens on the captured
corpus, more than anything else deterministic.
The outgoing default literal is recorded in supersededDefaults per the
protocol documented at `migrations`, so an account still carrying it can be
told it is running an old server default rather than a choice.
TestDefaultConfigMatchesTheHousePreset closes the drift the literal-vs-preset
duplication would otherwise allow; verified by mutation.
Signed-off-by: Osher-Elhadad <[email protected]>
…ray stops moving `tools` sits ahead of `system` and `messages` in the provider's prompt-cache hash, so any change to the array discards the ENTIRE cached prefix — not the tail, all of it. `InjectAuto` required a `<<cg:HASH>>` marker on the request, which made advertising a property of the TURN: the array grew on the first turn that offloaded and shrank again on the next turn that carried no marker. The comment claimed that "flips once, not per turn"; that holds only while markers persist, and every turn in between paid a whole-prefix miss, in both directions. Advertising now depends only on conditions that are stable for a whole session: the request declares tools, and the store persists. A session's tools array is therefore byte-identical on every request in it. The marker condition was not really about markers. It was protecting one path: a model calls expand, nothing resolves, and the host replays the model's raw tool_use to a client that implements no such tool. On an agent's own compaction request that reads as a summary that came back empty, and three of those disable auto-compact for the session. So the fix belongs at the resolution, not the advertisement — `resolved` already carries "[expand: original for id … is no longer available]" for every unresolved id, so the continuation is well formed whether anything came back or not. It is now sent: `got == 0` continues instead of bailing. Cost is one bounded upstream round (maxExpandRounds still caps the loop) and only when a model asks for an id that has aged out. The old cost was the prefix, on every turn where the marker set changed. Restoration was already appended rather than spliced, and now says so and is pinned. The marker stays where the offloader wrote it and the original arrives at the end as a tool_result, because `messages` is hashed in order: rewriting a message mid-transcript discards every cached byte after it, while appending two turns costs nothing. TestContinuationAppendsAndNeverRewritesAnEarlierMessage asserts that no pre-existing message changes by a byte, that the marker survives, and that the recovered text appears only in the last message. The bypass skip stays, and is not in tension with a byte-stable array: a bypassed request is an agent-compaction request whose system prompt and message set differ from the conversation's, so it hashes to its own prefix and shares no entry with the turns around it. Skipping it costs no cache; injecting into it would break the byte-identical forward that bypass promises. Two tests asserted the old behaviour and now assert the new invariant rather than being deleted. TestExpandToolAdvertisedOnlyWithMarkers becomes TestExpandToolAdvertisedOnEveryTurnButNeverOnACompaction, keeping the bypass case that is the one that must not change. TestMarkerFreeSSEStreamsThrough keeps its anti-buffering assertion — the property that matters — and now pins the peek boundary instead of expecting the first delta in the first read: advertising on every turn means every Anthropic stream is peeked, which ssepeek.go's bounded peek already exists to make affordable (23 of 30 responses buffered before it, 0 of 30 after). It also gains an assertion that nothing is DROPPED at that boundary, which every prior assertion would have missed. All four new tests verified by mutation: restoring the marker gate, making auto inject into a tool-less request, splicing the continuation over message 0, and restoring the `got == 0` bail each turn the relevant test RED. Signed-off-by: Osher-Elhadad <[email protected]>
added 3 commits
August 23, 2026 14:16
… two vacuous tests Review findings on #97, all three blockers plus two wrong numbers of mine. allow_on_caching_backend is INERT in housellm, and the reason I gave for it was refuted by the service's own ledger. The flag lifts exactly one check — `val.cached && !allowCached` in extract_econ's gate — and with `per_output: false` the only path into that gate is the cold sweep, whose branch returns `cached: false` by construction (extract_econ.go:145: an EXPIRED prefix is about to be re-billed at 1.25x fresh, so a token removed there is the most valuable there is, not the least). So `per_output: false` is the brake, not economic_gate. Production agrees: zero caching-backend declines across the measured window, every suppression "saving below call cost". The comment now says that. The flag stays in housellm — it is the account configuration the preset was asked to carry, and it costs nothing while per_output is off — and housellm joins TestNoDefaultConfigRunsExtractLLMOnCachingBackend, which it passes as shipped, so the combination cannot start spending by accident. DefaultExtractLLMForm no longer pre-arms it. That is the one value deliberately not matching housellm, because `per_output` is a CHECKBOX on the settings page: pre-arming the flag puts the net-negative combination one tick away, at a break-even extract_econ.go:333 prices at ~30,500 tokens/output against a largest-observed 2,053. A prefill must not arm something that becomes live when somebody changes a different field. The doc also stops claiming the form carries housellm's values verbatim — it does not model cold_cache.max_calls at all, so a prefilled account gets 4 rather than 20. The bypass skip is NOT free, and my comment said it was. isAgentCompaction fires on any last message with role "user" containing a compaction phrase, and in the Anthropic dialect a tool_result IS a user-role message — so a tool output quoting one of those phrases makes an ordinary mid-conversation turn bypass, lose the expand tool, and flip the tools array against the very prefix it shares. Measured: bypassed rows carry prefix_change at 26.7% against 1.44%, an 18.6x enrichment, zero cold_start, 22 of 30 mid-session (n=30, so the rate is indicative and the mechanism established). Not fixed here on purpose: the fix is to stop the detector matching a tool_result, which changes what bypass means for every caller of it and needs its own measurement. Injecting into a bypassed request instead would trade a documented byte-identical guarantee for an unmeasured gain. TestDefaultConfigMatchesTheHousePreset compared only Pipeline and Components, so mode, cache, store and observe could drift — and `cache` carries the keep-alive, which spends the caller's credential per ping. Extending it found real drift immediately (the literal states `mode: sync`, the preset leaves it out; normalised, since empty and sync are documented as identical, while observe-vs-empty still fails). But the extension was itself half vacuous, which is the fourteenth instance of that class here and the first of mine: applyPreset copies ONLY Pipeline and Components out of a rich preset and discards everything else it decoded, so pre.Cache is always the zero value however the preset document is written. The assertions catch drift on the LITERAL side — the direction that ships, since DefaultConfigYAML is what a tracking account runs — and the preset side is closed at its root instead, by forbidding a preset to declare a field applyPreset drops. A preset declaring `cache:` today would ship nothing at all. TestToonIsInNoPreset's exemption check only caught a name that is not a preset. Removing toon from both presets while keeping the exemption stayed green, leaving a standing permission for a component nobody runs. It now fails on that too. linecap's 20.3% is GROSS reach, not incremental value, and I repeated it as "the largest deterministic lever". Measured on the same 1,795-request corpus, house against house+linecap: +152,615 tokens, +0.797 pp, 14.5% of what was reachable once the offloaders ahead of it had taken their share. Corrected in the preset comment and both docs. Real, worth adding, an order of magnitude short of the headline. ssepeek.go cited `got == 0` as a live path to a client receiving a raw expand call; the previous commit removed it. It now names the paths that remain, including that non-Anthropic SSE is never peeked at all. Every new assertion verified by mutation: the caching-backend guard fails when per_output flips; the drift test fails on a literal-side cache block; the preset guard fails on a preset-declared cache block; the toon check fails on a stale exemption. Signed-off-by: Osher-Elhadad <[email protected]>
… two refuted figures Real-session verification of the previous commit. The fix pays and the mechanism is confirmed; two things it said are wrong. WHAT WAS MEASURED. Direct probe, byte-identical 9.5k-token system block, only `tools` changed: A->A read 9,471 / write 0; A->B write 9,558 / read 0 — the whole prefix re-created. Real 7-turn Claude Code session on the old build: tools 20->21 at the turn the first dedup marker appeared, and that turn billed write 43,359 / read 0 against the 40,320-token prefix the earlier turns had built, $0.0824 against $0.0071 for a comparable turn with no flip. After the fix: one tools hash across all 7 turns, that turn billed write 163 / read 43,135. Paired whole sessions in BOTH arm orders: $0.212401 -> $0.137185, 35.4% and 35.3% on 0.1 pp of spread, with total input tokens UP 313 — the same bytes repriced 1.25x -> 0.1x. A third controlled growing-prefix pair, arms matched on prefix tokens to 0.15%: 38.1%. The tool declaration's own cost is +129 tokens on the first write, inside all of those figures. OVERSTATED, now corrected. "Every marker-free turn in between paid a full prefix miss, in BOTH directions" is not what happens. A->B->A->B reads on all three flips, because the provider keeps both lineages alive within the TTL. The cost is ONE full-prefix write per NEW tools variant plus a doubled write delta while it alternates. The conclusion is unchanged — the real session had one variant and paid one full write, $0.070 of a $0.212 session — but the sentence was wrong and would have been quoted. Also stated plainly where it was implied otherwise: a session that never offloads saves nothing, and $10.75/1,000 requests is MODELLED off two sessions of one shape. REFUTED. ssepeek.go claimed the gateway "does not stream either — ttfb/wall 1.000 on 6 of 6 turns with no proxy in the path", and every argument that streaming work cannot pay here rested on it. Re-measured with no proxy in the path: 22 of 22 responses came back as text/event-stream with 38 events, ttfb/wall 0.47-0.78, p50 0.58-0.68, direct and proxied alike. Individual turns DO read 1.000 when generation finishes fast enough to arrive in one burst, which is the likeliest thing a sample of 6 caught on a metric whose value depends on generation length. The peek is still nearly free, for a different reason than that comment gave: the gap it adds is first-byte to first content_block_start, median 0.0 ms across 22 streams (mean 17.4, p95 3.3, max 379.4), because 18 of 22 delivered both events in the same TCP segment. The end-to-end paired measurement does NOT resolve (n=9, mean +804 ms, 95% CI -223..+1,831, per-pair sd 1.57 s — a 50 ms effect would need ~3,800 pairs), so no direction is quoted from it. And ssepeek.go's "23 of 30 buffered before / 0 of 30 after" is about the introduction of that file, not about the commit that made every tools-bearing request advertise the tool: git diff shows the file unchanged by it. What changed is how often the peek runs. Two things the verification confirmed rather than corrected, worth recording because they are the load-bearing halves. Restoration lands at the end on a real round trip: messages 8->10, all eight pre-existing messages byte-identical one by one, the marker still at index 6 with its hash id, the 12,825-byte original as the last message and in no earlier one — and the model named the first function in the restored file, which the marker does not contain. And the unresolved path completes the turn: same request, same dead id, old build returns stop_reason=tool_use with EMPTY text, new build returns end_turn with text. That costs one extra upstream round when it fires (paired n=9, median +986 ms), which is the intended trade. Auto-compact is untouched: a real compaction-shaped request still bypasses, advertises no expand tool, forwards the client's single tool, and came back with a 1,373-character summary. Residual this does not close, noted rather than fixed: a client alternating tool_choice between auto and a forced tool still moves the array, because injection is skipped on a forced tool_choice. Claude Code does not do this. Signed-off-by: Osher-Elhadad <[email protected]>
…o fix it
Delta review of the previous commit. All four of its mutations went RED, and it left
three things behind — one of them a claim that was still shipping to users.
D1. The Go comments stopped saying extract_llm runs on prompt-cached traffic; the two
doc pages an account holder actually reads did not. docs/hosted.md said housellm calls
the model "including on prompt-cached traffic", which is affirmatively false — with
`per_output: false` it runs only on a turn whose cache has expired — and
docs/reference/presets.md carried the refuted economic-gate sentence verbatim. Both now
say what the code does, and hosted.md says WHY the cold turn is the one that pays: it is
about to re-bill its whole transcript at the write rate, so a token removed there is the
most valuable one there is, against a tenth as much on a warm turn.
D2 is the same defect as the one the last commit fixed, inside the comment it rewrote to
fix it. That comment said the bounds remaining on a long session were
llm_max_per_request, the trigger and the gate. extract_llm.go:1168 switches on
`sweeping`: the sweep reads cold_cache.max_calls, the hot path reads
llm_max_per_request and llm_max_per_session, and they are the two arms of one if/else.
With per_output off, NEITHER per-request nor per-session is consulted at any value. So
the only thing bounding spend is cold_cache.max_calls (20 per sweep), the economic gate
and the 20,000-token pressure trigger — stated in config.go, form.go and presets.md,
which all named the unreachable pair.
That also corrects the previous commit's own framing of the form change:
llm_max_per_session 20 -> 0 and llm_max_per_request 2 -> 4 carry NO spend change,
because neither is reachable while per_output is off. "No per-session ceiling" was true
of the code and equally true at either value.
applyPreset now decodes into the two fields it actually carries rather than a full
Config. With KnownFields(true) a preset declaring `cache:` becomes a LOAD ERROR that
the existing TestEveryPresetBuilds catches, instead of a silent discard — verified by
mutation, which now fails with `field cache not found in type struct{...}`. That deletes
the 20-line guard added last commit, and it is the better shape for a reason that guard
could not fix: its list of ignored fields was hand-written, so adding a top-level Config
field would have reopened the hole silently, KnownFields being satisfied either way.
Correct today versus correct by construction. Only the preset-decode path changes; user
documents still decode into a full Config.
Carrying those fields instead was considered and rejected: Cache is full of int and
float knobs where 0 is not the same as unset, Mode already forced a ""/"sync"
normalisation in the drift test, and carrying would move that ambiguity into a merge
path — an abstraction with one implementation and zero callers.
D3. The form comment said "three differ" while listing AllowOnCachingBackend, which is
now the one value that does NOT differ; six changed. Fixed, with the two that matter
named and both marked as carrying no spend change.
Signed-off-by: Osher-Elhadad <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Two named configurations replace "codesmart minus
extract_llm" as the service default.houseformat→dedup→toon→cmdfilter→searchfold→textclean→extract→cachesplit→toolfilterhousellmextract_llminserted beforeextracthousebecomestenant.DefaultConfigYAMLand the standalone proxy's--presetdefault, so it is what an account runs unless it says otherwise.
housellmis appliedper account on request — its model calls spend the caller's own money, and that is a
consent decision rather than a default.
extract_llm, from measurement rather than opinionhousellmcarries theextract_llmblock this service has actually run, andDefaultExtractLLMForm(the settings-page prefill) now offers the same values instead ofa second opinion about them. Three differ from what the form returned before, and each
was once the silent reason a fully configured component did nothing:
allow_on_caching_backend: true. Unset means false, and the economic gate thenhard-declines every candidate whose tokens are prompt-cached — which on Claude Code
against Anthropic is the entire workload. That is how the component ran 251 times and
acted 0 times.
economic_gatestays on, so this buys spend when it pays, not spendon size.
trigger.min_request_tokens: 20000,context_messages: 2— a higher pressure barso most turns still make no call, and a shorter window per call.
llm_max_per_session: 0, which the component reads as UNLIMITED, by operatordecision. The bounds that remain are
llm_max_per_request: 4, the pressure trigger andthe gate.
cold_cache.max_calls: 20bounds one TTL-expiry sweep — a different knob witha different zero (
0there means the built-in 4,-1means unlimited).toolfilterin the default, with an empty listIt ships as a no-op until an account names a tool, MCP server or skill to stop sending.
It is in the default so that naming one is a settings change rather than a pipeline
change — the removal switch on the inventory page writes a list, not a new pipeline.
Two departures from this file's own rules, recorded rather than quietly made
The lossless trio no longer leads.
dedupandcmdfilterrun ahead ofsearchfoldand
textclean. The consequence is confined to attribution: two offloaders havealready edited the messages by the time the folds count theirs, so the per-component split
in
/statsis less honest thangeneral's. Totals are unaffected, and no ordering canlose content — all three folds verify-then-adopt.
toonruns, against its own retirement measurement: 0 acts on 5,752 productionrequests, 0 convertible candidates in 11.67M measured tokens. It is a
Reformat, so whatit costs is latency — 1.53 ms and one
TextTokenscall per tool message — never content.TestToonIsInNoPresetnow exempts exactly these two presets and fails on a staleexemption, so adding
toonto a third preset still has to be a decision somebody makeshere.
linecapis absent, and that is the omission worth re-measuring rather than either ofthe above: it took 20.3% of all shipped tokens on the captured corpus, more than
anything else deterministic in the catalogue.
Migration
The outgoing default literal is recorded in
supersededDefaultsper the protocoldocumented at
migrations, so an account still carrying it can be told it is running anold server default rather than a configuration it chose. Nothing rewrites a stored config.
An account with an EMPTY config tracks the default and picks
houseup at the restart withnothing to do. An account with a stored config keeps exactly what it has.
Tests
TestDefaultConfigMatchesTheHousePreset(new) closes the drift that theliteral-vs-preset duplication would otherwise allow: same pipeline order, same component
blocks, resolved through the loader the proxy uses. Verified by mutation — dropping
toolfilterfrom the literal fails it with the exact diff.TestToonIsInNoPresetkeeps the rule for every other preset and gained a stale-exemptioncheck.
TestDefaultConfigIsDeterministicstill passes:housenames no LLM component.TestEveryPresetBuilds,TestRichPresetsAgreeWithTheNameList,TestLosslessFoldsAreInEveryWorkingPreset,TestLinecapRunsLastAmongTheOffloaders,TestNoPresetEnablesCacheinjectByDefaultall pass unchanged.config,tenant,components/...,proxy,apply.codesmart/codesafestay registered and unchanged so the published SWE-bench numbersremain reproducible; every harness in
deploy/harborpasses--presetexplicitly, sochanging the flag default moves nothing that is measured.
Second commit: the expand tool stops moving the
toolsarraySeparate concern, same PR because it landed on this branch and splitting it would need a
force-push over a pushed ref. Review it as two changes.
toolssits ahead ofsystemandmessagesin the provider's prompt-cache hash, so anychange to the array discards the entire cached prefix — not the tail, all of it.
InjectAutorequired a
<<cg:HASH>>marker on the request, which made advertising a property of theturn: the array grew on the first turn that offloaded and shrank again on the next turn
that carried none. The comment claimed that "flips once, not per turn" — true only while
markers persist, and every turn in between paid a whole-prefix miss, in both directions.
Advertising now depends only on session-stable conditions: the request declares tools, and
the store persists. A session's
toolsarray is byte-identical on every request in it.The marker condition was not about markers
It was protecting one path: a model calls expand, nothing resolves, and the host replays the
model's raw
tool_useto a client that implements no such tool. On an agent's own compactionrequest that reads as a summary that came back empty, and three of those disable auto-compact
for the session.
So the fix belongs at the resolution, not the advertisement.
resolvedalready carried[expand: original for id … is no longer available]for every unresolved id, so thecontinuation is well formed whether anything came back or not. It is now sent:
got == 0continues instead of bailing. Cost is one bounded upstream round (
maxExpandRoundsstill capsthe loop) and only when a model asks for an id that has aged out. The old cost was the prefix,
on every turn where the marker set changed.
Restoration was already appended — now it says so and is pinned
The marker stays where the offloader wrote it, hash id and all, and the original arrives at the
end as a
tool_result.messagesis hashed in order, so rewriting a messagemid-transcript discards every cached byte after it while appending two turns costs nothing.
Nothing in
Continuation's signature stopped a future version from being "helpful" and puttingthe content back where it came from, which would read as a tidier transcript and cost the whole
prefix on every expand call.
Bypass stays skipped, and it costs no cache
A bypassed request is an agent-compaction request whose system prompt and message set differ
from the conversation's, so it hashes to its own prefix and shares no entry with the turns
around it. Skipping it costs nothing; injecting into it would break the byte-identical forward
bypass promises. The test case asserting that is kept unchanged.
Tests — four new, all verified by mutation
TestInjectAutoIsByteStableAcrossTurnsWithAndWithoutMarkersTestInjectAutoStillLeavesAToollessRequestAloneTestContinuationAppendsAndNeverRewritesAnEarlierMessagemessages.0TestAnExpandCallThatResolvesNothingStillFinishesTheTurngot == 0bailTwo existing tests asserted the old behaviour and were rewritten to the new invariant rather
than deleted:
TestExpandToolAdvertisedOnlyWithMarkers→TestExpandToolAdvertisedOnEveryTurnButNeverOnACompaction, keeping the bypass case, which is the one that must not change.TestMarkerFreeSSEStreamsThroughkeeps its anti-buffering assertion — the property that matters — and now pins the peek boundary instead of expecting the first delta in the first read. Advertising on every turn means every Anthropic stream is peeked, whichssepeek.go's bounded peek already exists to make affordable (23 of 30 responses buffered before it, 0 of 30 after). It also gained an assertion that nothing is dropped at that boundary, which every prior assertion would have missed.The honest cost
Every Anthropic SSE response is now peeked to its first
content_block_startrather than onlymarker-bearing ones. The peek is bounded and a normal answer still streams; non-Anthropic
dialects are not peeked at all. On the deployment this targets the upstream gateway does not
stream anyway (measured ttfb/wall 1.000 on 6 of 6 turns with no proxy in the path), so there is
no first-byte time to lose there — but on an upstream that does stream, this moves the first
client byte from
message_starttocontent_block_start.Full suite green, and
-race -count=1clean acrossexpand,proxy,apply,components,config,tenant: 0 failures, 0 data races.