Skip to content

refactor(database): dry session entry data#68

Merged
omarluq merged 2 commits into
mainfrom
refactor/database-session-store-dry
May 31, 2026
Merged

refactor(database): dry session entry data#68
omarluq merged 2 commits into
mainfrom
refactor/database-session-store-dry

Conversation

@omarluq
Copy link
Copy Markdown
Owner

@omarluq omarluq commented May 31, 2026

Summary

  • centralize zero-value session entry data construction
  • reduce boilerplate in session append helpers
  • keep session persistence behavior unchanged

Validation

  • mise exec -- go test ./internal/database
  • mise exec -- task ci
  • cr review --agent -t uncommitted --base main (timed out before findings)

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 31, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 88ec6ead-2b2d-49f6-b097-a893ab4189fc

📥 Commits

Reviewing files that changed from the base of the PR and between 5cbacdd and 596fa10.

📒 Files selected for processing (1)
  • internal/database/session_store.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/database/session_store.go

📝 Walkthrough

Summary by CodeRabbit

  • Refactor
    • Reworked how session entry data defaults are created and serialized to ensure consistent default values across all entry types.
    • Centralized default initialization so writes and reads behave uniformly, reducing subtle decoding differences when empty data is encountered.
    • Improves maintainability and predictability of session data handling without changing public interfaces.

Walkthrough

A single-file refactor centralizes EntryDataEntity default initialization in newEntryData() and updates six Append methods plus the decoder to build/initialize payloads from that helper before JSON (un)marshalling.

Changes

EntryDataEntity Default Centralization

Layer / File(s) Summary
Central default factory
internal/database/session_store.go
New newEntryData() helper returns an EntryDataEntity with all fields set to Go zero/default values.
Serialize and decode via default factory
internal/database/session_store.go
AppendCustomMessage, AppendThinkingLevelChange, AppendCompaction, AppendBranchSummary, AppendLabelChange, AppendSessionInfo now build JSON payloads by calling newEntryData() and setting only relevant fields; dataFromEntry initializes via newEntryData() before unmarshalling.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • omarluq/librecode#15: Related changes to EntryDataEntity/entry metadata fields that interact with session_store's JSON handling.

Poem

🐰 A little helper hopped in place,
Bringing defaults to every case—
No more scattered struct-littered trails,
Each Append now tells the same tales,
Quiet rabbit, tidy pace.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main refactoring change—centralizing session entry data construction through a DRY (Don't Repeat Yourself) approach, which aligns with the file changes shown in the summary.
Description check ✅ Passed The description is directly related to the changeset, outlining the centralization of zero-value construction, reduction of boilerplate, and validation performed, all consistent with the refactoring work shown.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/database-session-store-dry

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 31, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 62.42%. Comparing base (2e9e609) to head (596fa10).

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #68      +/-   ##
==========================================
- Coverage   62.64%   62.42%   -0.23%     
==========================================
  Files         188      188              
  Lines       17910    17803     -107     
==========================================
- Hits        11220    11113     -107     
  Misses       5591     5591              
  Partials     1099     1099              
Flag Coverage Δ
unittests 62.42% <100.00%> (-0.23%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
internal/database/session_store.go (1)

182-203: ⚡ Quick win

Consider simplifying newEntryData() to leverage Go's zero-value initialization.

In Go, the zero value of a struct is automatically initialized when using a struct literal. This function explicitly sets every field to its zero value, which is redundant:

EntryDataEntity{}  // Automatically gives: nil pointers, nil maps, false bools, 0 ints, "" strings

The current implementation increases maintenance burden because every new field added to EntryDataEntity must also be added here, whereas Go's zero-value initialization handles this automatically.

♻️ Proposed simplification
 func newEntryData() EntryDataEntity {
-	return EntryDataEntity{
-		Details:                    nil,
-		Display:                    nil,
-		FromHook:                   false,
-		FirstKeptEntryID:           "",
-		FromID:                     "",
-		Label:                      nil,
-		Name:                       "",
-		TargetID:                   "",
-		ThinkingLevel:              "",
-		ToolName:                   "",
-		ToolStatus:                 "",
-		ToolArgsJSON:               "",
-		TokenEstimate:              0,
-		ModelFacing:                nil,
-		CompactionFirstKeptEntryID: "",
-		CompactionTokensBefore:     0,
-		BranchFromEntryID:          "",
-		TokensBefore:               0,
-	}
+	return EntryDataEntity{}
 }

Or, if the only purpose is DRY and consistency, consider removing newEntryData() entirely and using EntryDataEntity{} directly at each call site, since the zero value is well-understood in Go.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/database/session_store.go` around lines 182 - 203, The newEntryData
function redundantly sets every field of EntryDataEntity to its zero value;
simplify by returning the zero-valued struct directly (i.e., return an
EntryDataEntity{}), or remove newEntryData and replace its call sites with
EntryDataEntity{} to avoid future maintenance when fields are added; update or
remove references to newEntryData accordingly so callers use the zero-value
struct.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@internal/database/session_store.go`:
- Around line 182-203: The newEntryData function redundantly sets every field of
EntryDataEntity to its zero value; simplify by returning the zero-valued struct
directly (i.e., return an EntryDataEntity{}), or remove newEntryData and replace
its call sites with EntryDataEntity{} to avoid future maintenance when fields
are added; update or remove references to newEntryData accordingly so callers
use the zero-value struct.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0f0f895f-c6e3-4406-97b7-65b78b3f9eaf

📥 Commits

Reviewing files that changed from the base of the PR and between 2e9e609 and 5cbacdd.

📒 Files selected for processing (1)
  • internal/database/session_store.go

coderabbitai[bot]
coderabbitai Bot previously approved these changes May 31, 2026
@sonarqubecloud
Copy link
Copy Markdown

@omarluq omarluq merged commit 76ed333 into main May 31, 2026
13 checks passed
@omarluq omarluq deleted the refactor/database-session-store-dry branch May 31, 2026 00:33
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