Repository navigation
Description
Environment
- garm built from
mainat1640cac(theForgeInstancesupport 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 usesgitea-runner register --ephemeral --no-interactive --instance "{{ .RepoURL }}" ...).
Steps to reproduce
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 firstforge-instance addcall returned an errorerror installing hook: unknown error, but the hook was in fact installed and active, so the entity and webhook end up usable.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> ....- Queue a workflow whose
runs-onmatches 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_jobwebhook 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_workflowis 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
fernvenue commentedon Nov 22, 2026
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
401is 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 toRunnerActive. The instance auth middleware (auth/instance_middleware.go) then accepted callbacks only while the recorded runner status wasInstallingorPending, so the runner's ownidlecallback, the one carrying its agent ID — is answered with401. 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 pastInstalling/Pending.gabriel-samfira commentedon Nov 23, 2026
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).
fernvenue commentedon Nov 23, 2026
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.
[-]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.[/+]fernvenue commentedon Nov 23, 2026
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 finalcallbacks/statusreturned 200 (no 401), the runner went pending -> installing -> active with its agent ID recorded, and the job completed..runneris already written byregisterat 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, ignoringis still logged (twice, right after the job finished). It comes fromhandleCompletedJobwhen 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 stayedactivein garm for at least a minute after the job had finished.I'll open a PR for the template change.
gabriel-samfira commentedon Nov 24, 2026
you can check the webhook payload in the webhook section of github/gitea. I suspect the payload did not include a runner name.
fernvenue commentedon Nov 24, 2026
Confirmed from the system webhook's deliveries for one job: the
queuedevent hasrunner_id: 0and norunner_name;in_progresshas bothrunner_idandrunner_name;completedhasrunner_idbut norunner_namefield at all. So Gitea omits the runner name from the completed event, andhandleCompletedJobreturns early on the empty name. The runner is therefore never marked terminated and its instance is never moved topending_deleteby the job, so a finished runner stays until the idle cleanup (about 6 minutes in our case).runner_idis present oncompleted, and it should be the same number that the install template reads from.runnerand reports asagent_idin the idle callback (which is only recorded now that the idle report comes first, PR #976). SohandleCompletedJobcould 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?gabriel-samfira commentedon Nov 24, 2026
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.