fix(0.41.1): auto-update hook preserves [server] extras + kbagent version refreshes cache - #302
Merged
Merged
Conversation
…sion refreshes cache Two bugs combined to break `kbagent serve --ui` for users who installed with `--with 'keboola-agent-cli[server]'` and had a stale cache entry. Bug 1: auto_update._perform_update dropped [server] extras - The fix landed in v0.40.2 patched only `kbagent update` (version_service._update_kbagent), not the startup auto-update hook. - `auto_update._perform_update` still ran a bare `uv tool install --upgrade git+...`, silently dropping fastapi+uvicorn. - Refactored both paths to share `build_kbagent_upgrade_command()` so the install-spec construction (`--with`, `--force`, pip fallback) stays byte-for-byte consistent. Bug 2: kbagent version did not refresh the auto-update cache - `get_versions()` made a live GitHub round-trip but never wrote the result to ~/.config/keboola-agent-cli/version_cache.json. - The 1h TTL'd cache stayed pinned to whatever the auto-update hook last wrote. Symptom: `kbagent version` shows "v0.41.0 available"; follow-up `kbagent serve --ui` auto-updates to the cached older version (e.g. 0.40.3) and breaks (Bug 1 then drops extras on top). - `get_versions()` now persists the freshly-fetched values via a lazy-imported `_write_cache` (lazy to avoid the auto_update <--> version_service import cycle). Write failures are caught and logged at debug level. Tests: - TestPerformUpdate.test_update_preserves_server_extras (extras path) - TestPerformUpdate.test_update_without_server_extras_uses_upgrade (no-extras path) - TestVersionService.test_persists_freshly_fetched_versions_to_cache - TestVersionService.test_cache_write_failure_does_not_break_get_versions Run: make check clean, 3313 tests pass.
7 tasks
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.
Summary
Two bugs combined to break
kbagent serve --uifor users who installed with--with 'keboola-agent-cli[server]'. Symptoms observed in production today:Bug 1 — Startup auto-update hook drops
[server]extrasThe fix in v0.40.2 patched only the explicit
kbagent updatecommand (version_service._update_kbagent). The startup auto-update hook inauto_update._perform_updatewas left running the old bareuv tool install --upgrade git+...— no--withflag, so the FastAPI + uvicorn extras a user originally installed with--with 'keboola-agent-cli[server]'got silently dropped on every auto-update.Fix: Refactored both paths to share
build_kbagent_upgrade_command()inversion_service.py. The helper probesimportlib.util.find_spec('fastapi')(reliable proxy for "user originally installed with[server]") and pairs--with 'keboola-agent-cli[server]'with--forcewhen extras are detected (--forceis uv's documented way to combine--upgrade+--withsince uv rejects them as a pair).Bug 2 —
kbagent versiondoes not refresh the auto-update cacheget_versions()made a live GitHub round-trip but did NOT write the result back to~/.config/keboola-agent-cli/version_cache.json. The 1-hour-TTL'd cache stayed pinned to whatever value the auto-update hook last wrote. The result:kbagent versioncorrectly showsv0.41.0 available(live fetch), but a follow-upkbagent serve --uion the same machine still auto-updates to whatever stale version the cache held (e.g. 0.40.3, written by an auto-update hook before 0.41.0 existed).Combined with Bug 1, this produced the worst-case scenario: the version check says "new release available",
serve --uiupgrades to a different older release, and fastapi disappears.Fix:
get_versions()now persists the freshly-fetched values via_write_cache(lazy-imported to avoid theauto_update ↔ version_serviceimport cycle). Write failures are caught and logged at debug level so the version command never crashes on a read-only HOME / disk-full edge case.Test plan
TestPerformUpdate.test_update_preserves_server_extras— when fastapi is importable,_perform_updateargv contains--force --with 'keboola-agent-cli[server]', NOT--upgrade.TestPerformUpdate.test_update_without_server_extras_uses_upgrade— when fastapi is NOT importable, argv contains plain--upgrade(no--with).TestVersionService.test_persists_freshly_fetched_versions_to_cache—get_versions()calls_write_cachewith the latest kbagent + MCP values.TestVersionService.test_cache_write_failure_does_not_break_get_versions— cache write OSError does NOT propagate (best-effort).make check: lint + format + skill + version + changelog + error-codes all clean.cd worktree && pip install -e .[server] && python -c "from keboola_agent_cli.auto_update import _perform_update; from unittest.mock import patch; ..."— confirmed argv inspection matches the expected commands in both branches.Diff stats
src/keboola_agent_cli/services/version_service.py: new module-levelhas_server_extras()+build_kbagent_upgrade_command(), removed the now-deadVersionService._has_server_extrasstatic helper, refactored_update_kbagentto delegate.src/keboola_agent_cli/auto_update.py:_perform_updatedelegates tobuild_kbagent_upgrade_command().src/keboola_agent_cli/services/version_service.py:get_versions()persists cache.tests/test_auto_update.py: 2 new tests pinning extras / no-extras branches.tests/test_version_service.py: 2 new tests for cache write + failure handling.src/keboola_agent_cli/changelog.py: 0.41.1 entry.pyproject.toml,plugins/kbagent/.claude-plugin/plugin.json,.claude-plugin/marketplace.json: version bump.