Skip to content

codeql_query_run does not auto-cache results for @kind problem / @kind path-problem queries without explicit format parameter #268

@data-douser

Description

@data-douser

Bug Report

Summary

codeql_query_run does not automatically cache results for @kind problem or @kind path-problem queries unless the format parameter is explicitly provided. Since these query kinds have well-defined output formats (SARIF), results should be auto-cached without requiring the caller to specify format.

Steps to Reproduce

  1. Run a @kind problem query without specifying format:
    codeql_query_run --database=<db> --query=ExampleQuery1.ql
    
  2. Call query_results_cache_lookup — returns cached: false.
  3. Re-run with format: sarif-latest:
    codeql_query_run --database=<db> --query=ExampleQuery1.ql --format=sarif-latest
    
  4. Call query_results_cache_lookup — returns cached: true.

Root Cause

In server/src/lib/result-processor.ts, the processQueryRunResults function returns early at lines 167-169 when neither format nor evaluationFunction is specified:

// If no format or evaluationFunction specified, return as-is
if (!format && !evaluationFunction) {
  return result;
}

This skips the entire caching path (line ~220+), which is gated behind BQRS interpretation.

Expected Behavior

For @kind problem and @kind path-problem queries, the result processor should auto-detect the query kind from metadata and default to sarif-latest interpretation, ensuring results are always cached.

Actual Behavior

Results are only cached when format is explicitly provided by the caller. Without it, the BQRS file is produced but never interpreted or cached.

Suggested Fix

In processQueryRunResults, when no format is specified, read the query metadata (@kind) and auto-set format to sarif-latest for problem / path-problem queries before the early-return check.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions