fix(webhooks): the managed Gitea webhook answers 202 and works in the background #538

Merged
sharang merged 1 commits from fix/webhook-async-202 into main 2026-10-09 11:22:01 +00:00
Owner

Approved for after the 2026-10-09 customer call; not part of v0.4.6.

What changes

  • (a) 202 after the signature check. POST /webhook/{tenant}/gitea-source verifies the signature, parses and routes the event, then answers 202 Accepted. Entitlement (automation_allowed), the tenant database, ensure_target and the scan run in a tokio::spawned task. Ignored events still answer 200; 401/404/400 are unchanged.
  • (b) 5 s timeout on the registry's Keycloak token request (registry.rs::bearer). The registry requests already had 5 s; the token POST only had the shared client's 30 s while holding the token lock.
  • (c) Durations logged. Gitea source webhook answered with status and elapsed_ms; the background task logs handled (outcome) or not handled (reason, e.g. refused: ...) with its own elapsed_ms.

Behaviour to know

  • A refusal by entitlement or ladder no longer shows as 403 in Gitea's delivery log; it is in the agent log (Gitea source webhook not handled: refused: ...).
  • Deliveries were already handled concurrently; with background work, a created and a deleted for the same repository arriving within milliseconds could still apply out of order, as before. The periodic sync corrects it.

Tests

  • tests/git_source.rs now expects 202 and waits for the target, its detection and the archive.
  • New unit test: a token endpoint that accepts and never answers fails after the request timeout, not 30 s.
  • clippy -p compliance-agent --all-targets -D warnings, fmt, both tests run locally against Mongo.

🤖 Generated with Claude Code

https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p

Approved for after the 2026-10-09 customer call; not part of v0.4.6. ## What changes - **(a) 202 after the signature check.** `POST /webhook/{tenant}/gitea-source` verifies the signature, parses and routes the event, then answers `202 Accepted`. Entitlement (`automation_allowed`), the tenant database, `ensure_target` and the scan run in a `tokio::spawn`ed task. Ignored events still answer 200; 401/404/400 are unchanged. - **(b) 5 s timeout on the registry's Keycloak token request** (`registry.rs::bearer`). The registry requests already had 5 s; the token POST only had the shared client's 30 s while holding the token lock. - **(c) Durations logged.** `Gitea source webhook answered` with `status` and `elapsed_ms`; the background task logs `handled` (outcome) or `not handled` (reason, e.g. `refused: ...`) with its own `elapsed_ms`. ## Behaviour to know - A refusal by entitlement or ladder no longer shows as 403 in Gitea's delivery log; it is in the agent log (`Gitea source webhook not handled: refused: ...`). - Deliveries were already handled concurrently; with background work, a `created` and a `deleted` for the same repository arriving within milliseconds could still apply out of order, as before. The periodic sync corrects it. ## Tests - `tests/git_source.rs` now expects 202 and waits for the target, its detection and the archive. - New unit test: a token endpoint that accepts and never answers fails after the request timeout, not 30 s. - clippy `-p compliance-agent --all-targets -D warnings`, fmt, both tests run locally against Mongo. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
sharang added 1 commit 2026-10-09 11:10:35 +00:00
fix(webhooks): the managed Gitea webhook answers 202 and works in the background
CI / Check (push) Skipped
CI / Detect Changes (pull_request) Skipped
CI / Deploy Agent (pull_request) Skipped
CI / Deploy Dashboard (pull_request) Skipped
CI / Deploy Docs (pull_request) Skipped
CI / Deploy MCP (pull_request) Skipped
CI / Check (pull_request) Successful in 10m45s
ccf63c4fdb
A verified delivery that asks for work is now answered 202 Accepted right
after the signature check. The entitlement check, ensure_target and the scan
run in a background task, so a slow registry or Keycloak no longer runs into
Gitea's delivery timeout. Ignored events still answer 200; bad signatures,
unknown sources and invalid JSON still answer 401/404/400.

The registry's Keycloak token request gets an explicit 5 s timeout (the
registry requests already had one); before, a hung Keycloak held the token
lock for the shared client's 30 s.

The handler logs its answer's status and duration; the background work logs
its outcome (or why it was refused) and its own duration.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
sharang merged commit e396141490 into main 2026-10-09 11:22:01 +00:00
Sign in to join this conversation.