Skip to content

Fix response-tracking and analytics for enforce routes and deployment edges (OSP-101)#5

Draft
BenItBuhner wants to merge 1 commit into
mainfrom
cursor/fix-response-tracking-analytics-053f
Draft

Fix response-tracking and analytics for enforce routes and deployment edges (OSP-101)#5
BenItBuhner wants to merge 1 commit into
mainfrom
cursor/fix-response-tracking-analytics-053f

Conversation

@BenItBuhner

Copy link
Copy Markdown
Owner

Summary

Fixes OSP-101: response-tracking and analytics were unreliable for some models and routing edges (notably custom deployments like Minimax M3).

Root causes addressed:

  1. Enforce mode dropped x-opencode-* headers — OpenAI routes built session headers but EnforceRouter never forwarded them to FallbackRouter, breaking upstream/session-scoped response counting when enforce was enabled.
  2. Winning route never recordedrecordRequestFinish supported resolvedProvider / resolvedModel but routes only logged the logical model, so per-edge analytics in the dashboard showed .
  3. No lifetime counters — the dashboard only reflected the last fetched window (15 records), not responses since process start.
  4. Reasoning models misclassified as empty — enforce treated content: null + reasoning_content as empty, causing false retries/failures for models like Minimax M3.
  5. Deployment URL templates ignored{model} / {{model}} in provider endpoint paths (e.g. Azure-style deployments) were not substituted.
  6. Streaming client aborts orphaned logs — aborted streams could skip recordRequestFinish.

Changes

  • Thread extraHeaders and resolvedRoute through EnforceRouterFallbackRouter
  • Record winning provider/model on every finish path (OpenAI + Anthropic)
  • Add process-lifetime request_stats to /health/detailed and /v1/admin/logs
  • Dashboard Responses card now shows finished count since start with ok/err breakdown
  • Treat reasoning_content / reasoning / thinking as non-empty in enforce validation
  • Substitute {model} in buildEndpointUrl using upstream model id
  • Shared buildUpstreamExtraHeaders helper; Anthropic routes now forward session headers too
  • Stream cancel() handler logs client-aborted requests (status 499)

Testing

  • bun test tests/enforce-router.test.ts tests/enforce-validator.test.ts tests/request-log.test.ts tests/provider-helpers.test.ts tests/fallback-router.test.ts — all pass
  • Full suite: 148 pass (3 pre-existing opencode-provider config fixture failures unrelated to this change)
  • bun run typecheck — passes (excluding pre-existing models-list.test.ts typing noise)

Linear

Resolves OSP-101

Linear Issue: OSP-101

Open in Web Open in Cursor 

… edges

- Thread x-opencode-* extraHeaders through EnforceRouter so session-scoped
  upstream analytics keep working when enforce mode is enabled
- Record winning provider/model on request finish for per-edge visibility
- Add process-lifetime response counters exposed via /health/detailed and
  /v1/admin/logs; dashboard now shows responses since process start
- Treat reasoning_content and similar vendor fields as non-empty in enforce
  validation so reasoning models (e.g. Minimax M3) are not falsely retried
- Substitute {model}/{{model}} in provider endpoint URLs for deployment edges
- Log client-aborted streams and forward session headers on Anthropic routes

Co-authored-by: Bennett Buhner <BenItBuhner@users.noreply.github.com>
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