Skip to content

fix(worker): make Jira repo selection smart via code evidence - #42

Merged
nambok merged 1 commit into
mainfrom
fix-smart-repo-selection
Jul 25, 2026
Merged

nambok merged 1 commit into
mainfrom
fix-smart-repo-selection

Conversation

@nambok

@nambok nambok commented Jul 25, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

TICKET-7881 ("override Tailwind tracking-tighter token") mis-routed to fitness-club-daily-schedule instead of web-app. Root cause: select_repo fed the LLM only each repo's name / description / top-level dirs and asked it to guess — a generic ticket has no repo hint in its prose, so the pick was arbitrary. (A hard CPM→web-app mapping was rejected as a bandaid; the selector itself needs to be smart.)

Fix — ground selection in code evidence

The repo that actually contains the ticket's identifiers is almost always the right one.

  • extract_ticket_search_terms() — regex-extracts distinctive identifiers (filenames, kebab/camel/Pascal/snake_case), deduped and capped.
  • select_repo() — probes up to 4 terms across the candidate repos (repos ≤ 10), tallies matches per repo, and either short-circuits to a uniquely-strong match or feeds the evidence into the LLM prompt ("STRONGLY prefer the repo with concrete matches").

Hardening (from adversarial review)

  • Resolve each repo's default branch instead of passing "HEAD" — "HEAD" 404s the snapshot ref lookup and silently falls back to the rate-limited Code Search API (up to 40 probes/triage → 403 after ~10 → corrupted evidence). This was a HIGH bug that would've silently defeated the feature.
  • Short-circuit requires ≥2 distinct identifiers agreeing on one repo; a single generic token is too weak to bypass the LLM (could re-trigger the exact mis-route).
  • Log search errors; if searches fail systemically, drop the evidence rather than present "no matches" as fact.

Verification

  • cargo clippy -p worker --all-targets -D warnings — clean
  • cargo fmt --check — clean
  • cargo test -p worker — new test: extractor catches TICKET-7881 (tracking-tighter, letter-spacing) and TICKET-7838 (ClassRow, GroupCard) identifiers; yields nothing for a prose-only ticket (clean LLM fallback)
  • End-to-end: after deploy I'll re-run TICKET-7881 and confirm it now routes to web-app.

Follow-up (tracked, not in this PR)

Selection snapshot-searches each candidate repo (downloads tarballs during triage). An org-scoped Code Search (org: qualifier, one call per term) would avoid the per-triage downloads. Memory: the repos ≤ 10 fan-out holds several snapshots; fine for normal repos, bounded by the tarball cap + API fallback for outliers.

CPM-7881 (a generic "override Tailwind tracking-tighter token" ticket) was
mis-routed to fitness-club-daily-schedule instead of speedboat. Root cause:
select_repo fed the LLM only each repo's name/description/top-level-dirs and
asked it to guess — a generic ticket has no repo hint in its prose, so the
guess was arbitrary.

Now selection is grounded in CODE EVIDENCE: extract the ticket's distinctive
identifiers (filenames, kebab/camel/Pascal/snake_case) and search each candidate
repo for them. The repo that actually contains `tracking-tighter` / `ClassRow`
is almost always the right one.

- extract_ticket_search_terms(): regex-extracts code-like identifiers, capped.
- select_repo(): probes up to 4 terms across candidate repos (repos<=10), tallies
  matches, and either short-circuits to a uniquely-strong match or feeds the
  evidence into the LLM prompt ("prefer the repo with concrete matches").

Hardening from adversarial review:
- Resolve each repo's DEFAULT branch instead of passing "HEAD" — "HEAD" 404s the
  snapshot ref lookup and silently falls back to the rate-limited Code Search API
  (would 403 after ~10 of up to 40 probes and corrupt the evidence).
- Short-circuit requires >=2 distinct identifiers agreeing on one repo; a single
  generic token is too weak to bypass the LLM (could re-trigger the mis-route).
- Log search errors and drop the evidence entirely if searches fail systemically,
  rather than presenting "no matches" as fact.

Test: extract_ticket_search_terms catches CPM-7881's (tracking-tighter,
letter-spacing) and CPM-7838's (ClassRow, GroupCard) identifiers, and yields
nothing for a prose-only ticket (clean LLM fallback).

Follow-up: selection downloads candidate-repo tarballs to snapshot-search; an
org-scoped Code Search would avoid the per-triage downloads (tracked separately).
@nambok
nambok merged commit b290b6d into main Jul 25, 2026
2 checks passed
@nambok
nambok deleted the fix-smart-repo-selection branch July 25, 2026 16:18
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