Skip to main content

Module session_backfill

Module session_backfill 

Source
Expand description

Backfill the registry record session_id from each agent’s provider transcript, so a cross-channel open --resumes the original conversation instead of starting a fresh session.

Background: the registry session_id is read on launch (surfaced to the picker, which passes it as --resume <sid> on the first turn of a reattached block — agent_handlers/session.rs) but was never written by production code, so it was always null. A fresh-build / cross-channel open therefore had no sid to resume and spawned a brand-new session, which then shadowed the original. See docs/retro/retro-cross-channel-conversation-continuity-regression-2026-06-16.md.

Production code now also writes it on every capture (core::persist_session_id, mirrored to the registry by the instance store); this idempotent startup pass backfills records that predate that write.

Functions§

backfill_session_ids
Populate session_id for registry records that lack one, from the agent’s largest provider session. Idempotent (skips records that already carry a non-empty id). Returns the number populated. Best-effort per record — a record with no source_agents_base or no transcript is skipped, never fatal.
find_largest_session_for_working_dir
Recovery lookup for a confirmed-stale --resume failure (docs/status/STATUS_CROSS_CHANNEL_RESUME_STALE_SESSION_ID_2026_08_20.md): rather than giving up and starting a blank conversation the moment a registry/inherited session_id turns out to be unreachable, look for the largest session actually on disk under this exact config_dir (the CLAUDE_CONFIG_DIR the CLI process is about to run with) for working_dir. None when config_dir is empty/unset (nothing to search) or no session exists — callers fall back to starting blank in either case, same as before this existed.
largest_session_id
The provider session id (jsonl stem) of the agent’s largest session across the candidate project roots (the account-wide default and, for identity-bound agents, the account’s home). We pick the largest, not the newest, on purpose: an accidental fresh session (one started when a blank cross-channel open failed to resume) must never win over the real conversation. None when there are no session files under any root.
largest_with_size 🔒
The largest (size, session-id) directly under projects_dir/<slug>, or None if the dir doesn’t exist / has no session files.
session_file_path
Absolute path of the transcript file --resume <sid> would need to find: <config_dir>/projects/<slug(working_dir)>/<sid>.jsonl.
session_is_reachable
Would --resume <sid> find its conversation under this exact CLAUDE_CONFIG_DIR? This is the whole of what the CLI checks before answering “No conversation found with session ID” — so asking it up front predicts a resume’s success without spawning anything.