Skip to content

worker: three-way apply of task patches, so plans with dependent tasks can open a PR - #83

Merged
OfficialAbhinavSingh merged 1 commit into
mainfrom
fix/pr-cumulative-patches
Nov 6, 2026
Merged

OfficialAbhinavSingh merged 1 commit into
mainfrom
fix/pr-cumulative-patches

Conversation

@OfficialAbhinavSingh

Copy link
Copy Markdown
Member

With the GitHub token now on the server, the PR gate picked up plan 5bbf7d86's request, then failed:

the change of task 1 does not apply: git failed: error: fulfilment/inventory.py: patch does not apply

All four tasks had passed. Task 1 depends on task 0.

Why. Each stored patch is git diff HEAD from a checkout of the plan's base. Before a dependent task runs, the worker applies its dependencies' patches (staged, not committed). So the dependent task's patch includes those changes again. The PR gate applies all patches in index order with a plain git apply, and that refuses the repeat.

Fix. Workspace.apply_patch now uses git apply --index --3way. A three-way merge sees the same change on both sides and takes it once. Two tasks that change the same lines differently still conflict and fail, as before. The worker applies dependency patches through the same method, so a task that depends on two tasks sharing a dependency no longer fails either.

Checks

  • Two new tests use real git diff --binary patches. A dependent task's patch that repeats its dependency's change now combines (the test fails on main with the production error). Two different edits to one line still refuse.
  • Replayed plan 5bbf7d86's actual stored patches against the sandbox repo:
    • plain apply: fails on task 1, the same as production;
    • --3way: all four apply, giving 2 files and +72 lines, and the repo's tests pass (58).
  • ruff, ruff format and pyright clean. 561 unit tests and 13 Docker sandbox tests pass.

After this deploys, the PR on 5bbf7d86 can be retried from its run page.

Not in this PR

  • The run page's change summary still adds up every task's patch, so it shows +168 for a +72 change. The diff endpoint concatenates the cumulative per-task patches.
  • A dependent task's allowed_paths check also counts the files its dependencies changed. They're staged in its sandbox, not committed.

…ependent tasks can open its PR

Every stored task patch is `git diff HEAD` of a checkout at the plan's base, so a dependent task's patch
also carries the changes of the tasks it depends on (they were applied to its sandbox, staged, not
committed). The pull-request gate applied the patches in index order with a plain `git apply`, which
refused the repeat. On plan 5bbf7d86 (four tasks, three depending on the first) every task passed and
the pull request failed with "the change of task 1 does not apply". `git apply --3way` sees the same
change on both sides and takes it once; two different changes to the same lines still conflict and
fail. Replaying that plan's real stored patches: a plain apply fails on task 1, the three-way apply
gives the expected two files, +72 lines, and the repository's tests pass. The worker applies
dependency patches with the same method, so a task depending on two tasks that share a dependency no
longer fails either.
@github-project-automation github-project-automation Bot moved this to Backlog in Kanban Nov 6, 2026
@OfficialAbhinavSingh
OfficialAbhinavSingh merged commit 66b80a5 into main Nov 6, 2026
1 check passed
@github-project-automation github-project-automation Bot moved this from Backlog to Done in Kanban Nov 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant