Skip to content

[Bug][Webhook] Posting by project name: the first call returns 404 and drops the payload, and the scheduled sync ignores the new connection #9418

Open

Description

@dmorfav

Search before asking

  • I had searched in the issues and found no similar issues.

What happened

The endpoints that post to a webhook by project name (POST /plugins/webhook/projects/:projectName/deployments, and the issues and pull_requests equivalents added in #8915) create the webhook connection on the first call through getOrCreateConnection (backend/plugins/webhook/api/deployments.go). That function has two problems.

1. The first call returns 404 and the payload is not stored.
err is first set by findByProjectName, which returns a not-found error when the connection does not exist yet. Inside the if err != nil block, projectOutput, err := services.GetProject(projectName) declares a new err that shadows the outer one. The function then ends with return connection, err, false, which returns the original not-found error. postDeployments (and postIssue, postPullRequests) return early when err != nil, so the caller gets a 404 although the connection and its blueprint connection were created, and the deployment sent in that first call is never stored. Sending the same payload again works.

2. The scheduled sync does not see the new connection until the blueprint is saved or the server restarts.
The connection is attached to the project's blueprint with a direct dal.Create(blueprintConnection). The cron job, however, runs a copy of the blueprint that reloadBlueprint loaded into memory (BlueprintJob{blueprint} in backend/server/services/blueprint.go), and nothing reloads it here. A manual "Collect Data" reads the blueprint from the database and includes the webhook, so everything looks fine at first. The next scheduled run plans from the stale copy, rebuilds project_mapping without the webhook's cicd_scopes/boards/repos rows, and the posted deployments stop counting for the project (DORA metrics drop) until someone saves the blueprint or restarts DevLake.

What do you expect to happen

  1. The first call stores the payload and returns 200, like the following ones.
  2. After the connection is attached, scheduled runs include it.

How to reproduce

  1. Create a project with a blueprint and a daily schedule, without any webhook connection.
  2. POST /api/rest/plugins/webhook/projects/<project>/deployments with a valid deployment. It returns 404, but a connection named <project>_deployments appears in the blueprint.
  3. Send the same request again: it returns 200 and the deployment is stored.
  4. Trigger "Collect Data" manually: the deployment is mapped to the project (project_mapping has webhook:<id> rows).
  5. Wait for the next scheduled run: project_mapping no longer has the webhook:<id> rows, and the deployment no longer counts for the project.
  6. Save the blueprint without changes (PATCH /blueprints/<id>) and trigger again: the rows come back and later scheduled runs keep them.

Anything else

Possible fix, both in getOrCreateConnection:

  1. Avoid the shadowing (for example projectOutput, getErr := services.GetProject(projectName)) and return nil as the error once the connection has been created.
  2. After dal.Create(blueprintConnection), reload the scheduled copy of the blueprint: either attach the connection through services.PatchBlueprint (which saves and reloads it, like the UI does) instead of inserting the row directly, or call services.ReloadBlueprints() afterwards.

Workaround: after the first call, send it again, and save the blueprint once (PATCH /blueprints/<id> with its current connections) so the scheduler picks up the new connection.

Version

v1.0.3-beta19 (the same code is on main)

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Activity

  1. shaynhornik commented on Nov 21, 2026

    @shaynhornik

    I'd like to work on this. Plan: stop the inner err from shadowing the not-found error in getOrCreateConnection so the first call stores the payload and returns 200, and reload the blueprint's scheduled job after the connection is attached so cron runs include it. I'll add tests for both and link the PR here.

  2. shaynhornik commented on Nov 21, 2026

    @shaynhornik

    PR is up: #9426. It fixes both parts: the first call now stores the payload and returns 200, and the blueprint's scheduled job is reloaded after the connection is attached.

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