codex-lb icon indicating copy to clipboard operation
codex-lb copied to clipboard

feat: add an upstream facet to dashboard request logs

Open joschi655 opened this issue 3 months ago • 2 comments

Pre-flight checklist

  • [x] I searched existing issues and discussions for similar proposals.
  • [x] This is a concrete proposal, not an open-ended question.

Problem / motivation

Request logs already persist and return modelSourceId and modelSourceKind for configured model-source traffic (#1129), but the dashboard neither displays nor filters by them.

As a result:

  • model-source requests appear as Unassigned in the Account column;
  • two sources serving the same model slug cannot be distinguished;
  • operators cannot isolate source-specific failures, latency, or cost;
  • historical traffic from a deleted source retains its stable source ID, but the dashboard provides no way to find or identify it.

Proposed change

Add an Upstream multi-select facet to the existing Request Logs view.

The facet uses observed request-log data, not merely currently configured sources, with this exhaustive taxonomy:

  • subscription_pool: rows where model_source_id IS NULL. This means the built-in subscription route family, including failures that occurred before a particular account was selected; it is not a claim that an account successfully served the request.
  • <model-source-id>: rows whose model_source_id exactly matches that stable source ID. Source kind remains display metadata rather than filter identity.

Proposed additive API shape:

GET /api/request-logs?upstream=subscription_pool&upstream=src_abc
{
  "upstreams": [
    {
      "id": "subscription_pool",
      "type": "subscription_pool",
      "displayName": null,
      "modelSourceKind": null,
      "isDeleted": false
    },
    {
      "id": "src_abc",
      "type": "model_source",
      "displayName": "Local vLLM",
      "modelSourceKind": "openai_compatible",
      "isDeleted": false
    }
  ]
}

Multiple values use OR semantics; this facet combines with the existing account, API-key, model, status, and timeframe filters using AND semantics. The upstream options facet should ignore its own current selection so another upstream can be added without clearing the first.

Options should contain only upstreams observed in matching, non-soft-deleted request logs. Current model-source names may be resolved from model_sources, but the stable ID remains authoritative:

  • renamed source: show its current name and retain the same filter ID;
  • duplicate names: disambiguate with the source ID;
  • deleted source: keep the option and show a localized Deleted model source · <id> fallback using the persisted kind;
  • never expose source base URLs, credentials, or API-key material.

The dashboard should show a compact model-source badge on source-routed rows and the full upstream ID/kind in request details. The filter can stay hidden when only one observed upstream option exists and no upstream filter is active, so subscription-only installations retain their current UI.

Compatibility and performance

This is additive and migration-free:

  • model_source_id, model_source_kind, and idx_logs_model_source_time already exist;
  • rows predating model sources correctly classify as subscription_pool;
  • requests without the new query parameter retain their filtering semantics;
  • source routing, selection, fallback, accounting, and client responses do not change;
  • there is no new setting, navigation item, README section, or deployment step.

The unfiltered upstream facet should follow the existing bounded facet contract: skip-scan distinct source IDs through idx_logs_model_source_time, plus one indexed NULL-presence probe for subscription_pool. Filtered option requests may retain the existing bounded DISTINCT path.

Because the demand rollup does not contain model_source_id, an active upstream filter must use the exact raw/indexed count path and include its selection in the request-log count-cache key rather than returning an incorrect rollup total.

First PR boundary

One focused Request Logs PR:

  • additive list/options API contract;
  • backend filtering and deleted-source label resolution;
  • URL-backed dashboard multi-select;
  • compact row/detail attribution;
  • localized labels in the existing dashboard locales;
  • OpenSpec change add-request-log-upstream-facet;
  • before/after screenshots.

Out of scope for this first PR:

  • Reports or overview aggregation by source;
  • a new provider discriminator or database migration;
  • routing/fallback behavior;
  • account-selection diagnostics;
  • model-source CRUD changes.

A reports facet can be considered separately because current report/demand rollups do not carry the source dimension.

Tests

  • subscription-only, individual-source, and mixed OR filtering;
  • source with the same model slug as another source;
  • deleted-source option and stable-ID filtering;
  • soft-deleted request-log exclusion;
  • upstream self-facet exemption and cross-facet behavior;
  • count-cache isolation and exact total when demand rollups exist;
  • unfiltered skip-scan parity on SQLite and PostgreSQL;
  • frontend URL persistence, reset, hidden single-option behavior, deleted fallback, badge/detail rendering, and older-response compatibility.

Alternatives considered

  • Infer the upstream from the model slug: ambiguous when multiple sources serve the same slug.
  • Join only currently configured sources: loses historical traffic after source deletion.
  • Add a new provider column: duplicates the existing generic source attribution and requires an unnecessary migration.
  • Include Reports immediately: expands the change into rollup/schema work and weakens the one-concern PR boundary.

Area

  • Dashboard UI
  • OpenSpec / docs

Additional context

  • Model-source foundation and request attribution: #1129
  • Embeddings request-log accounting: #1776
  • Request-log facet query contract: #1239
  • Request-log total rollup contract: #1615
  • Configurable request-log columns: #1503
  • Adjacent routing UX umbrella, not a duplicate: #1708

joschi655 avatar Aug 21 '26 16:08 joschi655

Checked against main 09a140fa9: the request-log API still has no source filter (app/modules/request_logs/api.py:75-88) and the dashboard parses but never shows modelSourceId/modelSourceKind. The proposed first-PR boundary (additive upstream query param + options facet, deleted-source fallback label, count-cache key includes the selection, no migration, no setting) fits the contribution rules. A PR needs an OpenSpec change, i18n for the new labels in all dashboard locales, and before/after screenshots.

Soju06 avatar Sep 28 '26 08:09 Soju06

I'd like to work on this, inside the first-PR boundary from your Sept 28 comment: additive upstream param and options facet, deleted-source fallback label, count-cache key that includes the selection, no migration, no setting.

On main at 72630bbfe, list_request_logs in app/modules/request_logs/api.py still takes no source parameter, and RequestLogsRepository.list_recent builds both the count-cache key and _DemandCountParams from accounts, API keys, model options and statuses only. Since the demand rollup has no model_source_id dimension, an active upstream filter has to join that cache key and take the raw count path.

My first step is to set up a fork per CONTRIBUTING, run make test-unit on main, and post the result here with a /api/request-logs call that shows the missing filter. After that I'll write the OpenSpec change add-request-log-upstream-facet before any code.

I'll post an update in this thread within 7 days. If I can't finish, I'll say so here so someone else can pick it up.

One question: your comment puts the count-cache key in this PR, and the issue body also asks to hide the filter when only one upstream is observed. Do both need to land in this first PR, or can either follow in a second one? My default is to keep both here, because without the cache-key change two different upstream selections would share one cached total for up to 30 seconds.

I use Claude Code to help read the code and draft my writing; any commands and output I post come from my own runs.

foojanbabaeeian avatar Nov 05 '26 01:11 foojanbabaeeian