Skip to content

Grok 1.0.13 moved session storage to SQLite — file-based discovery and transcript backfill are dead #331

Closed

Description

@wxtsky

Found while investigating #318. Grok shipped 1.0.13 (from the 0.2.x line) and replaced its on-disk session layout. Everything in AppState that reads Grok sessions from the filesystem now finds nothing.

What changed

Before (0.2.x):

~/.grok/sessions/<percent-encoded-cwd>/<session-uuid>/
    chat_history.jsonl
    summary.json
    events.jsonl
    updates.jsonl

After (1.0.13) — the whole tree is gone, replaced by a single index:

~/.grok/sessions/session_search.sqlite
CREATE TABLE session_docs (
    session_id   TEXT PRIMARY KEY,
    cwd          TEXT NOT NULL,       -- plain path, no percent-encoding
    updated_at   INTEGER NOT NULL,    -- unix seconds
    title        TEXT NOT NULL,
    content      TEXT NOT NULL,       -- flattened digest, not a transcript
    content_hash TEXT NOT NULL
);

plus an FTS5 mirror (session_docs_fts). meta holds session_search_schema_version = 4. The migration also drops empty ~/.grok/relocations/<session-id>.lock markers.

Verified locally: grok --version → grok 1.0.13 (5e9a58528b76) [stable], ~/.grok/sessions/ contains only the SQLite file, and find ~/.grok -name chat_history.jsonl returns nothing.

What breaks

All in Sources/CodeIsland/AppState.swift:

  • grokSessionCandidates(cwd:) walks ~/.grok/sessions/<encoded-cwd>/ → always empty, so findActiveGrokSessions returns nothing and matchGrokSessionsToProcesses has nothing to match.
  • grokEncodedCwd — 1.0.13 stores the plain path in a column; the percent-encoded directory name no longer exists.
  • transcriptPath points at chat_history.jsonl, so message backfill and the transcript tailer are dead.
  • The ("grok", "\(ConfigInstaller.grokHome())/sessions") watch now only fires when the SQLite index is rewritten.

Hooks are unaffected — they run out of ~/.grok/hooks/codeisland.json and don't touch session storage — so Grok cards still appear and still update. What's lost is everything discovery adds on top: recovering a session CodeIsland didn't see start, backfilling recent messages, and reattaching after a CodeIsland restart.

Notes for the fix

  • session_docs has no created_at, only updated_at. grokSessionProcessMatchScore leans on createdAt for its ±120s window and for the resumed-session branch, so the scoring needs rethinking rather than a straight port.
  • content is a flattened digest (title + a run of text and tool names), not turn-structured — usable for a preview line, not as a transcript source.
  • Both layouts will be in the wild for a while, so detection should be by what's on disk (SQLite present vs. cwd directories present) rather than by a version probe.
  • Reading the index while Grok is running means opening the SQLite read-only, and ideally in WAL-safe fashion, since Grok writes it live.

Filing rather than fixing because I have no live 1.0.13 session to verify against — the scoring change in particular needs a real session to test, and guessing at it risks hiding sessions that currently work via hooks.

Activity

  1. wxtsky commented on Sep 23, 2026

    @wxtsky
    OwnerAuthor

    Follow-up with a correction to my own premise, from a closer look (a copy of the index plus strings on the 1.0.13 binary; Grok was not launched).

    The SQLite file isn't a replacement store. session_search.sqlite is Grok's FTS5 search index, and 0.2.114 already had it: this machine's last_bootstrap_at matches the 0.2.114 launch in unified.jsonl. The 1.0.13 binary's own bundled docs and storage code still keep each session in sessions/<encoded-cwd>/<id>/ (summary.json, updates.jsonl, chat_history.jsonl): "JSONL is the source of truth; … additionally maintains a local SQLite FTS5 index". The session directories on this machine disappeared during that upgrade run, most likely an upgrade/relocation accident (30 relocations/*.lock markers were written at the same moment) rather than a format change. Nothing else under ~/.grok holds a transcript, and the index's content column is a digest, not a transcript.

    Fixed on main (e48c4a8), robust to both situations:

    • Discovery reads the per-session directories first. session_search.sqlite is a read-only fallback, opened without immutable so rows still sitting in Grok's live WAL are seen. An unexpected schema yields no rows rather than a guess. Sessions known only to the index are tracked without a transcript path.
    • Grok session ids are UUIDv7, so the embedded timestamp stands in for the missing created_at in scoring. The scorer's rules are unchanged, and it still prefers not matching when unsure.
    • The hook bridge only passes a chat_history.jsonl path once the file exists. This also fixes a real bug: a path recorded before the file was created was marked attached, and the tailer never retried it.
    • Old-layout support is unchanged.

    The same batch fixes #318 (a /resume in the same TUI leaving two cards). Still to confirm on a real machine: that a new 1.0.13 session creates its sessions/<cwd>/<id>/ directory. If it turns out it doesn't, that's a fresh issue with concrete evidence.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions