Skip to content

feat(api): reconcile managed attachments comment on issue_comment webhook#332

Merged
Zach Dunn (zachdunn) merged 1 commit into
mainfrom
feat/comment-reconcile-webhook
Jul 21, 2026
Merged

feat(api): reconcile managed attachments comment on issue_comment webhook#332
Zach Dunn (zachdunn) merged 1 commit into
mainfrom
feat/comment-reconcile-webhook

Conversation

@zachdunn

Copy link
Copy Markdown
Member

Summary

  • Heals the managed uploads-sh[bot] attachments comment on issue_comment webhook deliveries: if it's deleted or edited/mangled out from under the bot, reconcile invalidates the cached ghcomment: id and re-runs the existing binding-gated gather+upsert flow so it's recreated/repaired from the bound workspace's own data.
  • Extracted a shared gatherAndUpsert helper in apps/api/src/github-webhook.ts so pull_request auto-promotion and the new issue_comment reconcile both reuse the same "load bound workspace → gather → upsert" logic (was previously copy-pasted inline in autoPromoteAndComment).
  • Event filtering is a pure, I/O-free check on the payload (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 on action alone.
    • deleted: relevant only if the deleted comment's (still-included, pre-deletion) body carries the attachments marker and its author's user.type is "Bot".
    • edited: relevant only if the current body still carries the marker.
  • Loop guard: an edited event whose sender.type is "Bot" is treated as our own upsertBotComment PATCH (GitHub attributes App-token writes to the App's bot user) and is skipped — reconcile never re-triggers off its own write.
  • Same degrade-safe doctrine as the existing pull_request handling: every failure is caught and logged, never surfaced as a 5xx; the webhook path stays read/delete-only against github_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 — kept issue_comment out 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/unsubscribed issue_comment event should not turn the uploads github doctor health check red for existing installs. Instead, apps/web/src/pages/docs/github-app.astro now recommends subscribing to issue_comment as 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:

  1. Go to the GitHub App settings (github.com/settings/apps/<your-app> or org equivalent) → Permissions & eventsSubscribe to events.
  2. Tick issue_comment.
  3. Save.

Fixes #291

Test plan

  • pnpm --filter @uploads/api test — 821 tests passed (added apps/api/src/github-webhook-reconcile.test.ts: relevant bot-deletion reconciles, relevant marker-bearing edit reconciles, ordinary human created comment 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).
  • After deploy: tick issue_comment under 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.

…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.
@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are limited based on label configuration.

🏷️ Required labels (at least one) (2)
  • coderabbit:review
  • review
🚫 Excluded labels (none allowed) (1)
  • wip

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: cb66f737-e6c0-4e02-9110-c958dba253d6

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/comment-reconcile-webhook

Comment @coderabbitai help to get the list of available commands.

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

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

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

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

@zachdunn
Zach Dunn (zachdunn) merged commit 342ee81 into main Jul 21, 2026
5 checks passed
@zachdunn
Zach Dunn (zachdunn) deleted the feat/comment-reconcile-webhook branch July 21, 2026 11:59
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.
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.

Heal/reconcile the managed bot comment on issue_comment webhook events

1 participant