Skip to content

fix(lemonade): read Lemonade's CalVer version format in every version gate - #4302

Merged
kovtcharov-amd merged 1 commit into
amd:mainfrom
kovtcharov:stack/1-calver-parsing
Sep 25, 2026
Merged

kovtcharov-amd merged 1 commit into
amd:mainfrom
kovtcharov:stack/1-calver-parsing

Conversation

@kovtcharov

@kovtcharov kovtcharov commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

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 #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 #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

  • 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
  • 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
  • Passes with the pin still at 11.8.1, which is what makes this mergeable on its own
  • 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
  • black, isort, pylint (CI's exact invocation) clean
🔍 Why seven, and why the hub agents are read from source

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.

@github-actions github-actions Bot added llm LLM backend changes tests Test changes performance Performance-critical changes agents agent::email Email agent changes labels Sep 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Approve with suggestions

This fixes a real, silent failure: Lemonade's new date-based version numbers made every one of GAIA's version checks give up and say "can't tell", which meant the checks stopped running on development builds — and in one case waved a genuinely-too-old build through as fine. The fix is correct and the new tests are a real regression gate, not a restatement of the code.

Three things worth doing before merge, none of them blocking:

  • The new test can't catch the one import this change added. The tests for the two agent-package copies read the function out of its file and hand it the re module themselves, so if someone deleted the import re line this PR just added to the flagship agent, the test would still pass and the real server would crash. Add a check that those two files actually import it.
  • The email agent package's changelog wasn't updated. Its behaviour changed (its readiness check now understands the new format) and the package keeps an active "Unreleased / Fixed" section, which the project's hub-package rules say to keep in sync.
  • A version string with a leading space used to parse and now doesn't — a small step backwards that the old code got right by accident. One-character fix, applied to five spots.

Separately, this PR is itself the argument for deduplicating: the same twelve-line parser exists seven times, and the description admits one copy was missed on the first attempt. Four of the seven live in core and could share one implementation; only the two frozen agent packages genuinely need their own.

Real-world evidence

N/A — no evidence-bundle.md was produced for this PR, and the change can't be exercised here: proving it would need a live Lemonade v2026.39.1 (or a dev build), which the no-inference CI lane has no way to install. The PR states the pinned strings were verified against a real v2026.39.1 /api/v1/health, and I'm relaying that as the author's claim — I did not observe it. My verdict rests on static review plus re-deriving the parser's behaviour locally on the exact strings in the tests. Worth capturing a real gaia init and readiness-probe run against a CalVer Lemonade in the strix-halo lane before the pin bump lands later in this stack.

🔍 Technical details

I could not run pytest (not installed in this reviewer environment), so the test results below are reasoned from source, not executed. I did re-derive the parser standalone against every string in the test file and the results match the assertions, including "not-a-version" → None and (2026,39,1) > (11,9,0).

🟡 The hub-copy tests can't detect a missing import re (tests/unit/test_lemonade_calver.py:271)

_load_function_from_source synthesizes a module containing only from __future__ import annotations, import re, and the target FunctionDef. That means the compiled copy gets re regardless of whether the real file imports it. hub/agents/gaia/python/gaia_agent/server.py gained import re in this very PR solely for _version_meets_min — delete that line and test_flagship_agent_accepts_dev_calver still passes while the running server raises NameError. Since the stated purpose of this file is "a future parser simplification fails here instead of in the field", that is exactly the gap it should close. Cheap fix:

def test_hub_copies_import_re_at_module_level():
    """The AST loader injects ``re``; the real modules must import it themselves."""
    for path in (
        "hub/agents/email/python/gaia_agent_email/api_routes.py",
        "hub/agents/gaia/python/gaia_agent/server.py",
    ):
        source = (REPO_ROOT / path).read_text(encoding="utf-8")
        assert "\nimport re\n" in source, f"{path} no longer imports re"

🟡 gaia-agent-email CHANGELOG not updated (hub/agents/email/python/CHANGELOG.md)

api_routes._parse_version feeds _version_meets_min, which feeds the /init payload's Lemonade compatibility field (api_routes.py:3012). That is a behaviour change in a published package that maintains an active ## [Unreleased] / ### Fixed section — CLAUDE.md's hub-agent doc rule ("the CHANGELOG must name it") applies. hub/agents/gaia/python/ ships no CHANGELOG, so only the email package needs the entry.

🟢 Leading whitespace now fails to parse where it used to succeed

int(" 2026") is valid Python and returns 2026; re.match(r"\d+", " 2026") returns None, so the part raises AttributeError and the whole version goes indeterminate. Only gaia_agent/server.py .strip()s first. Verified locally: " 2026.39.1" → (2026, 39, 1) before, None after. Unlikely from a JSON version field but free to keep:

        parts = version.lstrip("v").split(".")[:3]
        return tuple(int(re.match(r"\s*(\d+)", p).group(1)) for p in parts)

Same two lines in src/gaia/agents/base/readiness.py:384, src/gaia/installer/init_command.py:1035, src/gaia/installer/lemonade_installer.py:137, src/gaia/installer/lemonade_installer.py:307, and hub/agents/email/python/gaia_agent_email/api_routes.py:394. (lemonade_client.py:4835 too, though its input comes from a stripped CLI probe.)

🟢 Seven copies of one parser — four of them can be one

readiness.parse_version is importable from core, and InitCommand._parse_version, LemonadeInstaller._parse_version, LemonadeInfo.version_tuple, and the _version_tuple closure in lemonade_client._check_version_compatibility are all byte-identical to it now. The two hub copies legitimately stay vendored (frozen sidecars, no gaia.installer import) — that's well argued in the test docstring. The four in-core ones are pure duplication, and the PR's own description ("the flagship agent's copy was missed on the first pass") is the cost of it. Not blocking, and reasonable to defer given this is stack 1/7, but worth a follow-up issue so the eighth copy doesn't appear.

🟢 ~ sorts before in Debian versioning

2026.39.0~12.abc1234 parses to (2026, 39, 0), i.e. equal to the 2026.39.0 release, but a ~ suffix conventionally denotes a pre-release of it. Harmless against the current 10.2.0 floor and clearly the intended behaviour ("dev builds should pass"); flagging only so it's a decision rather than an accident if the floor ever moves to an exact CalVer.

Strengths

  • The fix is complete and the test proves it. Seven independent call sites, each covered — the parametrized PARSERS list for the five that return tuples, dedicated cases for the two that compare. Fixing only some of them fails the suite.
  • The client gate's real bug is caught precisely. test_client_gate_rejects_an_old_dev_build ("9.1.0~4.deadbee" → False) pins the case the old except Exception: return True got actively wrong — returning "compatible" for an unparseable and too-old build. That's the difference between a check going quiet and a check answering incorrectly, and the test names it.
  • The AST-loading trick is the right call, well justified. importorskip on gaia_agent would turn this file into a silent CI skip — precisely the "the gate stopped running and nothing said so" failure it exists to prevent. The docstring explains the tradeoff instead of leaving a future reader to guess.
  • LemonadeInfo.version_tuple's docstring documents why it's hardened despite being shielded today — the invariant lives two files away and direct constructors bypass it. That's a genuine WHY comment, one of the few that earns its lines.

@kovtcharov
kovtcharov force-pushed the stack/1-calver-parsing branch from e13d973 to 16541f9 Compare September 25, 2026 07:12
@kovtcharov

Copy link
Copy Markdown
Contributor Author

All three fixed, and the first one was a real hole in my own test.

The AST loader hid a missing import. You were right that deleting import re from the flagship agent left every test green while the running server would raise NameError — I reproduced it before fixing. The synthesized module supplies re regardless of what the real file does. There is now a test asserting both vendored copies import it themselves, and I verified it fails when the import is removed.

Leading whitespace parses again — int(" 2026") was valid where re.match(r"\d+", " 2026") is not, so the new code quietly narrowed what the old accepted. Fixed in one place rather than five, because:

The four in-core copies are now one. You and two other reviewers landed on this independently, and the PR description admitting a missed copy is the argument. gaia.version.parse_version is the single implementation — that module already owns LEMONADE_VERSION and LEMONADE_MIN_VERSION, which is what these parsers compare against, so nothing new depends on anything it didn't already. A test asserts the entry points still delegate, so a re-inlined copy fails.

The email CHANGELOG has an Unreleased / Fixed entry naming the behaviour change.

🔍 Why the two hub copies stay vendored

I did check whether they could import the shared helper — #4304 noted both already import gaia.* at module scope, which is true. Two things stopped me:

packaging/freeze.py:32 deliberately avoids --collect-submodules gaia, so the sidecar bundles only what is statically reachable; and gaia/version.py runs version = get_package_version() at import time, an importlib.metadata lookup for a distribution a frozen binary has none of. It degrades to a logged warning rather than failing, but that is a warning on every sidecar start in exchange for deleting twelve lines.

So they stay vendored, the docstring now says that with the concrete reason instead of the old "does not bundle gaia.installer", and the tests read them out of their own source so they cannot drift.

Worth saying plainly: ~ sorting before its release in Debian versioning is a real semantic mismatch, and 2026.39.0~12 comparing equal to 2026.39.0 is deliberate rather than accidental. It only matters if a floor ever becomes an exact CalVer, and nothing does that today.

@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Approve with suggestions

Lemonade's switch to date-based version strings broke GAIA's version checks in a way that didn't look broken: on a development build the checks either went quiet ("can't tell", so they stopped checking and said nothing) or — in one place — answered compatible for a server that was genuinely too old. This PR teaches every parser the new format and collapses the five in-core copies onto one, with a regression test per copy.

The most valuable part is the one gate that answered wrong rather than unknown: an old development build was being waved through as passing. That's now correctly rejected, and there's a test pinned to exactly that case.

Nothing here blocks merge. Two things worth a look before you land it:

  • The tests promise more than they check. The docstrings say the two copies that ship inside frozen binaries "cannot drift" from the shared one — but those copies are only compared against four hand-written expected values, not against the shared parser itself. A version string outside those four could diverge silently.
  • The version checks aren't shown working on a real server. The test plan is unit tests and lint only. That's understandable — the date-based server this fixes doesn't exist on the current pin, which moves in a later PR in the stack — but a single readiness response and gaia init run against the currently pinned server would show the ordinary path didn't regress.

Separately, several of the new docstrings read as a history of the change ("it existed four times over… a fifth copy was missed"). Project convention puts that in the PR body and keeps the code to the one line a future reader needs.

Real-world evidence

No evidence-bundle.md was produced for this PR, and the description shows pytest and lint results only — so the verdict rests on static review plus what I could execute here.

pytest isn't installed in this container, so I could not run the suite. I did run the new parser and the test file's AST loader directly against the real source files:

'2026.39.1'            -> (2026, 39, 1)
'2026.39.0~12.abc1234' -> (2026, 39, 0)
'11.9.0'               -> (11, 9, 0)
'not-a-version'        -> None
'v2026.39.1'           -> (2026, 39, 1)
calver > last semver:  True

email  _parse_version:     (2026, 39, 1) (2026, 39, 0) None
gaia   _version_meets_min: True True False None

The date-based release and development strings parse to the right components, the old-version gate still bites, and garbage still reads as indeterminate. The two copies loaded out of the hub agents' source behave the same. The user-facing surfaces this changes — the email agent's readiness response, the flagship agent's readiness row, and gaia init's compatibility output — were not exercised here; that gap is the nudge above.

🔍 Technical details

Issues

🟡 Missing real-world evidence for the surfaces this changes (once, not per-file)

The diff changes observable output on three surfaces: GET /v1/email/init's compatible field (api_routes.py:404), the flagship agent's readiness gate (hub/agents/gaia/python/gaia_agent/server.py:419), and gaia init's version-compatibility path (init_command.py:1032). The test plan lists only pytest + black/isort/pylint.

The genuine mitigation: LEMONADE_VERSION is still 11.8.1 (src/gaia/version.py:14), so there's no CalVer server in CI to probe — the pin bump is #4303. But the spot regression is cheap and available now: one GET /v1/email/init request+response and one gaia init run against the 11.8.1 server, showing the semver path is unchanged. Worth attaching here, with the CalVer request/response landing on #4303 where a 2026.39.x server exists.

🟢 The vendored-copy drift guard is narrower than the docstrings claim (tests/unit/test_lemonade_calver.py:572)

version.py:35 and api_routes.py:392 both say the tests read the frozen copies "so they cannot drift from the core implementation." But test_the_core_parsers_are_one_implementation loops only the four in-core parsers; the email and flagship copies are checked against four literal expectations (2026.39.1, the dev build, 11.9.0, not-a-version). 10.2.0-rc1 — which the new leniency accepts as (10, 2, 0) — is covered nowhere, so the copies could diverge on it while every test stays green. Cross-check them against the canonical parser over a shared table:

@pytest.mark.parametrize(
    "probe",
    [RELEASE_CALVER, DEV_CALVER, LAST_SEMVER, "v10.2.0", "10.2.0-rc1",
     "10.10.0.1234", "not-a-version", "", None],
)
def test_the_vendored_copies_match_the_core_parser(probe):
    from gaia.version import parse_version as canonical

    assert _email_parse(probe) == canonical(probe)

(The flagship copy returns a bool rather than a tuple, so compare it against version_meets_min over the same table.)

🟢 Parse failure rides on AttributeError from None.group() (src/gaia/version.py:42, mirrored at api_routes.py:400 and server.py:432)

re.match(...).group(1) raising AttributeError is the "unparseable" path, but nothing at the call site says so — and server.py:436 narrows its except to (ValueError, AttributeError) with a comment that explains the regex, not why AttributeError is caught. Trimming that tuple during a future cleanup turns "return None" into a crash inside a readiness probe. An explicit check reads the same and can't be trimmed away:

    if not version:
        return None
    parts = str(version).strip().lstrip("v").split(".")[:3]
    matched = [re.match(r"\s*(\d+)", p) for p in parts]
    if not all(matched):
        return None
    return tuple(int(m.group(1)) for m in matched)

🟢 Docstrings narrate the change's history

src/gaia/version.py:25-27 ("It existed four times over, byte for byte, and a fifth copy was missed…"), readiness.py:377-379 ("four copies of it had to change together… and one was missed"), lemonade_installer.py:191-195, and the 25-line module docstring in the new test file. CLAUDE.md → "Code Comments — Short or Skip": keep the WHY to one line and put the history in the PR body, where it's already well told. The invariant parts are worth keeping — that version.py:122 runs an importlib.metadata lookup at import time (which is why the frozen copies exist) is real, verifiable, and non-obvious. The "one was missed" storytelling isn't.

Strengths

  • The substantive fix is the one that answered wrong, and it's pinned. _check_version_compatibility (lemonade_client.py:4834) ends with except Exception: return True, so int("0~12") raising meant 9.1.0~4.deadbee returned compatible. Raising on None inside _version_tuple keeps the deliberate don't-block-on-garbage policy while letting a parseable-but-old dev build reach the < min_tuple branch. test_client_gate_rejects_an_old_dev_build is the test that would have caught the original bug, and the docstring on test_client_gate_accepts_dev_calver honestly notes that case passed before the fix for the wrong reason.
  • The deduplication is justified per copy, not assumed. I checked the claim in version.py:33-34: line 122 does call get_package_version() at import time, so a frozen sidecar importing gaia.version really would log a metadata warning on every start. Keeping two vendored copies and testing them from source is the right call, not a shortcut.
  • importorskip was correctly rejected. _load_function_from_source (test_lemonade_calver.py:369) exists because gaia_agent isn't on sys.path in the unit CI job, and a skip here would reproduce the exact failure mode the file guards against — a gate that stopped running without saying so. test_the_vendored_copies_import_re_themselves closes the loader's own blind spot (it synthesizes import re, so a deleted real import would hide a NameError). That's unusually careful test design.
  • Leniency didn't become "everything parses." Existing assertions still hold — LemonadeInfo(version="invalid").version_tuple is None (test_init_command.py:42), version_meets_min("not-a-version", …) is None (test_agent_readiness.py:96), parse_version("10.10.0.1234") == (10, 10, 0). Verified locally: -1.2.3 and 2026.w39.1 still return None.

… 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.
@kovtcharov
kovtcharov force-pushed the stack/1-calver-parsing branch from 16541f9 to 12608a1 Compare September 25, 2026 08:00
@kovtcharov

Copy link
Copy Markdown
Contributor Author

All three addressed — and the first one was right in a sharper way than stated: my "cannot drift" test didn't prove it, and neither did my first attempt at fixing it.

The drift claim is now actually tested. The vendored copies are compared against gaia.version.parse_version itself over a shared corpus, not against hand-written expectations. When I first wrote that test I injected drift into the email copy to check it would fail — and it passed. The corpus only had leading whitespace, which str().strip() in the function body handles before the regex ever sees it, so the one character class that actually differs went untested. Added "2026. 39.1" and "2026.39. 1"; drift now fails 2 cases as it should.

Real-world evidence — ran the three surfaces against a live Lemonade reporting 11.8.1, the currently pinned release, which is the semver-path-unchanged check you asked for:

/api/v1/health -> version = '11.8.1'      parsed = (11, 8, 1)

gaia init compatibility  : True
flagship readiness gate  : True
email /init 'compatible' : True
base readiness probe     : True

and still biting on an old server:
          9.1.4 -> init=False  flagship=False  email=False
9.1.0~4.deadbee -> init=False  flagship=False  email=False

That second row is the one worth keeping: 9.1.0~4.deadbee is the case the pre-fix client answered True to. The CalVer request/response belongs on #4303, where a 2026.39.x server exists.

The docstrings are trimmed to the line a future reader needs; the "it existed four times over" history lives in the commit body where the convention puts it.

🔍 Stack note

This is the base of the stack, so all six PRs above it were rebased onto the amended commit. 320 tests pass at the tip and the doc gate is clean.

@kovtcharov

Copy link
Copy Markdown
Contributor Author

The Unit Tests (Windows smoke) failure here is not from this PR, and it is worth a maintainer's attention on its own.

One test fails out of 2,303: a path-containment check in the chat UI that behaves differently on Windows than on the platforms CI has been running. This PR changes Lemonade version parsing and touches none of the files involved.

It is newly exposed, not newly broken. The Windows smoke job was added to main earlier today in #4188, and the Unit Tests workflow has not run on main since 11 September — so these stacked PRs are among the first to exercise it. The same failure appears on #4304, which shares this commit, and will show on the rest of the stack as their runs reach it.

🔒 SECURITY CONCERN — the failing check is a containment guard, so this is a defence-in-depth gap rather than a test-only problem. I have deliberately not described the behaviour or attached a reproduction here. Please triage it privately: https://github.com/amd/gaia/security/advisories/new — cc @kovtcharov-amd

I am not fixing it in this stack: it is unrelated to a version bump, it sits in security-sensitive code, and a fix belongs with someone who can validate it on Windows. Flagging so the red check on these PRs is understood rather than assumed to be mine — and so it does not get waved through as flake.

@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Sep 25, 2026
Merged via the queue into amd:main with commit f4b63ff Sep 25, 2026
76 of 77 checks passed
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]>
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 added a commit to kovtcharov/gaia that referenced this pull request Sep 26, 2026
…amd#4308)

**Stack 7/7.** Merge after amd#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 | 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 | amd#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 (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 — fail-loudly picks the loud one.

**Turning it on stays open**, and is a real option for VRAM-constrained
machines. amd#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

- [x] **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
- [x] `pytest tests/unit/test_lemond_eviction_policy.py
tests/unit/test_lemond_request_budget.py
tests/unit/test_lemonade_embedded.py` — 72 pass
- [x] 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
- [x] `black`, `isort`, `pylint` clean
- [ ] Revisit with VRAM-pressure measurement on AMD GPU hardware before
considering turning it on

<details>
<summary>🔍 Why the threshold is left unset</summary>

`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.
</details>

---------

Co-authored-by: Kalin Ovtcharov <[email protected]>
Co-authored-by: Kalin Ovtcharov <[email protected]>
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 llm LLM backend changes performance Performance-critical changes tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants