Skip to content

fix(virtualmodels): persist session_affinity in the MongoDB store - #734

Open
SantiagoDePolonia wants to merge 1 commit into
mainfrom
fix/mongo-session-affinity
Open

fix(virtualmodels): persist session_affinity in the MongoDB store#734
SantiagoDePolonia wants to merge 1 commit into
mainfrom
fix/mongo-session-affinity

Conversation

@SantiagoDePolonia

@SantiagoDePolonia SantiagoDePolonia commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

The MongoDB virtual-models store never wrote or read `session_affinity`: the document struct had no field for it, `Upsert` did not `$set` it, and the decoder dropped it. On MongoDB, setting `session_affinity: false` on a load-balanced redirect silently reverted to the default (sticky sessions enabled) on the next refresh. The SQL stores were unaffected.

This adds the field to the Mongo document, writes it on upsert, reads it back, and extends the cross-backend store round-trip test so an explicit `false` survives and an unset value stays `nil`. The test fails on `main` against MongoDB and passes with the fix; SQLite and PostgreSQL pass before and after.

Summary by CodeRabbit

  • Bug Fixes
    • Session affinity settings now persist correctly when virtual models are saved and loaded.
    • Redirect configurations explicitly set to disabled retain that setting.
    • Policies without a session affinity value continue to preserve an unset state.

@coderabbitai

coderabbitai Bot commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: f7c1c888-6cde-423c-97f1-aa0015475284

📥 Commits

Reviewing files that changed from the base of the PR and between 9829580 and 3d2f546.

📒 Files selected for processing (2)
  • internal/virtualmodels/store_mongodb.go
  • internal/virtualmodels/store_test.go

Included review availability: Your plan provides up to 4 included reviews per hour; 2 remain after this review.


📝 Walkthrough

Walkthrough

MongoDB virtual model persistence now stores and restores the optional SessionAffinity field. Round-trip tests verify both explicit false and unset nil values.

Changes

Virtual model persistence

Layer / File(s) Summary
Session affinity storage and validation
internal/virtualmodels/store_mongodb.go, internal/virtualmodels/store_test.go
MongoDB documents and upserts now include session_affinity. Reads restore SessionAffinity. Tests verify explicit false and unset nil values.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 3d2f5

This change preserves the session-affinity setting in MongoDB-backed virtual models, including an explicit false value, while leaving other backends unchanged. No actionable merge-blocking risk remains after normal checks and review.

Poem

A rabbit checks the BSON trail,
False stays false without fail.
Nil remains neatly unset,
Round trips pass with no regret.
Hop, hop—the fields are met!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description check ✅ Passed The description clearly explains the bug, implementation, test coverage, and impact; it omits the template heading but includes the required information.
Title check ✅ Passed The title clearly and concisely identifies the MongoDB persistence fix for session_affinity.
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.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/mongo-session-affinity

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 0% with 20 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/virtualmodels/store_mongodb.go 0.00% 20 Missing ⚠️

📢 Thoughts on this report? Let us know!

@greptile-apps

greptile-apps Bot commented Aug 22, 2026

Copy link
Copy Markdown

Confidence Score: 5/5

Safe to merge based on successful MongoDB integration coverage of the changed persistence behavior.

The reviewed change has no remaining findings. The executed test covered all three session-affinity states and both transitions that clear a previously stored explicit value.

Files Needing Attention: No files need changes. internal/virtualmodels/store_mongodb.go and internal/virtualmodels/store_test.go were covered by the persistence validation.

T-Rex T-Rex Logs

What T-Rex did

  • A focused authored Go integration test against a disposable Docker MongoDB replica set was executed.
  • The test exercised first-write round trips for explicit false, explicit true, and unset SessionAffinity, plus updates from false to unset and true to unset.
  • All five test cases passed, confirming that the MongoDB store preserves the three-state value and clears a previously explicit value when updated to unset.
  • The test command and exact observed output were captured in the trex-artifacts/session-affinity-02-after.log file.
  • The focused integration test source was captured in trex-artifacts/session-affinity-01-before.go, and no product code was modified; the test was copied into the package for execution and removed afterward.

View all artifacts

T-Rex Ran code and verified through T-Rex

Reviews (1): Last reviewed commit: "fix(virtualmodels): persist session_affi..." | Re-trigger Greptile

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