Skip to content

Install template: idle status callback returns 401 when the runner picks up the job before userdata reports idle. #971

Open

Description

@fernvenue

Environment

  • garm built from main at 1640cac (the ForgeInstance support added in Add forge instance entity #800). No release tag contains it yet; the latest released version is v0.2.1, which predates the feature.
  • Self-hosted Gitea (latest) with Actions enabled, authenticating with an admin token.
  • External provider (Alibaba Cloud ECS spot), Linux ephemeral runners.
  • Runner install template derived from the stock gitea_linux (the register step uses gitea-runner register --ephemeral --no-interactive --instance "{{ .RepoURL }}" ...).

Steps to reproduce

  1. garm-cli forge-instance add --endpoint <endpoint> --credentials <admin-pat> --forge-type gitea --random-webhook-secret --install-webhook. The system webhook is created (events [workflow_job], active). Note: the first forge-instance add call returned an error error installing hook: unknown error, but the hook was in fact installed and active, so the entity and webhook end up usable.
  2. garm-cli pool add --forge-instance <id> --enabled --provider-name <p> --flavor <f> --image <img> --os-arch amd64 --os-type linux --tags ubuntu-latest --runner-install-template <gitea_linux-based template> ....
  3. Queue a workflow whose runs-on matches the pool tag from a repository that is only covered by the instance-level webhook (not registered as a repository or organization entity).

The same sequence with a repository-level pool behaves identically (see "Additional data point").

Observed

  • garm receives the workflow_job webhook and creates an instance: attempting to create a runner in pool / creating instance in pool.
  • The bootstrap on the instance succeeds step by step:
    • GET /api/v1/metadata/install-script/ -> 200
    • several POST /api/v1/callbacks/status -> 200
    • POST /api/v1/callbacks/system-info/ -> 200
    • then a final POST /api/v1/callbacks/status -> 401 (bytes=47).
  • The job is picked up by the runner and completes successfully, but the runner's final POST /api/v1/callbacks/status (idle, with the agent ID) returns 401, so garm never records the runner as idle or its agent ID.
  • Separately, job never got assigned to a runner, ignoring action=handle_workflow is logged when a completed event arrives with an empty runner name. It also appears when the 401 does not occur, so it is not caused by it.
    Expected
    The idle callback is accepted, so the runner is recorded as idle together with its agent ID.

Additional data point
The same 401 on the final status callback also occurs with repository-level pools: six occurrences between 2026-11-19 and 2026-11-22, all before any instance-level pool existed. It is not specific to forge instances.

Source-level observation
POST /api/v1/callbacks/status is handled by APIController.InstanceStatusMessageHandler behind instanceMiddleware. The middleware (auth/instance_middleware.go) rejects the request when the recorded runner status is neither Installing nor Pending, and that branch logs nothing. When the forge reports the job in_progress, handleInProgressJob (runner/pool/pool.go) moves the runner to Active, so an idle callback arriving after that is rejected. This is consistent with the timing above, but I have not instrumented the branch to confirm which check fires.

Activity

  1. fernvenue commented on Nov 22, 2026

    @fernvenue
    Author

    Update after further investigation: the job itself is not blocked. Cloud runners do register and execute the queued jobs successfully, verified end to end against a self-hosted Gitea (latest) with an external ECS provider, across repository and forge-instance-level pools. The 401 is a bookkeeping problem, not a scheduler failure.

    Cause, from the source: when the forge reports a job as in_progress, handleInProgressJob (runner/pool/pool.go) moves the runner to RunnerActive. The instance auth middleware (auth/instance_middleware.go) then accepted callbacks only while the recorded runner status was Installing or Pending, so the runner's own idle callback, the one carrying its agent ID — is answered with 401. garm therefore never records the runner as idle or its agent ID, and the job's completion cannot be matched back to a runner (job never got assigned to a runner, ignoring). The job still runs on the runner; only garm's accounting of it is wrong, which can also affect idle-runner lifecycle decisions.

    I'll open a PR that rejects callbacks only for runners in a terminal state (Terminated / Failed) instead of any state past Installing/Pending.

  2. gabriel-samfira commented on Nov 23, 2026

    @gabriel-samfira
    Member

    Interesting. So the runner picked up the job before the userdata script managed to phone home that it finished setting up the runner. That is one race condition I never expected. Does this also happen in agent mode?

    Edit: The reason I am asking is because this may be more easily fixed in the runner install template. Agent mode starts the agent first and the agent reports runner status. In non agent mode, we can set the status before starting the runner (right now it's reversed).

  3. fernvenue commented on Nov 23, 2026

    @fernvenue
    Author

    Thanks, that matches what we see. Timeline from our run (non-agent mode): the job started at 15:00:04Z, the runner's system-info callback arrived within the same second, and the idle status callback one second later got the 401. In the install template the idle report comes after systemctl enable --now, so the ephemeral runner can pick up an already-queued job before it reports idle.

    Agent mode: we haven't run it (the agent URL isn't reachable from the runners in this setup), so I can't say whether it reproduces there.

    I agree this belongs in the template. My middleware change loosens a check that looks deliberate (an instance that finished installing shouldn't keep authenticating), so I'll close #972. I'll try reporting idle before the service starts, and open a new PR against the template if that fixes it.

    I've also corrected the issue title and removed a claim about runners being created in more than one pool that I couldn't confirm. The jobs do run; only the bookkeeping is off.

  4. changed the title [-]Gitea forge instance: ephemeral runner registers but its status callback returns 401, so the job is never assigned.[/-] [+]Install template: idle status callback returns 401 when the runner picks up the job before userdata reports idle.[/+] on Nov 23, 2026
  5. fernvenue commented on Nov 23, 2026

    @fernvenue
    Author

    Tested the reorder in our (non-agent) install template: the idle report, system-info and the agent ID read now run before systemctl enable --now. With a repository-level pool the final callbacks/status returned 200 (no 401), the runner went pending -> installing -> active with its agent ID recorded, and the job completed. .runner is already written by register at that point, so reading the agent ID earlier works. Agent mode is still untested on our side.

    Separate observation: job never got assigned to a runner, ignoring is still logged (twice, right after the job finished). It comes from handleCompletedJob when the completed event arrives with an empty runner name, so it is not caused by the 401 as I wrote earlier. I haven't looked at the raw webhook payload yet, so I don't know whether the runner name is missing from Gitea's completed event or lost in parsing. The runner also stayed active in garm for at least a minute after the job had finished.

    I'll open a PR for the template change.

  6. gabriel-samfira commented on Nov 24, 2026

    @gabriel-samfira
    Member

    you can check the webhook payload in the webhook section of github/gitea. I suspect the payload did not include a runner name.

  7. fernvenue commented on Nov 24, 2026

    @fernvenue
    Author

    Confirmed from the system webhook's deliveries for one job: the queued event has runner_id: 0 and no runner_name; in_progress has both runner_id and runner_name; completed has runner_id but no runner_name field at all. So Gitea omits the runner name from the completed event, and handleCompletedJob returns early on the empty name. The runner is therefore never marked terminated and its instance is never moved to pending_delete by the job, so a finished runner stays until the idle cleanup (about 6 minutes in our case).

    runner_id is present on completed, and it should be the same number that the install template reads from .runner and reports as agent_id in the idle callback (which is only recorded now that the idle report comes first, PR #976). So handleCompletedJob could look the instance up by agent ID when the name is empty. I haven't tested that yet. Would you be open to such a fallback if I send a PR?

  8. gabriel-samfira commented on Nov 24, 2026

    @gabriel-samfira
    Member

    I think this is related:

    #939

    But to my shame I have not yet caught up with all the new open issues and PRs. Trying to go through them now and hopefully release a new version this week.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions