Skip to content

Fix: inference-parser misses /chat/completions from /v1-less proxies (opencode, litellm) - #823

Merged
huang195 merged 1 commit into
mainfrom
fix/inference-parser-vless-paths
Aug 31, 2026
Merged

Fix: inference-parser misses /chat/completions from /v1-less proxies (opencode, litellm)#823
huang195 merged 1 commit into
mainfrom
fix/inference-parser-vless-paths

Conversation

@msteinder

@msteinder msteinder commented Aug 30, 2026

Copy link
Copy Markdown
Member

Why

OpenAI-compatible proxies such as litellm (used by opencode) post to /chat/completions without the /v1 prefix. The OnRequest dispatch switch in inference-parser only matched /v1/chat/completions and /v1/completions, so these requests fell through to the default: return Continue arm — pctx.Extensions.Inference was never populated and abctl showed for model, method, and token counts on every opencode request.

Observed before the fix:

9    14:13:56.91   out   │┌ req   —    —                    ete-litellm.ai-mode…
9    14:13:59.27   out   │└ resp  —    —    200  2.36s       ete-litellm.ai-mode…

What changed

authbridge/authlib/plugins/inferenceparser/plugin.go

  • Extended the OnRequest switch case to also match /chat/completions and /completions.

authbridge/authlib/plugins/inferenceparser/plugin_test.go

  • Added TestInferenceParser_VlessPath_ChatCompletions and TestInferenceParser_VlessPath_Completions.

No changes to OnResponse or OnResponseFrame — the default branch there already routes to the OpenAI parsers, which is correct.

Testing

$ cd authbridge/authlib && go test ./plugins/inferenceparser/...
ok  github.com/rossoctl/cortex/authbridge/authlib/plugins/inferenceparser

Verified end-to-end: opencode requests through authbridge-proxy --demo now show model, token counts, and method in abctl.

Related issue(s)

Fixes #822

Assisted-By: Claude (Anthropic AI) noreply@anthropic.com

Summary by CodeRabbit

  • Bug Fixes
    • Added support for OpenAI-compatible /chat/completions and /completions endpoints without the /v1 prefix.
    • Requests through compatible proxies are now correctly parsed, including model details and action tracking.

OpenAI-compatible proxies (e.g. litellm used by opencode) post to
/chat/completions without the /v1 prefix. The OnRequest dispatch switch
only matched /v1/chat/completions and /v1/completions, so requests fell
through to the default arm and pctx.Extensions.Inference was never
populated — resulting in missing model, token counts, and method fields
in abctl session views.

Extend the switch to also match /chat/completions and /completions.
No changes to OnResponse or OnResponseFrame — the default branch there
already routes to the OpenAI parsers.

Add two tests: TestInferenceParser_VlessPath_ChatCompletions and
TestInferenceParser_VlessPath_Completions.

Fixes #822

Signed-off-by: steinder <steinder@us.ibm.com>
@coderabbitai

coderabbitai Bot commented Aug 30, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 430ff944-b13b-46c3-b1e0-c94f6351ec9a

📥 Commits

Reviewing files that changed from the base of the PR and between cb8bceb and 4bcb677.

📒 Files selected for processing (2)
  • authbridge/authlib/plugins/inferenceparser/plugin.go
  • authbridge/authlib/plugins/inferenceparser/plugin_test.go

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The inference parser now handles OpenAI-compatible /chat/completions and /completions paths without the /v1 prefix. Tests verify inference metadata, model extraction, and parser continuation.

Changes

OpenAI endpoint support

Layer / File(s) Summary
Unversioned endpoint dispatch and validation
authbridge/authlib/plugins/inferenceparser/plugin.go, authbridge/authlib/plugins/inferenceparser/plugin_test.go
The request parser accepts unversioned chat and completion paths. Tests verify parsed models, inference extensions, action state, and Continue results.

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

Merge Risk: ⚪ Minimal · up to 4bcb6

The change enables metadata extraction for two additional compatible completion paths using the existing parsing behavior, with no change to authorization, routing, or request handling. No actionable merge-blocking risk remains.

Suggested reviewers: huang195, ibrahim2595

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 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 Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the inference-parser fix for /v1-less OpenAI-compatible proxy paths. It is concise and directly related to the primary change.
Linked Issues check ✅ Passed The changes satisfy issue #822 by adding /chat/completions and /completions to OnRequest path matching. The added tests verify inference parsing for both paths, including model capture and action stat…
Out of Scope Changes check ✅ Passed All code and test changes directly support issue #822. No unrelated or out-of-scope changes are present.
Full details: Linked Issues check

Explanation

The changes satisfy issue #822 by adding /chat/completions and /completions to OnRequest path matching. The added tests verify inference parsing for both paths, including model capture and action status.

  • Fix all pre-merge checks with AI
✨ 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/inference-parser-vless-paths

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.

@mrsabath mrsabath 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.

Summary

Correct, minimal, well-scoped fix. Extends the OnRequest dispatch to match the /v1-less /chat/completions and /completions variants that litellm/opencode emit, restoring model and token telemetry in abctl.

What I verified against the source (PR head 4bcb677):

  • endpointPath() strips the query string via strings.Cut(path, "?"), so the new exact-match cases stay robust for /chat/completions?foo=bar.
  • Response side needs no change: OnResponse gates only on anthropicMessagesPath and defaults everything else to the OpenAI parsers, but it only runs when ext was populated on the request. So the request-switch fix is what unblocks the response telemetry too, end-to-end.
  • Legacy /completions (prompt-based) routed to parseOpenAIRequest still captures model + sampling params + IsAction correctly, which is exactly the telemetry intended.
  • Tests assert the real regression (Extensions.Inference != nil, correct Model, IsAction) using the same pipeline.Context{Path:...} shape the code reads.

My only note is the symmetric /messages gap for Anthropic-compatible proxies (inline), which is a non-blocking follow-up.

Areas reviewed: Go (inference-parser plugin + tests), Tests, commit/PR conventions.
Commits: 1, signed-off, conventional prefix, under 72 chars. CI: all green (Go CI x3, CodeQL go/python, Bandit, Trivy, pre-commit, CodeRabbit).

Verdict: APPROVE — no must-fix issues; the single comment is a suggestion for a follow-up.

var ext *pipeline.InferenceExtension
switch endpointPath(pctx) {
case "/v1/chat/completions", "/v1/completions":
case "/v1/chat/completions", "/v1/completions", "/chat/completions", "/completions":

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.

suggestion (non-blocking): same-class gap on the Anthropic side. anthropicMessagesPath is /v1/messages, so a /v1-stripping proxy (this PR's exact scenario) posting Anthropic-style traffic to /messages would still fall through to the default arm and record no inference telemetry. Out of scope for #822, but worth a follow-up (or a matching /messages case here) so the asymmetry is a deliberate choice rather than an oversight.

@huang195
huang195 merged commit f84cb50 into main Aug 31, 2026
22 checks passed
@huang195
huang195 deleted the fix/inference-parser-vless-paths branch August 31, 2026 23:12
@github-project-automation github-project-automation Bot moved this from New/ToDo to Done in Rossoctl Issue Prioritization Aug 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Fix: inference-parser misses /chat/completions requests from OpenAI-compatible proxies (opencode, litellm)

4 participants