Fix Archive Session for metadata-only cache hits - #2244
1 commit merged into
Conversation
|
Read this end-to-end on the PR worktree against What the change does
with LOCK:
if sid in SESSIONS:
SESSIONS.move_to_end(sid) # LRU: mark as recently used
return SESSIONS[sid]
This PR's fix at if getattr(s, "_loaded_metadata_only", False):
s = Session.load(sid)
if s is None:
raise KeyError(sid)
with LOCK:
SESSIONS[sid] = sis exactly the same shape as the existing if getattr(session, "_loaded_metadata_only", False):
try:
from api.models import get_session as _get_session
session = _get_session(session.session_id, metadata_only=False)so the pattern is already blessed for this kind of mutation route. One small inconsistency worth noting
Test coverage
Other archive-route mutations that have the same shapeThe same pattern exists at:
All three call VerdictLGTM as a focused fix for #2243. Minor consistency suggestion above is optional. The regression test pins the contract; the #1558 save-guard stays intact; CHANGELOG is correctly placed under Unreleased → Fixed. — maintainer |
18297f3
… 0.51.62) (#470) This PR contains the following updates: | Package | Update | Change | |---|---|---| | [ghcr.io/nesquena/hermes-webui](https://github.com/nesquena/hermes-webui) | patch | `0.51.61` → `0.51.62` | --- ### Release Notes <details> <summary>nesquena/hermes-webui (ghcr.io/nesquena/hermes-webui)</summary> ### [`v0.51.62`](https://github.com/nesquena/hermes-webui/releases/tag/v0.51.62) [Compare Source](nesquena/hermes-webui@v0.51.61...v0.51.62) ##### What's Changed - stage-355: 11-PR full sweep batch — metadata-only cache hit fixes + skill detail fix + phone UX + escaping + display-title projection + RFC update + test fixture hardening by [@​nesquena-hermes](https://github.com/nesquena-hermes) in [#​2263](nesquena/hermes-webui#2263) - Improve phone sidebar panel navigation by [@​franksong2702](https://github.com/franksong2702) in [#​2238](nesquena/hermes-webui#2238) - fix: reconcile stale sidebar display titles by [@​dso2ng](https://github.com/dso2ng) in [#​2241](nesquena/hermes-webui#2241) - Fix Archive Session for metadata-only cache hits by [@​franksong2702](https://github.com/franksong2702) in [#​2244](nesquena/hermes-webui#2244) - Fix metadata-only cache hits in session mutation routes by [@​franksong2702](https://github.com/franksong2702) in [#​2249](nesquena/hermes-webui#2249) - \[codex] Fix blank skill detail views by [@​franksong2702](https://github.com/franksong2702) in [#​2250](nesquena/hermes-webui#2250) - docs(runtime): codify [#​1925](nesquena/hermes-webui#1925) adapter contract and migration gates by [@​franksong2702](https://github.com/franksong2702) in [#​2251](nesquena/hermes-webui#2251) - \[codex] Show skill detail API errors by [@​franksong2702](https://github.com/franksong2702) in [#​2253](nesquena/hermes-webui#2253) - \[codex] Escape model picker display text by [@​franksong2702](https://github.com/franksong2702) in [#​2255](nesquena/hermes-webui#2255) - \[codex] Fix start.sh dotenv filtering load by [@​franksong2702](https://github.com/franksong2702) in [#​2257](nesquena/hermes-webui#2257) - \[codex] Harden update-link git fixture by [@​franksong2702](https://github.com/franksong2702) in [#​2259](nesquena/hermes-webui#2259) **Full Changelog**: <nesquena/hermes-webui@v0.51.61...v0.51.62> </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about these updates again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4xMDEuMSIsInVwZGF0ZWRJblZlciI6IjQzLjEwMS4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJyZW5vdmF0ZS9jb250YWluZXIiLCJ0eXBlL3BhdGNoIl19--> Reviewed-on: https://git.erwanleboucher.dev/eleboucher/homelab/pulls/470
Fix Archive Session for metadata-only cache hits (franksong2702, fixes nesquena#2243) # Conflicts: # CHANGELOG.md
Fix Archive Session for metadata-only cache hits (franksong2702, fixes nesquena#2243) # Conflicts: # CHANGELOG.md
Thinking Path
Archive Session fails only after the target session has already been touched by a metadata-only path. The archive endpoint loads the session with
get_session(sid), then mutatesarchivedand callssave(). When the in-memory LRU already contains a_loaded_metadata_only=Trueinstance, that cached stub is returned before a full disk load happens.Session.save()correctly refuses metadata-only instances under the #1558 guard because theirmessages=[]payload would risk overwriting the full transcript. So the bug is not the guard; it is that/api/session/archivemutates a cached metadata-only stub instead of upgrading it first.What Changed
Fixes #2243.
Changed 3 files: 59 insertions, 1 deletion.
api/routes.py: reloads a cached metadata-only session withSession.load(sid)before mutatingarchived, then refreshes the session cache with the full instance. The existing CLI/imported-session fallback stays unchanged.tests/test_metadata_save_wipe_1558.py: adds a regression test that places a metadata-only stub inSESSIONS, calls/api/session/archive, and asserts archive succeeds while the on-disk message history remains intact.CHANGELOG.md: documents the user-visible Archive Session fix.Why It Matters
Archiving is a common sidebar action. The pre-fix behavior looked like a dead click or
Archive failed, even though the session existed and the requested mutation was valid. This restores the expected Archive/Restore behavior without weakening the data-loss guard added for #1558.Verification
Local regression shape:
POST /api/session/archivethrough the route handler.archived=Truepersists, the cached object is now a full session, and all messages remain on disk.Commands run:
Result:
13 passedpluspy_compileandgit diff --checkpassed.Risks / Follow-ups
Low risk. This does not weaken the #1558 metadata-only save guard.
Session.save()still refuses metadata-only instances; this route simply reloads the full persisted session before performing a valid archive mutation. If the full reload fails, the endpoint falls through to the existing not-found/CLI fallback behavior instead of saving the stub.This PR intentionally does not change broader metadata-only cache semantics or session pin/move behavior.
Model Used
AI-assisted with OpenAI Codex, GPT-5. Human-directed scope and verification. No external code generation tools beyond local shell, tests, and GitHub CLI.