Skip to content

[DO-NOT-MERGE-YET] feat(complexity): add session routing observability - #6045

Closed
Madhuvod wants to merge 1 commit into
08-11-_do-not-merge-yet_complexity_cache-aware_session_routing_integrationfrom
08-11-_do-not-merge-yet_feat_complexity_add_session_routing_observability
Closed

[DO-NOT-MERGE-YET] feat(complexity): add session routing observability#6045
Madhuvod wants to merge 1 commit into
08-11-_do-not-merge-yet_complexity_cache-aware_session_routing_integrationfrom
08-11-_do-not-merge-yet_feat_complexity_add_session_routing_observability

Conversation

@Madhuvod

@Madhuvod Madhuvod commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds session observability to complexity-routed requests. When a governance routing rule evaluates a complexity tier through session policy (pinned or cache-aware), four new fields are now recorded on the request log: a tenant-scoped session hash, the session mode, the tier source (classified, memoised, or held), and the cumulative tier-switch count. These fields are surfaced in the log detail view and are filterable from the sidebar and API.

Changes

  • Added four new BifrostContextKey constants (ComplexitySessionID, ComplexitySessionMode, ComplexitySessionTierSource, ComplexitySessionSwitchCount) to the schema.
  • Introduced ComplexitySessionLogFields as an embedded struct on logstore.Log, keeping database columns and JSON response fields flat.
  • Added a migrationAddComplexitySessionColumns migration that idempotently adds the four nullable columns to the logs table, with partial indexes on the two low-cardinality filter columns (complexity_session_mode, complexity_session_tier_source). The session ID column is intentionally unindexed as it is display/export-only.
  • Extended SearchFilters with ComplexitySessionModes and ComplexitySessionTierSources, wired through applyFilters, canUseMatViewFilters (both new filters force the raw query path), and listSelectColumns.
  • Replaced duplicated inline complexity-field assignment in the logging plugin with a single applyComplexityContextToEntry helper that covers both the normal completion path and the minimal-error path, preventing future drift.
  • Added publishComplexitySessionLogContext and publishSessionClassificationTelemetry in the governance plugin to emit session context into the request context from within the lazy complexity closure only—requests whose rules never inspect complexity_tier receive no session log fields.
  • persistInitialSessionTier now returns the switch count and a known/unknown flag so callers can propagate it to telemetry without an extra store read.
  • Extracted parseComplexityFilters in the HTTP transport to deduplicate filter parsing across the log search, stats, and histogram endpoints, and added complexity_session_modes and complexity_session_tier_sources query parameters.
  • Added ComplexitySessionTierSource type, COMPLEXITY_SESSION_LOG_MODE_VALUES, COMPLEXITY_SESSION_TIER_SOURCE_VALUES, and COMPLEXITY_SESSION_TIER_SOURCE_LABELS to the UI type system.
  • Added a ComplexitySessionFilter sidebar section with mode and tier-source checkboxes, wired into URL state and the API filter builder.
  • Extended the log detail view to display session ID (with copy button), session mode, tier source, and switch count when present.

Type of change

  • Bug fix
  • Feature
  • Refactor
  • Documentation
  • Chore/CI

Affected areas

  • Core (Go)
  • Transports (HTTP)
  • Providers/Integrations
  • Plugins
  • UI (React)
  • Docs

How to test

# Core/Transports
go test ./framework/logstore/... ./plugins/governance/... ./plugins/logging/... ./transports/bifrost-http/handlers/...

# UI
cd ui
pnpm i
pnpm build

Enable a routing rule that references complexity_tier with session policy (pinned or cache_aware) configured. Send several requests in the same session. Verify that:

  • The log detail view shows the session ID, mode, tier source, and switch count.
  • Filtering by complexity_session_modes=pinned or complexity_session_tier_sources=held returns only matching rows.
  • Requests whose rules never evaluate complexity_tier have no session fields on their log entries.
  • Re-running the migration against an already-migrated database completes without error and leaves existing rows intact.

Breaking changes

  • Yes
  • No

Related issues

Security considerations

The session ID stored in the log is a hash of the already tenant-namespaced store key, not the raw caller identity, harness value, or fingerprint. The separately hashed tenant component in the key is not exposed. No PII reaches the log column.

Checklist

  • I read docs/contributing/README.md and followed the guidelines
  • I added/updated tests where appropriate
  • I updated documentation where needed
  • I verified builds succeed (Go and UI)
  • I verified the CI pipeline passes locally if applicable

@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 23f0957e-a7d8-4b1b-a4cb-80d4d12bd2e6

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Comment @coderabbitai help to get the list of available commands.

Madhuvod commented Aug 11, 2026

Copy link
Copy Markdown
Contributor Author

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@Madhuvod
Madhuvod force-pushed the 08-11-_do-not-merge-yet_feat_complexity_add_session_routing_observability branch from 4d0b5be to 901048f Compare August 11, 2026 12:48
@Madhuvod
Madhuvod force-pushed the 08-11-_do-not-merge-yet_complexity_cache-aware_session_routing_integration branch from 82164fb to 3fbdd04 Compare August 11, 2026 12:48
@Madhuvod
Madhuvod force-pushed the 08-11-_do-not-merge-yet_complexity_cache-aware_session_routing_integration branch from 3fbdd04 to ef83df2 Compare August 11, 2026 19:10
@Madhuvod
Madhuvod force-pushed the 08-11-_do-not-merge-yet_feat_complexity_add_session_routing_observability branch from 901048f to c59699c Compare August 11, 2026 19:10
@kohlivrinda
kohlivrinda force-pushed the 08-11-_do-not-merge-yet_complexity_cache-aware_session_routing_integration branch from ef83df2 to 7a3d7cc Compare August 12, 2026 11:31
@kohlivrinda
kohlivrinda force-pushed the 08-11-_do-not-merge-yet_feat_complexity_add_session_routing_observability branch from c59699c to 417bd3b Compare August 12, 2026 11:31
@Madhuvod
Madhuvod force-pushed the 08-11-_do-not-merge-yet_feat_complexity_add_session_routing_observability branch from 417bd3b to 7d2cb18 Compare August 12, 2026 15:14
@Madhuvod
Madhuvod force-pushed the 08-11-_do-not-merge-yet_complexity_cache-aware_session_routing_integration branch from 7a3d7cc to 06cc703 Compare August 12, 2026 15:14
@Madhuvod
Madhuvod force-pushed the 08-11-_do-not-merge-yet_feat_complexity_add_session_routing_observability branch 2 times, most recently from 8f98604 to e7b109e Compare August 12, 2026 22:06
@Madhuvod
Madhuvod force-pushed the 08-11-_do-not-merge-yet_complexity_cache-aware_session_routing_integration branch from b52c3cc to 97a29d7 Compare August 12, 2026 22:20
@Madhuvod
Madhuvod force-pushed the 08-11-_do-not-merge-yet_feat_complexity_add_session_routing_observability branch from e7b109e to 3e52dee Compare August 12, 2026 22:20
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