Skip to content

chore(digest): flip BRIEF_WHY_MATTERS_SHADOW to opt-in — default-on doubled gemini spend#4909

Merged
koala73 merged 1 commit into
mainfrom
chore/shadow-default-off
Jul 5, 2026
Merged

chore(digest): flip BRIEF_WHY_MATTERS_SHADOW to opt-in — default-on doubled gemini spend#4909
koala73 merged 1 commit into
mainfrom
chore/shadow-default-off

Conversation

@koala73

@koala73 koala73 commented Jul 5, 2026

Copy link
Copy Markdown
Owner

Problem (#4893)

api/internal/brief-why-matters.ts shipped shadow mode default-on at 100% sampling: every cache-miss story ran Promise.allSettled([analystPath, geminiPath]) — two gemini completions, one used, one stored only as an observability diff. The env flip (BRIEF_WHY_MATTERS_SHADOW=0, already live on Vercel prod) protects the current deployment, but the code default meant any fresh environment silently pays 2× again.

Fix

  • Shadow is now opt-in: only exactly '1' enables (env.BRIEF_WHY_MATTERS_SHADOW === '1'). Prod's explicit 0 is unchanged/redundant-safe.
  • Drift pin: the test suite's handwritten readConfig mirror now also asserts the handler source contains the same opt-in expression — the mirror asserting stale semantics unnoticed is exactly how default-on shipped in the first place.

Tests

tests/brief-why-matters-analyst.test.mjs: default expectation flipped (shadow=OFF), enable-token semantics inverted ('1' enables; yes/0/true/''/on don't), plus the source-text drift pin. 64/64 ✓, typecheck:api ✓, biome ✓.

Closes #4893

https://claude.ai/code/session_01YTm4GsLG2M7ZuaHF9MpZih

…oubled gemini spend

Shadow mode ran BOTH the analyst and gemini paths on every cache-miss
story (Promise.allSettled, one result discarded) and defaulted ON at 100%
sampling — a fresh deploy silently paid 2x for whyMatters long after the
comparison window ended (#4893). Only exactly '1' enables it now; prod
already carries an explicit '0' so behavior there is unchanged either way.

Adds a source-text drift pin: the test suite's handwritten readConfig
mirror now asserts the handler contains the same opt-in expression, so
the mirror can't silently assert stale semantics again.

Closes #4893

Claude-Session: https://claude.ai/code/session_01YTm4GsLG2M7ZuaHF9MpZih
@vercel

vercel Bot commented Jul 5, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
worldmonitor Ready Ready Preview, Comment Jul 5, 2026 5:46pm

Request Review

@koala73
koala73 enabled auto-merge (squash) July 5, 2026 17:43
@greptile-apps

greptile-apps Bot commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR flips the BRIEF_WHY_MATTERS_SHADOW env flag from default-on (opt-out via '0') to opt-in (only '1' enables), stopping the double-gemini spend on every cache miss in fresh environments. A "drift pin" test is also added to assert that the handler source contains the identical opt-in expression, making it impossible to silently regress the semantics again.

  • api/internal/brief-why-matters.ts: shadowEnabled now uses === '1' instead of !== '0', so any environment without an explicit opt-in value will never run both LLM paths.
  • tests/brief-why-matters-analyst.test.mjs: Test expectations are inverted to match the new default-off semantics, and a new drift-pin test reads the handler source at runtime to assert the exact gating expression, preventing undetected drift between the mirror and the real implementation.

Confidence Score: 5/5

Safe to merge — the change is a single expression flip that stops the two-path execution by default, with no impact on the primary response path.

The edit is surgically small: one boolean expression changed in the handler, one expression changed in the test mirror, one new test added. The shadow path itself is untouched; only whether it fires by default changes. The existing prod env var (BRIEF_WHY_MATTERS_SHADOW=0) continues to work correctly (still evaluates to false). The new drift-pin test closes the feedback loop that allowed the original regression to go undetected.

No files require special attention.

Important Files Changed

Filename Overview
api/internal/brief-why-matters.ts One-line logic inversion: shadowEnabled flipped from default-on (!== '0') to opt-in (=== '1'); comment updated to explain the rationale. No other logic changed.
tests/brief-why-matters-analyst.test.mjs Test mirror updated to match new opt-in semantics; default assertion inverted; enable/disable token sets swapped; new drift-pin test added to catch future handler/mirror desync.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Cache Miss] --> B{cfg.shadowEnabled\nAND sampleHardRoll?}
    B -- "BEFORE: default true\n(shadow=ON unless SHADOW=0)" --> C[Promise.allSettled\nanalyst + gemini\n2× LLM spend]
    B -- "AFTER: default false\n(shadow=OFF unless SHADOW=1)" --> D{cfg.primary}
    D -- analyst --> E[runAnalystPath only\n1× LLM spend]
    D -- gemini --> F[runGeminiPath only\n1× LLM spend]
    C --> G[choose primary result\nstore shadow diff]
    E --> H[cache write + respond]
    F --> H
    G --> H
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
    A[Cache Miss] --> B{cfg.shadowEnabled\nAND sampleHardRoll?}
    B -- "BEFORE: default true\n(shadow=ON unless SHADOW=0)" --> C[Promise.allSettled\nanalyst + gemini\n2× LLM spend]
    B -- "AFTER: default false\n(shadow=OFF unless SHADOW=1)" --> D{cfg.primary}
    D -- analyst --> E[runAnalystPath only\n1× LLM spend]
    D -- gemini --> F[runGeminiPath only\n1× LLM spend]
    C --> G[choose primary result\nstore shadow diff]
    E --> H[cache write + respond]
    F --> H
    G --> H
Loading

Reviews (1): Last reviewed commit: "chore(digest): flip BRIEF_WHY_MATTERS_SH..." | Re-trigger Greptile

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.

chore(digest): BRIEF_WHY_MATTERS_SHADOW is default-on at 100% sampling — every cache-miss runs TWO gemini calls, one discarded

1 participant