Skip to content

fix(github): let a session continue its own bot-published PR after others push - #187465

Merged
obviyus merged 4 commits into
mainfrom
fix/bot-pr-head-recovery
Oct 29, 2026
Merged

obviyus merged 4 commits into
mainfrom
fix/bot-pr-head-recovery

Conversation

@obviyus

@obviyus obviyus commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Fixes: after anyone else pushes to a PR that an agent session published through the managed publisher (for example roboclaw-bot), that session can never update the PR again.

Publishing correctly refuses to overwrite the other commits (push_rejected). But the documented recovery, prepare_pr, refused twice:

  1. Author check. prepare_pr only accepts PRs authored by the requester's own linked GitHub account. A PR the session published is authored by the publisher bot, so the session that created the PR was refused like a stranger: "This PR is not authored by a GitHub account linked to you."
  2. Clean-workspace check. The first prepare_pr in a session treats the PR as a fresh import and requires a clean workspace. The publishing session always has its own published commits and usually the unpublished fix it is trying to push.

Real case: #180294 on the team Gateway. A maintainer pushed 3 commits to the PR branch. The session's next fix failed with push_rejected 3 times over a week, and every prepare_pr attempt was refused. The agents then suggested reassigning session ownership, which cannot help (see below).

Why This Change Was Made

inspectOwnGitHubPullRequest is the one owner of "may this conversation act on this PR". It now also reads the conversation's latest published record. It admits the PR author when that record names this exact PR URL and the PR author is the publisher account recorded for it. A bot-authored PR from another conversation is still refused.

prepare_pr then treats the head this conversation last published as the already-prepared head. It uses the existing advanced-head path: save the workspace, merge the newer head, return conflicts. It does not use the first-import path that demands a clean workspace. The next ordinary publication appends to the same PR as a fast-forward. No new action, state or config.

Also:

  • The push_rejected next step now tells the agent to call prepare_pr for its own PR, not "apply the changes on top of that head" (which no tool could do).
  • The owner-only prepare_pr error now says it means the person who started the conversation. Reassigning the session owner does not transfer this; multi-user documents that reassignment keeps authority with the creator, and any agent turn can reassign. This check is unchanged on purpose; only the wording changed, because "owner" sent agents into an ownership-transfer loop.
  • Docs and the prepare_pr tool description state the new path.

User Impact

A session whose bot-published PR was updated by someone else can recover with prepare_pr and then publish to the same PR, keeping its saved work. Previously the only way out was a replacement PR or manual Git work by an operator.

Evidence

  • Production trace: team Gateway, session for feat(ui): comment on file, diff, and PDF selections in chat #180294. Publication records show 2 published updates by roboclaw-bot (account 309084314) to that PR URL, then 3 push_rejected failures. The PR's head moved because of 3 maintainer commits. Each prepare_pr call failed, either on the author check or on the creator check after an ownership reassignment.
  • Red then green through the agent tool and Gateway (src/gateway/github-pr-workspace-refresh.test.ts, "merges another writer's commits into this session's own bot-published PR"):
    • The session publishes a PR as the publisher bot.
    • A maintainer appends a commit to that branch.
    • The session has an unpublished edit.
    • prepare_pr runs, then publish.
    • main: failed, with the production error "This PR is not authored by a GitHub account linked to you…".
    • This branch: passed. The maintainer's file is merged and the unpublished fix is kept. Publish sends one fast-forward push leased on the maintainer's head, to the same PR, and that push contains both.
  • Authority is still enforced at both effects (same file, real prepare_pr and publication entry points):
    • A bot-authored PR this session did not publish is refused; no binding is written.
    • A revoked requester is refused before the newer head is accepted. The workspace HEAD, files and binding are unchanged, with no GitHub writes.
    • A requester revoked after a successful prepare_pr is refused at publication ("no longer authorized"), with zero pushes; the PR branch stays at the maintainer's head.
    • Reassigning the session owner still does not grant prepare_pr; the creator check is unchanged and covered by the existing adoption suite.
  • Also new: a bot-authored PR this session did not publish is still refused, and an unchanged own PR after the base advanced prepares cleanly (it fetches the newer base and writes the binding).
  • Related suites: 160 tests across preparation, refresh, inspect, existing-PR publication, publication actions, base refresh, imported actions, PR workspace adoption, and the github_publish tool all pass. The one failure in the first run was a test asserting the old owner-check wording, now updated. pnpm test src/gateway/github-pr-workspace-refresh.test.ts --maxWorkers=1: 16 passed, 71 s wall. GitHub transport is synthetic in these tests (real Gateway, Git, session and publication owners); no live GitHub run.
  • pnpm check:changed passes (format, typecheck, lint, guards) with the dead-export scan skipped; that scan fails on files this PR does not touch, which are already on main.

No overlap with Pash/Sarah changes.

Merge danger: two-way door. No schema, config or stored-state change; a revert restores the old refusals. Blast radius: prepare_pr, inspect_pr, and publication to a prepared PR, for sessions with a published PR. If the new check were wrong, a session could merge and push to a PR whose author matches its own recorded publisher account. The URL and account must both match this conversation's own publication record, and the existing publisher write-access and remote-head checks still run before any push.

@clawsweeper

clawsweeper Bot commented Oct 29, 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: M labels Oct 29, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 29, 2026
@obviyus
obviyus marked this pull request as ready for review October 29, 2026 07:46
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. 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:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 29, 2026
@clawsweeper

clawsweeper Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Allows a conversation to refresh and continue its own bot-published PR after another writer advances its branch.

Example: A conversation publishes through roboclaw-bot, another writer adds maintainer.txt, and the conversation has an unpublished artifact.txt edit.

  • Before: Publication rejects the advanced branch, while prepare_pr rejects the bot author.
  • After: prepare_pr preserves the local edit and integrates maintainer.txt; publication appends both to the same PR.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Focused and correct with meaningful production-owner authority coverage; confidence remains bounded by synthetic GitHub transport rather than a shipped-entry-point demonstration.
Proof confidence 🦐 gold shrimp (3/6) Sufficient (terminal): For this collaborator-authored PR's authority gate, the reported production-owner harness covers successful same-PR recovery, rejection of an unrelated bot PR, revocation before source acceptance, and revocation after preparation with zero pushes and an unchanged upstream branch. Source inspection confirms the real profile and session owners enforce those decisions; GitHub I/O remains synthetic. This addresses the previous review's requested authority evidence.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A conversation cannot update its own bot-published PR after someone else pushes, despite preserving its local work.
Reason: This collaborator-authored repair restores an existing contribution workflow and preserves the original PR, discussion, incoming commits, and saved edits.

Merge readiness

✅ Ready for maintainer review

This PR repairs a source-confirmed contribution workflow failure that remains on main. No introduced defect was found, and the added production-owner authorization cases address the previous review concern.

Priority: P1
Reviewed head: 6d97f639825759632713ae94f06a9e3d1a78307e

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: No live GitHub continuation run is supplied; the applicable authority evidence uses real production owners and local Git with synthetic GitHub transport.
Agent review details

How this fits together

The github_publish tool dispatches to Gateway inspection, workspace preparation, and publication owners, which combine current requester authority with session receipts and GitHub observations before changing workspace files or pushing source.

flowchart TD
  A[Conversation tool request] --> B[Gateway requester authority]
  B --> C[Session receipt and PR inspection]
  C --> D[Existing workspace integration]
  D --> E[Bound PR publication]
  E --> F[Guarded Git push]
Loading

Technical review

Best possible solution:

Reuse the conversation's verified publication receipt to enter the existing PR integration path while retaining current requester and final-effect guards.

Do we have a high-confidence way to reproduce the issue?

Current main's linked-author check rejects a publisher-bot PR before recovery can integrate its newer head; the PR reports a matching production incident and a red-to-green registered-tool regression, which this read-only review did not execute.

Is this the best way to solve the issue?

The patch is a focused repair using existing receipt, authorization, and integration owners, with no competing merge implementation or new configuration.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 241614b59cf5.

Provenance checked

  • Own-PR inspection and authorization changes intended behavior with a stated reason (01c2c60: Inspection verified linked authorship and current private-repository access without granting later write authority.)
  • Initial import versus advanced-head integration keeps the original intent (13c8407: Initial import required pristine source; subsequent refresh preserved guest work through the existing source-integration journal.)
  • Bot-author refusal guidance changes intended behavior with a stated reason (777007b: Distinguish authorship-policy refusals from broken credentials while refusing another conversation's bot-authored PR.)
  • Creator-only preparation and destination reconciliation keeps the original intent (18e94f2: Explicit preparation reconciles the original PR's current destination while preserving source history and current write eligibility.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Current main still lacks recovery: At fetched main, inspection accepts linked PR authorship without consulting the conversation's publication receipt, and preparation derives its previous head only from an existing imported-PR binding. (src/gateway/github-publication-inspect.ts:136, 241614b59cf5)
  • Receipt selection remains session scoped: The existing receipt reader matches agent, session ID, lifecycle, worktree, repository fingerprint, and branch; the patch additionally requires the observed PR URL and author account to match that receipt. (src/gateway/github-publication-shared-read.kernel.ts:105, 6d97f6398257)
  • Previous authority concern addressed: The updated harness uses real session, profile, preparation, publication, and Git owners. It checks successful continuation, refusal of an unrelated bot PR, unchanged workspace after requester revocation, and zero pushes after revocation following preparation; GitHub transport is synthetic. (src/gateway/github-pr-workspace-refresh.test.ts:235, 6d97f6398257)
  • Existing security owners retained: Requester policy rechecks current role, creator eligibility, session access, and invocation authority; preparation rechecks PR write eligibility before accepting source, while action writes retain their final transport guard. (src/gateway/github-publication-requester.ts, 6d97f6398257)
  • Exact-head checks: Paginated current-head check reads show no failed or pending check runs; openclaw/ci-gate, dependency review, and security-sensitive review statuses are successful, and GitHub reports the PR mergeable and clean. (6d97f6398257)
  • Feature history and retained proof: The inspection and refresh contracts originate in feat: inspect existing own pull requests #178055 and feat: refresh imported pull request source #178298. Downloaded screenshots show that earlier imported-PR refresh flow, not this new bot continuation path. Video preparation reports 'ffprobe failed: spawnSync ffprobe ENOENT'; the browser fallback returned 'Cache miss'. Some historical blobs were unavailable locally, while relevant commit history, current source, and linked PR explanations were readable. (src/gateway/github-pr-workspace-preparation.ts, 241614b59cf5)

PR surface

Source +29, Tests +164, Docs +9. Total +202 across 11 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 6 48 19 +29
Tests 4 169 5 +164
Docs 1 10 1 +9
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 11 227 25 +202

Review metrics

Metric Value Why it matters
Production versus test changes Production +48/-19; tests and support +169/-5 The production growth connects existing receipt and integration owners; regression coverage protects continuation, unrelated-PR rejection, unchanged-head preparation, and revocation at both effects.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.
  • remove merge-risk: 🚨 security-boundary: Current PR review selected no merge-risk labels.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P1: A reported and source-confirmed failure blocks an existing agent contribution workflow after another writer advances its PR.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-29T08:15:31.316Z sha 33d4a34 :: needs real behavior proof before merge. :: none

Reviewed October 29, 2026, 6:24 AM ET / 10:24 UTC (Revision 2).

@obviyus

obviyus commented Oct 29, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and 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. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 29, 2026
@clawsweeper clawsweeper Bot added the status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. label Oct 29, 2026
@obviyus
obviyus merged commit 4ececc4 into main Oct 29, 2026
141 checks passed
@obviyus
obviyus deleted the fix/bot-pr-head-recovery branch October 29, 2026 10:27
@obviyus

obviyus commented Oct 29, 2026

Copy link
Copy Markdown
Collaborator Author

Landed as 4ececc4.

  • Bug: a session could not update its own bot-published PR after another writer pushed to it. prepare_pr refused the bot author, then demanded a clean workspace.
  • Fix: inspect_pr/prepare_pr admit the PR when this conversation's own publication record matches its URL and publisher account. Preparation merges the newer head into the saved work through the existing advanced-head path. The creator-only check is unchanged; its error now says that reassigning the owner does not transfer it.
  • Proof: Gateway-level tests show red on main and green here (prepare, then a fast-forward publish that keeps the maintainer commit and the unpublished fix). Other tests still refuse a foreign bot PR and a revoked requester at both effects. CI green; ClawSweeper ready on the exact head.

Thanks to Jacqueline for the #180294 report that exposed this.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 30, 2026
…hers push (openclaw#187465)

## What Problem This Solves

Fixes: after anyone else pushes to a PR that an agent session published through the managed publisher (for example `roboclaw-bot`), that session can never update the PR again.

Publishing correctly refuses to overwrite the other commits (`push_rejected`). But the documented recovery, `prepare_pr`, refused twice:

1. **Author check.** `prepare_pr` only accepts PRs authored by the requester's own linked GitHub account. A PR the session published is authored by the publisher bot, so the session that created the PR was refused like a stranger: "This PR is not authored by a GitHub account linked to you."
2. **Clean-workspace check.** The first `prepare_pr` in a session treats the PR as a fresh import and requires a clean workspace. The publishing session always has its own published commits and usually the unpublished fix it is trying to push.

Real case: openclaw#180294 on the team Gateway. A maintainer pushed 3 commits to the PR branch. The session's next fix failed with `push_rejected` 3 times over a week, and every `prepare_pr` attempt was refused. The agents then suggested reassigning session ownership, which cannot help (see below).

## Why This Change Was Made

`inspectOwnGitHubPullRequest` is the one owner of "may this conversation act on this PR". It now also reads the conversation's latest published record. It admits the PR author when that record names this exact PR URL and the PR author is the publisher account recorded for it. A bot-authored PR from another conversation is still refused.

`prepare_pr` then treats the head this conversation last published as the already-prepared head. It uses the existing advanced-head path: save the workspace, merge the newer head, return conflicts. It does not use the first-import path that demands a clean workspace. The next ordinary publication appends to the same PR as a fast-forward. No new action, state or config.

Also:
- The `push_rejected` next step now tells the agent to call `prepare_pr` for its own PR, not "apply the changes on top of that head" (which no tool could do).
- The owner-only `prepare_pr` error now says it means the person who started the conversation. Reassigning the session owner does not transfer this; [multi-user](https://docs.openclaw.ai/concepts/multi-user) documents that reassignment keeps authority with the creator, and any agent turn can reassign. This check is unchanged on purpose; only the wording changed, because "owner" sent agents into an ownership-transfer loop.
- Docs and the `prepare_pr` tool description state the new path.

## User Impact

A session whose bot-published PR was updated by someone else can recover with `prepare_pr` and then publish to the same PR, keeping its saved work. Previously the only way out was a replacement PR or manual Git work by an operator.

## Evidence

- **Production trace:** team Gateway, session for openclaw#180294. Publication records show 2 published updates by `roboclaw-bot` (account 309084314) to that PR URL, then 3 `push_rejected` failures. The PR's head moved because of 3 maintainer commits. Each `prepare_pr` call failed, either on the author check or on the creator check after an ownership reassignment.
- **Red then green through the agent tool and Gateway** (`src/gateway/github-pr-workspace-refresh.test.ts`, "merges another writer's commits into this session's own bot-published PR"):
  - The session publishes a PR as the publisher bot.
  - A maintainer appends a commit to that branch.
  - The session has an unpublished edit.
  - `prepare_pr` runs, then publish.
  - `main`: **failed**, with the production error "This PR is not authored by a GitHub account linked to you…".
  - This branch: **passed**. The maintainer's file is merged and the unpublished fix is kept. Publish sends one fast-forward push leased on the maintainer's head, to the same PR, and that push contains both.
- **Authority is still enforced at both effects** (same file, real `prepare_pr` and publication entry points):
  - A bot-authored PR this session did not publish is refused; no binding is written.
  - A revoked requester is refused before the newer head is accepted. The workspace HEAD, files and binding are unchanged, with no GitHub writes.
  - A requester revoked after a successful `prepare_pr` is refused at publication ("no longer authorized"), with zero pushes; the PR branch stays at the maintainer's head.
  - Reassigning the session owner still does not grant `prepare_pr`; the creator check is unchanged and covered by the existing adoption suite.
- **Also new:** a bot-authored PR this session did not publish is still refused, and an unchanged own PR after the base advanced prepares cleanly (it fetches the newer base and writes the binding).
- **Related suites:** 160 tests across preparation, refresh, inspect, existing-PR publication, publication actions, base refresh, imported actions, PR workspace adoption, and the `github_publish` tool all pass. The one failure in the first run was a test asserting the old owner-check wording, now updated. `pnpm test src/gateway/github-pr-workspace-refresh.test.ts --maxWorkers=1`: 16 passed, 71 s wall. GitHub transport is synthetic in these tests (real Gateway, Git, session and publication owners); no live GitHub run.
- `pnpm check:changed` passes (format, typecheck, lint, guards) with the dead-export scan skipped; that scan fails on files this PR does not touch, which are already on `main`.

No overlap with Pash/Sarah changes.

**Merge danger:** two-way door. No schema, config or stored-state change; a revert restores the old refusals. **Blast radius:** `prepare_pr`, `inspect_pr`, and publication to a prepared PR, for sessions with a published PR. If the new check were wrong, a session could merge and push to a PR whose author matches its own recorded publisher account. The URL and account must both match this conversation's own publication record, and the existing publisher write-access and remote-head checks still run before any push.

Co-authored-by: Ayaan Zaidi <[email protected]>
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 P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant