Skip to content

fix: hide prepare_pr from direct sessions - #179725

Merged
shakkernerd merged 1 commit into
mainfrom
hide-prepare-pr-direct
Oct 21, 2026
Merged

shakkernerd merged 1 commit into
mainfrom
hide-prepare-pr-direct

Conversation

@shakkernerd

@shakkernerd shakkernerd commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes: github_publish offers prepare_pr to 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_pr imports 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_base and upload_evidence: one predicate per action decides both what the tool offers and what the Gateway accepts. prepare_pr was 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 the github_publish action 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. The pullRequestUrl misuse error in those sessions now points only at inspect_pr instead of naming an action the session does not have.

Sandboxed sessions in a writable managed workspace keep prepare_pr exactly as before, with the same schema and description text. inspect_pr, publish, edit, ready, request_review and the operator actions keep their current availability, and refresh_base and upload_evidence keep the rules from #178671. Linked GitHub identity verification and the existing write-access checks are unchanged. The Gateway still refuses a direct prepare_pr call 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.ts gains canPrepareGitHubPullRequest, 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:

  • Tool visibility (src/agents/tools/github-publish-tool.ts): the action enum filter, the prepare_pr description paragraph and the pullRequestUrl misuse error all read the predicate. The sandbox context is a session and configuration fact, so the tool definition stays stable within a session, as src/agents/agent-tools.prefix-stability.test.ts requires.
  • Gateway enforcement (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_pr is 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 covered refresh_base and upload_evidence across 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 that prepare_pr is in the enum and described exactly when the sandbox is writable and managed.

  • Before the fix, on main at 424c582 with only the test change applied, the file failed 6 of 28 tests. The direct session case failed with 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 accepted prepare_pr in its schema although the Gateway refuses it.
  • With the fix, the same file passes 28 of 28.

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_pr paragraph; the paragraph as it now stands on main is what this change makes conditional:

Check Result
Changed-file formatting and oxlint passed, 0 warnings
Type checks (core, core tests, UI, extensions, scripts) passed
13 related test files: the tool, registration, publication-inheritance and prompt-prefix tests, plus the Gateway prepare_pr, imported-PR refresh, existing-PR publication, actions, imported-actions, base-refresh, evidence, inspect and workflow tests 247 passed, 0 failed

src/agents/agent-tools.prefix-stability.test.ts passing confirms the tool definition still depends only on session facts.

Consumer tests adapted to the new availability:

  • src/agents/openclaw-tools.registration.test.ts builds the tool through the real tool assembly with a sandbox that has no managed worktree, so it now expects prepare_pr to be rejected, like refresh_base.
  • src/agents/agent-tools.publication-inheritance.test.ts gives the child a writable managed sandbox, so the preparation-only inherited policy case still proves that prepare_pr survives inheritance.
  • The prepare-only deployment policy case in github-publish-tool.test.ts builds the tool with a capable sandbox for the same reason.

src/gateway/github-pr-workspace-preparation.test.ts drives prepare_pr through 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.

@shakkernerd shakkernerd self-assigned this Oct 21, 2026
@clawsweeper

clawsweeper Bot commented Oct 21, 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 gateway Gateway runtime agents Agent runtime and tooling size: S labels Oct 21, 2026
@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components.

No secops approval is required. This comment is informational because the PR author has Maintain or Admin access.

  • Current SHA: 657c1a3dbbbe5ef118a2a1c84a486f985da66f1d
  • Maintainer: @shakkernerd
  • Repository role: maintain

These security sensitive changes were made:

  • src/agents/sandbox/github-publication.ts: Controls sandbox containment or tool execution authority. Check filesystem and network isolation, approval scope, and command allowlists.

Carefully review these changes before merging.

@clawsweeper clawsweeper Bot added the clawsweeper:intake:bug Preliminary submission classification; full source review pending. label Oct 21, 2026
@shakkernerd
shakkernerd force-pushed the hide-prepare-pr-direct branch from 0d6adfa to e30e694 Compare October 21, 2026 17:32
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Oct 21, 2026
@clawsweeper

clawsweeper Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: stale review; fresh review needed.

Summary
The latest durable ClawSweeper review was for head e30e694e6ddf16b457bd5572ba5bdca431af2b89, but the PR head is now 657c1a3dbbbe5ef118a2a1c84a486f985da66f1d. 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-21T18:24:20.903Z sha e30e694e6ddf16b457bd5572ba5bdca431af2b89 :: needs maintainer review before merge. :: none

@shakkernerd
shakkernerd force-pushed the hide-prepare-pr-direct branch from e30e694 to 657c1a3 Compare October 21, 2026 18:28
@clawsweeper clawsweeper Bot removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 21, 2026
@shakkernerd
shakkernerd merged commit 51ad689 into main Oct 21, 2026
120 of 122 checks passed
@shakkernerd
shakkernerd deleted the hide-prepare-pr-direct branch October 21, 2026 18:47
@shakkernerd

Copy link
Copy Markdown
Contributor Author

Fixed: github_publish now offers prepare_pr only in sessions with a writable managed sandbox, so agents running directly on the host no longer see an action the Gateway always refuses.

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

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation gateway Gateway runtime P2 Normal backlog priority with limited blast radius. security-sensitive-changed size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant