feat(api): reconcile managed attachments comment on issue_comment webhook#332
Merged
Merged
Conversation
…hook Heals the uploads-sh[bot] attachments comment when it's deleted or mangled (issue #291): a bot-authored deletion or an edit still bearing the attachments marker invalidates the cached ghcomment: id and re-runs the binding-gated gather+upsert flow, reusing gatherCommentBody/ upsertBotComment via a new shared gatherAndUpsert helper. The payload check is I/O-free so ordinary human comments (fired on every comment in every installed repo) return near-instantly, and a bot-attributed sender on an edit is treated as our own PATCH and skipped to avoid a loop. Kept optional/best-effort rather than added to REQUIRED_WEBHOOK_EVENTS, since the App works fully without it.
|
Important Review skippedAuto reviews are limited based on label configuration. 🏷️ Required labels (at least one) (2)
🚫 Excluded labels (none allowed) (1)
Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
uploads-api | 44970f8 | Commit Preview URL Branch Preview URL |
Jul 21 2026, 11:40 AM |
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
uploads-web | 44970f8 | Commit Preview URL Branch Preview URL |
Jul 21 2026, 11:41 AM |
This was referenced Jul 21, 2026
Zach Dunn (zachdunn)
added a commit
that referenced
this pull request
Jul 21, 2026
…eal (#334) github-app.astro accreted separate notes across #324/#332 for the doctor health-check and the recommended issue_comment subscription; restructure it into one coherent page: permissions vs events (required vs recommended, doctor as the verification tool), a new repo-bindings section (first-claim- wins, unlink, admin reassign, and reassurance that other workspaces can't post to your repo), a dedicated self-healing-comments section, and a short newcomer orientation for readers arriving from the bot comment's docs link who have never seen the CLI. Both agent skills covered stage-as-you-go branch staging in #322 but predate unlink, doctor, and the not_authorized cross-tenant decline (#325/#327): add the remedy path (link --status, then unlink or ask an operator), doctor as the health check, what not_authorized means (no gh fallback), and that the bot comment self-heals so agents don't panic-repost when it briefly disappears.
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
uploads-sh[bot]attachments comment onissue_commentwebhook deliveries: if it's deleted or edited/mangled out from under the bot, reconcile invalidates the cachedghcomment:id and re-runs the existing binding-gated gather+upsert flow so it's recreated/repaired from the bound workspace's own data.gatherAndUpserthelper inapps/api/src/github-webhook.tssopull_requestauto-promotion and the newissue_commentreconcile both reuse the same "load bound workspace → gather → upsert" logic (was previously copy-pasted inline inautoPromoteAndComment).isReconcilableCommentEvent) — this event fires on every comment in every installed repo, so ordinary human comments return immediately with no DB/API calls:created: never relevant, rejected onactionalone.deleted: relevant only if the deleted comment's (still-included, pre-deletion) body carries the attachments marker and its author'suser.typeis"Bot".edited: relevant only if the current body still carries the marker.editedevent whosesender.typeis"Bot"is treated as our ownupsertBotCommentPATCH (GitHub attributes App-token writes to the App's bot user) and is skipped — reconcile never re-triggers off its own write.pull_requesthandling: every failure is caught and logged, never surfaced as a 5xx; the webhook path stays read/delete-only againstgithub_repo_links(findRepoLink/deleteRepoLink) — it never creates a binding (kept the existing pinning test green, added the same "no recordRepoLink/setRepoLink import" assertion to the new test file).REQUIRED_WEBHOOK_EVENTS(apps/api/src/github-app.ts) is unchanged — keptissue_commentout of it. Reconcile is a nice-to-have self-heal, not required for the App's core functionality (title cache invalidation, auto-promotion), so an uninstalled/unsubscribedissue_commentevent should not turn theuploads github doctorhealth check red for existing installs. Instead,apps/web/src/pages/docs/github-app.astronow recommends subscribing toissue_commentas optional. Happy to reconsider and add it to a "recommended" (non-ok-gating) tier in the doctor output as a follow-up if we want visibility into whether it's subscribed.Operator step (required after deploy)
This handler does nothing until the App is subscribed to the event — same silent-failure trap issue #293/#324 fixed for
issues/pull_request. After deploying this PR:github.com/settings/apps/<your-app>or org equivalent) → Permissions & events → Subscribe to events.issue_comment.Fixes #291
Test plan
pnpm --filter @uploads/api test— 821 tests passed (addedapps/api/src/github-webhook-reconcile.test.ts: relevant bot-deletion reconciles, relevant marker-bearing edit reconciles, ordinary humancreatedcomment ignored (no fetch calls), human-authored deletion with marker-like text ignored, bot-sender edit doesn't loop, no-binding no-op, stale cached id is invalidated before re-hunting (no wasted PATCH-to-404), a forced downstream throw is swallowed, and the existing "no binding-write import" pin is asserted against the updated file).pnpm -r typecheck— clean (pre-existing Astro-file warnings unrelated to this change).issue_commentunder the App's Subscribe to events (see Operator step above), then verify by deleting/mangling a managed comment on a bound repo and confirming it's recreated.