dokploy icon indicating copy to clipboard operation
dokploy copied to clipboard

An error have occured: Deployment not found

Open oussamaboumaad opened this issue 9 months ago • 19 comments

To Reproduce

  1. use Dokploy v0.27.0
  2. Create an app, Gitlab provider .. add env whatever,
  3. update to new version v0.27.1
  4. try to deploy your app again.
  5. you'll probably see the issue

Current vs. Expected behavior

I have deployed applications that were working just fine on version v0.27.0. After recent update, I cannot deploy them. I even had webhooks working just fine before, but now both webhook / manual deployment get me the following errors

Error [TRPCError]: Deployment not found
    at async XP.autorun [as processFn] (dist/server.mjs:1:889) {
  code: 'BAD_REQUEST'
}
Error Error [TRPCError]: Error creating the deployment
    at async XP.autorun [as processFn] (dist/server.mjs:1:889) {
  code: 'BAD_REQUEST'
}
Error [TRPCError]: Deployment not found
    at async XP.autorun [as processFn] (dist/server.mjs:1:889) {
  code: 'BAD_REQUEST'
}
Error Error [TRPCError]: Error creating the deployment
    at async XP.autorun [as processFn] (dist/server.mjs:1:889) {
  code: 'BAD_REQUEST'
}

Expected behavior

app to deploy as normal as it should be

Provide environment information

OS: 

PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
NAME="Debian GNU/Linux"
VERSION_ID="12"
VERSION="12 (bookworm)"
VERSION_CODENAME=bookworm
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
`
Dokploy : v0.27.1

Which area(s) are affected? (Select all that apply)

Application

Are you deploying the applications where Dokploy is installed or on a remote server?

Same server where Dokploy is installed

Additional context

No response

Will you send a PR to fix it?

Maybe, need help

oussamaboumaad avatar Feb 19 '26 10:02 oussamaboumaad

same problem

KonstantinRogozhkin avatar Feb 19 '26 15:02 KonstantinRogozhkin

same here , it happens with github application private repos

AbanoubNassem avatar Feb 20 '26 07:02 AbanoubNassem

Got the same issue.

A temporary solution is to delete all recently failed deployments and then manually deploy again

lightumcc avatar Feb 20 '26 21:02 lightumcc

All my applications are from GitLab, and my entire GitLab is private (Self-Hosted).. so maybe that is the issue ???

The weird thing is that it didn't happen for all my apps, just few of them at random.

oussamaboumaad avatar Feb 22 '26 11:02 oussamaboumaad

Thanks @lightumcc, I had the same problem and your suggested workaround fixed it

lamhoangtung avatar Feb 22 '26 16:02 lamhoangtung

this is not a workaround , every time we push to deployment it breaks , and we have to delete the automated deployment and manually deploy it

AbanoubNassem avatar Feb 24 '26 15:02 AbanoubNassem

This is only happening with gitlab?

Siumauricio avatar Feb 25 '26 17:02 Siumauricio

@Siumauricio Github as well

AbanoubNassem avatar Feb 25 '26 17:02 AbanoubNassem

Just to understand, have you used the delete deployment functionality while the build is running?

Siumauricio avatar Feb 25 '26 17:02 Siumauricio

If you have the exact steps to reproduce the issue would be great, the steps suggested above work well for me.

Siumauricio avatar Feb 25 '26 17:02 Siumauricio

@Siumauricio for me dokploy it linked to github repo, on push to main branch , once I push it fails immediately, however when I delete the failed deployment and manually deploy it works and it actually picks-up the github commit message , was working fine the for over a year now only when updated to 27.1 , it broke

AbanoubNassem avatar Feb 25 '26 17:02 AbanoubNassem

Just to understand, have you used the delete deployment functionality while the build is running?

Possibly .. I don't remember, I might've done it with one or two.. but not all the failing ones.

magixus avatar Feb 25 '26 20:02 magixus

If you have the exact steps to reproduce the issue would be great, the steps suggested above work well for me.

I would've gladly mentioned the extract reproducible steps, unfortunately, the only thing that I did was upgrading from v0.27.0 to v0.27.1 while always of course using private self-hosted GitLab repos.

Problem is, I have other applications, same GitLab repo, same configs ... but didn't fail when manually or automatically deployed.

magixus avatar Feb 25 '26 20:02 magixus

logs shows:

Error [TRPCError]: Deployment not found
at async XP.autorun [as processFn] (dist/server.mjs:1:889) {
code: 'BAD_REQUEST'
}
Error Error [TRPCError]: Error creating the deployment
at async XP.autorun [as processFn] (dist/server.mjs:1:889) {
code: 'BAD_REQUEST'
}
Error [ExecError]: Command execution failed: Command failed: pkill -2 -f "docker build"
at m (.next/server/chunks/8192.js:42:1740)
at async q (.next/server/chunks/2035.js:124:2501)
at async (.next/server/chunks/2035.js:1:22764) {
command: 'pkill -2 -f "docker build"',
stdout: '',
stderr: '',
exitCode: null,
originalError: Error: Command failed: pkill -2 -f "docker build"
at ignore-listed frames {
code: null,
killed: false,
signal: 'SIGINT',
cmd: 'pkill -2 -f "docker build"',
stdout: '',
stderr: ''
},
serverId: undefined
}

AbanoubNassem avatar Feb 26 '26 06:02 AbanoubNassem

@Siumauricio I have another application that was working all good, after updating the branch in General / Deploy I start facing same issue on every single deploy

magixus avatar Feb 26 '26 15:02 magixus

same

amirho1 avatar Feb 27 '26 10:02 amirho1

I think this has been fixed in version 0.28.1 (latest update). probably because they revert the API in commit : https://github.com/Dokploy/dokploy/commit/9507745cc0ae251bfdafb5e2afc826be029f19f9

can anyone confirm ?

oussamaboumaad avatar Mar 01 '26 02:03 oussamaboumaad

for me it still the same even with 0.28.1

AbanoubNassem avatar Mar 01 '26 04:03 AbanoubNassem

Root Cause Analysis

I just hit this on v0.28.2 with a GitHub-sourced app (Dockerfile build type). I spent time digging into the Dokploy source code and I believe I found the exact root cause. It's a self-reinforcing error loop in createDeployment() that makes the app permanently undeployable once it enters the error state.

The bug step by step

1. Initial failure (transient)

createDeployment() in packages/server/src/services/deployment.ts calls removeLastTenDeployments() before creating the deployment record. If anything fails during this function — a filesystem error, a race condition when two webhooks fire simultaneously, a missing log file — execution falls into the catch block.

2. The catch block poisons the state

The catch block does two things that make recovery impossible:

catch (error) {
    // Creates a NEW deployment record with status: "error" and logPath: ""
    await db.insert(deployments).values({
        applicationId: deployment.applicationId,
        status: "error",
        logPath: "",     // <-- THIS IS THE POISON
        errorMessage: `An error have occured: ${error instanceof Error ? error.message : error}`,
        ...
    });
    // Locks the application in error state
    await updateApplicationStatus(application.applicationId, "error");
    throw new TRPCError({ code: "BAD_REQUEST", message: "Error creating the deployment" });
}

3. Next deploy attempt hits the same wall

On the next deploy attempt, createDeployment() calls removeLastTenDeployments() again. This function iterates old deployments and calls removeDeployment() for each one. When it hits the poisoned record (with logPath: ""):

  • removeDeployment() deletes the DB record, then runs rm -f ${deployment.logPath} — which with an empty string becomes rm -f with no argument (or with path.join("") → ".")
  • If this fails, or if another concurrent deployment already deleted it, removeDeployment() throws "Deployment not found"
  • This propagates up to createDeployment()'s catch block
  • The catch block creates ANOTHER poisoned deployment record with logPath: ""
  • applicationStatus is set to "error" again
  • The cycle repeats on every deploy attempt

Why some apps break and others don't

The initial trigger is transient and race-condition dependent. In my case, I had two apps in the same project with identical configs (same GitHub provider, same branch, same Dockerfile build type). The API app deployed fine. The web app got unlucky — likely a race condition from rapid webhook triggers — and entered the loop.

The actual errors in sequence

Every failed deploy produces this exact pattern in Dokploy logs:

Error [TRPCError]: Deployment not found        ← removeDeployment() failing on cleanup
Error [TRPCError]: Error creating the deployment  ← createDeployment() catch block

And creates a deployment record in the DB with:

status: "error", logPath: "", errorMessage: "An error have occured: Deployment not found"

Additional bug: copy-paste error in removeDeployment

removeDeployment() has a wrong fallback error message in its catch block:

catch (error) {
    const message = error instanceof Error ? error.message : "Error creating the deployment";
    //                                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    //                                        Should be "Error removing the deployment"
}

This makes logs confusing because a deletion failure reports as a creation failure.

No recovery mechanism exists

  • applicationStatus = 'error' is set in the catch block but nothing ever resets it on retry
  • The startup cleanup (initCancelDeployments) only handles "running" → "cancelled", not "error" → "idle"
  • The deploy/redeploy router procedures don't check applicationStatus, so jobs are queued but always fail inside the worker

How to reproduce

  1. Create an application with GitHub/GitLab provider
  2. Deploy it successfully at least once
  3. Manually insert a poisoned deployment record:
    INSERT INTO deployment ("deploymentId", "applicationId", "title", "status", "logPath", "errorMessage", "startedAt", "finishedAt")
    VALUES (gen_random_uuid()::text, '<APP_ID>', 'Test', 'error', '', 'An error have occured: test', NOW(), NOW());
    
  4. Make sure the app has 10+ deployments total (so removeLastTenDeployments triggers)
  5. Try to deploy — it will fail with "Deployment not found" / "Error creating the deployment" and never recover

Workaround

What actually fixes it (confirmed on v0.28.2):

-- Delete all poisoned error deployments for the affected app
DELETE FROM deployment 
WHERE "applicationId" = '<APP_ID>' 
AND "status" = 'error' 
AND "logPath" = '';

-- Reset application status
UPDATE application 
SET "applicationStatus" = 'done' 
WHERE "applicationId" = '<APP_ID>';

Then redeploy manually.

Suggested fixes

  1. Don't create error deployment records in createDeployment()'s catch block — or at minimum, don't create them with logPath: "". The error record with empty logPath is what poisons subsequent cleanup cycles.

  2. Make removeDeployment() gracefully handle already-deleted deployments — return null instead of throwing when the deployment doesn't exist. Cleanup should be idempotent.

  3. Add a guard in removeLastTenDeployments() — skip deployments that have empty logPath or wrap individual removeDeployment() calls in try-catch so one failed cleanup doesn't abort the entire operation.

  4. Fix the copy-paste error in removeDeployment()'s catch block ("Error creating the deployment" → "Error removing the deployment").

  5. Add a recovery mechanism — either reset applicationStatus before each deploy attempt, or add a "retry/reset" button in the UI that clears the error state.

Hope this helps track down the fix! Happy to help test a patch if needed.

vcode-sh avatar Mar 02 '26 08:03 vcode-sh