Here's my review of the feat/model-hint-persistence branch (8 commits, +570/-34 across 20 files):
Summary
This branch captures the LLM model name from agent hooks and persists it through to checkpoint metadata. The core challenge is that some agents report the model before SessionState exists (Claude Code on SessionStart, before TurnStart), so a lightweight .model hint file bridges the gap.
Architecture
The design is clean and well-reasoned:
Claude Code → model on SessionStart → hint file → read on TurnStart → into SessionState
Gemini CLI → model on BeforeModel (after TurnStart) → write directly to SessionState, fallback to hint file
Hint file cleaned up alongside state file in ClearSessionState and StateStore.Clear
The doc comment on StoreModelHint (lines 200-218 of session_state.go) is excellent — it explains the "why" clearly.
Issues
1. Hint file derived from state file path via string slicing — fragile
This assumes stateFile always ends in .json. If sessionStateFile() ever changes its extension, this silently breaks. Consider using strings.TrimSuffix or computing from sessionID directly:
The same pattern appears in session/state.go:349 (StateStore.Clear), which at least knows the sessionID and stateDir directly — but both could be more explicit.
2. Duplicate hint file cleanup in two layers
Both StateStore.Clear (session/state.go:349) and ClearSessionState (strategy/session_state.go:286-295) independently clean up .model hint files. This works but is a maintenance trap — if you add another hint file type (e.g., .agent), you need to remember to update both.
Consider whether the strategy layer should be the single owner of hint file lifecycle, since it's the one creating them.
3. handleLifecycleModelUpdate doesn't validate session ID
Other handlers (e.g., handleLifecycleSessionStart) call validation.ValidateSessionID(). This handler skips that, which means a malicious session ID could flow into StoreModelHint (which does validate) or LoadSessionState (which doesn't validate at the top level). Not a real security concern since the agent controls the input, but it's inconsistent with the pattern.
4. Model not populated on TurnEnd when session state already has it
In handleLifecycleTurnEnd (line 257), the model hint is only loaded from the hint file:
go
if event.Model == "" && sessionID != unknownSessionID {
if hint := strategy.LoadModelHint(ctx, sessionID); hint != "" {
But after TurnStart, the model is stored in SessionState.ModelName. If the hint file was already consumed and the state has the model, this still works because SaveStep likely reads from state.ModelName. But if any downstream code in handleLifecycleTurnEnd uses event.Model directly, it would be empty when:
The hint file doesn't exist (already cleaned up or never created)
The model was set via handleLifecycleModelUpdate directly into state
Worth checking if event.Model is used downstream in the turn-end flow, or if it's safe because the strategy reads from state.ModelName.
5. Minor: sessionInfoRaw consolidation dropped Model from SessionEnd
types.go now has Model on sessionInfoRaw with omitempty, which is used for both SessionStart and SessionEnd. This means SessionEnd payloads would parse a model field if present. Not a bug, but worth noting that the type is now wider than before.
Style Nits
lifecycle_test.go test cases for ModelUpdate only test the no-op paths (empty model, empty session ID). No test for the happy path where state exists or where the hint file is written. These are covered by session_state_test.go, but a lifecycle-level integration test would add confidence.
The factoryaidroid/transcript.go change (adding slog.Warn on corrupt settings) is a good improvement but seems like a drive-by fix unrelated to model hint persistence. Could be a separate commit for cleaner history.
What Looks Good
Thorough test coverage in session_state_test.go — round-trip, empty model no-op, missing file, path traversal, whitespace trimming, cleanup with/without state file
The StateStore.Clear test in state_test.go mirrors the strategy-layer tests — good layered coverage
Gemini BeforeModel tests cover both the happy path and the empty-model nil-event case
The consolidation of sessionStartRaw → sessionInfoRaw removes unnecessary duplication
Verdict
Solid feature. The hint file approach is pragmatic for the cross-process timing problem. The main thing I'd address is issue #1 (fragile string slicing) and issue #2 (dual-layer cleanup ownership). The rest are minor.
User
who creates the hintfile initially?
Assistant
Looking at the code flow, there are two entry points that create hint files:
1. handleLifecycleSessionStart (lifecycle.go:99-104) — for Claude Code, which sends model on its SessionStart hook (before any TurnStart):
go
if event.Model != "" {
if err := strategy.StoreModelHint(ctx, event.SessionID, event.Model); err != nil {
2. handleLifecycleModelUpdate (lifecycle.go:158-162) — fallback path for Gemini CLI's BeforeModel hook when session state doesn't exist yet:
go
if err := strategy.StoreModelHint(ctx, event.SessionID, event.Model); err != nil {
Though for Gemini, the primary path writes directly to SessionState.ModelName (lines 149-155) since BeforeModel typically fires afterTurnStart has already created the state. The hint file is only the fallback when state load fails.
Both ultimately call strategy.StoreModelHint() which writes to .git/entire-sessions/{session_id}.model.
User
let's change it to TrimSuffix
User
[Request interrupted by user for tool use]
User
could we not just remove any suffix? isn't there a filename helper for this?
Assistant
Yes — strings.TrimSuffix still hardcodes ".json". Go has filepath.Ext and you can pair it with strings.TrimSuffix:
But even simpler, there's no need to derive from stateFile at all. We already have sessionID and the directory. Let me check what's available.
Assistant
We can just use filepath.Dir(stateFile) + sessionID — but even better, we already have getSessionStateDir and this mirrors how StoreModelHint builds the path. Let me just use that directly:
User
[Request interrupted by user for tool use]
User
taking a step back: we want to remove anything for that session id anyhow, so couldn't we just simplify this an look for anyfile starting with the SessionId and delete it in this folder?
Assistant
Good call — that's much more future-proof. Instead of tracking each hint file type, just glob for sessionID.* and remove them all.
Assistant
Both locations — session/state.go:349-352 and strategy/session_state.go:286-295. Let me update both to glob for sessionID.*:
Assistant
Now let me check if the strings import is still needed:
Assistant
Still used in LoadModelHint. Now let me update the tests to match — they no longer need to derive the hint file path from the state file:
Assistant
Now check if the test file needs the filepath import:
Assistant
Need to add path/filepath:
Assistant
Now let me verify everything compiles and tests pass:
Assistant
There's a leftover stateFile variable in session/state.go. Let me fix that:
Assistant
The linter wants error checks in the test file. Let me also check if the production code has the same issue:
Assistant
4 occurrences total. The filepath.Glob error only happens on a malformed pattern (which ours isn't), but the linter insists. I'll use //nolint:errcheck for the production code (best-effort cleanup) and check the error in tests:
Assistant
But that second test reuses err — let me check:
Assistant
That reuses err with := which is fine since it's a new scope declaration. Let me run fmt+lint+tests:
Assistant
Clean. Now tests:
Assistant
All green. Both cleanup sites now glob for sessionID.* and remove everything, so adding new hint file types in the future requires zero changes to cleanup logic.
User
can you double check we are not writing any other files there we would want to keep?
Assistant
Now let me check what StateStore.List scans for — that's how sessions are discovered:
Assistant
The directory only contains files written by this codebase. Everything is sessionID-prefixed:
{sessionID}.json — session state (written by Save)
{sessionID}.json.tmp — atomic write temp file (renamed to .json)
{sessionID}.model — model hint (written by StoreModelHint)
List() filters to .json only, so .model and .tmp files are already ignored during enumeration. The glob sessionID.* will only match files for that specific session. No other session's files can match because session IDs are unique (date + UUID format).
This is safe. No collateral damage from the glob approach.