ISSUE DESCRIPTION Woodpecker services appear to be running on UI & API after pipeline…
- User
ISSUE DESCRIPTION
Woodpecker services appear to be running on UI & API after pipeline completes
Component
server
Describe the bug
Some regression with newer releases (3.14.x) With kubernetes backend and pipelines defining services, the services are not cleaned properly. The pods from kubernetes backend are destroyed properly, but the woodpecker API still show these steps as state=running.
These are only cleaned after the pipeline times out. This prevents timely deploys as pipeline executions are not getting green status (although, as a mitigation, the pipeline waiting services can be cancelled, after which the deploy can be made).
Steps to reproduce
- Install woodpecker next-d05c597374
- Use kubernetes backend
- Define pipeline with services running infinitely, like running postgres
services: - name: postgres image: public.ecr.aws/docker/library/postgres:16-alpine3.21 ports: - 5432 environment: POSTGRES_PASSWORD: somepass POSTGRES_USER: someuser POSTGRES_DB: somedb steps: - name: wait-for-postgres image: public.ecr.aws/docker/library/postgres:16-alpine3.21 environment: DB_HOST: postgres DB_PORT: 5432 MAX_WAIT: 60 commands: - ./scripts/wait-for-postgres.sh- Run the pipeline, observe pods start for the service and the step
- once wait-for-postgres step completes, the pods are destroyed, but API still shows the service as running, also visible on Web UI.
pr-build > clone (#2): Step: clone Started: 1779195580 Stopped: 1779195594 Type: clone State: success pr-build > postgres (#3): Step: postgres Started: 1779195594 Stopped: 0 Type: service State: running pr-build > wait-for-postgres (#4): Step: wait-for-postgres Started: 1779195596 Stopped: 1779195602 Type: commands State: successExpected behavior
Pipeline services are stopped once the pipeline steps complete, the pipeline completes.
System Info
next-d05c597374 kubernetes backend, bitbucket datacenter forgeAdditional context
No response
Validations
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Assistant
I’ll first map the repository and locate the pipeline/service lifecycle code, then inspect recent related changes and existing tests before constructing a focused reproduction.
- Assistant
The search found a server RPC test whose name exactly describes the intended cleanup behavior. I’ll inspect that implementation/test and its git history, then run the focused package tests to see whether the regression is already captured but failing under a specific path.
- Assistant
The repository already contains a prior attempted fix (
#6337), but package tests cannot start because this environment has neitherGOMODCACHEnorGOPATHconfigured. I’ll inspect the complete workflow-finalization path and compare that fix with its surrounding refactors; afterward I’ll configure a temporary Go cache for validation. - Assistant
The attempted fix moved child cleanup before status computation, but subsequent sanitization work changed its terminal status. I need determine why the reported service remains
running: likelyStep.Running()no longer recognizes it, the persistence helper rejects the transition, orDonenever reaches cleanup due to state validation. I’ll inspect these predicates/helpers and the exact later commit diffs. - Assistant
The cleanup currently targets every running child and marks it
killed;WorkflowStatusmay translate that into success only for service-type steps. The unit fixture omitsType, so it may not represent production semantics. I’ll inspect status aggregation, step transition code, and agent-side ordering to identify the real mismatch (especially whether Kubernetes teardown cancels the workflow context beforeDoneRPC is delivered). - Assistant
UpdateStepToStatusSkippeddeliberately turns any started daemon intosuccess, so the nominal service path is correct. However,completeChildrenIfParentCompletedswallows persistence errors andDonecontinues, which can leave the database exactly as reported while acknowledging backend teardown. I’ll still verify agent context/order and inspect store behavior to see whether a concrete database error is likely (for example optimistic state checks or malformed timestamps), then build an end-to-endDoneunit reproduction with mocks rather than relying only on the helper test. - Assistant
Agent ordering is sound: backend
Runreturns after teardown, thenDoneuses a live fallback context. The production persistence method is a straightforward update, so the current helper should fix the exact report—but it is overly broad: it silently turns all started running command/plugin steps into success, not just long-lived services. I’ll run the focused tests now and inspect the branch/head metadata to establish whether this checkout contains an incomplete pre-existing patch that needs tightening. - Assistant
The focused run only failed due a second environment variable (
GOCACHE), not code. One more possible explanation is a race: if step status callbacks are asynchronous, a late “service running” update could overwrite cleanup afterDone. I’ll inspect tracer callback synchronization and retry semantics before changing server logic, because fixing ordering at the source is preferable to masking it. - Assistant
Focused tests pass, confirming the existing test only validates the helper’s happy path. I’ll inspect the tracer now; if calls are synchronous, I’ll harden server finalization by limiting cleanup to service steps and propagating cleanup failures, then add no tests (per instruction) but use a temporary reproduction script or existing test selection to verify behavior.
- Assistant
Detached step completion tracing runs in a goroutine, but server sanitization prevents late updates after workflow completion, so it cannot restore
running. The current head indeed contains the upstream fix for this issue in history. To make the implementation robust rather than submitting no-op, I’ll correct its transactional error handling: child finalization must succeed before the workflow is acknowledged/completed. Today a failedStepUpdateis logged and ignored, permanently reproducing “pod gone, API running.” The helper will attempt all children, aggregate errors, andDonewill return an error so the agent’s retry mechanism can retry finalization instead of acknowledging inconsistent state. - Assistant
The focused tests pass with the hardening change. Its retry behavior is safe: successful child updates become terminal in storage, failed ones remain running, and because the workflow itself is still running, a repeated
Doneonly retries the remaining children. I’ll now inspect gRPC error classification to confirm server-side storage errors are retryable, then run the broader server and agent suites plus static checks relevant to the edited package. - Assistant
The broad suite passed all compiled server/agent packages; only router/web setup failed because the checked-out repository lacks generated
web/distembed assets. One concern emerged: generic gRPC errors may map toUnknown, which the client treats as permanent, so relying solely on agent retry is not guaranteed. Even so, returning the failure avoids falsely acknowledging an inconsistent workflow; queue lease timeout can reschedule it. I’ll inspect the transport wrapper’s error mapping and run lint/vet on the edited package before deciding whether explicitcodes.Internalwrapping is warranted. - Assistant
There is no transport-wide mapping, so a raw storage error becomes
Unknownand is not immediately retried by the agent. I’ll make this finalization failure explicitlycodes.Internal, matching the client’s retry policy, while preserving the underlying aggregate error text. This ensures a transient database failure cannot leave services running in API state after Kubernetes cleanup. - Assistant
I’ll confirm the adapter returns peer errors unchanged, then apply the internal-status wrapping at the RPC boundary and rerun focused tests/vet.
- Assistant
The adapter does return errors unchanged. I’ll wrap only child-finalization storage failures as gRPC
Internal, avoiding any change to authorization/validation retry semantics.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.