Repository navigation
feat: prepare existing PR source in a managed workspace - #178233
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: needs maintainer review before merge. What this changesAdds prepare_pr to import an existing own pull request into a clean managed workspace while preserving guest Git history. Example: Continue shakkernerd/openclaw-guest-pr-demo pull request 1 in an empty /workspace.
Review scores
ProductKind: Feature · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open: it adds useful, maintainer-approved preparation behavior absent from main, with no blocking correctness finding. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe Gateway brokers GitHub access for sandboxed conversations, verifies the requester and PR source, and passes accepted source through the existing managed-workspace reconciliation owner. flowchart LR
A[Conversation request] --> B[GitHub publication tool]
B --> C[Gateway preparation action]
C --> D[Requester and PR verification]
D --> E[Workspace reconciliation owner]
E --> F[Canonical and sandbox files]
E --> G[Session worktree association]
Technical reviewBest possible solution: Land the focused preparation stage through the existing reconciliation owner, retaining explicit refusals for capabilities owned by follow-up PRs. Do we have a high-confidence way to reproduce the issue? This is a new capability; current-main source confirms that own-PR inspection does not install its source. Is this the best way to solve the issue? The change extends the existing source integration and recovery owners, preserves ordinary base-refresh behavior, and avoids introducing a competing workspace lifecycle. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 3241b4220e8c. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +942, Tests +1062, Docs +33. Total +2037 across 26 files. Added test files: 1. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (6 earlier review cycles)
Reviewed October 21, 2026, 7:23 AM ET / 11:23 UTC (Revision 7). |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
🦞👀 Re-review progress:
|
Add the github_publish action prepare_pr. For a PR authored by the requester's currently verified linked GitHub account, it re-verifies the author, checks that the shared publisher may update the PR head (same repository push, or a user-owned fork with maintainer edits and base push), and installs that exact head into a clean managed workspace through the existing reconciliation owner, recording the original PR association on the session worktree binding without publishing. Dirty, untracked, staged or unpublished initial work refuses with that work intact; a newer remote head, a protected head and a non-writable fork refuse with the reason. An interrupted first import resumes its accepted head on retry, and a repeated same-head preparation leaves later edits untouched. Existing publication and PR actions refuse an imported association until their original-PR handling lands. Refs #178055
f6a4786 to
087a07f
Compare
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Added: |
After prepare_pr binds a conversation's workspace to the guest's own original PR, the existing github_publish actions edit, ready, request_review and upload_evidence act on that bound PR before any new push and without a publication receipt: the action handler selects the workspace binding before consulting shared publication receipts, returns a pullRequest descriptor with the observed remote head instead of a fabricated publication, and requires expectedHeadCommit without a requestId. Receipt-backed actions keep their requestId precondition. Every guest action re-verifies the linked author and private repository access through own-PR inspection; writes also recheck the publisher's write eligibility at the effect and preserve a human title/body change observed there. merge, close and inspect on the bound PR still require full operator write access, so an administrator can land it from the same conversation while a guest's later turns stay restricted. The target check compares the bound PR's immutable repository IDs, number, branch and author so a changed target refuses. Refs #178233
After prepare_pr binds a conversation's workspace to the guest's own original PR, the github_publish actions edit, ready, request_review and upload_evidence act on that bound PR before any new push and without a publication receipt: the action handler selects the binding before publication receipts, returns a pullRequest descriptor with the observed remote head, and requires expectedHeadCommit without a requestId, while receipt-backed actions keep their requestId precondition. Every guest action re-verifies the linked author and private repository access, writes recheck publisher write eligibility at the effect and preserve a human title/body change observed there, and merge, close and inspect on the bound PR still require full operator write access, so an administrator can land it from the same conversation while a guest's later turns stay restricted. Refs openclaw#178233.
) Adds the github_publish action prepare_pr: for a PR authored by the requester's verified linked GitHub account whose head the shared publisher may update, it installs that exact head into the conversation's clean managed workspace and records the original PR association without publishing. Dirty or unpublished work, a newer remote head, a protected head and a non-writable fork are refused with the reason and the existing work preserved; an interrupted first import resumes its accepted head on retry. Refs openclaw#178055.
After prepare_pr binds a conversation's workspace to the guest's own original PR, the github_publish actions edit, ready, request_review and upload_evidence act on that bound PR before any new push and without a publication receipt: the action handler selects the binding before publication receipts, returns a pullRequest descriptor with the observed remote head, and requires expectedHeadCommit without a requestId, while receipt-backed actions keep their requestId precondition. Every guest action re-verifies the linked author and private repository access, writes recheck publisher write eligibility at the effect and preserve a human title/body change observed there, and merge, close and inspect on the bound PR still require full operator write access, so an administrator can land it from the same conversation while a guest's later turns stay restricted. Refs openclaw#178233.
Builds on #178055 (own-PR inspection, including copied GitHub
/changeslinks), which has landed onmain; this PR now targetsmaindirectly.What Problem This Solves
A guest can identify their own existing GitHub PR, but that does not put its source in the conversation's managed sandbox. Starting from the selected project's current base can also give the guest different files from the PR they intend to continue.
This adds explicit
github_publishpreparation by PR URL on top of the own-PR inspection contract. It covers an existing managed project workspace or an explicitly empty managed workspace.User Impact
prepare_prverifies the current linked author, original PR source and publisher write eligibility, then installs the exact PR head into a clean workspace. It preserves the conversation's workspace directory, sandbox scope and guest Git history. Dirty, untracked, staged or unrelated unpublished initial work causes a clear refusal with that work intact.An interrupted first import resumes its original accepted source. Repeating a completed same-head preparation leaves subsequent edits and indexes untouched. If the remote head has advanced after preparation, this action refuses rather than silently resetting or merging source; later-head updates are a separate contribution.
One accepted edge case: a push to the PR branch while the first import is still fetching is not observed by that import. The workspace receives, and the association records, the head that inspection and the write-eligibility check verified when preparation started, so a push during the import behaves exactly like a push a moment after it: the next preparation reports that the original head advanced. Re-reading GitHub inside the acceptance step would not close that window; it would only turn a completed import into an interrupted one whose retry resumes the same accepted head.
Preparation records the original PR association without publishing. Existing publication and PR actions refuse an imported association until their original-PR handling is implemented, so an earlier publication receipt cannot select a different target. Ordinary unbound-chat adoption is outside this PR. No configuration or database schema migration is required.
Write eligibility is what the shared publisher can actually do with the PR head: a same-repository head the publisher may push, or a user-owned fork head with maintainer edits allowed and base push access. Protected heads and organization forks are refused with that reason. Nothing here grants a guest merge, auto-merge or any broader scope; the association is a selection, not authority.
Why This Change Was Made
The current managed workspace reconciliation owner already coordinates the canonical checkout and sandbox projection, retains interrupted file effects and preserves the running workspace location. Preparation uses that owner with the verified PR head as its explicit initial source. It checks both workspace copies before initial synchronization and retains the original head through native Git recovery state. An accepted transfer is settled before any guest command on retry, because interruption can leave the registered runtime paused until that owner completes recovery.
The minimum original PR identity and accepted source are stored with the existing session worktree binding. They survive reuse of that same workspace, while newly allocated workspaces remain unbound. Permission observations are not stored as durable authority. Existing base refresh keeps its merge behavior; the imported PR's review comparison uses its common ancestor with the PR base, without merging a newer base into the imported files.
The responsibilities are split by owner:
github-pr-workspace-preparation.tsruns the action (verification, preflight, installation, binding);github-publication-pr-preflight.tsholds the publisher write-eligibility rules;github-publication-workspace-review.tscomputes the imported PR's review base;session-worktree-binding.tsreads and writes the association on the existing worktree binding; the tool text, protocol schema, method scope and docs expose the action.Evidence
Candidate and history
This head is the same contribution as the previously reviewed head 7f2098a, rebuilt as one linear commit: first on #178055's rebased head (ba0875a), then replayed onto
mainonce #178055 landed there as 01c2c60. The earlier merge-based history is replaced; the applied content is the same 26-file change (+2243/−211 before the test adaptations described below). Replaying ontomainneeded one more test resolution:src/gateway/server.worktree-preparation.test.tswas compacted by #179267, so this PR's reuse case (thegithubPullRequestbinding survives reuse of the same worktree) is reinserted in that compact shape. A file-by-file comparison of the patch before and after the replay shows no other change beyond context lines.On the earlier head, two hosted checks were red.
check-lint-core-2ran its core lint stripes to completion with every stripe exiting 0 and onlymax-lineswarnings on files this PR does not touch; the same job passes on #178055's rebased head, so that failure belonged to the old base state.checks-node-changed-16failed intest/e2e/qa-lab/runtime/required-native-same-session.e2e.test.ts, an unchanged qa-lab runtime scenario asserting workspace naming through public RPC. Neither recurred after the rebuild.The first head replayed onto
mainfailed one hosted shard twice: two cases ofsrc/gateway/worker-environments/placement-dispatch-move-recovery.test.ts(a concurrent foreign abandonment that "did not fence its remote owner", and a claim-replacement assertion reading an older claim). This PR does not touch placement or dispatch code, and the file passed every remote run on both this branch and itsmainbase, isolated, beside its shard neighbors, under the pinned Bun runtime and at the hosted worker budget. The cause was a stale cached placement read during forced abandonment onmainitself, reproduced on cleanmainand repaired by #179448 after that head's base. The current head is replayed onto amainthat includes the repair.That last replay also restores the
exportofinspectOwnGitHubPullRequestinsrc/gateway/github-publication-inspect.ts. A sweep of orphaned exports onmainremoved it while this PR was its only importer; the preparation owner calls it to re-verify the PR author before any source transfer. That one line is the only change to the patch beyond the replay.Remote validation on this head
Rebuilding on current
mainneeded two test-only adaptations, both to main's rewrittengithub_publishtool test shape (#178968, #178991): the tool no longer takes acallGatewayoption, so the preparation-dispatch case insrc/agents/tools/github-publish-tool.test.tsnow drives the mocked in-process Gateway the way its siblings do, and the registered-action harness insrc/gateway/github-pr-workspace-preparation.test.tsroutes the tool throughwithPublicationToolTransport, the same transportgithub-publication-inspect.test.tsuses. Assertions are unchanged. Product code did not need adaptation.Remote validation on this exact tree against
main(Linux), in stage order:oxlintcore selection passed).core,ui,extensions,extensions-test,scriptsandtest-rootprograms, with no graph left unrun.The same batch had already passed on the earlier candidate based on #178055's branch (383 cases; the two extra cases are #178055's own additions to the inspection test). Hosted CI, automated review and independent review run again on this head; the broader importer set for the changed session types is covered by the hosted changed-file selection.
Registered action coverage
The registered action tests exercise the real requester, session, Git and workspace reconciliation owners with synthetic GitHub reads and local fixture fetches. They cover same-repository and maintainer-edit fork sources, a newer clean project base, an immutable empty source, prior-work refusal, current permission refusals, same-head idempotency and interrupted initial import while the remote head advances.
The private-source cases include an authorized control, refusal of the wrong author before fetching, and real synthetic-profile role revocation and verified-email reassignment after a successful awaited head fetch. These calls go through the registered action and real Git/session owners. Each denial preserves both workspace copies' HEAD, index, status and binding, leaves the PR-only file absent, and performs no GitHub write. GitHub reads and the fetch transport are fixtures; the protected live guest identities were not changed.
The interruption scenarios observe the existing owner's recovery-required error after canonical acceptance, then prove that a retry completes the originally accepted PR head even after GitHub advances. It retains guest refs and excludes the newer head's files. The registered-runtime control reproduced the earlier failure where a retry probed Git while the runtime remained paused; with owner settlement ahead of the probe, that same test passes using the production sandbox binding, filesystem bridge, runtime registry and reconciliation owner (external container I/O simulated). A separate control retains the database close/reopen path. The existing base-refresh action and same-workspace lifecycle controls also pass.
Tool policy coverage keeps preparation in both the callable and static action definitions, including preparation-only inherited policies, and keeps it discoverable before managed workspace allocation; refresh and evidence keep their separate sandbox capability checks.
Prior-head records
The earlier head 2d12aaa had a clean independent review, a Platinum automated review and passing hosted CI; head 7f2098a was rated Platinum as well. Those are prior-head records. Independent review, automated review and hosted CI run again on this head.
Actual managed-workspace verification (retained from an earlier candidate)
A restricted guest used natural UI requests through the admitted tool on the combined runtime 617f152e8112ae21211e84f3461d74efdff218b4 (tree 61d29b1f65c1f03bc510a1248e20e699feef75cf). The preparation, source-transfer and binding contribution is unchanged since then; supporting runtime-quiescence and retained-session-read updates from the prerequisite were rechecked in the integrated registered-action batch. Broader caller and UI integration code differs, so the captures establish the listed ordinary-container scenarios rather than a deployment of the entire current PR checkout.
Both explicit empty workspaces and worktrees from a selected registered project were exercised. In the selected-project case, one later natural PR-link message imported all eleven exact PR files; the original project's main commit, index, clean status and ten file hashes were unchanged, while the guest kept its original HEAD, branch and history. Role/link revocation, cold-load compatibility and newer-head refusal retain separately identified source-level checks; they are not claimed as live variants here. Ordinary unbound-chat adoption, later remote-head imports and publication remain separate contributions.
Persisted-data compatibility
The changed contract is an optional field inside the existing worktree JSON value. The v2026.10.5 canonical session projector has a byte-identical projection function to the candidate and preserves the nested worktree value. This PR changes no stored-entry format, schema version, migration or update driver. Registered action tests begin with the existing association-absent worktree shape, preserve prior work on refusal, and retain the new association after actual database close/reopen and reuse of the same worktree. This is compatibility proof for that persisted contract; a full deployed v2026.10.5 upgrade was not run.
Visual evidence
Selected-project continuation through preparation, 34.76 seconds
selected-project-continuation-continuous.mp4
Visual verification
These captures are retained from the earlier candidate named below; the preparation behavior they show is unchanged on this head.
617f152e8112ae21211e84f3461d74efdff218b4Empty managed workspace recording
The earlier 43-second continuous preparation recording remains available:
guest-initial-preparation-continuous.mp4