Skip to content

feat(lemonade): state GAIA's eviction policy instead of inheriting it - #4308

Merged
kovtcharov-amd merged 10 commits into
amd:mainfrom
kovtcharov:stack/7-auto-evict
Sep 26, 2026
Merged

kovtcharov-amd merged 10 commits into
amd:mainfrom
kovtcharov:stack/7-auto-evict

Conversation

@kovtcharov

@kovtcharov kovtcharov commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Stack 7/7. Merge after #4307. GitHub will not let a PR here base on a fork branch, so all seven target main and this diff includes its parents' until they merge — this PR's own change is its top commit.

# PR What
1 #4302 CalVer parsing across every version gate
2 #4304 The doc gate learns pin vs floor
3 #4303 The pin bump to v2026.39.1
4 #4305 Auto-bump workflow refreshes the digests
5 #4306 Candidate prereleases get smoke-tested
6 #4307 Request budget follows the window
7 ← this PR Eviction policy is stated, not inherited

Lemonade v2026.39.1 added VRAM auto-eviction. Its default today is off, but it is a new knob and GAIA's residency model rests on which way it points — so the value is now written into the config GAIA controls rather than inherited from a release nobody has read yet.

The policy is off, and that is a decision rather than caution. GAIA assumes a chat model and an embedder stay co-resident: RAGSDK scopes its embedder unload so a global /unload cannot take the chat model with it (#1544), the non-streaming path regained a reload check after an embedder warm-up evicted the model (#1030), and ModelSlotBroker serialises sidecar loads so they do not race the slot. Eviction under VRAM pressure is that same failure arriving from underneath.

It is also the wrong trade here. Under pressure the choice is a loud load failure or a silent eviction that resurfaces later as a cold reload or a truncated answer — fail-loudly picks the loud one.

Turning it on stays open, and is a real option for VRAM-constrained machines. #4170 asks for measurement on AMD GPU hardware first, and this machine has none, so enabling it is not part of this change.

Test plan

  • Verified against a real lemond: it accepts the boolean, and a string makes the server exit with type must be boolean, but is string — so the key is genuinely parsed rather than ignored
  • pytest tests/unit/test_lemond_eviction_policy.py tests/unit/test_lemond_request_budget.py tests/unit/test_lemonade_embedded.py — 72 pass
  • Tests assert the policy is stated (not merely absent-and-defaulting), that it survives into the file lemond reads, and that the private-instance settings are not clobbered
  • black, isort, pylint clean
  • Revisit with VRAM-pressure measurement on AMD GPU hardware before considering turning it on
🔍 Why the threshold is left unset

auto_evict_threshold_pct (0.9 upstream) is inert while eviction is off, and writing it next to auto_evict=false reads as if it applies. A test asserts it stays unset for exactly as long as the policy is off.

tests/integration/test_lemonade_model_residency.py already pins the capacity accounting this depends on — max_models is per model type, so an LLM plus an embedder need no tuning — and is the right place to extend when enabling eviction is measured.

@github-actions github-actions Bot added documentation Documentation changes devops DevOps/infrastructure changes llm LLM backend changes tests Test changes performance Performance-critical changes cpp agents agent::email Email agent changes tui Go terminal UI (gaia-tui) labels Sep 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Approve with suggestions

This bumps GAIA to Lemonade 2026.39.1, teaches every version check to understand the new CalVer format, pins automatic VRAM eviction off rather than inheriting whatever upstream defaults to, and adds a weekly job that smoke-tests next week's Lemonade candidate before it becomes a release. The reasoning is well argued and the test coverage is unusually thorough — I verified the four pinned download checksums against the live release and all four match exactly.

One thing worth fixing before this lands: the new candidate smoke job can quietly stop testing anything and still report success. It picks the candidate release by asking GitHub for the release list, but the way the list is filtered breaks if the newest candidate ever falls past the first page of results — the job then silently decides there's nothing to test and goes green. That's the exact "the check turned itself off and nobody noticed" failure this whole PR exists to prevent. It works today because only two candidates exist; it's a one-line fix.

Smaller things, all optional: the candidate checker never actually exercises the one broken-contract case it cites as motivation (it only checks that the health response still has the right top-level fields, never the nested model details); the docs navigation file carries a hardcoded Lemonade version that the new version gate still can't see, which is the same blind spot this PR closes elsewhere; and the failure-reporting step will file a "contract broken" issue for any earlier hiccup, including the download or the server simply not starting.

Real-world evidence

No automated evidence bundle was produced for this run, so the verdict rests on static review plus what I could verify directly from this environment. Two checks I ran myself, both clean:

  • All four pinned embeddable download checksums match the real published release, byte for byte — so the embedded install will not fail for users on the new pin.
  • The new documentation version gate passes across the whole repo, and I re-ran its regex against every case its tests claim: it catches the stale pins and leaves all six minimum-version floors and the IP address alone.

The PR itself carries the on-machine proof for the eviction setting (a real Lemonade server accepting the value, and rejecting a wrong type), which is the right evidence for that surface. Not exercised here: gaia lemonade embedded start end to end on a machine with a GPU, and the new weekly job's first live run.

🔍 Technical details

Issues

🟡 The candidate picker mis-reads paginated results (.github/workflows/lemonade-candidate-smoke.yml:92-94)

gh api --paginate --jq applies the jq filter to each page separately and concatenates the outputs, so [.[] | select(...)] | first emits one result per page. I confirmed this against the live endpoint: with per_page=5 the filter returns the matching object followed by a null for every other page.

It survives today only by luck — command substitution strips the trailing empties, and both existing candidate-v* prereleases sit on page 1. The moment a candidate lands on a later page while an older one is still on an earlier one, release_json holds two objects, tag becomes multi-line, asset is malformed, url comes back empty, and the run takes the no $asset yet — skipping this run branch. Green job, nothing smoked, no signal.

--slurp is rejected alongside --jq, so pipe to jq instead (verified working):

            release_json=$(gh api repos/lemonade-sdk/lemonade/releases --paginate --slurp \
              | jq -c '[.[][] | select(.prerelease and (.tag_name | startswith("candidate-v")))] | first')

🟢 The contract checker never exercises the nested shape it cites (util/check_lemonade_contract.py:44-46, :83)

The module docstring names the 9.1.4 regression — ctx_size moving out of the top level into all_models_loaded[N].recipe_options — as one of the two things that have actually broken. But check_health_shape only asserts top-level key presence, and the smoke job loads no model, so all_models_loaded is always []. That exact regression class would still pass. Either pull a tiny model in the workflow and assert the nested shape, or trim the docstring so it doesn't promise coverage that isn't there.

🟢 docs/docs.json is still outside the gate (util/check_doc_versions.py:39-47)

SCAN_PATHS globs only **/*.md and **/*.mdx, so the navbar label "v0.24.1 · Lemonade 2026.39.1" (docs/docs.json:518) is invisible to the checker — the same blind spot this PR closes for tui/ and .claude/. It was updated by hand here; next bump it can go stale silently. A targeted JSON check on that one key would close it.

🟢 The noqa comment describes cleanup that doesn't happen (tests/unit/test_doc_version_gate.py:36)

# noqa: SIM115 - closed in the finally below — the finally restores sys.stdout and nothing else; _devnull is never closed.

_devnull = open(os.devnull, "wb")  # noqa: SIM115 - lives for the module's lifetime

🟢 if: failure() over-reports (.github/workflows/lemonade-candidate-smoke.yml:167)

The reporting step fires on any prior step failure — uv pip install, the archive download, the server not becoming healthy — and files or comments on an issue asserting the contract is broken. Gating on the contract step's own outcome (give it an id and check steps.<id>.outcome == 'failure') keeps the rolling issue meaningful; infra flakes are already visible as a red run.

Strengths

  • Every copy of the version parser is covered, including the two that can't be imported. tests/unit/test_lemonade_calver.py compiles _parse_version/_version_meets_min straight out of the hub agents' source via ast rather than reaching for importorskip — and the docstring explains exactly why a skip would defeat the purpose. That reasoning is right, and the flagship agent's copy (noted as missed on the first pass) is now pinned.
  • The client gate test catches the reason, not just the result. test_client_gate_rejects_an_old_dev_build targets the case where the pre-fix code returned True via the swallow-everything except branch — a genuinely old build waved through. Testing the wrong-for-the-right-reason case is the hard part and it's here.
  • The bare-pin regex is defensible. Opt-in per file, with the v-prefix convention as the pin/floor separator and inline documentation of the six things a repo-wide pattern would wrongly match. I ran the pattern against every case in the test file and against the whole repo: it catches both stale pins and leaves all the floors — plus 127.0.0.1 — untouched.
  • _global_timeout_seconds derives from the window instead of adding a second number to drift. The env override raises rather than silently falling back, which is the Fail-Loudly rule applied correctly.
  • The eviction rationale is written where the next reader will be. The comment above _LEMOND_CONFIG links the decision to [Bug][P0]: RAG embedder load issues a global /unload that evicts the chat model → 100s+ cold reloads & eval timeout #1544, [Bug]: 1.4MB file indexed no response to queries in the UI #1030 and ModelSlotBroker, and the deliberate omission of auto_evict_threshold_pct is itself pinned by a test.

@kovtcharov

Copy link
Copy Markdown
Contributor Author

Thanks — this one sat unanswered longer than it should have. All five are addressed; three had already landed in the rebuild, two are new here.

Pagination — taken your version. Mine avoided --paginate entirely with per_page=100, which works (74 releases today, and a candidate is always among the newest), but that is an assumption that merely happens to hold. --paginate --slurp | jq removes it for about three extra API calls a week. Verified both against the live endpoint; both return candidate-v2026.40.0.

The nested shape is now checked, and — more to your point — the script says when it couldn't. On an idle server all_models_loaded is empty, so rather than pull a model in CI it checks the shape when one is present and otherwise prints that it skipped:

[NOTE] No model was loaded, so the nested all_models_loaded[].recipe_options.ctx_size
       shape was NOT checked. Load a model before running this to cover it.

Reporting "contract holds" for something never looked at is the same class of problem as the gate this stack exists to fix.

if: failure() over-reporting — scoped to the contract step's own outcome, so a failed download or a server that never came up no longer files "Lemonade broke GAIA".

The noqa comment — fixed; _devnull is never closed, so it now says it lives for the module's lifetime.

docs.json — left as-is, and I think correctly: it is outside the version gate's globs, but tests/unit/test_docs_json_release.py asserts the navbar label matches LEMONADE_VERSION, so it fails CI if it goes stale. Different mechanism, same coverage — teaching the checker to parse JSON would add a second gate for one key.

🔍 Stack note

The pagination fix lives in #4306 and the noqa fix in #4304, so both this PR and everything between were rebased onto them. This PR's own change — the eviction policy — is unchanged.

Kalin Ovtcharov added 2 commits September 25, 2026 01:00
… gate

Lemonade v2026.39.1 changes the version format from X.Y.Z to YYYY.WW.N,
with development builds shaped YYYY.WW.0~<count>.<hash>, and its release
notes call out that anything parsing or comparing version strings has to
be updated.

A release CalVer already compared correctly by accident, since 2026 > 11.
Development builds do not: int("0~12") raises, and every one of GAIA's
version parsers turned that into None. Callers read None as "cannot
tell" and deliberately do not block on it, so the gates went quiet on
candidate builds with nothing saying so.

The Lemonade client was worse than quiet. Its handler returns
"compatible" when parsing fails, so an old development build such as
9.1.0~4.deadbee was waved through as passing rather than reported
unknown — the gate did not stop checking, it answered wrong.

There were six copies of the parser, and the first attempt at this
change missed one. The four in core are now one implementation in
gaia.version, which is where the constants they compare against already
live; the other two are vendored in the flagship agent and the frozen
email sidecar, which bundle only what is statically reachable and cannot
afford gaia.version's import-time metadata lookup. The tests read those
two out of their own source, and assert they still import re themselves
— the AST loader supplies it, so a deleted import would otherwise leave
every test green and the running server raising NameError.

Leading whitespace parses again too: int(" 2026") was valid where
re.match(r"\d+", " 2026") is not, which quietly narrowed what the old
code accepted.

This lands ahead of the version bump on purpose: the parsers have to
understand the new format before the pin moves to a release using it.
…lone

The v2026.39.1 bump had to hand-fix stale Lemonade pins the gate could
not reach: it scanned only docs/ and cpp/, and matched only a version
written with a "v" prefix. One of those pins lives in a Go source
comment in the TUI, so Markdown-only globs would miss it again.

Both halves are fixed. tui/ is scanned including its Go sources, and a
bare "Lemonade <semver>" is checked in the files that opt into
BARE_VERSION_PIN_FILES.

The gate also stops marching FLOORS forward, which it had been doing.
"v11.8.1+" means "that release or newer" — it names where a feature
first shipped — while a bare "v11.8.1" is the pin. The text pattern now
requires the absence of a floor marker, so the two stop being treated
alike.

src/**/*.py is deliberately not scanned. Source comments about Lemonade
are history or justification rather than pins: scanning src/ flags
exactly "Lemonade v10.1.0 changed its default port" and "EmbeddingGemma
is validated on Lemonade v10.9.0", both of which a bump must leave
alone, and nothing that needs to move.

The opt-in for bare versions is the same argument. Applied repo-wide the
pattern matches six things it must not touch for every two it should,
including the 127.0.0 inside an IP address, so the pattern carries its
own guards and the list is a second line of defence rather than the only
one.

The reachability test now asserts the stale FILES are scanned rather
than that their directories are listed — the earlier version passed
while the Go pin it described sat behind a Markdown-only glob.
Kalin Ovtcharov added 5 commits September 25, 2026 01:05
Moves the pin GAIA installs and tests against from v11.8.1, past
v11.9.0, to the first CalVer release. The version gates learned that
format first; this moves the pin onto it.

The embeddable SHA-256 pins are keyed by a filename containing the
version, so they go stale on every bump. Refreshed here, and verified
two ways — hashed locally, and cross-checked against the digest GitHub
publishes for each asset.

docs/guides/npu.mdx goes the OTHER way, from v11.8.1+ back to v10.2.0+.
That line is a minimum-version floor in a requirements list, but the doc
gate could not tell a floor from a pin, so every previous bump marched
it forward. It had drifted to claiming NPU support needs a release nine
versions newer than the one the npu profile actually enforces. The gate
now leaves floors alone, so this is the last time that number moves on
its own.

The C++ setup page told users to start the server with a command
Lemonade deleted in 10.7, directly under the version it had just told
them to install, and gave the same command again in the requirements
table. It now says what the README already said: how the server starts
depends on the install, and there is no cross-platform serve command.
That page is in scope because this change edits it; the same string
survives in 77 other places, which needs its own sweep.

The macOS uninstall provenance and the TUI preflight launchd label both
say they track the pin, so both were re-verified against the real
v2026.39.1 .pkg rather than bumped on faith: every path and pkgutil
identifier they name is unchanged. The preflight comment is now written
v-prefixed so the gate holds it to the pin instead of relying on someone
noticing.
The scheduled bump workflow edited version.py and the docs but never
touched EMBEDDABLE_SHA256, whose keys contain the version. Every future
run would have opened a PR with four stale digests — a broken
`gaia lemonade embedded install` for anyone who took it, and a red CI
job on the PR itself.

The bump now rewrites those pins from the release API, stripping the
`sha256:` prefix the API publishes: the dict stores bare hex, which is
what the install-time check compares a downloaded file against. Told to
use the digest "exactly as published" an agent would have written
`sha256:235c…` into every value and broken every embedded install, with
only the network-gated integration test to catch it. The jq in the
prompt now does the stripping so there is nothing to get wrong; running
it against the real release reproduces the four committed pins exactly.

The cheap shell gate grew to match: it checks the four embeddable
archives alongside the two installers, and that each carries a digest,
before the paid model step runs.

Those guards skip rather than fail, which is right for a release still
uploading its assets and wrong for one that renamed them — a skip that
repeats leaves the pin silently frozen. Each now writes to the job
summary so a stuck bump is visible without reading logs.

The floor rule in the prompt is also corrected. It claimed the checker
stays silent on floors, which was only true for floors written without a
"v"; a "v10.2.0+" floor was flagged exactly like a pin until the checker
learned the difference.
…th ends

Closes amd#4171.

Lemonade 11.9.0 replaced a fixed 120s prefill ceiling with a
configurable global_timeout, defaulting to 600s. GAIA took the default,
and at the window it pins that is short: a long document arrives as one
large prefill, and 65536 tokens on a slow machine does not finish inside
ten minutes. The request dies and the answer comes back truncated, which
is the shape of amd#1030.

Raising it on the server alone would have changed nothing a user can
see. GAIA's own client gives up at DEFAULT_REQUEST_TIMEOUT, so the
smaller of the two wins and a 2048s server budget still died at 900s —
reintroducing exactly the second-number-that-drifts this set out to
remove, while looking fixed. One helper now feeds both lemond's config
and the client's read timeout.

The budget follows the window, the way budget_for_ctx already does for
truncation: 32K gets 1024s, 64K gets 2048s, capped at 3600s so a wedged
request still ends, and never below the old client default so this only
ever raises the ceiling. The divisor is a deliberately pessimistic floor
on prefill throughput — overshooting costs wall-clock only on a request
that was already failing, while undershooting truncates a real answer.

It is resolved per call rather than as a default argument, so
GAIA_CTX_SIZE and the device profile still move it.
GAIA_LEMONADE_REQUEST_BUDGET overrides it outright for a slower machine,
is honored at both ends so they cannot be set to disagree, and raises on
an unusable value rather than falling back — a timeout quietly other
than the one you set is worse than being told to fix it. It is
documented where GAIA_CTX_SIZE already is.

Verified against a real lemond: it accepts the key, and a non-number
makes the server exit with a type error, so the value is parsed rather
than ignored as an unknown field.
Closes amd#4172.

Lemonade v2026.39.1 started publishing candidate builds as GitHub
prereleases about a week ahead of the matching stable release. That same
release changed the version format to CalVer and silently switched off
GAIA's version gates — found by hand, after the fact, by reading the
release notes. candidate-v2026.39.1 had existed for seven days.

A scheduled job now installs the current candidate's embeddable build (a
~6 MB archive that runs as a plain subprocess, no installer and no
machine-wide state) and checks the contract GAIA depends on: the
reported version still reaches a real verdict through GAIA's gates, and
/health still carries the fields GAIA reads.

It reports rather than gates — its own schedule, never a pull request,
one rolling issue instead of one per Friday — and only the contract step
files that issue. A failed download or a server that never started is an
infrastructure problem, and filing it as "Lemonade broke GAIA" would cry
wolf in a thread meant to be trusted.

Two things the check is careful about. It queries the release list
WITHOUT --paginate: gh applies --jq per page, so "| first" across pages
yields one object per page and the next command reads several
concatenated objects or the wrong one. And the nested shape GAIA reads a
loaded model's context size from — the one that actually moved in 9.1.4
— is only checkable when a model is loaded, so on an idle server the
script says it did not check it rather than reporting a pass it did not
earn.

An unparseable version is a FAILURE here even though every other caller
in GAIA treats it as non-blocking: catching that is the entire job.

Verified against the real candidate-v2026.40.0 — it reports 2026.40.0,
the health schema is intact, and the contract holds, so the next
Lemonade release does not break GAIA.
Closes amd#4170.

Lemonade v2026.39.1 added VRAM auto-eviction. Its default today is off,
but it is a new knob and GAIA's residency model rests on which way it
points — so the value is written into the config GAIA controls rather
than inherited from a release nobody has read yet.

The policy is off, and that is a decision rather than caution. GAIA
assumes a chat model and an embedder stay co-resident: RAGSDK scopes its
embedder unload so a global /unload cannot take the chat model with it
(amd#1544), the non-streaming path regained a reload check after an
embedder warm-up evicted the model (amd#1030), and ModelSlotBroker
serialises sidecar loads so they do not race the slot. Eviction under
VRAM pressure is that same failure arriving from underneath.

It is also the wrong trade here. Under pressure the choice is a loud
load failure or a silent eviction that resurfaces later as a cold reload
or a truncated answer, and fail-loudly picks the loud one. Turning it on
is a real option for VRAM-constrained machines, but the issue asks for
measurement on AMD GPU hardware first and this machine has none.

auto_evict_threshold_pct is left unset: it is inert while eviction is
off, and writing it next to auto_evict=false reads as if it applies.

Verified against a real lemond: it accepts the boolean, and a string
makes the server exit with "type must be boolean, but is string" — so
the key is genuinely parsed rather than ignored as an unknown field.
kovtcharov added a commit to kovtcharov/gaia that referenced this pull request Sep 25, 2026
… gate (amd#4302)

**Stack 1/7.** Merge this first. GitHub will not let a PR here base on a
fork branch, so all seven target `main` and this diff includes its
parents' until they merge — **this PR's own change is its top commit**.

| # | PR | What |
|---|----|------|
| 1 | **← this PR** | CalVer parsing across every version gate |
| 2 | amd#4304 | The doc gate learns pin vs floor |
| 3 | amd#4303 | The pin bump to v2026.39.1 |
| 4 | amd#4305 | Auto-bump workflow refreshes the digests |
| 5 | amd#4306 | Candidate prereleases get smoke-tested |
| 6 | amd#4307 | Request budget follows the window |
| 7 | amd#4308 | Eviction policy is stated, not inherited |

---

Lemonade v2026.39.1 changes the version format from `X.Y.Z` to
`YYYY.WW.N`, and its release notes say outright that anything parsing or
comparing version strings has to be updated. GAIA does that in **seven**
independent places.

A release CalVer already compared correctly by accident — `2026 > 11`.
Development builds do not: they are shaped `2026.39.0~12.abc1234`,
`int("0~12")` raises, and every parser turned that into `None`. Callers
read `None` as "cannot tell" and deliberately do not block on it, so the
gates went quiet on candidate builds with nothing saying so.

The Lemonade client was worse than quiet. Its handler returns
*compatible* when parsing fails, so an old development build like
`9.1.0~4.deadbee` was **waved through as passing** rather than reported
unknown — the gate did not stop checking, it answered wrong.

This lands ahead of the version bump on purpose: the parsers have to
understand the new format before the pin moves to a release that uses
it.

## Test plan

- [x] `pytest tests/unit/test_lemonade_calver.py` — 35 pass, and they
fail on the pre-fix tree (8 cases), so they are a regression gate rather
than a restatement of the implementation
- [x] Every copy is covered: the five tuple parsers by parametrization,
plus the two that compare instead of returning a tuple (the client's
gate and the flagship agent's) by their own cases
- [x] Passes with the pin still at 11.8.1, which is what makes this
mergeable on its own
- [x] `pytest tests/unit/test_init_command.py
tests/unit/test_lemonade_version_check.py
tests/unit/test_agent_readiness.py
tests/unit/agents/email/test_init_endpoint.py` — 254 pass
- [x] `black`, `isort`, `pylint` (CI's exact invocation) clean

<details>
<summary>🔍 Why seven, and why the hub agents are read from
source</summary>

The parsers: the base agent readiness probe, the Lemonade client's
compatibility gate, `InitCommand._parse_version`,
`LemonadeInstaller._parse_version`, `LemonadeInfo.version_tuple`, the
flagship GAIA agent's readiness server, and the frozen email sidecar.
The last two keep their own copies because neither can import
`gaia.installer`.

`LemonadeInfo.version_tuple` is shielded today — `check_installation`
fills `version` from `get_installed_version`, which already strips the
suffix — but that invariant lives two files away and callers construct
`LemonadeInfo` directly, so it is fixed too.

The tests compile the two hub-agent parsers out of their source with
`ast` rather than importing them. `gaia_agent` is not installed in the
unit-test CI job (the root `conftest` only puts a hub agent on
`sys.path` when its package already resolves), and the usual answer —
`importorskip` — would turn this file into a silent skip in CI, which is
the exact failure it exists to catch.
</details>

Co-authored-by: Kalin Ovtcharov <[email protected]>
pull Bot pushed a commit to bhardwajRahul/gaia that referenced this pull request Sep 25, 2026
…md#4304)

**Stack 2/7.** Merge after amd#4302. GitHub will not let a PR here base on
a fork branch, so all seven target `main` and this diff includes its
parents' until they merge — **this PR's own change is its top commit**.

| # | PR | What |
|---|----|------|
| 1 | amd#4302 | CalVer parsing across every version gate |
| 2 | **← this PR** | The doc gate learns pin vs floor |
| 3 | amd#4303 | The pin bump to v2026.39.1 |
| 4 | amd#4305 | Auto-bump workflow refreshes the digests |
| 5 | amd#4306 | Candidate prereleases get smoke-tested |
| 6 | amd#4307 | Request budget follows the window |
| 7 | amd#4308 | Eviction policy is stated, not inherited |

---

The v2026.39.1 bump had to fix two stale pins by hand because no gate
could see them: `util/check_doc_versions.py` scanned only `docs/` and
`cpp/`, and only matched a version written with a `v` prefix. A bump is
only as complete as the paths that gate can reach.

Both halves are fixed — `tui/` and `.claude/` are now scanned, and a
bare `Lemonade <semver>` is checked in files that opt in.

**The opt-in is the point.** A bare version is ambiguous in a way a
`v`-prefixed one is not. Applied repo-wide the pattern matches six
things it must not touch for every two it should: minimum-version
floors, the per-agent floor in a YAML example, a recorded observation in
an eval scorecard, and the `127.0.0` inside an IP address. Marching a
floor forward turns a true statement into a false one — worse than the
staleness this is meant to catch.

## Test plan

- [x] `pytest tests/unit/test_doc_version_gate.py` — 13 pass, covering
both directions
- [x] Planting a stale bare pin in each opt-in file is **caught** (exit
1, named correctly); the `tui` floor is **untouched**
- [x] Planting a `v`-prefixed stale pin in `tui/README.md` is caught —
the new scan path works
- [x] `python util/check_doc_versions.py` clean on the real tree
- [x] `black`, `isort`, `flake8` clean

<details>
<summary>🔍 The measurement behind the design</summary>

Running a naive bare-version pattern across the scanned corpus produced
8 matches, of which **6 were false positives**:

```
min_lemonade_version: "10.2.0"              # a per-agent floor in a YAML example
Lemonade **10.2.0** or newer                # a floor
against the 10.2.0 floor                    # a floor, in prose
lemonade_version: 10.8.0                    # a recorded eval-scorecard value
http://127.0.0.1:9099/api/v1                # not a version at all
```

So the pattern carries its own guards — whole-word anchor, no `:` or `=`
between the word and the number, not an IP octet, not followed by a
floor marker — and the opt-in list is the second line of defence rather
than the only one. The tests assert each of those shapes stays
unmatched.

One gap is deliberately left open: a bare `Lemonade <semver>` is still
invisible outside the opt-in files, even inside `docs/`. Closing it
properly needs a real pin-vs-floor marker, not a looser regex.
</details>

---------

Co-authored-by: Kalin Ovtcharov <[email protected]>
pull Bot pushed a commit to bhardwajRahul/gaia that referenced this pull request Sep 25, 2026
**Stack 3/7.** Merge after amd#4304. GitHub will not let a PR here base on
a fork branch, so all seven target `main` and this diff includes its
parents' until they merge — **this PR's own change is its top commit**.

| # | PR | What |
|---|----|------|
| 1 | amd#4302 | CalVer parsing across every version gate |
| 2 | amd#4304 | The doc gate learns pin vs floor |
| 3 | **← this PR** | The pin bump to v2026.39.1 |
| 4 | amd#4305 | Auto-bump workflow refreshes the digests |
| 5 | amd#4306 | Candidate prereleases get smoke-tested |
| 6 | amd#4307 | Request budget follows the window |
| 7 | amd#4308 | Eviction policy is stated, not inherited |

---

Moves the pin GAIA installs and tests against from v11.8.1, past
v11.9.0, to the first CalVer release. amd#4302 taught the version gates to
read that format; this moves the pin onto it.

The embeddable SHA-256 pins are keyed by a filename containing the
version, so they go stale on every bump. Refreshed here, and verified
two ways — hashed locally, and cross-checked against the digest GitHub
publishes for each asset.

Minimum-version **floors** are deliberately untouched. "through Lemonade
11.8.1+" and "requires Lemonade 11.8.1 or later" name the release a
feature first shipped in, not the pin, and `git log -L` confirms neither
has moved since amd#3672 added them. Bumping one would turn a true
statement into a false one.

## Test plan

- [x] Cold embedded install end-to-end into an isolated `GAIA_HOME` —
download URL, SHA-256 verification, unpack, server start, and a real
generation through `LemonadeClient` on `Gemma-4-E4B-it-GGUF`
- [x] `/api/v1/health` reports `2026.39.1` and still carries
`all_models_loaded`, the field GAIA reads
- [x] `pytest tests/integration/test_lemonade_release_assets.py
tests/integration/test_lemonade_embeddable_assets.py` — live upstream
checks against the new pin: all platform installers resolve, all four
digests match
- [x] `python util/check_doc_versions.py` clean
- [ ] CI green on the Windows/Linux runners, where `gaia init` actually
installs

<details>
<summary>🔍 Two claims re-verified rather than bumped on faith</summary>

The macOS uninstall provenance and the TUI preflight launchd label both
say they track the pin, so both were checked against the real v2026.39.1
`.pkg` rather than having a number swapped: every path and `pkgutil`
identifier they name is unchanged (`ai.lemonadeserver.server.*`,
`/Library/LaunchDaemons/ai.lemonadeserver.server.plist`,
`/usr/local/bin/{lemonade,lemond,lemonade-tray}`).

Two stale pins here were invisible to `util/check_doc_versions.py` — it
scanned only `docs/` and `cpp/`, and only matched a `v`-prefixed
version. They are fixed by hand in this PR; amd#4304 teaches the gate to
see both classes so the next bump cannot repeat it.
</details>

---------

Co-authored-by: Kalin Ovtcharov <[email protected]>
pull Bot pushed a commit to bhardwajRahul/gaia that referenced this pull request Sep 25, 2026
…#4305)

**Stack 4/7.** Merge after amd#4303. GitHub will not let a PR here base on
a fork branch, so all seven target `main` and this diff includes its
parents' until they merge — **this PR's own change is its top commit**.

| # | PR | What |
|---|----|------|
| 1 | amd#4302 | CalVer parsing across every version gate |
| 2 | amd#4304 | The doc gate learns pin vs floor |
| 3 | amd#4303 | The pin bump to v2026.39.1 |
| 4 | **← this PR** | Auto-bump workflow refreshes the digests |
| 5 | amd#4306 | Candidate prereleases get smoke-tested |
| 6 | amd#4307 | Request budget follows the window |
| 7 | amd#4308 | Eviction policy is stated, not inherited |

---

The scheduled Lemonade bump workflow edited `version.py` and the docs
but never touched `EMBEDDABLE_SHA256`, whose keys contain the version.
Every future run would therefore have opened a PR with four stale
digests — a broken `gaia lemonade embedded install` for anyone who took
it, and a guaranteed-red CI job on the PR itself.

The bump now rewrites those pins from the release API's own `digest`
field, with an instruction never to carry a value over or invent one,
and to stop rather than open a PR when an embeddable asset has no digest
published.

The cheap shell gate grew to match: it checks the four embeddable
archives alongside the two installers, and that each carries a `sha256:`
digest, *before* the paid model step runs. Catching a partial upload
there costs nothing.

## Test plan

- [x] Both new guards run against the real v2026.39.1 release under
`bash` (not zsh — `echo` mangles the JSON there and `jq` fails
misleadingly): all six assets present, all four digests published
- [x] `sort -V` still ranks the CalVer release above the last semver
one, so the "is it newer" guard survives the format change
- [x] YAML parses
- [ ] Next scheduled run, or a manual `workflow_dispatch`, opens a PR
whose digests match the release

<details>
<summary>🔍 Also corrected in the prompt</summary>

The agent is told the doc gate now reaches `tui/` and `.claude/`
(amd#4304), and — explicitly — that a minimum-version **floor** is never
bumped. The checker is built to skip those, so an agent "fixing" one the
gate stayed silent on would be introducing the exact error this stack
avoided by hand.
</details>

---------

Co-authored-by: Kalin Ovtcharov <[email protected]>
kovtcharov-amd added a commit to kovtcharov/gaia that referenced this pull request Sep 26, 2026
…ins (amd#4307)

**Stack 6/7.** Merge after amd#4306. GitHub will not let a PR here base on
a fork branch, so all seven target `main` and this diff includes its
parents' until they merge — **this PR's own change is its top commit**.

| # | PR | What |
|---|----|------|
| 1 | amd#4302 | CalVer parsing across every version gate |
| 2 | amd#4304 | The doc gate learns pin vs floor |
| 3 | amd#4303 | The pin bump to v2026.39.1 |
| 4 | amd#4305 | Auto-bump workflow refreshes the digests |
| 5 | amd#4306 | Candidate prereleases get smoke-tested |
| 6 | **← this PR** | Request budget follows the window |
| 7 | amd#4308 | Eviction policy is stated, not inherited |

---

Lemonade 11.9.0 replaced a fixed 120s prefill ceiling with a
configurable `global_timeout`, defaulting to 600s. GAIA took the
default, and at the window it pins the default is not enough: a long PDF
arrives as one large prefill, and 65536 tokens on a slow machine does
not finish inside ten minutes. The request dies and the answer comes
back truncated — the shape of amd#1030.

The budget is now derived from the context size rather than being a
second number that can drift from it. `GPU_CTX_SIZE`, `NPU_CTX_SIZE` and
`GAIA_CTX_SIZE` all move it: 32K gets 1024s, 64K gets 2048s, a short
window keeps upstream's 600s floor, and everything is capped at 3600s so
a wedged request still ends.

`GAIA_LEMONADE_GLOBAL_TIMEOUT` overrides it for a machine slower than
the assumed floor. An unusable value **raises** instead of falling back
to the derived number — a timeout that is quietly not the one you set is
worse than being told to fix it.

This applies to the embedded instance GAIA owns and writes config for. A
system-wide Lemonade install keeps its own settings.

## Test plan

- [x] **Verified against a real `lemond`**: it accepts the key, and
feeding it a non-number makes the server exit with `type must be number,
but is string` — so the value is genuinely parsed, not ignored as an
unknown field
- [x] GAIA's own restart writes `"global_timeout": 2048` on this
machine's GPU profile and the server comes up clean, with no complaint
in the log
- [x] `pytest tests/unit/test_lemond_request_budget.py
tests/unit/test_lemonade_embedded.py` — 68 pass
- [x] Covers the derived value at both pinned windows, the 600s floor,
the 3600s cap, a nonsense window, and every override shape including the
ones that must raise
- [x] `black`, `isort`, `pylint` clean

<details>
<summary>🔍 Where the divisor comes from</summary>

The budget is `ctx_size` over an assumed **floor** for prefill
throughput of 32 tokens/second, clamped to [600, 3600]. Deliberately
pessimistic: overshooting costs wall-clock only on a request that was
already failing, while undershooting truncates a real answer.

`write_config()` runs on every `start()`, so a device-profile or
`GAIA_CTX_SIZE` change moves the budget with it rather than leaving a
stale number in the file.
</details>

---------

Co-authored-by: Kalin Ovtcharov <[email protected]>
Co-authored-by: Kalin Ovtcharov <[email protected]>
# Conflicts:
#	tests/unit/test_lemond_request_budget.py
kovtcharov-amd added a commit to kovtcharov/gaia that referenced this pull request Sep 26, 2026
…ses (amd#4306)

**Stack 5/7.** Merge after amd#4305. GitHub will not let a PR here base on
a fork branch, so all seven target `main` and this diff includes its
parents' until they merge — **this PR's own change is its top commit**.

| # | PR | What |
|---|----|------|
| 1 | amd#4302 | CalVer parsing across every version gate |
| 2 | amd#4304 | The doc gate learns pin vs floor |
| 3 | amd#4303 | The pin bump to v2026.39.1 |
| 4 | amd#4305 | Auto-bump workflow refreshes the digests |
| 5 | **← this PR** | Candidate prereleases get smoke-tested |
| 6 | amd#4307 | Request budget follows the window |
| 7 | amd#4308 | Eviction policy is stated, not inherited |

---

Lemonade v2026.39.1 started publishing candidate builds as GitHub
prereleases about a week ahead of the matching stable release. That same
release changed the version format to CalVer and silently switched off
GAIA's version gates — found by hand, after the fact, by reading the
release notes. `candidate-v2026.39.1` had existed for seven days.

A scheduled job now installs the current candidate's embeddable build —
a ~6 MB archive that runs as a plain subprocess, no installer and no
machine-wide state — and checks the contract GAIA actually depends on:
the reported version still reaches a real verdict through GAIA's gates,
and `/health` still carries the fields GAIA reads. Both are regressions
that already happened; `ctx_size` moved out of the top level in 9.1.4.

It **reports, it does not gate**. It runs on its own schedule, never on
a pull request, and a break files one rolling issue instead of one issue
per Friday. What GAIA pins is untouched — the bump workflow still tracks
`releases/latest` and still ignores prereleases.

## Test plan

- [x] **Run against the real `candidate-v2026.40.0`** — the next
Lemonade release, which exists now. It reports `2026.40.0`, the health
schema is intact, and the contract holds, so the next release does not
break GAIA
- [x] Candidate detection verified against the live API: resolves the
newest `candidate-v*` prerelease and its `ubuntu-x64` asset URL
- [x] `pytest tests/unit/test_lemonade_contract_check.py` — 11 pass, and
the suite **fails when the checker is gutted**, so it cannot launder a
break into a green job
- [x] Failure paths covered: an unparseable version, a missing version,
a version below the floor, and each dropped health key
- [x] `black`, `isort`, `flake8` clean; YAML parses

<details>
<summary>🔍 Two deliberate choices</summary>

**The check is a script, not inline YAML**, so it is testable and
runnable by hand: `python util/check_lemonade_contract.py
http://localhost:8000/api/v1`.

**An unparseable version is a FAILURE here**, even though every other
caller in GAIA treats it as non-blocking. Catching exactly that is the
entire job — a checker that shrugged at it would have passed the CalVer
switch.

It also grew `--api-key` / `$LEMONADE_API_KEY` support, because pointing
it at GAIA's own embedded instance returned 401 — found only by running
it against a live server rather than a fixture.
</details>

---------

Co-authored-by: Kalin Ovtcharov <[email protected]>
Co-authored-by: Kalin Ovtcharov <[email protected]>
@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Sep 26, 2026
Merged via the queue into amd:main with commit 3b95a0d Sep 26, 2026
29 of 31 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the stack/7-auto-evict branch September 26, 2026 05:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent::email Email agent changes agents cpp devops DevOps/infrastructure changes documentation Documentation changes llm LLM backend changes performance Performance-critical changes tests Test changes tui Go terminal UI (gaia-tui)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants