Skip to content

fix: snapshot persistence rewrites transcripts without updating user-turn/activity metadata#836

Closed
sam-saffron-jarvis wants to merge 1 commit into
SamSaffron:mainfrom
sam-saffron-jarvis:feat/codereview-04ff6031
Closed

fix: snapshot persistence rewrites transcripts without updating user-turn/activity metadata#836
sam-saffron-jarvis wants to merge 1 commit into
SamSaffron:mainfrom
sam-saffron-jarvis:feat/codereview-04ff6031

Conversation

@sam-saffron-jarvis

Copy link
Copy Markdown
Contributor

What changed

  • Updated internal/session.SQLiteStore.ReplaceMessages to recompute and persist session metadata in the same transaction as the transcript rewrite.
  • The replace path now refreshes:
    • user_turns
    • last_user_message_at
    • last_message_at
    • existing compaction-boundary clearing / updated_at
  • Added a regression test covering both failure modes:
    • initial ReplaceMessages must populate the metadata from the persisted transcript
    • rerunning ReplaceMessages with an unchanged prefix must preserve the original persisted activity timestamps instead of deriving them from freshly rebuilt in-memory snapshot timestamps

Why this is high-value

persistSnapshot is used for durable pre-stream saves, replace-history runs, and reconciliation after persistence errors. Before this change, it could successfully rewrite the transcript rows while leaving session metadata stale because it relied on store.Update(...), and Update intentionally does not write turn counters. That produced real sessions whose transcript existed but whose user-turn count and activity timestamps stayed at 0/NULL/old values.

This directly affects sidebar ordering and exported session stats, especially when a run fails before later append-only callbacks can repair the metadata.

Validation

  • gofmt -w internal/session/sqlite.go internal/session/sqlite_test.go
  • go build ./...
  • go test ./...
  • Added regression test: TestSQLiteStoreReplaceMessagesRecomputesActivityMetadata

@SamSaffron SamSaffron closed this Jun 19, 2026
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