fix(webhook-agent-ingest): stop the internal-key gate from blocking token-authed callbacks#3719
Merged
Merged
Conversation
…oken-authed callbacks Completion callbacks authenticate with a scoped X-Callback-Token, validated by the callbacks handler. They were never meant to present the internal API key. But because /api/callbacks is mounted under /api, the internalApiMiddleware /api/* matcher rejected them with 401 before they reached that handler, leaving the webhook request stuck 'inprogress' forever (cloud-agent-next treats 401 as a permanent, non-retryable delivery failure). Let the /api/callbacks subtree skip the internal-key check so its own scoped-token auth runs. The route remains authenticated — just by the token it already carries, not the internal key. URL is unchanged, so callback URLs already persisted in in-flight cloud-agent-next session DOs keep working (no transition window). Adds unit tests that mount the routers as index.ts does (the prior isolated callbacks test could not catch this) and a real-worker integration regression.
Contributor
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Executive SummaryThe fix correctly exempts Files Reviewed (3 files)
Fix these issues in Kilo Cloud Reviewed by claude-4.6-sonnet-20260217 · 488,913 tokens Review guidance: REVIEW.md from base branch |
johnnyeric
approved these changes
Jun 3, 2026
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
Webhook triggered Cloud Agent sessions finished their work, but the webhook request stayed
inprogressin the UI forever.Root cause: completion callbacks authenticate with a scoped
X-Callback-Tokenthat the callbacks route validates. They are not meant to present the internal API key. But the callbacks route is mounted under/api, and the/apirouter runs an internal API key middleware on every path beneath it. That middleware returned401for the callback before it reached the route that validates the token the callback already carried. Cloud Agent delivery treats a401as permanent and does not retry, so the request was never moved out ofinprogress.The fix lets the
/api/callbackssubtree skip the internal API key check so its own token validation runs. The route stays authenticated, by the token it already carries rather than the internal key. The callback URL is unchanged, so URLs already stored in running sessions keep resolving, with no transition window.Architecture note for an unfamiliar reviewer: inbound webhooks already work because they are mounted at
/inbound, outside/api. The callbacks route was the only token validated route trapped behind the internal API key gate.The functional change is a single guard in
internalApiMiddleware; the rest of the diff is a comment and tests.Verification
This is auth and routing logic. The failure it fixes only reproduces with a live webhook trigger and a full session, so manual testing focused on confirming the root cause rather than a deployed run:
401on callback delivery (delivery happened, the endpoint returned401, and it was classified permanent).401body, proving the request is rejected by the internal API key middleware before the callbacks handler runs.Automated unit and integration tests are included in the diff and not listed here per the template.
Visual Changes
N/A
Reviewer Notes
return next()for the/api/callbacks/prefix at the top ofinternalApiMiddleware./api/callbacksis the callback handler, which always validates the scoped token (missing headers return400, bad token returns401, session mismatch returns403). No unauthenticated route is exposed.app.route()mounting,c.req.pathis the full request path (verified for hono 4.12.18), so the prefix check matches. The trailing slash avoids matching an unrelated path such as/api/callbacksX./apirouter otherwise contains only trigger CRUD routes, which still require the internal API key. The new unit tests assert both that callbacks pass without the key and that trigger routes still reject without it./api, so the middleware interaction was untested. The new tests mount the routers the way the worker does.