Skip to content

feat(ext): expose the detected session ID to request rewriters - #612

Open
SantiagoDePolonia wants to merge 2 commits into
feat/ext-route-selectorfrom
feat/ext-session-id
Open

feat(ext): expose the detected session ID to request rewriters#612
SantiagoDePolonia wants to merge 2 commits into
feat/ext-route-selectorfrom
feat/ext-session-id

Conversation

@SantiagoDePolonia

@SantiagoDePolonia SantiagoDePolonia commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds SessionID to ext.Input. Session detection (SessionCapture) already runs before RequestRewriteMiddleware, so the user-path-scoped session ID is in the request context when rewriters fire — this just surfaces it.

Motivation: lets a rewriter keep per-conversation decisions stable across messages, e.g. GoModel Pro's content-aware tier router pinning its easy/hard model choice to the session instead of re-deciding (and potentially flip-flopping) on every message.

Stacked on #611 (base: feat/ext-route-selector); rebase to main if it lands first.

Tests

TestRequestRewriteMiddlewareExposesSessionID — stamps a session via ExtraMiddleware (which runs before rewriters, standing in for the detector) and asserts the rewriter observes it.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Request rewriters can now access the detected client session ID via the rewrite input, enabling consistent decisions across a conversation.
  • Bug Fixes
    • Session information is now correctly carried through the request-rewriting flow so it’s available to rewriters as expected.
  • Tests
    • Added coverage to verify request rewriters receive the expected session ID during rewriting.

@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@SantiagoDePolonia, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 16 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: a23252a3-756a-4e09-b03c-f9a79184d4ac

📥 Commits

Reviewing files that changed from the base of the PR and between 1a3bd5b and 5a91572.

📒 Files selected for processing (3)
  • ext/ext.go
  • internal/server/request_rewrite.go
  • internal/server/request_rewrite_test.go
📝 Walkthrough

Walkthrough

ext.Input now exposes the detected session ID to request rewriters. RequestRewriteMiddleware populates it from request context, and a test verifies propagation through session stamping and rewriting.

Changes

Session ID propagation

Layer / File(s) Summary
Session ID input and middleware propagation
ext/ext.go, internal/server/request_rewrite.go, internal/server/request_rewrite_test.go
ext.Input includes a path-scoped SessionID; request rewriting copies it from context, and middleware coverage verifies that rewriters receive the stamped value.

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

Poem

A rabbit twitched its nose with glee,
“A session tag now hops along!”
Through context fields and rewrite paths,
The rewriter finds where it belongs.
“sess-42!” we cheer in song.

🚥 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%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly states the main change: exposing detected session IDs to request rewriters.
Description check ✅ Passed It covers what changed, why, and testing, though it uses Summary/Tests instead of the template's Description section.
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
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/ext-session-id

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 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.

Inline comments:
In `@internal/server/request_rewrite_test.go`:
- Around line 122-154: Convert TestRequestRewriteMiddlewareExposesSessionID into
a table-driven test covering both a populated session ID and an absent session
ID. For each case, configure the session-stamping middleware accordingly,
execute the request, and assert the rewriter observes the expected session
value, including an empty default when no session is present.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: ef829019-e33f-432e-920d-8082be09d54a

📥 Commits

Reviewing files that changed from the base of the PR and between c31d624 and 3d71ff7.

📒 Files selected for processing (3)
  • ext/ext.go
  • internal/server/request_rewrite.go
  • internal/server/request_rewrite_test.go

Comment thread internal/server/request_rewrite_test.go
@greptile-apps

greptile-apps Bot commented Jul 28, 2026

Copy link
Copy Markdown

Confidence Score: 5/5

The PR appears safe to merge with no actionable defects identified.

The session-capture middleware runs before request rewriting and stores the identifier in the same request context from which the new field is populated; existing repository construction of the extended input uses keyed fields.

Files Needing Attention: No files need attention.

T-Rex T-Rex Logs

What T-Rex did

  • The TestRequestRewriteMiddlewareExposesSessionID test was executed and passed with a 200 status for POST /v1/chat/completions.
  • The server package gomodel/internal/server reported an ok result in about 0.007 seconds.
  • A log artifact captures the test run evidence for review and verification.

View all artifacts

T-Rex Ran code and verified through T-Rex

Reviews (1): Last reviewed commit: "feat(ext): expose the detected session I..." | Re-trigger Greptile

SantiagoDePolonia and others added 2 commits July 28, 2026 19:49
Session detection already runs before the rewrite middleware, so the
scoped session ID is sitting in the request context when rewriters fire.
Surfacing it on ext.Input lets a rewriter keep per-conversation decisions
stable — for example pinning a model-tier choice to the session instead
of re-deciding on every message.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@SantiagoDePolonia

Copy link
Copy Markdown
Contributor Author

Converted the session-propagation test to table-driven cases (detected session propagates / no session yields empty) in 5a91572, and rebased on the latest #611.

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.

1 participant