Skip to content

sync attributes an unrelated branch's issue to a release when that branch points at the release commit #142

Closed

Description

@jeisaacs

Summary

sync reads git ref decorations (git log --format=…%D) to recover "the branch this commit came from". On a non-merge commit that is the tip of the default branch, any unrelated branch that happens to point at that same commit is treated as the source branch, and its name is mined for an issue key.

Creating a topic branch off an up-to-date main and pushing it — with no commits on it yet — is enough to attach that branch's issue to the next release, even though the issue has no commits, no PR, and no work at all.

extractBranchName (src/git.ts) filters out tag: refs and a common set (main, master, develop, …), then returns the longest remaining ref. A branch named after a ticket always beats origin/main on length, so it always wins.

#108 removed decoration-based extraction for merge commits. The commit that trips this is a plain chore: bump version commit, so that guard does not apply.

Impact

Real incident. Our continuous pipeline releases on every merge to main; a version-bump commit is the tagged release commit.

  • 14:26:56 — PR #1283, feat(DEV-4617): …, squash-merges to main
  • 14:27:11 — chore: bump version to 0.2.248 [skip ci] → 2a8dfce6, tagged v0.2.248, now tip of main
  • 14:33:24 — a developer creates and pushes branch DEV-4661 off main. Zero commits on it. (Its first commit landed 4 days later.)
  • 14:34:35 — deploy runs linear-release sync --release-version=0.2.248
=> Found 2 commits between 17c00713… and 2a8dfce6…
=> Retrieved issue keys: DEV-4661
=> Issues [DEV-4661] and pull requests [1283] have been added to release v0.2.248

DEV-4617 is the issue that actually shipped. DEV-4661 was an unstarted ticket that got a release, a "Deployed to Dev" status transition, and eventually a "Done - In Prod" — for work that did not exist. It was noticed because a developer asked why a ticket he had just created was already on a release.

Sampling our last 15 releases, sync's key set disagreed with the PR titles in the range every time: usually empty (our subjects are feat(DEV-1234): …, no magic word), twice attributing the wrong ticket via this path, and once extracting RFC-7807 from a commit body reading "implements RFC-7807" (implement is a magic word). In this repo the decoration path is effectively the only issue signal sync has, and it is the unreliable one.

Reproduction

Git fixture — an empty branch created off the release commit:

mkdir -p demo/upstream && cd demo/upstream && git init -q --bare && cd ..
git clone -q upstream work && cd work
git config user.email [email protected] && git config user.name t
echo 1 > f && git add f && git commit -qm "chore: initial" && git tag v0.2.247
echo 2 > f && git commit -aqm "feat(DEV-4617): add private S3 bucket (#1283)"
echo 3 > VERSION && git add VERSION && git commit -qm "chore: bump version to 0.2.248 [skip ci]"
git tag v0.2.248
git branch DEV-4661                      # <-- no commits, just a pointer at the release commit
git branch -m master main
git push -q -u origin main DEV-4661 && git push -q origin --tags && git fetch -q origin
git log --format='%H | %s%n   DECOR=[%D]' v0.2.247..v0.2.248
8b540a6… | chore: bump version to 0.2.248 [skip ci]
   DECOR=[HEAD -> main, tag: v0.2.248, origin/main, origin/DEV-4661, DEV-4661]
9b88331… | feat(DEV-4617): add private S3 bucket (#1283)
   DECOR=[]

Feeding that decoration string to the current main (7a4f8c6):

import { extractBranchName } from "./src/git.ts";
import { extractLinearIssueIdentifiersForCommit } from "./src/extractors.ts";

const decor = "HEAD -> main, tag: v0.2.248, origin/main, origin/DEV-4661, DEV-4661";
const branchName = extractBranchName(decor);
console.log("branchName  :", branchName);
console.log("identifiers :", JSON.stringify(extractLinearIssueIdentifiersForCommit({
  sha: "8b540a6",
  message: "chore: bump version to 0.2.248 [skip ci]",
  branchName,
  parents: ["9b88331"],
})));
branchName  : origin/DEV-4661
identifiers : [{"identifier":"DEV-4661","source":"branch_name"}]

Expected: no issue key from the bump commit; DEV-4617 comes from the squash subject of the other commit in the range.
Actual: DEV-4661, sourced from an unrelated branch that merely shares a SHA.

Secondary observation

normalizedBranches strips remotes/<remote>/, but git log %D emits origin/main, not remotes/origin/main. So the common guard never matches a remote-tracking ref:

"HEAD -> main, tag: v1, origin/main"                      -> origin/main
"HEAD -> main, tag: v1, origin/main, origin/DEV-4661"     -> origin/DEV-4661
"HEAD -> main, tag: v1, origin/main, origin/renovate/lockfile" -> origin/renovate/lockfile

Harmless on its own (origin/main yields no identifier), but it means the default-branch guard is not actually doing anything in a CI checkout, and the longest-name tiebreak is left to decide.

Suggested fix

The core assumption — "the refs decorating a commit identify the branch that produced it" — only holds while a commit is still exclusively on its topic branch. Once it is on the default branch, other branches can and do point at it.

Options, roughly in order of preference:

  1. Ignore decorations when the commit is on the default branch. Once a commit has landed, the producing branch is recorded in the merge/squash subject (extractBranchNameFromMergeMessage, (#123)), which is already parsed. Extending the Ignore branch-ref decorations on merge commits when extracting issue keys #108 reasoning from "merge commits" to "commits reachable from the default branch" would close this.
  2. Ignore decorations when more than one non-common branch points at the commit, or when the commit is also the default branch's tip. Ambiguity should mean "no branch", not "longest name wins".
  3. Strip a remote prefix before the common check so origin/main is recognised (fixes the secondary observation regardless of the above).
  4. An opt-out — e.g. --no-branch-detection — for repos that want subject/PR attribution only. --issue-pattern is documented as additive, so it cannot currently be used to turn this off.

Environment

  • Reproduced on main @ 7a4f8c6 (Refactor sync release description argument (#141)).
  • Production incident on CLI v0.7.0, GitHub Actions, actions/checkout@v4 with fetch-depth: 0, continuous pipeline, one release per merge to main.
  • extractBranchName is byte-identical between v0.7.0 and current main, so upgrading does not change the behaviour.

Activity

  1. linear-code commented on Sep 14, 2026

    @linear-code
    Contributor
  2. added
    bug
    on Sep 14, 2026
  3. axelniklasson commented on Sep 15, 2026

    @axelniklasson
    Collaborator

    @jeisaacs thanks for filing this issue! I just released version 0.18.0, which adds --no-branch-ref-detection to disable issue detection from Git branch refs.

    We kept this behavior to support fast-forward merges where the issue key exists only in the branch name. From the commit graph and branch refs alone, we can’t reliably distinguish that case from an empty branch created from an already-shipped commit. Enabling the flag disables branch-only attribution for both cases; commit-message and PR/MR detection remain enabled.

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

Metadata

Metadata

Assignees

Labels

GitHubRelease CLIbug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions