Repository navigation
feat: refresh imported pull request source - #178298
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: stale review; fresh review needed. Summary Next step Review history (1 earlier review cycle)
|
f6a4786 to
087a07f
Compare
Security-sensitive guard clearedCurrent revision: This PR no longer changes files in the maintainer security-review tier. Separate CODEOWNERS requirements still apply to security policy and enforcement files. |
1b34547 to
e844170
Compare
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
84f158f to
7b74f99
Compare
A repeat prepare_pr on a bound PR whose remote head advanced now merges that head into the same managed workspace through the existing source-merge journal, instead of refusing it. Conflicts return conflictPaths with the accepted headCommit; the caller resolves them and repeats with conflictsResolved and expectedHeadCommit. The accepted head stays pinned through interruption, a newer head found during recovery is reported through headChanged, and remote identity and permission are rechecked after the fetch before the source is accepted. Files with both staged and unstaged changes are refused so an index-only version is not lost.
A refresh that returns conflicts applies the merged bytes before the guest index is restaged, so an imported file the guest staged but never committed is left partially staged. The next prepare_pr, acknowledging the conflicts or recovering an interrupted transfer, refused that state. Only admitting a new source checks partial staging now; a resumed integration already passed it.
e844170 to
281af0a
Compare
Skipping the partial-staging check for a resumed refresh let completion replace a version the guest staged after a conflict. The sandbox Git state now reports each partially staged path with its index object, and a pending integration accepts only entries still at their pre-refresh bytes, which the workspace HEAD records until the merge completes; any other staged-only version is refused before the index is rewritten.
A refresh whose host merge completed (or fast-forwarded) but whose sandbox review base failed left refreshed imported files staged at their pre-refresh entries with no merge in progress, so the advertised retry refused them. ORIG_HEAD now records the pre-refresh snapshot for every source refresh, and pending staged entries are compared with it in both the conflict and the merged states. Entries compare by mode and object, so a staged mode change is refused like other new guest staging.
|
Added: repeating |
Repeating prepare_pr for a conversation's bound PR now integrates the PR's newer remote head into the same managed workspace instead of refusing it, preserving the guest's edits, untracked files and Git history. Conflicts return conflictPaths with the accepted headCommit; the guest resolves them and repeats with conflictsResolved and expectedHeadCommit. The accepted head stays pinned through interruption or conflicts, a further remote advance is reported through headChanged, and the PR's author, write eligibility and head are rechecked after the fetch. Files with both staged and unstaged changes are refused before a new head is admitted, and remote history without common ancestry is refused without being pinned. A resumed or retried refresh accepts only index entries still at their pre-refresh mode and object, which the workspace records as ORIG_HEAD, so completion never replaces a version the guest staged in the meantime.
Builds on #178233 (
prepare_pr) and #178281 (actions on an imported PR), both merged.What Problem This Solves
prepare_prlets a contributor continue their own existing PR in a conversation: OpenClaw verifies the PR is theirs, installs its head into the conversation's managed workspace, and binds the session to that PR. PRs keep moving after that, though. The contributor pushes from another machine, a co-author adds a commit, or a review fix lands on the branch. Today, once the workspace is bound, any newer remote head is refused:The conversation is then stuck on a stale copy of the PR. The guest has no supported way to pick up the new commits without abandoning the workspace and the work in it.
User Impact
Repeating
prepare_prfor the bound PR now integrates its newer head into the same managed workspace:status: "conflicts"withconflictPathsand the acceptedheadCommit. After resolving the files, the caller repeatsprepare_prwithconflictsResolved: trueandexpectedHeadCommitset to thatheadCommit. A stale or mismatched acknowledgement is refused and cannot select a different source.Preparation still makes no GitHub writes and grants no publication, merge or close authority. The first import still requires a pristine workspace, and
refresh_basekeeps its existing behavior. The refresh wording and the acknowledgement fields are offered only where the conversation has a writable managed sandbox, which is the same condition the Gateway already enforces forprepare_pr.Publishing the refreshed workspace back to the original PR head is separate work.
Why This Change Was Made
The refresh reuses the source-merge journal that
refresh_basealready uses for integrating a newer base into the managed workspace, rather than adding a second merge path:src/gateway/github-pr-workspace-preparation.ts): when the session's bound PR has a newer head, it admits that head as the accepted source while keeping the last completed head distinct until integration finishes. An interrupted or conflicted refresh therefore resumes the same accepted head after a restart. If GitHub advanced again in the meantime, recovery completes the pinned head and reports the newer one throughheadChangedfor the next explicit refresh. The binding is only marked prepared once integration completes without pending conflicts.src/gateway/github-publication-base-refresh.ts): the source is now reserved only after ancestry is established, so unrelated history is refused without pinning it. Messages name the action that is being acknowledged (prepare_prorrefresh_base).src/gateway/github-publication-workspace-review.ts, journal): the sandbox Git state read reports each partially staged file with its index object, and a refresh refuses any before it admits a new head. Imported PR files stay staged in the guest index until the guest commits them, so a conflict or an interruption leaves refreshed files staged at their pre-refresh bytes until the integration completes. When acknowledging or retrying that refresh, an entry is accepted only while its mode and object still match the pre-refresh snapshot, which the managed workspace records asORIG_HEADwhen it admits the newer head (previously only the first import did). That holds whether the merge is still pending, was interrupted, or already completed while the sandbox review base still has to be prepared. A version or mode the guest staged in the meantime is refused, so completion never replaces it.session-github-publication.ts,github-publish-tool.ts):prepare_praccepts the optional acknowledgement fields and returnsconflictPaths; the tool forwards them and describes the refresh flow.The shared PR fixture moved into
github-pr-workspace-preparation.test-support.tsso the existing preparation tests and the new refresh tests run against the same real-Git workspace setup.Evidence
Before and after on the registered action
The new
src/gateway/github-pr-workspace-refresh.test.tsdrives the registeredprepare_prGateway action through the agent tool with real Git repositories, session persistence, source projection and the production sandbox binding; only GitHub and container I/O are synthetic. It covers a clean refresh and repeated acknowledgement, recovery of a pending refresh before a further head (with and without a bound runtime), staged-only guest bytes, unrelated remote history, and Stop, role, linked-identity, permission and remote-head changes during the refresh.Independent review of earlier heads found staging cases that the refresh tests now cover:
Checks on this head (remote Linux runner)
github-publish-tool.test.tsAn early tool-test run caught the refresh wording appearing in conversations without a writable managed sandbox. The wording is now conditional on the same sandbox condition the Gateway enforces for
prepare_pr.Hosted CI runs the full suite on this head; it was green on the previous head with the same base.
Earlier live recordings
These were captured on earlier builds of this branch, before it was rebased onto #178281. The refresh owner code they exercise is unchanged by the rebase; the tool text and its surroundings were updated since. They show the flow in a real conversation; the tests above are the proof for this head.
Additive refresh of a private PR with an unpublished local note (one natural request; the local note and guest Git state survive, one incoming file is added):
guest-send-through-additive-refresh.mp4
Conflict acknowledgement and a later separate refresh (an older publication receipt is refused while a conflict is pending; the guided acknowledgement completes the pending head and reports a newer one; a separate refresh then accepts it and keeps the resolved local note):
02-exact-e2-resolution-acknowledged.mp4
Separate clips of the prior-receipt refusal and of the later refresh:
01-pending-prior-receipt-refusal.mp4
03-separate-e3-refresh-prepared.mp4
In the conflict recording the prompt supplies
conflictsResolvedandexpectedHeadCommit, so it proves the guided acknowledgement path rather than unaided discovery of those arguments.