fix(bud-closure): prevent running code synthesis on BUD close - #185
Merged
Conversation
Closing a BUD via PATCH /api/v1/buds/{id} (status -> closed/prod) was
dispatching an incremental repo scan through
bud_closure._trigger_impacted_repo_scan against whichever HEAD the repo
happened to point at -- no main-branch / merge / deployment / HEAD-advance
check. On 2026-06-02 this caused BUD #8's close to deactivate 10
cross-cutting features (Permissions & Roles, Auth Context, Sandbox
Refunds, etc.) at a SHA the BUD never even shipped to main.
Repo scans now live exclusively in the PR-merge GitHub webhook
(api/v1/github_webhook.py -> services/scan/pr_merge_update.py), which
already gates on main_branch and only fires when a real merge advances
the tracked HEAD.
on_bud_closed keeps every other side effect: contributor XP, BUD-shipped
SP, BUD learning metrics (CLOSED only), and the post-close Learning
Agent. The linked-features in_progress -> done transition continues to
run upstream in bud.py via feature_lifecycle.transition_feature_for_bud,
unchanged.
CLAUDE.md and CHANGELOG.md updated so future readers find the scan
trigger in the right place.
Verified locally: with the patch loaded, PATCH BUD 246 prod -> closed
produced no new row in scans and no features.is_active flips on the
impacted repo (taskflow-web stayed at 5 active / 0 inactive).
Signed-off-by: Arun Rajkumar <mickyarunr@gmail.com>
Merged
7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
_trigger_impacted_repo_scanside effect fromservices/bud_closure.on_bud_closed. Repo scans now live exclusively in the PR-merge GitHub webhook (api/v1/github_webhook.py→services/scan/pr_merge_update.py), which already gates on the repo'smain_branch.in_progress → donetransition continues to run upstream inbud.pyviafeature_lifecycle.transition_feature_for_bud, unchanged.CLAUDE.mdandCHANGELOG.mdso future readers find the scan trigger in the right place; tighten the stale comment inapi/v1/bud.py:986.Why
Forensic investigation of prod on 2026-06-02 showed that closing BUD #8 fired an incremental repo scan against the impacted repo at whatever HEAD that repo happened to be on. The scan had no main-branch / merge / deployment / HEAD-advance check. Because the full-scan reconciler in
services/scan/stages/synthesize.py:362does not passdeactivate_filter, every active feature the narrow BUD-impact synthesis didn't re-confirm got sweep-deactivated.Concretely: BUD #8 ("Fail-loud on Rapyd webhook ↔ API status divergence so retry cron picks it up") was a narrow fix in one impacted repo. Closing it triggered
scansrowbaa9b580-1d4d-45d0-b6ab-71a63bd0938b, which then flipped 10 cross-cutting features (Permissions & Roles, Auth Context, Sandbox Refunds, Application Configuration, Build/Test/Process Tooling, Pagination, Payment Link Detail Models, Role-based Access Control Middleware, Service URL Manager, Platform Reference Enums) tois_active=falseat SHA96cd92d…— a SHA the BUD never shipped to main and that no merge-to-main event ever produced. The user invariant is "scans only run when a merge with main happens"; this restores that invariant for the BUD-closure path.The full-fallback reconciler sweep is a separate defect (Stage 2, follow-up PR) that also affects PR-merge above the narrow-cap. This PR addresses the trigger gap only.
Test plan
ruff check backend/— zero issues.ruff format --check backend/app/services/bud_closure.py backend/app/services/bud_metrics.py— already formatted.mypy backend/app/— 492 source files, no issues.pytest backend/tests/— 1814 passed, 0 failed.pr-review-toolkit:code-reviewersubagent review — addressed both findings (staleCHANGELOG.md:28claim and stalebud.py:986inline comment).Notification bell icon redesign, impacted repotaskflow-web) fromclosedtoprod. With the patch loaded (uvicorn--reloadauto-restart confirmed via PID start time),PATCH /api/v1/buds/eb3a389c-… {status: "closed"}returned 200 and:scanscount: 3 before, 3 after — no scan triggered ✅featuresfor the impacted repo: 5 active / 0 inactive before and after — no sweep ✅closed(transition succeeded) ✅scansrow appears in response to BUD close events going forward; PR-merge webhooks continue to createscansrows as before.Follow-up
Stage 2 (separate PR) will fix the reconciler matching defect that causes the full-scan path to mass-deactivate features whose new synthesis has a different
cluster_signaturedespite cosine similarity ≥ 0.85 (e.g. "Cache Service" ↔ "Cache Service", "Vendor Rollout Flags" ↔ "Vendor Rollout Flags") — see the plan file for the design.