Skip to content

feat(route): expose affinity context after upstream attempts - #652

Merged
SantiagoDePolonia merged 1 commit into
mainfrom
fix/route-success-affinity
Aug 6, 2026
Merged

feat(route): expose affinity context after upstream attempts#652
SantiagoDePolonia merged 1 commit into
mainfrom
fix/route-success-affinity

Conversation

@SantiagoDePolonia

@SantiagoDePolonia SantiagoDePolonia commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Adds virtual-model source and session metadata to route outcomes so extensions can update prompt-cache affinity after the attempt that actually succeeds, including failover attempts.\n\nThis is the small core companion required by GoModel Pro PR #10.\n\nTests: go test ./ext ./internal/app; full pre-commit suite passed.

Summary by CodeRabbit

  • New Features

    • Route outcomes now include the originating model and client session details.
    • Requests using aliased workflows can preserve and report their requested model information.
  • Improvements

    • Enhanced route tracking helps provide clearer visibility into model selection and session-affinity behavior.

Copilot AI lite review requested due to automatic review settings August 5, 2026 22:47

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

RouteOutcome now records the originating virtual model and client session. Route-selector request-end hooks derive these values from request context, and tests verify the metadata after successful routing.

Changes

Route affinity metadata

Layer / File(s) Summary
Route outcome metadata
ext/route.go
RouteOutcome now includes Source and SessionID fields.
Request context integration
internal/app/app.go, internal/app/app_test.go
Request-end hooks derive workflow source and session data from context. Tests verify the reported values for successful routing.

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

Possibly related PRs

Suggested reviewers: copilot

Poem

A rabbit records each route,
With source and session in its pouch.
The hook reports what workflows chose,
Tests confirm the fields it shows.
Hop, hop—affinity now knows!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Title check ✅ Passed The title clearly summarizes the change to expose route affinity context after upstream attempts.
Description check ✅ Passed The description explains the change, purpose, related work, and tests, but does not use the template headings.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/route-success-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.

@SantiagoDePolonia SantiagoDePolonia changed the title Expose route affinity context after upstream attempts feat(route): expose affinity context after upstream attempts Aug 5, 2026

@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/app/app_test.go`:
- Around line 36-52: Add table-driven cases to
TestRouteSelectorHooksExposeSuccessfulRouteAffinityContext for a missing
workflow, missing resolution, and AliasApplied == false. For each case, invoke
routeSelectorHooks.OnRequestStart and OnRequestEnd with the existing request
context, then verify outcome.Source is empty while outcome.SessionID remains
"session-a"; retain the current alias-applied case and its expected "smart"
source.
🪄 Autofix

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: e13340b4-9214-4426-bf27-3c4bcc2bdc55

📥 Commits

Reviewing files that changed from the base of the PR and between 49ee2e5 and 127cc1b.

📒 Files selected for processing (3)
  • ext/route.go
  • internal/app/app.go
  • internal/app/app_test.go

Comment thread internal/app/app_test.go
Comment on lines +36 to +52
func TestRouteSelectorHooksExposeSuccessfulRouteAffinityContext(t *testing.T) {
selector := &routeObservationSelector{}
hooks := routeSelectorHooks(selector)
ctx := core.WithSessionID(context.Background(), "session-a")
ctx = core.WithWorkflow(ctx, &core.Workflow{Resolution: &core.RequestModelResolution{
Requested: core.NewRequestedModelSelector("smart", ""),
ResolvedSelector: core.ModelSelector{Provider: "openai", Model: "gpt"},
AliasApplied: true,
}})
ctx = hooks.OnRequestStart(ctx, llmclient.RequestInfo{Provider: "openai", Model: "gpt"})
hooks.OnRequestEnd(ctx, llmclient.ResponseInfo{Provider: "openai", Model: "gpt", StatusCode: http.StatusOK})

if selector.outcome.Source != "smart" || selector.outcome.SessionID != "session-a" {
t.Fatalf("route affinity context = %q/%q, want smart/session-a",
selector.outcome.Source, selector.outcome.SessionID)
}
}

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.

📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add cases for workflows without an applied alias.

This test covers only the alias-applied path. Add table-driven cases for a missing workflow, a missing resolution, and AliasApplied == false. Verify that Source is empty and SessionID remains available.

As per coding guidelines, “Tests should cover request translation, response normalization, error handling, default configuration, and provider-specific parameter mapping.”

🤖 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/app/app_test.go` around lines 36 - 52, Add table-driven cases to
TestRouteSelectorHooksExposeSuccessfulRouteAffinityContext for a missing
workflow, missing resolution, and AliasApplied == false. For each case, invoke
routeSelectorHooks.OnRequestStart and OnRequestEnd with the existing request
context, then verify outcome.Source is empty while outcome.SessionID remains
"session-a"; retain the current alias-applied case and its expected "smart"
source.

Source: Coding guidelines

@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 80.00000% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/app/app.go 80.00% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@greptile-apps

greptile-apps Bot commented Aug 5, 2026

Copy link
Copy Markdown

Confidence Score: 5/5

T-Rex T-Rex Logs

What T-Rex did

  • The focused regression test against HEAD demonstrated that the route outcome retained the originating affinity (Source and SessionID) across a failed primary and a successful failover.
  • A full set of tests, including race checks, was executed and all package and race-enabled tests passed.
  • A before-PR comparison in a detached worktree showed that building against HEAD^ would fail to compile without the new RouteOutcome.Source and RouteOutcome.SessionID fields, confirming the change introduces these fields.
  • Direct inspection of the changes located in internal/app/app.go and internal/llmclient/client.go showed how the affinity is obtained from the callback context and threaded into end hooks, validating the intended wiring.

View all artifacts

T-Rex Ran code and verified through T-Rex

Reviews (1): Last reviewed commit: "feat(route): expose affinity context on ..." | Re-trigger Greptile

@SantiagoDePolonia
SantiagoDePolonia merged commit 3b56e36 into main Aug 6, 2026
21 of 22 checks passed
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.

3 participants