Repository navigation
fix(release): wait for the new version on npm before syncing the template - #747
Conversation
…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>
|
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)
|
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>
🤖 AppKit PR bot🔬 Run evalsStart an eval for this PR from the evals-monitor app: Go to Evals Monitor → 📦 Try this PR's app templateScaffolds a new app from this PR's SDK build. Run it in any folder (requires the GitHub CLI — gh run download 45813212574 -R databricks/appkit -n appkit-template-0.105.0-pr.9bedeee-work-14-template-sync-waits-until-the-747 -D appkit-pr-747 \
&& unzip -o "appkit-pr-747/appkit-template-0.105.0-pr.9bedeee-work-14-template-sync-waits-until-the-747.zip" -d "appkit-pr-747" \
&& databricks apps init --template "appkit-pr-747"The template pins |
|
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)
Pre-existing (not required, there before this change)
|
|
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)
|
|
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)
|
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>
|
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. |
| // keeps it that way if a config default changes. | ||
| const { stdout, stderr } = await execFileAsync( | ||
| "npm", | ||
| ["view", `${name}@${version}`, "version", "--prefer-online"], |
There was a problem hiding this comment.
This breaks when npm inherits npm_config_json=true: npm view then prints "0.104.0" with quotes, so the comparison at line 45 never matches and the wait runs to timeout. Pass --json explicitly and parse it, or force plain output.
| ["view", `${name}@${version}`, "version", "--prefer-online"], | ||
| { | ||
| cwd, | ||
| timeout: Math.max( |
There was a problem hiding this comment.
Killing each probe after 60s is new. A slow registry that install would have waited for (npm's fetch timeout is 5 minutes) now fails the whole publish after about 10 minutes. Is 60s per probe intended, or could it use the fetch timeout?
| Math.min(PROBE_TIMEOUT_MS, deadline - Date.now()), | ||
| ), | ||
| }, | ||
| ).catch((error) => ({ |
There was a problem hiding this comment.
Every failed npm view is retried as "not on the registry yet", including a missing npm, bad config or an auth error. That's up to ten minutes of misleading warnings. Retry only not-found and transient registry errors, and fail fast on the rest.
| console.log(`✓ ${name}@${version} is on the npm registry`); | ||
| break; | ||
| } | ||
| if (Date.now() + delay > deadline) { |
There was a problem hiding this comment.
This gives up whenever the next full backoff would pass the deadline, even with time left. With the defaults it can quit around 575s while reporting a 600s timeout. Sleep for the smaller of the backoff and the remaining time, then probe once more before failing.
| // through the release pipeline, so they must not ship in the template. | ||
| git("tag", "-a", tag, "-m", `Template v${version}`) && | ||
| // The branch may have moved while we waited for the registry. | ||
| git("pull", "--rebase", "origin", branch) && |
There was a problem hiding this comment.
This breaks when the checkout has an unrelated modified tracked file: git pull --rebase refuses to run, and the old flow pushed fine. Is the runner guaranteed to have a clean checkout? If not, use --autostash, or skip the rebase when the remote hasn't moved.
| VERSION, | ||
| { | ||
| cwd: directory, | ||
| timeoutMs: 1_000, |
There was a problem hiding this comment.
The one-second budget includes starting npm for the first, already-available package. On a slow runner that package can time out, and the assertion naming the second package fails with no real regression. Use a fake probe and clock here, or give npm startup more time.
| "a registry that never answers still ends the wait on time", | ||
| { timeout: 60_000 }, | ||
| async () => { | ||
| await fakeRegistry({ "@databricks/appkit": "stall" }); |
There was a problem hiding this comment.
Nothing checks that npm actually reached the server, so this can pass by killing npm during startup without ever stalling on a response. Wait for the request to arrive before measuring the timeout.
| let server: Server; | ||
| const requests = new Map<string, number>(); | ||
|
|
||
| /** |
There was a problem hiding this comment.
Not blocking, but this doc comment just restates the threshold, cache header and "stall" branches the helper already shows. Drop it, and keep only comments that explain npm's behavior.
| git(runner, "push", "-q", "origin", "main"); | ||
| const released = git(runner, "rev-parse", "HEAD"); | ||
|
|
||
| // A change merged to main after the release was cut. |
There was a problem hiding this comment.
Not blocking, but this comment narrates the clone, commit and push right below it, and the test name already gives the scenario. It can go.
| // 1. Update template package.json | ||
| const templatePath = join(ROOT, "template", "package.json"); | ||
| const templateJson = JSON.parse(readFileSync(templatePath, "utf-8")); | ||
| // The packages this release just published. |
There was a problem hiding this comment.
Not blocking, but "the packages this release just published" repeats what the package list and release-version assignment next to it already say. It can go.
- npm view runs with --json and its answer is parsed, so an inherited npm_config_json no longer turns "0.104.0" into a value that never matches. - Only not-yet-published (E404), throttling, 5xx and the network errors npm itself retries are waited out; auth, config or a missing npm fail at once with npm's error code. - A probe may run until the deadline instead of being killed after 60 s, so a slow registry that npm install would wait for is not cut off early. - Near the deadline the wait sleeps only the time left and checks once more, instead of quitting while it still had time. - git pull --rebase uses --autostash: the job's own install can leave unrelated tracked files modified, which made the pull refuse to run. - Tests: minimum request counts, a single never-served package for the timeout message, a deadline check, a fail-fast case, a stall measured from the request's arrival, and a dirty-checkout push. Narrating comments dropped. Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: mario.cadenas <mario.cadenas@databricks.com>
|
Review 6 · 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 change waits for both template-pinned AppKit packages before installation, refreshes npm metadata during install, and keeps the tag on the release checkout's commit. I found no qualifying defect. The prescribed local check stopped at unchanged knip diagnostics before it reached Vitest, and I could not run the private release workflow. Nit (not required, below the gate)
|
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 apnpmlink 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 pnpmundoes 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 commit5d44365fmakes the check run again. It only corrects a comment:npm viewalready revalidates its cache by default, so--prefer-onlinethere is a guard, not the fix.I ran the exact check command the way
finish.shruns 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.tsrannpm installright 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:
tools/wait-for-npm-version.ts. Before installing, it pollsnpm view <pkg>@<version> version --prefer-onlinefor each package the script pins (@databricks/appkitand@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 installnow runs with--prefer-online. Because of--min-release-age, npm fetches the same full packument for the install asnpm viewdoes, so the probe checks the same document.git pull --rebasebefore tagging.git push --atomic origin HEAD refs/tags/template-v<version>. Before,--follow-tagssilently 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.tools/wait-for-npm-version.test.tsuses 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:
--atomicleft 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-onlineis not tested either; the wait test passes with or without it.For the release workflow (private repo), for you to take over:
--lockfile-only) may fetch the abbreviated packument, which the CDN can refresh at a different time than the full onenpm viewchecks. Its existing 2 s / 4 s retries are the only cover.Also noticed:
.gitignore(tmp) andknip.json: knip falsely reportspackages/appkit/bin/appkit.jsand the root devDependenciesesbuildandoraas unused when the checkout's path contains atmpfolder. It passes in the same tree at a normal path.apps/dev-playground/client/package-lock.json:pnpm installat the root once rewrote it (it removed extraneous../../../packages/appkit-uientries). I reverted it; I didn't change it.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