Module transcript_backfill

Module transcript_backfill 

Source
Expand description

One-shot backfill of pre-existing agent CONVERSATIONS into the GLOBAL transcript store, so the 9 (and any) agents created before cross-channel transcripts shipped load their history when opened from a fresh channel.

The merged feature (#1399) mirrors new agent output into the global agent:<defId>:current zone, but pre-existing conversations were never mirrored — they live only in the channel they ran in. This scans every channel/dev objects.db for blocks belonging to each agent definition, reads the richest output from that channel’s filestore.db, and seeds the global zone with it.

Source = the channel block’s output, NOT the provider .jsonl. The block output is the exact stdout stream-json the renderer already parses (parseHistoryLines + the claude-stream-json translator); the provider ~/.claude/projects/<slug>/<sid>.jsonl transcript is a different envelope (queue-operation / user+parentUuid/sessionId) the renderer can’t consume, so copying it would render empty. Using the block output needs zero translation.

The seeded snapshot overlay uses sourceBlockId: "", which the frontend treats as “matches any block” — so opening the agent (a fresh local block with no local output) takes the v2 fast-path and the blockfile:read_range global fallback (#1399) serves the backfilled zone.

Marker-gated (.transcripts_backfilled, version-stamped) like the definition backfill (registry::def_migrate); read-only on every scanned SQLite (the global store is the only thing written).

Structs§

BackfillStats

Constants§

BACKFILL_VERSION 🔒
Bump to re-run the backfill once for everyone (e.g. when the source-selection logic improves).
MARKER 🔒

Functions§

backfill_transcripts_once
Seed the global transcript zone for each agent in def_ids from its richest channel/dev block output. Marker-gated under transcripts_dir. Best-effort — any per-DB failure is skipped, never fatal.
collect_data_dirs 🔒
Every <home>/channels/*/versions/*/data and <home>/dev/<branch>[/<sub>]/data (mirrors registry::def_migrate::collect_scan_dbs, returning the data dir).
count_nonblank_lines 🔒
dir_subdirs 🔒
marker_version 🔒
overwrite_zone_file 🔒
Create-or-replace a zone file with exactly bytes (FileStore write_file requires the file to exist first).
read_agent_blocks 🔒
Read all blocks from objdb whose meta.agentId is in want, returning (def_id, block_oid) pairs. Read-only.
read_zone_output 🔒
Reassemble a zone’s output file bytes directly from db_file_data (read-only, avoids opening a second writable FileStore on another channel). Returns None when absent or empty. Agent output is non-circular, so concatenating parts in partidx order matches FileStore::read_file.
seed_global_zone 🔒
Write bytes as the zone’s output and a v2 snapshot overlay (sourceBlockId: "") so the open path restores it cross-channel.
write_marker 🔒