Skip to content

perf(meta-phases): let the model decide when to browse, not the prompt - #20

Merged
AbirAbbas merged 1 commit into
mainfrom
perf/let-meta-phases-decide-when-to-browse
May 6, 2026
Merged

perf(meta-phases): let the model decide when to browse, not the prompt#20
AbirAbbas merged 1 commit into
mainfrom
perf/let-meta-phases-decide-when-to-browse

Conversation

@AbirAbbas

Copy link
Copy Markdown
Contributor

Why

Each meta-phase (meta_semantic, meta_mechanical, meta_systemic) was burning 15–40 minutes apiece in production, even though Kimi K2.6 is fast per-turn. Profiling traced this back to the prompts themselves, not to the model or harness.

Two pieces of prompt language were doing the damage in all three lenses:

  1. "Investigation Protocol" — explicitly told the model "browse the actual source files... Read the changed functions. Then find their callers. Trace how data flows..."
  2. "Quality Gate" — explicitly rejected diff-only answers: "If your rationale says 'visible in the diff' or 'based on the patches', you have not investigated enough."

That turned every phase into a 20–40 turn opencode session of file reads, when the diff patches plus the intake/anatomy summary already contain almost everything these phases need to produce dimensions. The model wasn't slow — it was being instructed to do expensive exploration before it was allowed to answer.

What

Replaced the mandate with neutral framing in all three meta-phase prompts:

  • "Working with Context": the diff + intake/anatomy summary is usually enough. Repo access is still available (cwd=repo_path); use it sparingly, only when the diff genuinely doesn't show what you need (e.g., to confirm an unchanged caller's signature).
  • "Quality Bar": each dimension must be SPECIFIC — named files, function names, line ranges. The diff already carries those, so a dimension grounded in the diff is good. Vague dimensions are still rejected. What's no longer penalized is correct dimensions produced from the diff in 2 turns instead of 30.

Each lens keeps its existing bullets (semantic = logic/contracts/concurrency/security, mechanical = signatures/imports/decorators, systemic = patterns/coverage/migrations), the target_files requirement, and the output schema. The structural contract is unchanged.

Also in this PR

Bumped the in-code default model openrouter/moonshotai/kimi-k2.5kimi-k2.6 in config.py and .env.example to match what's actually deployed via Railway env. Local dev was silently running on an older model than prod.

Expected impact

This is one half of a two-PR change. The other half (in agentfield) addresses three orthogonal harness issues:

  1. The 600s opencode timeout, which kills slow-but-progressing calls
  2. Auto-retrying the entire opencode call on timeout (currently TRANSIENT_PATTERNS includes "timeout", so a 10-min timeout silently triggers up to 3 more 10-min retries)
  3. Schema validation failures rerunning the entire opencode subprocess instead of just reformatting the existing text output

This PR alone should chop meta-phase wall time roughly in half by simply not forcing useless exploration. With the agentfield fixes layered on top, total review runtime should drop from 60–110+ min to well under an hour for typical PRs.

Test plan

  • PYTHONPATH=src pytest — 25 passed (1 pre-existing test_cost_tracker failure on main, unrelated to this PR)
  • Smoke imports of anatomy_phase, meta_semantic, meta_mechanical, meta_systemic resolve cleanly
  • After merge: trigger a real review on a multi-file PR and compare per-phase durations against baseline (anatomy: 903s, meta_*: 800–1000s each in the run that prompted this PR)

🤖 Generated with Claude Code

…the prompt

The meta_semantic / meta_mechanical / meta_systemic phases were burning
15–40 minutes apiece in production, even though Kimi K2.6 is fast
per-turn. Profiling traced this back to the prompts themselves: each
phase had an "Investigation Protocol" section that *mandated* browsing
the actual source files, and a "Quality Gate" that *rejected*
diff-only answers ("If your rationale says 'visible in the diff' or
'based on the patches', you have not investigated enough").

That language turned every phase into a 20–40 turn opencode session
of file reads, when the diff patches plus the intake/anatomy summary
already contain almost everything these phases need to produce
dimensions. The model wasn't slow — it was being instructed to do
expensive exploration before it was allowed to answer.

Replaced the mandate with neutral framing:

  - "Working with Context": diff + intake/anatomy is usually enough.
    Repo access is available; use it sparingly, only when the diff
    genuinely doesn't show what you need.
  - "Quality Bar": dimensions must be specific (named files, line
    ranges). The diff already carries those; a dimension grounded in
    the diff is good. Vague dimensions are still rejected.

Each lens keeps its specific bullets (semantic = logic/contracts,
mechanical = signatures/imports, systemic = patterns/coverage) and
its target_files requirement. The output schema is unchanged. What
changes is the model is no longer penalized for producing a correct
answer from the diff in 2 turns instead of 30.

Also bumped the in-code default model openrouter/moonshotai/kimi-k2.5
→ k2.6 to match what's actually deployed in production. Local dev was
silently running on an older model than prod.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@AbirAbbas
AbirAbbas merged commit 07969c2 into main May 6, 2026
2 checks passed
@AbirAbbas
AbirAbbas deleted the perf/let-meta-phases-decide-when-to-browse branch May 6, 2026 13:24
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.

1 participant