Skip to content

feat(#844): instrument the real pr-review to emit LSP-pilot records (gated stream-json capture) #960

Description

@don-petry

Epic: #839 (LSP pilot) · Story: #844 · Builds on: #952 (standalone runner + lsp_pilot_measure.sh)

Summary

Upgrade the LSP-pilot comparison from the standalone probe shipped in #952 to riding the real production pr-review. Make the review path emit one pilot-schema JSONL record per reviewed PR, so every auto-review becomes a free LSP-off ("A") sample, and flipping LSP_PILOT_ENABLED yields the matching LSP-on ("B") sample through the same pipeline — a true apples-to-apples A/B with zero synthetic data.

Why

PR #952 landed the extractor (scripts/lsp_pilot_measure.sh), the harness (scripts/lsp_pilot_compare.sh, #841), and a standalone scripts/lsp_pilot_run.sh that re-runs reviews with a simplified prompt. The standalone driver does not use the production review, so its "A" side isn't what production actually does.

The blocker for using the real review: the headline metrics nav_tokens/tool_calls are only computable from the model's per-tool-call stream-json transcript, but the engine runs claude --output-format json (aggregate usage only — scripts/engine.sh:660) and never captures that transcript. So today a real review cannot produce a pilot record.

What to build

Behind the pilot being active (REVIEW_MCP_CONFIG set / LSP_PILOT_ENABLED=true), capture what's needed and emit a pilot record from the real review.

Acceptance criteria

  1. Gated stream capture. When the pilot is active, the deep/audit/rubber-duck claude tiers additionally capture the --output-format stream-json --verbose transcript to a temp file. When the pilot is OFF, behaviour is byte-for-byte unchanged — no stream capture, no extra flags, no new records. (The five consumer repos that don't set LSP_PILOT_ENABLED must be wholly unaffected.)
  2. Record emission. After a PR review completes under the pilot, invoke scripts/lsp_pilot_measure.sh on the captured transcript + TOKEN_LOG_FILE to append exactly one pilot-schema record to TOKEN_LOG_FILE — the existing Token Cost Observatory channel already uploaded as the token-usage-<run_id> artifact (.github/workflows/pr-review.yml:445). Discriminate it with a kind (e.g. kind:"lsp_pilot_run") so scripts/token_report.sh keeps excluding it from cost aggregation (its filter is (.kind // "token_usage") == "token_usage").
  3. Record contents. pr join key (<repo>#<number>@<head_sha>), variant (lsp-off when the flag is off / lsp-on when on), candidate, nav_tokens, tool_calls, findings/false_positives (from the [Phase 2] Add the LSP finding-verification step to the deep/audit pr-review tiers #843 verification records), cold_start_s (from the [Phase 2] Cache the LSP index and enforce the 30s cold-start SLA with auto-skip #846 lsp_cold_start record), real reported usage, and wall_time_s.
  4. Harness compatibility. Emitted records must join by pr and render via scripts/lsp_pilot_compare.sh unchanged (reuse feat(#844): live LSP off-vs-on comparison runner + measurement extractor #952's schema exactly).
  5. Tests. Unit coverage for: the capture gate (active vs off), record emission/shape, and the off-pilot no-op. shellcheck --severity=warning -x scripts/*.sh clean; existing test_lsp_pilot_measure / test_lsp_coldstart_sla / test_token_metrics suites stay green.
  6. Scope & safety. Additive + opt-in only. Do not modify the thin caller stubs beyond allowed inputs. Preserve all action/SHA pinning. pr-review.yml is consumed by 5 repos — no off-pilot change.

Out of scope

Done when

A real pr-review running under the pilot drops one lsp_pilot_run record into its token-usage-<run_id> artifact, and lsp_pilot_compare.sh renders an off-vs-on table from two such records (flag off vs on) with no synthetic input.

Metadata

Metadata

Assignees

No one assigned

    Labels

    dev-leadFor dev-lead agent pickupenhancementFeature requests

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions