Repository navigation
fix: hide prepare_pr from direct sessions - #179725
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. |
|
0d6adfa to
e30e694
Compare
|
Codex review: stale review; fresh review needed. Summary Next step Review history (1 earlier review cycle)
|
e30e694 to
657c1a3
Compare
|
Fixed: |
Sessions without a writable managed sandbox no longer see the github_publish prepare_pr action; the tool and the Gateway now decide its availability with one shared predicate, and sandboxed managed-workspace sessions keep it unchanged.
What Problem This Solves
Fixes:
github_publishoffersprepare_prto sessions whose agent runs directly on the host, although the Gateway only accepts it from a writable managed sandbox, so an agent asked to continue an existing PR picks an action that can only fail.prepare_primports an existing PR's head into the conversation's managed sandbox workspace so a guest can keep working on their own PR. Since it landed, the tool listed it in its action enum and described it in every session that can publish, whatever the execution mode. The Gateway, meanwhile, refuses it unless the caller's sandbox is enabled, has a backend, uses a managed worktree and is writable. A direct session therefore sees a documented action that it can never perform, and the first thing it learns is a refusal.#178671 fixed the same mismatch for
refresh_baseandupload_evidence: one predicate per action decides both what the tool offers and what the Gateway accepts.prepare_prwas added after that pattern existed but still decided availability with an inline condition in the Gateway and offered itself unconditionally in the tool.User Impact
Sessions without a writable managed sandbox no longer see
prepare_pr: it is absent from thegithub_publishaction enum and its description paragraph is omitted. That covers direct host sessions as well as read-only, unmanaged, backend-less and disabled sandboxes, which all received the same Gateway refusal before. ThepullRequestUrlmisuse error in those sessions now points only atinspect_prinstead of naming an action the session does not have.Sandboxed sessions in a writable managed workspace keep
prepare_prexactly as before, with the same schema and description text.inspect_pr,publish,edit,ready,request_reviewand the operator actions keep their current availability, andrefresh_baseandupload_evidencekeep the rules from #178671. Linked GitHub identity verification and the existing write-access checks are unchanged. The Gateway still refuses a directprepare_prcall with the same two messages as before: one asking to run it from the conversation's sandboxed agent in a managed workspace, and one explaining that a read-only workspace needs a writable sandbox.Why This Change Was Made
src/agents/sandbox/github-publication.tsgainscanPrepareGitHubPullRequest, next to the two predicates from #178671. Today it requires the same sandbox facts as base refresh (enabled, backend, managed worktree, not read-only), but it is a separate decision: PR preparation and base refresh are distinct actions whose eligibility is expected to diverge, and each should be changeable without silently moving the other.The predicate is used in both places that decide the action's availability:
src/agents/tools/github-publish-tool.ts): the action enum filter, theprepare_prdescription paragraph and thepullRequestUrlmisuse error all read the predicate. The sandbox context is a session and configuration fact, so the tool definition stays stable within a session, assrc/agents/agent-tools.prefix-stability.test.tsrequires.src/gateway/github-pr-workspace-preparation.ts): the inline condition is replaced by the predicate. The read-only message is kept for read-only sandboxes and the managed-workspace message for everything else, so callers that bypass the tool schema still get a refusal that names what to do.The docs page for GitHub identity actions now states where
prepare_pris offered, matching the sentences #178671 added for the other sandbox-only actions.Evidence
The decisive case is the table-driven construction test in
src/agents/tools/github-publish-tool.test.ts, which already coveredrefresh_baseandupload_evidenceacross direct, writable managed, read-only managed, unmanaged, missing-backend, missing-file-bridge, missing source-aware read and disabled sandboxes, with and without operator actions. It now also checks thatprepare_pris in the enum and described exactly when the sandbox is writable and managed.prepare_pr: expected true to be false(the enum still offered it), as did the read-only, unmanaged, missing-backend and disabled cases, and the unmanaged dispatch case acceptedprepare_prin its schema although the Gateway refuses it.All checks below ran on a remote Linux box (32 CPU) against this exact tree, after rebasing onto main with #178298 and #178318. Those PRs rewrote the
prepare_prparagraph; the paragraph as it now stands on main is what this change makes conditional:prepare_pr, imported-PR refresh, existing-PR publication, actions, imported-actions, base-refresh, evidence, inspect and workflow testssrc/agents/agent-tools.prefix-stability.test.tspassing confirms the tool definition still depends only on session facts.Consumer tests adapted to the new availability:
src/agents/openclaw-tools.registration.test.tsbuilds the tool through the real tool assembly with a sandbox that has no managed worktree, so it now expectsprepare_prto be rejected, likerefresh_base.src/agents/agent-tools.publication-inheritance.test.tsgives the child a writable managed sandbox, so the preparation-only inherited policy case still proves thatprepare_prsurvives inheritance.github-publish-tool.test.tsbuilds the tool with a capable sandbox for the same reason.src/gateway/github-pr-workspace-preparation.test.tsdrivesprepare_prthrough the real Gateway handler against a real git worktree. It still refuses a session without a sandbox ("sandboxed agent") and a read-only sandbox ("read-only") before preparing the PR in a writable managed sandbox, which shows enforcement and both refusal texts are unchanged.The same test file still fails 6 of 28 against current main's production code (e18310f), so main does not already provide this behavior.