Skip to content

fix(webhook): report failed deliveries in webhook test and log the last attempt - #777

Merged
jeff-r2026 merged 1 commit into
Tencent:mainfrom
huiq777:fix/webhook-test-reports-failures
Sep 24, 2026
Merged

jeff-r2026 merged 1 commit into
Tencent:mainfrom
huiq777:fix/webhook-test-reports-failures

Conversation

@huiq777

@huiq777 huiq777 commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

Summary

teamai webhook test reports every endpoint as successful, including one that answers 500 or times out. sendToEndpoint logs failures but never tells its caller, so testWebhook's try/catch can't see them. The same loop has two smaller gaps. A 5xx or 429 on the final attempt isn't logged at all, and a timeout is retried immediately instead of backing off.

sendToEndpoint now resolves to whether the endpoint accepted the event. It logs the final failure with its cause (status 500 or timed out after 5000ms) and backs off after a timeout the same way it does after any other failure. webhook test prints success only when delivery actually succeeded. sendWebhook is unchanged for callers: a failing webhook still never fails the command that fired it.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature causing existing behavior to change)
  • Documentation only
  • Refactor / internal cleanup

Test Plan

  • npx tsc --noEmit passes

  • npx vitest run passes (4500 passed, 1 skipped)

  • Added/updated tests for the change. New cases in src/__tests__/webhook.test.ts:

    • success is reported only for an accepted event
    • a 5xx after retries is reported as a failure, with the final warning
    • a non-retryable 4xx makes a single attempt and is reported as a failure
    • a timeout is retried after the 1s backoff, not immediately, and reported as a failure (fake timers)
    • sendWebhook logs a delivery whose last attempt fails

    The 4 behavioral cases fail on main and pass here.

Real CLI record

Built CLI, provider: git team repo with two json endpoints on a local HTTP server: /ok answers 200, /fail answers 500 with retries: 1.

### upstream/main build
ℹ Testing webhook to http://127.0.0.1:18765/ok...
✔ Webhook test successful: http://127.0.0.1:18765/ok
ℹ Testing webhook to http://127.0.0.1:18765/fail...
✔ Webhook test successful: http://127.0.0.1:18765/fail
### this branch
ℹ Testing webhook to http://127.0.0.1:18765/ok...
✔ Webhook test successful: http://127.0.0.1:18765/ok
ℹ Testing webhook to http://127.0.0.1:18765/fail...
⚠ Webhook to http://127.0.0.1:18765/fail failed after 2 attempt(s): status 500
✖ Webhook test failed: http://127.0.0.1:18765/fail
### server log (both runs)
POST /ok -> 200
POST /fail -> 500
POST /fail -> 500

Related Issues

None filed. I found this while reading the webhook integration from #665.

Notes for Reviewers

  • webhook test still exits 0 when a test fails, as before. I kept the change to the reporting; a non-zero exit code could be a follow-up if you want the command to be scriptable.
  • Feishu and WeCom can reject a message with HTTP 200 and an error in the body (code / errcode), which response.ok doesn't catch. That's out of scope here.
  • AI assistance (Claude Code) was used for the implementation and for running the tests and the CLI check locally.

🤖 Generated with Claude Code

…last attempt

sendToEndpoint swallowed every failure without telling its caller, so
`teamai webhook test` printed "Webhook test successful" for an endpoint that
answered 4xx/5xx or timed out. A 5xx or 429 on the final attempt was not
logged at all, and a timeout was retried immediately instead of backing off.

sendToEndpoint now resolves to whether the endpoint accepted the event,
logs the final failure with its cause, and backs off after a timeout like
after any other failure. `webhook test` reports success only for a delivery
that went through; sendWebhook keeps never failing the calling command.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jeff-r2026 jeff-r2026 self-assigned this Sep 24, 2026
@github-actions

Copy link
Copy Markdown

Findings

  • [P1 blocking] Validate or normalize retries before using attempt < retries at src/webhook.ts:106. The schema accepts any number, so retries: 1.5 performs two attempts, logs that it will retry again, waits unnecessarily, then exits without the promised final warning; negative values make no request at all. Require a non-negative integer or calculate a fixed attempt count.

The PR description includes both a test plan and a real-CLI verification record, so no testing-documentation finding.

@jeff-r2026
jeff-r2026 self-requested a review September 24, 2026 07:02
@jeff-r2026
jeff-r2026 merged commit aa6a883 into Tencent:main Sep 24, 2026
11 checks passed
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.

2 participants