Skip to content

fix: fix patch application#228

Open
derekbarbosa wants to merge 5 commits into
sashiko-dev:mainfrom
derekbarbosa:fixes/baseline-apply
Open

fix: fix patch application#228
derekbarbosa wants to merge 5 commits into
sashiko-dev:mainfrom
derekbarbosa:fixes/baseline-apply

Conversation

@derekbarbosa
Copy link
Copy Markdown
Collaborator

Fix patch application failures and add diagnostics

Investigation of patchsets stuck in Failed To Apply status revealed four distinct root causes in the reviewer pipeline:

  1. Patchsets with base-commit: trailers referencing subsystem tree SHAs that exist in the local object store but are not reachable from any named ref. git worktree add rejects these even though git rev-parse resolves them, causing the highest-priority baseline candidate to fail silently before any patch application is attempted.
  2. Patches targeting trees that have diverged slightly from all available baselines. Both git am and git apply reject these due to strict context matching, even when the actual patch hunks are unambiguous.
  3. 40 [GIT PULL] maintainer pull requests being ingested as patchsets. These contain git URLs and branches, not diffs, and always fail application. 29 were still pending review.
  4. Version references like 7.1 and 7.2 extracted from subjects (e.g., "Fixes for 7.1", "sched_ext/for-7.2") producing baseline candidates for tags that don't exist yet during release candidate phases. Harmless but noisy in attempt logs.

To fix this, we employ the following:

  • Worktree creation now retries at HEAD when the target SHA is unreachable from any named ref
  • Added git apply -C2 as a third fallback after git am and git apply for context drift, tagged as git-apply-C2 in review metadata.
  • [GIT PULL] messages are excluded from patchset classification at parse time
  • Version tag baseline candidates (e.g., v7.1) are verified locally before being added, eliminating spurious resolution failures during RC phases

along with more logging on failure failure/success paths.

Assisted-by: Claude Opus 4.6 noreply@anthropic.com
Signed-off-by: derekbarbosa derekasobrab@gmail.com

git worktree add rejects commit SHAs that exist in the object
store but are not reachable from any named ref. This occurs
when patchsets specify a base-commit SHA from a subsystem tree
that has been fetched but is not pointed to by a local branch
or tag.

Add a fallback that retries worktree creation at HEAD when the
initial attempt with the target SHA fails. The existing phase 2
reset --hard repositions the worktree to the correct commit,
which works with loose objects regardless of ref reachability.

This fixes worktree creation failures for 9 patchsets observed
in production where base-commit SHAs were valid objects but
unreachable from any ref.

Assisted-by: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: derekbarbosa <derekasobrab@gmail.com>
When both git am and git apply fail due to minor context
divergence between the patch baseline and the tested tree,
fall back to git apply -C2 which requires only 2 lines of
surrounding context instead of the default 3.

Add apply_raw_diff_relaxed to GitWorktree for reduced-context
application. Mark results with method git-apply-C2 in the
review metadata so downstream consumers can distinguish
reduced-context applications from strict ones.

The commit message for patches applied via this fallback
includes an explicit annotation: (Applied via git apply -C2).

Assisted-by: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: derekbarbosa <derekasobrab@gmail.com>
GIT PULL messages are maintainer pull requests containing a git
URL and branch to fetch, not applicable diffs. They often
include inline diffstats that trigger diff detection, causing
them to be classified as patchsets. These always fail patch
application since there is no diff to apply.

Exclude subjects containing [GIT PULL] from patchset
classification alongside the existing reply and reproducer
filters. Messages are still stored for threading and archive
purposes but no patchset record is created.

40 GIT PULL messages were observed as patchsets in production,
with 29 pending review (all destined to fail) and 7 already
marked Failed To Apply.

Assisted-by: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: derekbarbosa <derekasobrab@gmail.com>
When extract_version_tag produces a kernel version from the
subject (e.g., 7.1 from Fixes for 7.1), the code adds a
LocalRef candidate like v7.1. During release candidate phases
these tags do not yet exist in the local repo, producing a
guaranteed failed resolution attempt and noise in the baseline
attempt logs.

Verify the tag exists via git rev-parse before adding it as a
candidate. The stable branch RemoteTarget is still added
unconditionally for .y versions since it relies on remote
fetching rather than local tag presence.

Assisted-by: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: derekbarbosa <derekasobrab@gmail.com>
Add structured logging across the patch application pipeline
so failures and fallback paths are visible in production logs:

- git_ops: warn when worktree creation falls back to HEAD,
  error when both attempts fail
- reviewer: warn with git am stderr when it fails before
  falling back, warn when all apply methods are exhausted
  for a patch
- patch: info when a GIT PULL message is filtered out
- baseline: info when a version tag candidate is skipped
  because it does not exist locally

Assisted-by: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: derekbarbosa <derekasobrab@gmail.com>
@derekbarbosa derekbarbosa force-pushed the fixes/baseline-apply branch from 7ea9999 to cf05777 Compare June 4, 2026 04:25
@derekbarbosa derekbarbosa marked this pull request as ready for review June 4, 2026 04:25
@derekbarbosa derekbarbosa changed the title WIP: Fix patch application fix: fix patch application Jun 4, 2026
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