Skip to content

Use style chunk severity definitions instead of hardcoded integers in CEL filters #1095

Open

Description

@kyasbal

Background & Problem

The CEL filter fields (timelineQuery, timelineExclusionQuery, and logQuery) handle severities as plain integers. These integers come from two sources that are not linked:

  • The CEL constants UNKNOWN, INFO, WARNING, ERROR, and FATAL are declared as int and bound to the fixed values 0 to 4 in pkg/server/workbench/cel/env.go.
  • The severity of a log is the Order field of its severity definition in the style chunk of the loaded .khi file. The definitions are registered in pkg/task/inspection/inspectioncore/severity.go.

This causes three problems:

  1. The constants can drift from the file. The hardcoded values match today only because the registered orders are also 0 to 4. If a severity is added, renamed, or reordered, the CEL constants become wrong without any error. The CEL references (khi://cel/timeline and khi://cel/log) are generated from the style chunk, so they can also list a constant or a value that the CEL environment does not have.
  2. Severities are raw integers in CEL. severity, minSeverity(int), and hasSeverity(int | list<int>) accept any integer. Expressions such as severity == 2 or hasSeverity(7) compile, but their meaning depends on internal order values. The review of feat(workbench): add SearchTimelines tree aggregation for MCP (#1043) #1089 raised the same point for the MCP search tools: severities should not be used as integers.
  3. hasSeverity cannot match a severity with an order of 8 or more. indexTimelinesParallel stores the severities of each timeline in the 8-bit TimelineData.SeverityMask and silently skips orders of 8 or more. The hasSeverity binding also returns false for values outside 0 to 7. The current definitions do not reach this limit, but nothing prevents a new definition from reaching it.

The same filter pipeline serves the Web UI (Workbench.FilterTimeline) and the MCP tools (Workbench.ExecuteFilter), so both are affected.

Proposed Solution

Make the severity definitions in the style chunk the single source of truth for CEL:

  1. Generate the CEL severity constants from the style chunk of the loaded file, one constant per definition, named by its upper-case label. Remove the hardcoded constants and values from env.go.
  2. Give severities their own CEL type backed by the definitions. severity, minSeverity, and hasSeverity accept only severity values. Comparison operators such as severity >= WARNING keep working and compare by the Order field of the definition. Integer literals no longer work as severities.
  3. Replace the integer StyleResolver.ResolveSeverity with a lookup that returns the *khifilev6.Severity definition. buildSeverityMap in pkg/server/workbench/severity_count.go, added in feat(workbench): add SearchTimelines tree aggregation for MCP (#1043) #1089, already builds this lookup for the MCP search tools.
  4. Replace the 8-bit TimelineData.SeverityMask with a set that has no size limit, such as a set of severity IDs. Keep the most severe definition of each timeline for minSeverity.
  5. Generate the CEL references from the same definitions, and describe severities as named constants without integer values.

Design note: CEL expressions are currently compiled without a loaded file in two places. CELValidationServer validates queries for the Web UI with only the query text, and the MCP tools call workbench.ValidateFilter before they acquire the workbench. With per-file constants, these checks need the style chunk of the target inspection, or the check for unknown severity names must move to the point where the file is loaded.

Alternatives Considered

  • Generate integer constants from the style chunk but keep the int type: This fixes the drift with a small change. However, integer literals still compile as severities, which goes against the review of feat(workbench): add SearchTimelines tree aggregation for MCP (#1043) #1089.
  • Use severity labels as strings, such as minSeverity("ERROR"): This needs no custom CEL type. However, a typo in a label is found only at evaluation time unless labels are checked during compilation, and the order still needs a lookup. It also changes the expressions that the Web UI toolbar generates.

Out of Scope

Acceptance Criteria

  • pkg/server/workbench/cel/env.go has no hardcoded severity constants or values. The constants come from the style chunk of the loaded file.
  • severity, minSeverity, and hasSeverity use a severity type backed by the style chunk definitions. Comparing a severity with an integer literal fails at compile time.
  • Documented expressions such as severity >= WARNING and minSeverity(ERROR) keep working, including the expressions that the Web UI toolbar generates.
  • minSeverity and hasSeverity work for any number of definitions and any Order value.
  • The CEL references list exactly the severity constants that the CEL environment declares.
  • Tests cover a style chunk with a custom severity, such as a new label or an order of 8 or more.

Related Code & Context

Activity

  1. added
    area:backend-core
    type:refactor
    on Oct 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:backend-coretype:refactor

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions