Skip to content

fix: wrap webhook handler's arq enqueue in try/except#41

Merged
JohnRDOrazio merged 3 commits intomainfrom
fix/webhook-arq-try-except
Apr 7, 2026
Merged

fix: wrap webhook handler's arq enqueue in try/except#41
JohnRDOrazio merged 3 commits intomainfrom
fix/webhook-arq-try-except

Conversation

@JohnRDOrazio
Copy link
Copy Markdown
Member

@JohnRDOrazio JohnRDOrazio commented Apr 6, 2026

Summary

  • Wraps the get_arq_pool() and pool.enqueue_job() calls in the GitHub webhook push handler with try/except error handling
  • Adds a pool is not None guard before enqueueing, matching the defensive pattern used elsewhere
  • Matches the existing error-handling pattern from the merge endpoint (lines 203-213)
  • Prevents Redis/ARQ failures from returning 500 to GitHub, which would cause delivery failures and webhook retries

Closes #24

Test plan

  • Verify the webhook endpoint returns {"status": "ok"} even when Redis is unavailable
  • Verify that when Redis is available, the run_remote_check_task job is still enqueued correctly
  • Confirm the warning is logged when the arq pool fails
  • Review that the fix matches the pattern in the merge endpoint (lines 203-213)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Webhook-driven remote sync checks now verify background job queue availability before starting. If the queue is unavailable or enqueueing fails, the failure is logged and suppressed, and the sync status is restored to its prior state instead of remaining stuck in "checking". This prevents propagated errors and improves sync status accuracy and webhook reliability.

Matches the error-handling pattern already used in the merge endpoint
(lines 203-213). Without this, a Redis failure during webhook processing
returns 500 to GitHub, causing delivery failures and retries.

Closes #24

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 6, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: bf3ffb13-069f-446b-b309-ddb40c1fb04b

📥 Commits

Reviewing files that changed from the base of the PR and between b9bc4b0 and 5c05d5f.

📒 Files selected for processing (1)
  • ontokit/api/routes/pull_requests.py

📝 Walkthrough

Walkthrough

The GitHub push webhook handler in pull_requests.py snapshots sync_config.status, sets it to "checking" and commits, then attempts to acquire an ARQ pool and enqueue a remote check. Enqueueing is gated on a non-None pool and wrapped in try/except; on failure it logs, restores the prior status, commits, and suppresses the error.

Changes

Cohort / File(s) Summary
Webhook ARQ enqueue handling
ontokit/api/routes/pull_requests.py
Snapshot previous sync_config.status, set status="checking" and commit before enqueue attempt; get_arq_pool() and enqueue_job() calls are wrapped in try/except; only enqueue if pool is non-None; on pool absence or exceptions, log a warning with exc_info=True, restore prior status and commit; exceptions are suppressed.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant GitHub as GitHub (push webhook)
    participant Handler as Webhook Handler
    participant DB as Database
    participant ARQ as ARQ Pool / Queue
    participant Log as Logger

    GitHub->>Handler: POST push event
    Handler->>Handler: find matching RemoteSyncConfig
    alt file_path in touched files
        Handler->>Handler: snapshot old_status
        Handler->>DB: set sync_config.status = "checking" and commit
        Handler->>ARQ: await get_arq_pool()
        alt pool != None
            Handler->>ARQ: enqueue run_remote_check_task
            ARQ-->>Handler: enqueue success
        else pool is None
            Handler->>Log: warn "ARQ pool not available"
            Handler->>DB: restore old_status and commit
        end
        alt enqueue raises exception
            Handler->>Log: warn with exc_info=True
            Handler->>DB: restore old_status and commit
        end
    else no match
        Handler->>Log: debug "no sync needed"
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 I sniffed the webhook in the night,
I set a flag then held on tight,
If queues go missing, I don't cry—
I log, restore, and let it lie.
A cautious hop, and off we fly! 🥕

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately describes the main change: adding try/except error handling around ARQ enqueuing in the webhook handler.
Linked Issues check ✅ Passed The code changes implement all requirements from issue #24: wrapping get_arq_pool() and enqueue_job() in try/except, adding pool None check, matching the merge endpoint pattern, and preventing HTTP 500 responses on Redis/ARQ failures.
Out of Scope Changes check ✅ Passed All changes are directly scoped to issue #24 requirements. The addition of status snapshotting and rollback logic represents a reasonable defensive enhancement aligned with the core objective of preventing webhook failures on ARQ errors.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/webhook-arq-try-except

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@JohnRDOrazio
Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 6, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@JohnRDOrazio
Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 7, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@ontokit/api/routes/pull_requests.py`:
- Around line 682-693: The code sets sync_config.status = "checking" and commits
before attempting to enqueue the remote job, which can leave state stuck if
get_arq_pool() fails or returns None; change the flow so the status is only set
and service.db.commit() is called after a successful enqueue (i.e., after
get_arq_pool() returns a non-None pool and pool.enqueue_job completes), or if
you must keep the pre-commit, add a rollback in the except and the pool None
path that resets sync_config.status to its prior value and commits, and ensure
logger.warning is called when pool is None; key symbols: sync_config,
get_arq_pool, pool.enqueue_job, service.db.commit, logger.warning.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ce2bc496-a737-496d-91ab-924b8c8ebad6

📥 Commits

Reviewing files that changed from the base of the PR and between 1a14032 and 1c131f3.

📒 Files selected for processing (1)
  • ontokit/api/routes/pull_requests.py

Move the status update and db commit to after pool.enqueue_job()
succeeds, so a failed or unavailable ARQ pool doesn't leave
sync_config.status stuck as 'checking'. Also log a warning when
the pool is None.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@ontokit/api/routes/pull_requests.py`:
- Around line 682-696: Scope the ARQ error handling to only the pool/enqueue
calls and persist the "checking" state before awaiting the enqueue: set
previous_status = sync_config.status; set sync_config.status = "checking" and
call await service.db.commit() immediately, then wrap only get_arq_pool() and
await pool.enqueue_job("run_remote_check_task", str(project_id)) in a try/except
that logs ARQ errors; if enqueue fails, revert sync_config.status =
previous_status and persist that rollback (await service.db.commit() or
rollback) so the remote_sync_service.py sees the updated state and we don't
leave a queued job inconsistent with DB state. Use the existing names
sync_config.status, get_arq_pool(), enqueue_job(), and service.db.commit() to
locate the code.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f835bc19-f966-4f7c-ac69-27238a7dbb63

📥 Commits

Reviewing files that changed from the base of the PR and between 1c131f3 and b9bc4b0.

📒 Files selected for processing (1)
  • ontokit/api/routes/pull_requests.py

Set sync_config.status = "checking" and commit before attempting the
enqueue so that remote_sync_service sees the updated state immediately.
If the ARQ pool is unavailable or enqueue fails, revert the status to
its previous value and commit the rollback. This avoids a race where
the worker starts before the status commit, and ensures the DB stays
consistent on failure.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@JohnRDOrazio JohnRDOrazio merged commit be76ce0 into main Apr 7, 2026
16 checks passed
@JohnRDOrazio JohnRDOrazio deleted the fix/webhook-arq-try-except branch April 7, 2026 08:58
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.

fix: wrap webhook handler's arq enqueue in try/except

1 participant