Skip to content

fix(release): wait for the new version on npm before syncing the template - #747

Open
MarioCadenas wants to merge 4 commits into
mainfrom
work/14-template-sync-waits-until-the-
Open

MarioCadenas wants to merge 4 commits into
mainfrom
work/14-template-sync-waits-until-the-

Conversation

@MarioCadenas

Copy link
Copy Markdown
Collaborator

What

Template sync waits until the new release is on npm

Why

: template sync waits until the new release is on npm

Commits on work/14-template-sync-waits-until-the- (not pushed; the board pushes them):

  • e0c28428: the fix.
  • 5d44365f: a comment correction.

Why the check failed ("sh: pnpm: not found"): pnpm had never been enabled on this machine. I ran the repo's documented setup step corepack enable pnpm, which adds a pnpm link to ~/.nvm/versions/node/v24.22.1/bin. That directory is on the PATH the check runs with. This changes the machine, not the repo; corepack disable pnpm undoes it.

The board runs the check only once per commit. So the second failure message was the cached 10:18 result for e0c28428. The new commit 5d44365f makes the check run again. It only corrects a comment: npm view already revalidates its cache by default, so --prefer-online there is a guard, not the fix.

I ran the exact check command the way finish.sh runs it: in my working folder, with this session's PATH and the 900 s timeout. It passed in 43 s.

Cause of the release bug: tools/publish-template-tag.ts ran npm install right after publish. The registry didn't serve the new version yet. The two retries came 2 s and 4 s later, and npm answered them from its local cache (the packument it had just fetched, cacheable for 5 minutes), so all three attempts failed with ETARGET.

What changed:

  • New file tools/wait-for-npm-version.ts. Before installing, it polls npm view <pkg>@<version> version --prefer-online for each package the script pins (@databricks/appkit and @databricks/appkit-ui). Retries start 5 s apart and double up to 30 s. All packages share one 10-minute limit. On timeout the script exits 1 with "<pkg>@<version> is still not on the npm registry after 600s" plus npm's last output.
  • npm install now runs with --prefer-online. Because of --min-release-age, npm fetches the same full packument for the install as npm view does, so the probe checks the same document.
  • Another cause of "fails the first time, passes on re-run": the push. Main can move while the job waits, and the longer wait makes that more likely. The sync commit is now rebased onto the latest branch with git pull --rebase before tagging.
  • The push is now git push --atomic origin HEAD refs/tags/template-v<version>. Before, --follow-tags silently skipped a tag that already existed on the remote. The branch moved and the script still printed "✓ pushed". Now the commit and the tag land together or not at all.
  • Test tools/wait-for-npm-version.test.ts uses a fake HTTP registry that serves the version only after N requests. It checks the wait succeeds with exactly N tries per package, and that a timeout names the package and version.

Checked:

  • The full check command passes, as above.
  • I ran the real script with 0.104.0 in a sandbox repo with a local bare origin. It waited, regenerated both lockfiles, committed, rebased, and pushed the commit and the tag atomically.
  • In separate sandbox runs, the rebase picked up a commit merged meanwhile, and --atomic left the branch alone when the tag already existed.

Not covered by a test: the git changes (rebase and atomic push) were only checked by hand in the sandbox. The install's --prefer-online is not tested either; the wait test passes with or without it.

For the release workflow (private repo), for you to take over:

  • With the wait, a job could take up to about 10 minutes of waiting, then a few minutes of installs. That fits the 15-minute timeout, but the margin is small. Raising the job timeout to 20 minutes would give room.
  • No ordering change is needed in the workflow; the wait in this repo is enough.
  • Residual risk: pnpm (--lockfile-only) may fetch the abbreviated packument, which the CDN can refresh at a different time than the full one npm view checks. Its existing 2 s / 4 s retries are the only cover.

Also noticed:

  • .gitignore (tmp) and knip.json: knip falsely reports packages/appkit/bin/appkit.js and the root devDependencies esbuild and ora as unused when the checkout's path contains a tmp folder. It passes in the same tree at a normal path.
  • apps/dev-playground/client/package-lock.json: pnpm install at the root once rewrote it (it removed extraneous ../../../packages/appkit-ui entries). I reverted it; I didn't change it.
  • pnpm 11 ignores the machine's NPM_CONFIG_REGISTRY, so a pnpm install that has to download goes to the blocked registry.npmjs.org. Installs work here only because the pnpm store already holds every package.

How it was verified

pnpm install --frozen-lockfile && pnpm run check && pnpm run knip && pnpm build && pnpm run typecheck && pnpm vitest run --changed "$(git merge-base HEAD origin/main)" passed.

Screenshots

None

Notes

None

MarioCadenas and others added 2 commits November 24, 2026 10:18
…late

The template sync ran npm install right after publish, before the registry
served the new version, so every attempt failed with ETARGET (npm also reused
its stale cached packument between retries). The script now polls
`npm view <pkg>@<version> --prefer-online` for each package it pins, with
backoff for up to 10 minutes, and fails naming the package and version if it
never appears. npm install also runs with --prefer-online.

The longer wait widens the window for main to move, so the sync commit is
rebased onto the latest branch before tagging, and the commit and tag are
pushed in one atomic push (with the tag named explicitly; --follow-tags
silently skipped a tag that already existed on the remote).

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: mario.cadenas <mario.cadenas@databricks.com>
npm view already revalidates its cache by default, so the flag is a guard
against a config change, not what defeats a stale packument.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: mario.cadenas <mario.cadenas@databricks.com>
@MarioCadenas

Copy link
Copy Markdown
Collaborator Author

Review 1 · Fail · 1 major

Does the change do what the task asked? No. Gate: major and worse must be fixed.

1 finding (1 important). 1 finding (1 important). The fake registry tests pass, and the script now probes both pinned packages before npm install. The wait still has no effective ten-minute bound when an npm view subprocess is slow or stalled, so the release job can expire without the requested package/version timeout message. The brief's example /xavier-review and /security-review commands were unavailable here.

Important (required)

  • major: A slow or stalled npm view can overrun the ten-minute wait and the release job without the promised timeout error. (tools/wait-for-npm-version.ts)
    Proof: Read the helper and caller at tools/publish-template-tag.ts:105. Local npm reports fetch-timeout=300000 ms and fetch-retries=2, so one probe may consume over ten minutes before the helper checks its deadline; no stalled-process simulation was run.

npm's own fetch timeout (5 minutes, retried twice) let a single stalled
`npm view` outlast the 10-minute wait, so the release job could time out
without the package/version message. Each probe now gets at most 60 s, and
never more than the time left before the deadline; a probe that is cut off
is reported as "npm view did not answer in time".

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: mario.cadenas <mario.cadenas@databricks.com>
@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

🤖 AppKit PR bot

🔬 Run evals

Start an eval for this PR from the evals-monitor app: Go to Evals Monitor →

📦 Try this PR's app template

Scaffolds a new app from this PR's SDK build. Run it in any folder (requires the GitHub CLI — gh auth login — and the Databricks CLI):

gh run download 45383716465 -R databricks/appkit -n appkit-template-0.104.1-pr.a3404fd-work-14-template-sync-waits-until-the-747 -D appkit-pr-747 \
  && unzip -o "appkit-pr-747/appkit-template-0.104.1-pr.a3404fd-work-14-template-sync-waits-until-the-747.zip" -d "appkit-pr-747" \
  && databricks apps init --template "appkit-pr-747"

The template pins @databricks/appkit and @databricks/appkit-ui to tarballs built from this branch, so the scaffolded app runs against this PR's code.

@MarioCadenas

Copy link
Copy Markdown
Collaborator Author

Review 2 · Pass · 1 minor, 1 pre-existing

Does the change do what the task asked? Yes. Gate: major and worse must be fixed.

2 findings (1 nit, 1 pre-existing): nothing needs fixing. No findings: nothing needs fixing. The new probe timeout fixes F1: a stalled npm view now ends within the wait and reports the package and version. The prescribed repository check passed, and I found no qualifying finding in this round.

Nit (not required, below the gate)

  • minor: Security: The new git pull --rebase origin <branch> puts any commits that reached the branch during the wait of up to 10 minutes into the release identity's template-v tag, so the template that databricks apps init users get may not be the tree the release pipeline built and scanned; before this change, a moved branch made the push fail. (tools/publish-template-tag.ts:179)
    Proof: I compared git show 8b99a203:tools/publish-template-tag.ts (commit, tag, then git push origin HEAD --follow-tags: a moved branch is rejected as non-fast-forward and nothing is pushed) with lines 179-184 now (rebase onto origin/, then tag and push the result). The prepare-release.yml template-artifact job builds template.zip from the release commit, not from the rebased tree. To use this, someone needs write access to the branch, and I did not run the script. A possible fix: after the pull, fail if the pulled-in commits touch template/.

Pre-existing (not required, there before this change)

  • minor: Security: The template sync commit is marked [skip ci], and the script never runs tools/check-template-lock-registry.ts, so lockfiles regenerated on a runner pointed at a non-public registry would be committed and tagged without the check that ci.yml applies to the committed template locks. (tools/publish-template-tag.ts:176)
    Proof: ci.yml:111 runs check-template-lock-registry.ts on the committed template locks, but the sync commit says [skip ci]. prepare-release.yml:179-180 runs the check only on the artifact copy. This script regenerates template/package-lock.json and template/pnpm-lock.yaml with npm/pnpm install and commits them unchecked. I could not see whether the secure runner's npm points at JFrog.

@MarioCadenas
MarioCadenas marked this pull request as ready for review November 24, 2026 10:54
@MarioCadenas
MarioCadenas requested a review from a team as a code owner November 24, 2026 10:54
@MarioCadenas

Copy link
Copy Markdown
Collaborator Author

Review 3 · Pass · 1 minor

Does the change do what the task asked? Yes. Gate: major and worse must be fixed.

1 finding (1 nit): nothing needs fixing. No findings: nothing needs fixing. The prior stalled-probe fault is fixed: each npm view call is bounded by the remaining wait time, and the stalled-registry test passes with the promised package and version error. I found no qualifying fault in this round; the required repository check passed and left the working tree clean. The /xavier-review and /security-review skills named in the brief were unavailable here.

Nit (not required, below the gate)

  • minor: Security: git pull --rebase origin <branch> puts any commits that reached the branch during the wait (up to 10 minutes) into the release identity's template-v tag, so the template that databricks apps init users get may not be the tree the release pipeline built and scanned; before this change, a moved branch made the push fail. (tools/publish-template-tag.ts:179)
    Proof: Line 179 at HEAD is still ["git", ["pull", "--rebase", "origin", branch]], and it runs before git tag -a template-v${version} (line 180) and git push --atomic origin HEAD refs/tags/template-v${version} (line 184). git log -L179,179:tools/publish-template-tag.ts 8b99a203..HEAD shows only e0c2842 adding it, and git show --stat 5d44365f 391a3a5c shows that neither later commit touches tools/publish-template-tag.ts.

@MarioCadenas MarioCadenas changed the title Template sync waits until the new release is on npm fix(release): wait for the new version on npm before syncing the template Nov 24, 2026
@MarioCadenas

Copy link
Copy Markdown
Collaborator Author

Review 4 · Fail · 1 major

Does the change do what the task asked? Yes. Gate: major and worse must be fixed.

1 finding (1 important). No findings: nothing needs fixing. The change meets the task as far as this review can verify: it waits for both pinned AppKit versions, refreshes npm metadata during install, and preserves the commit and tag in an atomic push. The required repository check passed, and the fake-registry tests exercised delayed availability, timeout reporting, and a stalled registry. I found no qualifying fault.

Important (required)

  • major: Security: The new git pull --rebase origin <branch> before tagging lets template-vX point at commits merged to main after release vX was cut. Template code that never went through the secure release pipeline then ships to every databricks apps init user pinned to that version. (tools/publish-template-tag.ts:179)
    Proof: Scratch repo in $TMPDIR/rebase-demo with a bare origin. The runner committed 'chore: release v1'. A second clone pushed 'feat: merged to main after release was cut', which changes template/app.ts. The runner then ran the script's exact sequence: commit the sync, git pull --rebase origin $(git rev-parse --abbrev-ref HEAD), git tag -a template-v2, git push --atomic origin HEAD refs/tags/template-v2. git log template-v2 on origin shows the sync commit on top of the post-release commit, and git show template-v2:template/app.ts prints 'unreleased change'. Before this change the tag sat di

Rebasing the sync commit onto the latest branch before tagging let
template-v<version> include commits merged after the release was cut, which
never went through the release pipeline yet would ship to every app created
from that template. The tag now goes on the sync commit on top of the
checked-out release; only the branch gets the sync replayed onto newer
commits. The git steps move into tools/push-template-tag.ts with a test
that recreates the race.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: mario.cadenas <mario.cadenas@databricks.com>
@MarioCadenas

Copy link
Copy Markdown
Collaborator Author

Review 5 · Pass

Does the change do what the task asked? Yes. Gate: major and worse must be fixed.

No findings: nothing needs fixing. No findings: nothing needs fixing. The change meets the task as reviewed in this round. The tag is created on the release checkout before the branch is rebased, and the moved-main test and required repository check pass. No qualifying finding remains.

No findings.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant