Skip to content

feat: refresh imported pull request source - #178298

Merged
shakkernerd merged 4 commits into
mainfrom
refresh-imported-pr
Oct 21, 2026
Merged

shakkernerd merged 4 commits into
mainfrom
refresh-imported-pr

Conversation

@shakkernerd

@shakkernerd shakkernerd commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Builds on #178233 (prepare_pr) and #178281 (actions on an imported PR), both merged.

What Problem This Solves

prepare_pr lets 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 original PR head advanced after preparation. Updating an already prepared workspace is not available yet; its existing source and edits were preserved.

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_pr for the bound PR now integrates its newer head into the same managed workspace:

  • Guest work done since the last preparation is preserved, including uncommitted edits, untracked files and the guest's own Git history (HEAD, branch and commits are not reset).
  • When the newer head conflicts with that work, the call returns status: "conflicts" with conflictPaths and the accepted headCommit. After resolving the files, the caller repeats prepare_pr with conflictsResolved: true and expectedHeadCommit set to that headCommit. A stale or mismatched acknowledgement is refused and cannot select a different source.
  • A file with both staged and unstaged changes is refused before anything is touched, with a message to commit the staged part first, so an index-only version is never lost.
  • Repeating a completed preparation at the same head still leaves files and the index unchanged.
  • Remote history that cannot be merged (no common ancestry) is refused without being recorded as a pending refresh.

Preparation still makes no GitHub writes and grants no publication, merge or close authority. The first import still requires a pristine workspace, and refresh_base keeps 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 for prepare_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_base already uses for integrating a newer base into the managed workspace, rather than adding a second merge path:

  • Preparation owner (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 through headChanged for the next explicit refresh. The binding is only marked prepared once integration completes without pending conflicts.
  • Authority after fetch: a source fetch can outlive the observation it started from. Before the newer head is accepted, the PR's write eligibility, linked author and current head are verified again. A Stop, a role change, a changed linked identity, lost permission or a moved remote head during the refresh leaves the previously imported source in place.
  • Source-merge journal (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_pr or refresh_base).
  • Index safety (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 as ORIG_HEAD when 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.
  • Protocol and tool (session-github-publication.ts, github-publish-tool.ts): prepare_pr accepts the optional acknowledgement fields and returns conflictPaths; the tool forwards them and describes the refresh flow.

The shared PR fixture moved into github-pr-workspace-preparation.test-support.ts so 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.ts drives the registered prepare_pr Gateway 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.

  • Before this PR (production files from feat: support actions on imported pull requests #178281's head, this branch's tests): all 10 cases fail. Each reaches the registered action and is refused with "Updating an already prepared workspace is not available yet".
  • This branch: all 10 pass, alongside the existing preparation cases.

Independent review of earlier heads found staging cases that the refresh tests now cover:

  • A conflicted or interrupted refresh that also changed an imported file the guest had staged but not committed left that file partially staged, and the guest's acknowledgement was refused. The test's newer head now changes such a file. On the first reviewed head both variants failed with "Commit the staged changes in files that also have unstaged changes…"; now the acknowledgement succeeds and the guest index holds the integrated bytes.
  • A version the guest stages while the conflict is pending must not be replaced at completion. The test stages one and expects the acknowledgement to be refused with that staged version intact. On the second reviewed head, which skipped the check for a pending refresh, the staged version was replaced; now it is refused, a staged mode change on the same bytes is refused too, and once the guest restores the refresh's entry, the acknowledgement succeeds.
  • A clean refresh whose host merge completed but whose sandbox review-base step failed must finish on the retry its error message asks for. A new case fails that step once and retries; on the third reviewed head the retry was refused, and now it completes with the integrated bytes staged.

Checks on this head (remote Linux runner)

Check Result
Changed-file formatting and lint passed
Type checks: core test graphs, core, ui, extensions, extensions-test, scripts, test-root passed
Gateway tests: refresh, preparation, base-refresh actions, imported-PR actions, inspect, workflows, session read 7 files, 130 cases passed
Protocol schema test 17 cases passed (unchanged by the last correction)
github-publish-tool.test.ts 28 cases passed (unchanged by the last correction)

An 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):

Before After
Unpublished local note exists before the refresh request Refresh adds the incoming file and reports the preserved local note and Git history
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):

View Before After
Pending source and prior-receipt refusal Existing conflict remains pending Publication owner refuses the older receipt while preparation is pending
Accepted completion and separate refresh Pending head completes and reports a newer remote head A separate refresh accepts the newer head and preserves 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 conflictsResolved and expectedHeadCommit, so it proves the guided acknowledgement path rather than unaided discovery of those arguments.

@clawsweeper

clawsweeper Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: web-ui App: web-ui gateway Gateway runtime agents Agent runtime and tooling size: XL labels Oct 20, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:feature Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:feature Preliminary submission classification; full source review pending. labels Oct 20, 2026
@clawsweeper

clawsweeper Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: stale review; fresh review needed.

Summary
The latest durable ClawSweeper review was for head 13773ca3bd98a9d8906dbdc1dd24be07c765d794, but the PR head is now 1b34547058b16085c03c5048051bb2e117d64094. Its old verdict and PR readiness labels are no longer current.

Next step
Run or wait for a fresh ClawSweeper review on the current PR head.

Review history (1 earlier review cycle)
  • reviewed 2026-10-20T09:19:17.877Z sha 13773ca :: needs real behavior proof before merge. :: none

@clawsweeper clawsweeper Bot removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 21, 2026
@shakkernerd
shakkernerd force-pushed the prepare-existing-pr branch 4 times, most recently from f6a4786 to 087a07f Compare October 21, 2026 12:32
Base automatically changed from prepare-existing-pr to main October 21, 2026 12:55
@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Security-sensitive guard cleared

Current revision: ddbe9cd56094aef77431c7855d284ed29b94928e

This PR no longer changes files in the maintainer security-review tier.

Separate CODEOWNERS requirements still apply to security policy and enforcement files.

@shakkernerd
shakkernerd changed the base branch from main to imported-pr-actions October 21, 2026 13:24
@shakkernerd

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added the clawsweeper:intake:feature Preliminary submission classification; full source review pending. label Oct 21, 2026
Base automatically changed from imported-pr-actions to main October 21, 2026 13:55
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.
@shakkernerd
shakkernerd force-pushed the refresh-imported-pr branch 2 times, most recently from e844170 to 281af0a Compare October 21, 2026 14:04
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.
@shakkernerd shakkernerd self-assigned this Oct 21, 2026
@shakkernerd
shakkernerd merged commit 13c8407 into main Oct 21, 2026
133 checks passed
@shakkernerd
shakkernerd deleted the refresh-imported-pr branch October 21, 2026 17:07
@shakkernerd

Copy link
Copy Markdown
Contributor Author

Added: repeating prepare_pr in a conversation that continues its own existing PR now merges that PR's newer commits into the same workspace, keeping the guest's work and returning any conflicts for resolution and acknowledgement.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 22, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling app: web-ui App: web-ui clawsweeper:intake:feature Preliminary submission classification; full source review pending. docs Improvements or additions to documentation gateway Gateway runtime P2 Normal backlog priority with limited blast radius. size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant