Skip to content

Keep recorded branch labels stable across re-imports - #44

Merged
starkdmi merged 1 commit into
mainfrom
fix/stable-branch-labels
Oct 8, 2026
Merged

starkdmi merged 1 commit into
mainfrom
fix/stable-branch-labels

Conversation

@starkdmi

@starkdmi starkdmi commented Oct 8, 2026

Copy link
Copy Markdown
Owner

Summary

A project's branch label came from the record when it carried one, and otherwise from the checkout's HEAD at scan time. HEAD at scan time says nothing about where a past session ran, so a re-import made while a repository sat on another branch relabeled its history and moved those sessions' rollups to that branch.

  • Codex: session_meta records the branch, but turn_context repeats only the cwd. Each turn_context resolved the project again without a branch, fell back to HEAD, and overwrote the recorded branch, so almost every session took the checkout's branch. A turn in the directory session_meta named now keeps the remote and branch it recorded. A turn in another directory has no recorded branch.
  • HEAD fallback removed. A branch is labeled only when the record carries one, and is otherwise left unset. A recency heuristic would still guess, and would make parse output depend on when the scan ran.
  • OpenCode records no branch, so its sessions are no longer labeled.
  • Claude Code and Grok Build archive scans now pass the branch their records carry, instead of relying on the fallback.
  • Parser revisions bumped for Codex, Claude Code, OpenCode, and Grok Build. The first scan after upgrading rescans and re-archives them once, and drops every branch taken from a checkout's HEAD. Rollups for sessions whose branch changes are marked dirty once.

Verification

  • cargo fmt -p statsai-adapters, cargo clippy -p statsai-adapters --all-targets -- -D warnings, cargo test -p statsai-adapters

  • ./scripts/rust-ci.sh full (passed locally and in the pre-push hook)

  • New adapter tests re-scan the same sessions with different branches checked out:

    • A Codex session keeps its session_meta branch and hash across checkouts.
    • A Codex session without a git block, and a turn that moved to another directory, never take the checkout's HEAD.
    • An OpenCode session keeps its branch unset across checkouts.

    The three Codex tests fail with the fix reverted.

  • Ran the build against an isolated clone of a real store: a full rescan restored Codex sessions to the branches their records carry, and a second uncached rescan changed no branch label or hash.

A project's branch label came from the record when it carried one, and
otherwise from the checkout's HEAD at scan time. HEAD at scan time says
nothing about where a past session ran, so every re-import made while a
repository sat on another branch relabeled its history and moved those
sessions' rollups to the new branch.

Codex hit this on almost every session. `session_meta` records the
branch, but `turn_context` repeats only the cwd, and each one resolved the
project again without a branch and fell back to HEAD. A turn in the
directory `session_meta` named now keeps the remote and branch it
recorded. A turn in another directory has no recorded branch.

The HEAD fallback is gone. A branch is labeled only when the record
carries one, and is otherwise left unset. OpenCode records no branch, so
its sessions are no longer labeled. Claude Code and Grok Build archive
scans now pass the branch their records carry.

Codex, Claude Code, OpenCode, and Grok Build parser revisions are bumped,
so the first scan after upgrading rescans and re-archives them once and
drops every branch taken from a checkout's HEAD.
@starkdmi
starkdmi merged commit 8fecf2f into main Oct 8, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant