Skip to content

feat(synthesis): feed the merged PR description and review thread into commit synthesis - #563

Merged
davesheffer merged 5 commits into
mainfrom
feat/pr-context-synthesis
Oct 29, 2026
Merged

davesheffer merged 5 commits into
mainfrom
feat/pr-context-synthesis

Conversation

@davesheffer

Copy link
Copy Markdown
Owner

Phase 1 of #562. On squash-merge repos the why often lives in the PR description, not the commit that lands. Synthesis now reads it.

What changes

  • New src/synthesis/prContext.ts. When a commit subject names its PR (Title (#N), or Merge pull request #N from …) and origin is GitHub, it fetches the PR with the user's own gh (gh api --hostname github.com repos/{o}/{r}/pulls/{N}).
  • Match check: the PR must be merged, and either its merge_commit_sha equals the commit or the subject is GitHub's default <PR title> (#N). A same-numbered PR from a fork or a cherry-pick never lends its description.
  • Bounds: template <!-- --> comments are dropped, the body is capped at 8000 chars, and the title is collapsed to one line.
  • Prompt: the description goes in a separate fenced section labeled as untrusted data, in both the draft and the Critic (--verify) prompts. A forged fence in the body is neutralized. The Critic schema now counts the PR description as evidence, so alternatives the PR backs are not pruned.
  • Never fetched for local-only/private captures or the deterministic draft. No PR text reaches any provider for private mode.
  • Degrades silently: no GitHub origin, no gh, offline, unauthenticated → no context. Lookups are async (backfill workers keep overlapping) and memoized per process. After 2 straight transport failures the process stops asking; a 404 or an issue number is an answer, not a failure. Opt out with HUNCH_PR_CONTEXT=0.
  • Provenance: synth evidence records pr=#N when the section was sent.

Not in this PR

  • A plain GitHub merge commit (Merge pull request #N) is still skipped as a trivial subject unless its body is substantive, so in practice this targets squash merges.
  • Branch commits of merge-commit PRs aren't mapped to their PR (that would need a commit→PR lookup).
  • Phase 2 (review-thread context) stays gated on the noise audit.

Verification

  • npx tsc --noEmit: exit 0.
  • node tooling/run-tests.mjs on pr-context, provider, cliproviders, synthesis, private-capture, provider-exec, workspaces: 113/113, exit 0.
  • New tests cover subject parsing, the match/reject rules, offline and no-origin degrade, the breaker (and that 404s don't trip it), bounding, the prompt fencing in draft and verify, end-to-end syncCommit to a fake endpoint with pr=#42 in provenance, and that localOnly / private: true never look up PR text.
  • Live smoke against this repo: PR docs(readme): video first, plus a GIF of Hunch blocking a change #560 fetched (~1.7s, merge-sha match); a real 404 returns null without throwing.
  • Two critic passes. Findings fixed: the breaker latched on 404s, sync execFileSync blocked backfill workers, GHE GH_HOST, the multi-line title, and a vacuous private test. Accepted as design: the breaker doesn't half-open in a long-lived hunch mcp process, and concurrent identical lookups aren't deduped.

🤖 Generated with Claude Code

davesheffer and others added 2 commits October 29, 2026 14:51
On squash-merge repos the why often lives in the PR description, not the
commit that lands (#562: 39% of discussed PRs across 12 repos). When a
commit subject names its PR ("Title (#N)" or "Merge pull request #N"),
fetch the description with the user's own `gh` and give it to the model
as a separate, fenced section labeled as untrusted data.

- One `gh api` call per commit, memoized per process; any failure (no
  GitHub origin, no gh, offline, unauthenticated) degrades to no context.
- The PR must match the commit: its merge sha, or GitHub's default squash
  subject "<title> (#N)". Unmerged PRs are ignored.
- Body bounded to 8000 chars after dropping template comments.
- Never fetched for local-only/private captures or deterministic drafts.
- The Critic sees the same section, so PR-backed alternatives survive it.
- Provenance records pr=#N in the synth evidence. HUNCH_PR_CONTEXT=0 opts out.

Phase 1 of #562; review-thread context stays gated on the noise audit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review findings on the PR-context change:
- gh/git now run through async execFile, so a backfill's parallel workers
  are not frozen by a blocking lookup; the origin is memoized per root.
- After two straight lookup failures (gh missing, offline, timed out) the
  process stops asking. A 404 or an issue number is an answer, not a
  failure, so it no longer disables PR context for the rest of a backfill.
- `gh api --hostname github.com`, since the origin is proven github.com even
  when gh defaults to an Enterprise host.
- PR title collapsed to one line before it reaches the prompt.
- Tests: 404s don't trip the breaker; `private: true` alone never looks up.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
hunch Ready Ready Preview Oct 29, 2026 3:57pm UTC

@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

🧠 Hunch — Engineering Memory Guard

✅ This PR touches no recorded invariants (directly or via blast radius) and re-introduces nothing deliberately retired across 5 changed file(s).

📜 Hunch Constitution — 2 policy receipt(s)

  • ✅ pol_01cf084e1e satisfied — symbol:renderAdoptedDoc does not reach symbol:writeFileAtomic
    • receipt: sha1:24a86d91eee745d5daf9c7ece386fc5e4ea97725
  • ✅ pol_3f3aee11ad satisfied — symbol:src/store/db.ts:openDb does not reach external:better-sqlite3
    • receipt: sha1:638fa084c49dade8f2ccf1a45ceab29e21fb7236

The env-surface gate requires every env read in src to be registered with
a covering test; the opt-out test in test/pr-context.test.ts covers it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…esis

Phase 2 of #562. On the Critic-verified path only, fetch the merged PR's
human review thread (conversation comments, review bodies, inline review
comments; bots dropped) with one `gh api graphql` call and hand it to the
model as its own fenced, labeled, untrusted DATA section, capped at 14000
chars. The query takes the newest messages (`last:`) and marks the thread
truncated when GitHub holds older ones; the char cap keeps the opening and
the end, where review converges.

A thread failure keeps the description and trips a separate thread breaker,
so a GraphQL-only problem never silences working description lookups. All
four fences, and the PR title, are neutralized in untrusted text. The
verifier is told to flag thread-drawn claims the diff does not show landed.

Refs #562

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@davesheffer davesheffer changed the title feat(synthesis): feed the merged PR description into commit synthesis (#562 phase 1) feat(synthesis): feed the merged PR description and review thread into commit synthesis Oct 29, 2026
@davesheffer

Copy link
Copy Markdown
Owner Author

Phase 2 (#568, critic-reviewed, 31/31 tests) is fast-forwarded into this branch so both phases land in one merge for 1.48.0. See #568 for the phase-2 description, noise-gate numbers and unmeasured mitigations.

@davesheffer
davesheffer merged commit 1cb56e7 into main Oct 29, 2026
14 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 29, 2026
@davesheffer
davesheffer deleted the feat/pr-context-synthesis branch November 3, 2026 03:23

This branch was successfully deployed

1 active deployment
Preview — 76860953 Deployed Oct 29, 2026 by vercel[bot]
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant