Skip to content

Idle shutdown: redeliver the GitHub webhook that woke the instance (direct-webhook mode) #3811

Done

Description

@integry

Part of the runtime-abstraction epic (#3758). This blocks #3804: its live smoke can't pass until this lands.

Problem: with direct webhooks, idle shutdown loses the event that wakes the instance

Evidence from a live run of the Fly smoke workflow (https://github.com/integry/propr/actions/runs/45654340384; fixture webhook delivery log):

Time (UTC) Event Result
16:34:25–29 ping, issues.opened, issues.labeled (llm-claude) 200 in under 1 s, instance awake
16:37:01 issues.labeled (AI), sent while the Machine was stopped timeout after 10 s: "context deadline exceeded (Client.Timeout exceeded while awaiting headers)", 1 attempt

GitHub gives a webhook delivery 10 seconds and does not retry automatically. Fly's proxy starts the stopped Machine on that request, but a cold wake takes about 16 s to the first 200 (measured earlier on the tutorial deploy). The instance comes up, but the AI label that woke it is never processed: issue #7 in the fixture repository got no ProPR comment for 20+ minutes.

docs/docs/operations/idle-shutdown.md covers this only for Connect intake: the relay caches deliveries and the instance asks for a replay on wake. Direct webhooks have no equivalent. The docs also assume a cold start of 5–10 s, which is optimistic.

Fix: redeliver failed deliveries after an idle wake (direct-webhook mode)

  1. When: on startup after an idle stop, i.e. when the idle state shows a stop (shutdownAt/intakeStoppedAt) and GITHUB_EVENT_INTAKE_MODE=direct_webhook. Run it once the webhook endpoint is accepting requests, so redeliveries are processed.
  2. What: list the App webhook's deliveries with the App JWT (GET /app/hook/deliveries, paginated with cursor, newest first) back to the stop time minus a small margin (about 2 min). Select failed deliveries (status_code 0 or ≥ 400, or status not OK) for which no later successful delivery with the same guid exists. Request redelivery with POST /app/hook/deliveries/{delivery_id}/attempts.
    • Cap the count (for example 200) and log any skipped.
    • Respect rate limits.
    • Never redeliver deliveries older than the stop window.
  3. Deduplication: make sure a redelivered event (same X-GitHub-Delivery GUID) is processed exactly once, even if the original was partly received. Check the existing webhook duplicate suppression and extend it if needed.
  4. Observability: log a summary at info level (scanned, failed, redelivered, skipped), and expose the last result in the idle-shutdown status the API already reports.
  5. Repository-level webhooks: document that only the GitHub App's own webhook is recovered (that's what the tutorial sets up). A repository webhook would need a token with repository-hook access; mention it, but don't implement it unless it's trivial.
  6. The smoke workflow (.github/workflows/fly-e2e.yml): stop creating a repository webhook with the PAT. Point the fixture GitHub App's own webhook at the disposable instance instead (PATCH /app/hook/config with the App JWT, using the App credentials from FLY_E2E_APP_ENV: URL https://$APP.fly.dev/webhook, the generated secret, content type JSON). Restore or clear it in an always() cleanup step. The App must be subscribed to Issues and Pull request events: check that, and document the requirement. This makes the smoke exercise exactly the tutorial's path, including recovery.
  7. Docs: in idle-shutdown.md and the Fly tutorial, explain that the waking delivery times out on GitHub's side and is redelivered by the instance after start, and put the measured cold start (about 15–20 s to first response) in place of the 5–10 s claim.

Acceptance

  • Unit tests:
    • delivery selection (failed vs. succeeded with the same GUID, the time window, pagination, the cap);
    • no recovery outside direct-webhook mode or without a recorded stop;
    • redelivery requests are made once.
  • Live: the Fly smoke workflow passes end to end: idle stop, wake by the AI label, the PR created on Sprites, cleanup. Run it through the temporary branch that adds a push trigger (workflow_dispatch needs the workflow on the default branch), and link the run in the PR.

Activity

  1. propr-dev commented on Nov 25, 2026

    @propr-dev
    Contributor

    🤖 AI processing has started for this issue using codex agent with gpt-6.2-astra model.

    I'll analyze the problem and work on a solution. This may take a few minutes.

    Processing Details:

    • Agent: codex
    • Model: gpt-6.2-astra
    • Branch: 3811/gpt-6.2-astra-idle-shutdown-redeliver-t-20261125-1715-kfx
    • Base Branch: 3758-epic-runtime-abstraction-sc0
    • Worktree: issue-3811-20261125-1715-gpt-6.2-astra-kfx

    🔍 Track Task Execution

  2. integry commented on Dec 1, 2026

    @integry
    OwnerAuthor

    Done in #3812, which merged into the runtime epic; the epic merged into main with #3774 and ships in 0.9.4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions