…04 (DX-30310)
cm:branches:merge polled GET /v3/stacks/branches_queue/{uid} immediately
after submitting the merge. When that poll lands before the merge worker
has registered the job, the API answers 404 "Invalid merge job UID"
(error code 131). getMergeQueueStatus routed every non-429 error to
handleErrorMsg, which printed the message and called process.exit(1), so
the CLI reported a failed merge while the job completed in the background
and never printed the merge UID.
- getMergeQueueStatus: keep the 429 retry, throw other errors to the
caller instead of exiting the process
- isMergeJobNotRegistered: detect 404 / error code 131
- fetchMergeStatus: treat 404 and an empty queue as "not registered yet"
and retry up to 5 times with a short linear backoff; if the status still
can't be read (or the check fails otherwise), return the merge UID with
statusUnknown instead of failing. Failed merges are still reported.
- executeMerge: follow any non-complete merge that returns a UID instead
of returning nothing
- MergeHandler: for statusUnknown, print the merge UID and the
cm:branches:merge-status command instead of an error
- Unit tests for the 404/empty-queue retry, the fallback, the 429 retry
and the handler output
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Summary
Fixes DX-30310:
csdx cm:branches:mergeprintedError: Invalid merge job UIDand exited with code 1 about 0.5 s after submitting, while the merge job then completed successfully in the background. The customer believed the merge had failed, retried, and hit CMA-23222 (a second merge failing with "No items available for merge" and an extra revert branch).Root cause
executeMerge→fetchMergeStatuspolledGET /v3/stacks/branches_queue/{uid}immediately after the merge POST.{"errorMessage": "Invalid merge job UID", "errorCode": 131}. In the customer's Observe timeline, the poll arrived 38 ms beforemessage_processed.getMergeQueueStatussent every non-429 error tohandleErrorMsg, which prints the message and callsprocess.exit(1). So there was no retry, the merge UID was never printed, and the handler's existing "check later withcm:branches:merge-status" fallback never ran.Changes
utils/index.tsgetMergeQueueStatuskeeps the 429 retry; any other error is thrown to the caller instead of exiting the process.isMergeJobNotRegistered()detects 404 / error code 131.utils/merge-helper.tsfetchMergeStatustreats a 404 or an emptyqueueas "not registered yet" and retries up to 5 times with a short linear backoff (1 s, 2 s, … 5 s).statusUnknown: trueinstead of failing.executeMergefollows any not-yet-complete merge that returns a UID, instead of returningundefinedand printing nothing.branch/merge-handler.ts: forstatusUnknown, printsMerge job submitted. Merge UID: …, the reason, and thecsdx cm:branches:merge-status -k … --merge-uid …command, instead of an error.interfaces/index.ts: optionalstatusUnknownandreasononMergeJobStatusResponse.Testing
Unit tests (
test/unit/utils/merge-branch-handler.test.ts), 10 new cases:getMergeQueueStatusthrows instead of exiting, and still retries on 429isMergeJobNotRegisteredexecuteMergefollows unusual statuses8 of them fail on the old code. Branches suite: 132 passing, 1 pending;
tscclean; no new lint warnings.End to end on a dedicated test stack (AWS NA), using the real
csdx2.0.2 binary and a real merge of 4 changed content types (dev→main, Prefer Compare → Both → Execute). The customer's race depends on network timing, so for C–E only the firstGET branches_queuecall(s) were answered with the API's exact 404 by an HTTP interceptor (nock). Every other request, including the merge itself, hit the real API.Error: Invalid merge job UIDWaiting for the merge job to be registered... (Retry 1/5)→ Merged the changes successfullyMerge job submitted. Merge UID: …+merge-statuscommandmerge-status→ completeC reproduces the customer's report exactly; D and E show the fix.
Notes for reviewers
open,papaparse,csv-parsevia@contentstack/cli-utilities;minimatchvia@oclif/core). This PR changes no dependencies. Talisman passed.pnpm testin this package fails atpretest(tsc -p test) because of missing mocha globals in three test files this PR doesn't touch; tests were run with mocha directly.cm:branches:difflabels, fix(branches): label content type option changes in branch diff (DX-30314) #386), CMA-23222 (backend).🤖 Generated with Claude Code