Skip to content

Hash session+branch for sidecar dedup (FACT-176)#330

Merged
michael-webster merged 2 commits into
mainfrom
impl/fact-176-sidecar-branch-dedup
May 22, 2026
Merged

Hash session+branch for sidecar dedup (FACT-176)#330
michael-webster merged 2 commits into
mainfrom
impl/fact-176-sidecar-branch-dedup

Conversation

@michael-webster
Copy link
Copy Markdown
Contributor

@michael-webster michael-webster commented May 13, 2026

Summary

  • Sidecar state files are now named sidecar.<sessionID>-<hash8>.json where hash8 = sha256(sessionID + ":" + branch)[:4], so concurrent sessions and different branches each get isolated state without the raw branch name appearing in the filename.
  • Auto-named sidecars (created by chunk validate when no active sidecar exists) now use the same <base>-<sessionID>-<hash8> scheme instead of embedding the raw branch string directly. Falls back to the sanitised branch name when no session ID is present.

Test plan

  • go test -race ./internal/sidecar/... — unit tests for sidecarFileName hash stability and per-branch uniqueness
  • go test -race ./internal/cmd/... — unit tests for sidecarAutoName with/without session ID
  • Acceptance tests: TestValidateHookMode_SessionIsolation verifies two concurrent sessions see separate state files

🤖 Generated with Claude Code

@michael-webster michael-webster force-pushed the impl/fact-176-sidecar-branch-dedup branch from c95fa6d to 0a51546 Compare May 13, 2026 15:31
@michael-webster michael-webster changed the title checkpoint the claude work. Hash session+branch for sidecar dedup (FACT-176) May 13, 2026
@michael-webster michael-webster marked this pull request as ready for review May 13, 2026 15:36
@michael-webster michael-webster force-pushed the impl/fact-176-sidecar-branch-dedup branch from 0a51546 to 916d4f6 Compare May 13, 2026 15:51
@schurchleycci
Copy link
Copy Markdown
Contributor

Two things from claude:

currentBranch logic is duplicated in three places — the same git -C <dir> rev-parse --abbrev-ref HEAD pattern appears in internal/sidecar/active.go (as currentBranch()), inlined inside sidecarAutoName() in internal/cmd/validate.go, and again as gitCurrentBranch() in the acceptance test. Since cmd/validate.go already imports internal/sidecar, the simplest fix is to export currentBranch as sidecar.CurrentBranch and use it in both call sites. The acceptance test helper can stay local.

TestSidecarFileNameCases hollow assertion for the both-present case — the test checks structural properties of the filename (prefix, suffix, hash length) rather than the actual value. Since the hash is deterministic, consider pinning it directly using hashFor():

{"sess-1", "main", "sidecar.sess-1-" + hashFor("sess-1", "main") + ".json"},

Regressions become immediately visible without having to parse the filename apart.

Copy link
Copy Markdown
Contributor

@schurchleycci schurchleycci left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comments from Claude seem worth addressing, but otherwise this looks good!

- Sidecar state files are now named sidecar.<sessionID>-<hash8>.json
  where hash8 = sha256(sessionID+":"+branch)[:4], isolating concurrent
  sessions and branches without exposing raw branch names in filenames.
- Auto-named sidecars use the same <base>-<sessionID>-<hash8> scheme;
  falls back to sanitised branch name when no session ID is present.
- Export sidecar.CurrentBranch so cmd/validate.go can reuse it instead
  of duplicating the git invocation inline.
- Pin hash assertions in tests with hashFor() instead of structural checks.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@michael-webster michael-webster force-pushed the impl/fact-176-sidecar-branch-dedup branch from 7d735f7 to da8fa2d Compare May 22, 2026 20:00
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@michael-webster michael-webster merged commit d48d9fa into main May 22, 2026
6 checks passed
@michael-webster michael-webster deleted the impl/fact-176-sidecar-branch-dedup branch May 22, 2026 23:30
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.

2 participants