Stale Patch Reconciliation
SkillDev toolsstale-patch-reconciliation — Reconcile a stale patch/diff against a current checkout.
Available today. Use it from your connected AI after setup.
No other account needed.
Connect ahel once, and every AI you use reads what you have installed.
Then ask your AI: use the Stale Patch Reconciliation skill
What this skill tells your AI
The instructions your AI receives, as published by atlasomnia/hermes-custom-pack in skills/stale-patch-reconciliation/SKILL.md and read by ahel’s review.
Use when a patch/diff must be compared with, repaired against, or refreshed for a moving checkout — "is this patch still needed", "does upstream already contain it", "what changed since it was written", "reconcile X.diff with HEAD", or "make apply-patches pass again".
This skill has two explicit modes:
- Analysis mode (default): read-only archaeology and a minimal repair plan. Do not edit, reset, stash, clean, update, or restart.
- Repair mode (only when authorized): implement the invariant in an isolated worktree, run focused gates, regenerate the patch from the current baseline and an explicit file allowlist, then apply it to the live checkout only after clean/reverse checks pass. Preserve unrelated dirty work exactly.
Deliverable shape: (1) behavioral invariant, (2) exact gaps/call sites, (3) upstream status, (4) drift cause, (5) minimal repair, (6) focused gate evidence, and (7) artifact/applicator verification. Coordinate writer ownership through shared-worktree-agent-orchestration.
Core sequence
-
Read the full patch first. Paginate the whole diff; note every file touched and the old-file line numbers of each hunk. The hunks are the map for later drift attribution.
-
Git history archaeology — does the feature exist anywhere?
git log --all --oneline -i --grep=<feature>— commits mentioning it by namegit log --all --oneline -S'<feature>'— commits adding/removing the string (catches renames/variants)git log origin/main -S'<feature>'— empty means NOT upstream (private branches don't count as upstream)git merge-base --is-ancestor <sha> HEAD && echo YES || echo NO— ancestry testgit branch -a --contains <sha>— which branches carry the commits
-
Snapshot-branch trap. If
git merge-base HEAD <branch>returns EMPTY output, the branch is likely built on a parentless snapshot commit. Confirm withgit log --format='%h parents: %P' -1 <sha>— no parents = root/snapshot commit (e.g. "chore: snapshot upstream main for private feature review"). Such a branch shares NO ancestry with HEAD, so lineage tools mislead; treat the branch's cumulative diff as the feature and ignore ancestry. -
Quantify staleness read-only.
git apply --check <patch>validates without applying (safe). Per-file apply map:
for f in $(grep '^diff --git' <patch> | awk '{print $3}' | cut -d/ -f2-); do
git apply --check --include="$f" <patch> >/dev/null 2>&1 && echo "OK $f" || echo "FAIL $f"
done
CAUTION: exit code after a pipe reflects the last command (head), not git apply — read the error text, not $?. Files whose hunks apply cleanly today are "context-compatible"; failed files are where the rework lives.
-
Attribute drift.
git log --oneline <branch-or-sha>..HEAD -- <paths>lists upstream commits since the branch point. Read the ones touching failing files to explain each failed hunk (parser renames, schema field additions, UI refactors). Report drift as "hunk N fails because upstream renamed X → Y" — that is the minimal-plan input. -
Read current call sites. Grep current line numbers for every function the patch touches and compare signatures against the patch's expectations. Note which upstream refactors the reimplementation must target (e.g. new parser API, new CommandDef fields).
-
Live-checkout concurrency (shared worktrees). The tree can change MID-analysis — a concurrent writer may implement the very feature being reconciled. Re-verify
git status --porcelainand re-grep at the END; report a final snapshot with "may already be stale" on line numbers. Distinguish pre-existing dirty files from concurrent-writer edits so the parent doesn't lose work.
Repair mode: isolated three-way reconciliation
When the user authorizes implementation or the applicator must be repaired:
- Freeze ownership before mutation. Recheck Git root, branch, HEAD, complete status, OS writers/descendants, and any waiting launcher. Record pre-existing dirty files as protected. A controller that has not yet produced a report may still have mutated the tree; perform a delayed post-launch status scan before trusting its preflight.
- Create a clean detached worktree from the current HEAD. Never trial-apply a stale patch directly to a dirty authoritative checkout. Use
git apply --3way --index <patch>there; inspect everygit diff --name-only --diff-filter=Uconflict and preserve current upstream behavior plus the patch's invariant. Do not resolve conflicts by taking all ofoursor all oftheirs. - Treat conflict placement as suspect. Three-way application can match a weak context anchor inside an existing helper or test class. For additive tests, rebuild from the current HEAD file and insert only the patch's added block at a stable semantic anchor; then run the test file. This avoids duplicated commands, missing delimiters, and tests nested inside another test.
- Run focused gates in the isolated tree. Start with
git diff --check, language syntax/type checks, and the smallest RED→GREEN tests for each invariant. Use the project's real dependency environment; if a temporary worktree lacks dependencies, reify from the lockfile in that worktree (offline when the cache is complete) rather than mutating the live checkout. Report unavailable tests as unavailable, never as passing. - Regenerate the artifact for the current baseline. From a clean current-HEAD worktree, produce each patch with an explicit reviewed file allowlist. Do not include unrelated dirty files, generated output, dependencies, or broad historical branch deltas. Keep the refreshed artifact outside the source checkout when necessary.
- Prove applicator behavior twice.
git apply --checkagainst a clean current-HEAD worktree must pass;git apply -R --checkagainst the repaired tree must also pass. Run the real applicator once and require zero missing/non-clean patches. Re-run it only after inspecting a failure; never loop the same command underset -eor through a pipeline that masks the true exit code. - Close out independently. Re-scan the live process tree, verify the authoritative checkout contains only the intended feature changes plus protected pre-existing dirt, run final focused gates at the same tree, and report exact paths, hashes, exit codes, and any deferred lifecycle gate separately.
Pitfalls
- macOS system
python3(3.9.x) cannot import the hermes-agent repo:TypeError: unsupported operand type(s) for |: 'type' and 'type'— PEP 604 annotations are syntax-valid but runtime-invalid on <3.10, sopython3 -m py_compilePASSES while import fails. Always use./.venv/bin/pythonfor imports/tests in that repo. - Running
./.venv/bin/python -m pytestfrom a gateway session can trip the terminal tool's lifecycle guard —ValueError: embedded null byteincron/lifecycle_guard.py, triggered whenever the command's FIRST EXECUTABLE TOKEN contains a/(relative.venv/bin/pythoncounts; barepython3and slash-as-argument forms pass). Verified workarounds, lightest first: (1) run the command insideexecute_codevia plainsubprocess.run([...])— the sandbox bypasses the guard; (2) use barepython3 -m pytest/python3 -cwhen the system interpreter has the deps; (3) shift the slash path to an argument (file .venv/bin/pythonpasses). Full root-cause detail: see the pitfalls section of this skill. - Task-spec line numbers go stale under parallel uncommitted work. A delegated spec citing
supervisor.py:309/428andpolicy.py:158matched the live tree at348/422and157because a parallel task had uncommitted edits in the same files. Verify every cited line against the actual file before editing; anchor patches on unique string context, never on line numbers. patchreplace_allmatches EXACT text. Two sites that look identical can differ in formatting (oneraiseon a single line, an identical-looking one wrapped across three), soreplace_allsilently leaves a site untouched. After any multi-site replace, grep the file for the old identifier and confirm EVERY site changed.- Prove zero new failures when the suite was already red. When an API change lands while tests still use the old signature, every affected test fails the same way (e.g. 38/38
TypeError: ... unexpected keyword argumentat test-helper lines, plus cascades likeFileNotFoundErrorfrom a helper that raised earlier). Categorize failures by error type and failing line before claiming your change is clean — do not touch tests owned by another lane. - "Upstream contains it" requires the origin/main check, not just local branches — private feature branches (
fix/*,feat/*) routinely carry unmerged work. - A parentless snapshot branch makes
git log <branch>..HEADshow the feature commits as "not in HEAD" even when HEAD contains equivalent code — verify with content greps, not lineage alone. - Applicators may contain archive-first fallbacks that silently skip a refreshed root artifact while exiting 0. When refreshing a patch, inspect branch precedence, make the root artifact win when present, and verify both a real apply and a second idempotent run.
Reference
Signals
- GitHub stars
- 56
- Forks
- 5
- Last commit
- Aug 2026
Advanced
- Catalog kind
- skill
- Gateway key
stale-patch-reconciliation- Source
- github.com/atlasomnia/hermes-custom-pack