Skip to content

fix(ci): local source trust: rewrites need a source made here; PR refspec globs and grafts (D-1322, D-1431) - #563

Open
acamarata wants to merge 2 commits into
mainfrom
fix/trust-d1322-rewrite-patch-id
Open

acamarata wants to merge 2 commits into
mainfrom
fix/trust-d1322-rewrite-patch-id

Conversation

@acamarata

@acamarata acamarata commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Fixes D-1322 (high) and D-1431 (medium, D01-D04 and D06) in TRUST local source trust. Both block P7-TRUST-99.

D-1322: rewrites of someone else's commit

Root cause: every rebase step, commit --amend and cherry-pick counted as a commit created on this machine. A stranger's pull request that was rebased, amended or cherry-picked therefore classified as owner.

Fix (internal/run/trust_git_patch.go, internal/trust/source/local.go): a rewrite counts as created here only when its change has a source made here. That means one of two things:

  • its patch equals the patch of a commit made here, or of a commit on the default branch (patch matching ignores whitespace and hunk positions, and file order does not matter);
  • for an amend, the commit it amended counts as made here (its older reflog neighbour, and it must have the same parents).

A rewrite of a stranger's commit never counts, even when nothing refers to the original any more (branch deleted, FETCH_HEAD overwritten, reflog entries gone). Reason: local.rewrite_not_made_here. If the patches cannot be compared, the owner path stays closed for rewritten commits.

These cases fail closed and need --trust owner: a rebase step where you resolved conflicts, a squash or fixup, your own commits rewritten on another machine, and an amend whose original reflog entry has expired.

D-1431: D04 and D06

  • D04: a fetch refspec that maps anything other than refs/heads/* is now excluded up to the first glob in its destination. refs/remotes/origin/gh-pr/*/head is no longer read as an origin branch.
  • D06: a grafts file (info/grafts or $GIT_GRAFT_FILE) makes the history unknown. The checkout is classified untrusted (local.history_grafted), and this check runs before reachability.

Tests (mm4, darwin/arm64)

  • Red team TestD01-TestD04 and TestD06 (-tags security) are now regular tests. On origin/main 3d7da3f, D01-D03 give owner [local.created_here], D04 gives collaborator [local.on_origin_ref], and D06 gives owner [local.reachable_from_default].
  • replay_test.go: pure tests, plus real-git fixtures for these cases:
    • a stranger's commit that is rebased, amended or cherry-picked, including once its original is gone (expired reflog, deleted entries);
    • a collaborator's branch that is rebased;
    • the mid-path glob refspec, and both grafts sources;
    • your own pushed branch rebased, chained content amends then a rebase, and a cherry-pick or backport, all of which stay owner.
  • go test ./... and -tags security ./test/security/...: all new and touched tests pass. The remaining failures also fail on pristine origin/main on mm4: attest TestProfile_, gates/truth TestDrill, nodes/registry, cloudvm, run TestInfraPostsError, test/security TestApproval*/TestCotenancy*/TestRecordedForkPR*, and redteam C37, C38 and D13. Architecture checks pass.

The trust guide is updated. The Epic D17 amendment and the debt rows are in nself-org/hq#36.

…ot created here (D-1322)

Local source trust read every rewrite (rebase step, commit --amend,
cherry-pick) as a commit created on this machine, so rebasing or amending a
stranger's pull request, or cherry-picking one of its commits, classified the
run owner.

- A rewritten commit is a replay when its patch (added and removed lines,
  whitespace and hunk positions ignored, file order free) equals a commit that
  arrived here: reachable from a remote-tracking ref, refs/pull/*, a FETCH_HEAD
  line or a reflog arrival entry, off the default branch, and not made here.
- A cherry-pick counts as made here only when its patch equals a commit made
  here (not itself a cherry-pick) or one on the default branch, which covers a
  source commit nothing refers to any more.
- A replay keeps the owner path closed and is reported as
  local.replayed_arrived_patch; patches that could not be compared close it too.
- Red team D01-D03 run as regular tests; real-git fixtures cover the
  stranger's replays and the operator's own rebased, amended and
  cherry-picked commits (pushed or not), which stay owner.
…fts never raise trust (D-1322, D-1431)

- A rebase step, amend or cherry-pick counts as created here only when its
  patch equals a commit made here (or on the default branch), or, for an
  amend, the commit it amended counts (older reflog neighbour, same parents).
  A rewrite of a stranger's commit no longer reads as owner when nothing
  refers to the original any more. Reason: local.rewrite_not_made_here.
- D04: a fetch refspec destination with a glob anywhere (gh-pr/*/head) is
  excluded up to its first glob, so a mapped pull request is not an origin
  branch.
- D06: a grafts file (info/grafts or $GIT_GRAFT_FILE) makes the history
  unknown: untrusted with local.history_grafted, before the reachability path.
- Red team D04 and D06 run as regular tests; new fixtures cover a rebased or
  amended stranger commit with its original gone, own amends chained into a
  rebase, the mid-path glob and both grafts sources.
@acamarata acamarata changed the title fix(ci): a rebase, amend or cherry-pick of someone else's commit is not created here (D-1322) fix(ci): local source trust: rewrites need a source made here; PR refspec globs and grafts (D-1322, D-1431) Oct 29, 2026

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