Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

fix(ci): piece release no longer fails when another run already published the version (#16656)

Hazem Adel02205ce6c73f
diff --git a/brain/knowledge/engineering/ci-pipeline.md b/brain/knowledge/engineering/ci-pipeline.md
index 3cd954ee91f..7d1d2315a09 100644
--- a/brain/knowledge/engineering/ci-pipeline.md
+++ b/brain/knowledge/engineering/ci-pipeline.md
@@ -26,6 +26,7 @@ The PR checks that decide whether a change builds and passes tests. Lives in `.g
- Two turbo invocations running at the same time in one job race on `cache: false` builds: the retired pipeline failed `api#build` with "@activepieces/shared has no exported member" for a member that exists, because a second invocation was rewriting `shared/dist` while api's tsc read it. One invocation per job.
- `--affected` and `--filter` intersect in turbo; there is no union flag. To run "the affected packages plus this fixed set" in one invocation, pass the affected names (the `changes` job outputs them as JSON) as explicit `--filter=<name>` arguments alongside the fixed ones. Two invocations rebuild the shared dependency chain twice because `build` is uncached.
- Pieces are the one place the pipeline overrides the dependency graph, by decision (2026-09-24). A piece runs when its own files changed; every piece runs when `pieces/framework` or `pieces/common` changed. A change to `core-piece-types`, `core-utils`, `core-formula` or `core-execution` does not pull the 700+ pieces in, although they depend on it, because that cost about 20 minutes per such PR (5 of the last 60). The accepted blind spot: a core type change that breaks piece compilation is caught when pieces are published (`release-pieces.yml`), not in the PR. The `changes` job computes this with two turbo listings, `ls --filter='[base...HEAD]'` (changed directly) and `ls --affected` (plus dependents).
+- Two pushes to main a few minutes apart can both try to publish the same piece version in `release-pieces.yml`. The second run's "already published" check reads npm's `latest` dist-tag, which can stay stale for minutes after a publish, so it publishes again and npm answers `409 Cannot publish over previously staged version` (2026-10-19, `[email protected]`). `publishNpmPackage` treats a failed publish as success when `npm view <name>@<version>` resolves; a `concurrency` group would not help, since the runs did not overlap.
- The engine's tests execute five pieces (`AP_DEV_PIECES` in `packages/server/engine/vitest.config.ts`: http, data-mapper, approval, webhook, delay), so those five are engine devDependencies. That edge is what makes `--affected` pull engine in when one of them changes; without it a pieces-only PR ran the piece's checks and skipped the engine tests that exercise it (caught on the retirement PR, 2026-09-27). Three lists name the same set and must move together: that `AP_DEV_PIECES`, `@activepieces/engine#test` `dependsOn` in `turbo.json`, and engine's devDependencies.
- `TURBO_SCM_BASE` must be `origin/<base branch>` in CI. turbo's default base is `main`, which a CI checkout does not have, so without it every run degrades to "everything affected".
- Required status checks are set by a repo admin (branch ruleset on `main`) and match on job display name. A job its `if:` skips reports `skipped`, which GitHub counts as passing, so every job here can be required: `changes`, `lint`, `build-test`, `api (ce)`, `api (cloud)`, `api (ee, unit, migrations)`, `tool-search (postgres)`. A workflow-level skip (`on.paths`) leaves a required check pending forever, so keep the filtering inside the `changes` job. On 2026-09-27, when the old `ci.yml` was retired, nothing was required yet: `isRequired` was false on every check and the only ruleset enforced codeowner review.
diff --git a/tools/scripts/utils/publish-npm-package.ts b/tools/scripts/utils/publish-npm-package.ts
index 149396e2434..01a6df650e9 100644
--- a/tools/scripts/utils/publish-npm-package.ts
+++ b/tools/scripts/utils/publish-npm-package.ts
@@ -1,6 +1,7 @@
import assert from 'node:assert'
import { argv } from 'node:process'
import { execSync } from 'node:child_process'
+import { tryCatchSync } from '@activepieces/core-utils'
import { existsSync, readFileSync, writeFileSync } from 'node:fs'
import { readPackageJson } from './files'
import { packagePrePublishChecks } from './package-pre-publish-checks'
@@ -92,11 +93,23 @@ export const publishNpmPackage = async (path: string): Promise<void> => {
assertNoUnpublishableDeps(`${outputPath}/package.json`)
assertNoSemverRanges(`${outputPath}/package.json`)
- execSync(`npm publish --access public --tag latest`, { cwd: outputPath, stdio: 'inherit' })
+ const { error } = tryCatchSync(() => execSync(`npm publish --access public --tag latest`, { cwd: outputPath, stdio: 'inherit' }))
+ if (error) {
+ if (!isVersionOnRegistry({ name: json.name, version })) {
+ throw error
+ }
+ console.info(`[publishProject] publish failed but version is already on registry, path=${path}, version=${version}`)
+ return
+ }
console.info(`[publishProject] success, path=${path}, version=${version}`)
}
+function isVersionOnRegistry({ name, version }: { name: string, version: string }): boolean {
+ const { data } = tryCatchSync(() => execSync(`npm view ${name}@${version} version`, { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }))
+ return data?.trim() === version
+}
+
const main = async (): Promise<void> => {
const path = argv[2]
await publishNpmPackage(path)