Repository navigation
fix(chat): keep sessions in ~/.gaia/sessions and refuse corrupt files - #4371
Conversation
gaia chat saved full transcripts to ./.gaia/sessions in whatever directory it
started from, often a git repo, and a truncated session file was treated as
"not found", so the next save silently replaced the user's history with an
empty session.
- Sessions default to <GAIA_CONFIG_DIR>/sessions, matching the documented
~/.gaia/sessions location, so they resume from any directory.
- Saves write to a temp file and os.replace it, so a crash mid-save keeps
the previous file intact.
- A present-but-unparseable file raises SessionCorruptError (and leaves the
file untouched) instead of returning None.
- session_id must match [A-Za-z0-9._-]{1,128}, must not be all dots, and
must resolve inside the session dir.
Fixes #4219
A session_id that can't be a session file name (../x, a:b) reached the agent
build, raised ValueError from the session store, and came back from /query as
a generic 500. It is the caller's mistake, so it is now a 400 whose message
names the allowed characters.
- validate_session_id() in the chat session store is the one definition of a
valid id; the server checks it before building an agent on /query and before
the lookup on /sessions/{session_id}/bypass.
- SPEC, SKILL, README and CHANGELOG say 400 on both routes.
# Conflicts: # hub/agents/chat/python/CHANGELOG.md # hub/agents/gaia/npm/SPEC.md
Skill audit
✅ All audited skills cleared the tier they claim. Per-finding detail is withheld here on purpose. Read it in the Security > Code scanning tab, or download the |
# Conflicts: # hub/agents/gaia/npm/CHANGELOG.md
|
Verdict: Approve with suggestions 🟢 This is a clean, well-motivated fix: sessions land in Two small things worth tidying before or just after merge: 🟢 The Windows-only test uses a raw path as a regex match string. 🟢 except (OSError, ValueError, TypeError, AttributeError, KeyError) as e:🔍 Technical detailsWindows regex test — # current
with pytest.raises(SessionCorruptError, match=str(path)):
# fix
with pytest.raises(SessionCorruptError, match=re.escape(str(path))):KeyError gap — The existing exception tuple is Both are 🟢 nits — neither blocks merge. |
Verdict: Approve with suggestionsChat transcripts now live in Three things worth addressing:
Real-world evidenceThe automated evidence stage failed to run — The change touches two surfaces the project expects evidence for — the 🔍 Technical details🟡 Important1. No migration or hint for sessions left behind in the old location ( The default moves from a cwd-relative 2. The path-permission cache rides along with the sessions directory (
3. Input narrowing shipped under an unchanged contract version (
4. No surface evidence for a CLI + HTTP change — see the visible section above; flagged once, not per file. 🟢 MinorWindows-only regex escape in the new test ( (add
UI sessions are invisible to listing and cleanup ( Validation-by-side-effect ( Strengths
|
gaia chatsaved full transcripts and indexed-file paths to./.gaia/sessionsin whatever directory it started from, often a git repo where they could be committed by accident. A truncated session file was treated as "not found", so the next save quietly replaced the user's history with an empty session. Sessions now live in~/.gaia/sessions(the location the docs already promised), saves are atomic, and a corrupt file raises an error and is left untouched instead of being overwritten.Session ids are now restricted to 1–128 characters from
A-Z a-z 0-9 . _ -, which blocks../escapes. The flagship server checks this up front, so a caller sending any other id (such asa:bor../x) to/v1/gaia/queryor/v1/gaia/sessions/{session_id}/bypassgets a 400 naming the allowed characters, not a 500. UUIDs and ids likes1are unaffected. The gaia SPEC, SKILL, README, and CHANGELOG document this.Sessions saved by earlier versions stay where they were. The chat CHANGELOG tells users to move them into
~/.gaia/sessions.Replicates #4311 onto a branch this session can push to — that PR lives on the
kovtcharov/gaiafork, whose push access was revoked mid-review, so it could no longer be refreshed against main and wentCONFLICTING. No content changes beyond conflict resolution against current main.🔍 Conflict resolution
Two conflicts, both doc-only and both purely additive — no Python file conflicted:
hub/agents/chat/python/CHANGELOG.md— main added a/clear-cachebullet under the same## Unreleasedheading this PR adds its sessions bullet to. Kept both.hub/agents/gaia/npm/SPEC.md§5.2 — main appended the one-shot/idle-deletion paragraphs to the same sentence this PR extends with the session-id rule. Kept both, session-id rule first so it sits next to the sentence it qualifies.The review ask on #4311 (invalid
session_idreturning 500) was addressed by its second commit at 07:02Z, after the 06:55Z review.Test plan
hub/agents/chat/python/tests/test_session_storage.py: 14 pass, 1 fails Windows-only (see below)hub/agents/gaia/python/tests/test_server_query.py: 49 pass, including../x,a:b,a/b,...and a 129-character id getting a 400 on/queryand bypass while a UUID ands1still workhub/agents/gaia/python/tests/ hub/agents/chat/python/tests/: 528 pass, 3 skipped, 1 Windows-only failuretest_truncated_session_is_loud_and_not_overwrittenpasses on theubuntu-latestrunner this suite uses but fails on a Windows dev box —pytest.raises(match=str(path))treats the Windows path's backslashes as regex escapes (\U). Pre-existing in fix(chat): keep sessions in ~/.gaia/sessions and refuse corrupt files #4311, not introduced here, and invisible to CI;re.escape(...)fixes it if you want it in scope.