Skip to content

Keep the removed environment pull request SDK methods working through the GitHub PR Status plugin - #7205

Merged
ymichael merged 3 commits into
mainfrom
bb/restore-runtime-shims-for-removed-pr-sdk-methods-thr_jjr3pxi44d
Nov 6, 2026
Merged

ymichael merged 3 commits into
mainfrom
bb/restore-runtime-shims-for-removed-pr-sdk-methods-thr_jjr3pxi44d

Conversation

@ymichael

@ymichael ymichael commented Nov 6, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

#6125 (first shipped in bb 0.47.0) deleted the server plugin SDK methods bb.sdk.environments.pullRequest, markPullRequestReady, markPullRequestDraft and mergePullRequest outright, along with core's routes. Every other retirement took the name out of the typings only. The runtime kept working and the build warned with the replacement. Published plugins that still call these four now get TypeError: ... is not a function. Community plugins genui (project/environments.ts, project/source.ts) and linear (server.ts's PR-merged → Done write-back, hidden behind an as never cast) are broken today, and about 14 marketplace plugins reference the methods.

What changed

These four follow the pattern the Git plugin's retired reads use (retired-environment-reads.ts, retired-sdk-members.ts):

  • Runtime adapters in packages/sdk/src/areas/retired-environment-pull-requests.ts, mixed into sdk.environments next to the Git read adapters. The EnvironmentsArea typings are unchanged. Each one forwards to the bundled GitHub PR Status plugin (bb--github-pr-status) and returns the old shape:
    • pullRequest({ environmentId }) calls pullRequests with keys: [environmentId] and returns that row: available with pullRequest, absent, or unavailable with message. The plugin's row schema is the same as the old ThreadPullRequest field for field. It returns unavailable if the plugin sends back no row.
    • markPullRequestReady / markPullRequestDraft / mergePullRequest call markReady / markDraft / merge. They return { ok: true, action: "pull_request_ready" | "pull_request_draft" | "pull_request_merge", message }, and merge also returns method. The messages are the same strings the old route returned.
    • Errors: a plugin not_found refusal becomes 404 environment_not_found. A conflict refusal becomes 409 pull_request_action_failed and keeps the plugin's reason ("Pull request is not a draft", "No pull request found", …), matching the old route's 409s. When the plugin is disabled, the call fails with the RPC error, as the Git read adapters do.
  • Plugin caller token (apps/server/src/services/plugins/plugin-api.ts). A plugin's bb.sdk already sends plugins.callRpc with the plugin's caller token. sdk.environments, though, came from the shared base SDK, so the adapters reached bb--github-pr-status as an anonymous client. The plugin answers client (app viewer) reads from its saved row and refreshes it in the background. For a PR merged long ago, that saved row can still say open, while markReady, which always reads fresh, finds no PR. wrapSdkForPlugin now builds the retired environment members (these four and the Git reads) on the caller-token callRpc, via createRetiredEnvironmentMembers from @bb/sdk (its own module, so the published plugin SDK types are unchanged). pullRequest then waits for a row fresher than 10 seconds, as the old route and a direct callRpc from a plugin do.
  • Build warning in packages/plugin-build/src/retired-sdk-members.ts. The four names join the same environments.<name> scan (member access, optional chaining, bracket access, destructuring). The warning names the replacement call, e.g. bb.sdk.plugins.callRpc({ pluginId: "bb--github-pr-status", method: "merge", input: { environmentId, method } }), and points at the github-pr-status skill. Builds still never fail.
  • Recorded in docs/api_to_audit.md, in a new "Retired environment pull request methods" section next to the Git reads entry.

No wire, CLI or published SDK surface changes. check-plugin-sdk-version.mjs reports "Plugin SDK surface unchanged".

How you verified

  • New packages/sdk/test/retired-environment-pull-requests.test.ts drives the real SDK over the HTTP transport. It covers the read's row passthrough and the missing-row case, each action's RPC path, input and old result shape, and the 409 and 404 refusal mappings. Each test fails on main, where the members don't exist.
  • retired-sdk-members.test.ts adds detection of all four names in the forms genui and linear use (including bb.sdk.environments.pullRequest({ environmentId }) as never, destructuring with an alias, and optional chaining). It also checks the exact merge warning text and that pullRequests RPC calls aren't flagged.
  • Live, against a running bb server and its real GitHub PR Status plugin, using this branch's SDK source:
    • pullRequest on an environment with an open PR returned {"outcome":"available","pullRequest":{"number":6248,…,"checks":{"state":"passing",…}}}, the shape genui's pullRequestInfo and linear's pr-runner read.
    • pullRequest on a branch without a PR returned {"outcome":"absent"}.
    • markPullRequestReady on that environment was refused before any write: 409 pull_request_action_failed HTTP 409: No pull request found. That contradicted the read. Observe the owned child exit in the shutdown regression #6248 was merged on Oct 25, and the read was a saved Oct 24 row, served because my harness called with no caller token (an app viewer read). Inside a plugin the same thing happened, because sdk.environments didn't carry the token. That is fixed in the second commit. bb pull-request show env_p5z4xpvfak now returns absent, matching the action.
  • plugin-sdk.test.ts adds a running-server test. It calls a plugin's bb.sdk.environments.pullRequest and markPullRequestReady and asserts that both requests carry the plugin's x-bb-plugin-caller token. It fails without the plugin-api.ts change. The existing whoami test covers how the token resolves to a plugin caller.
    • mergePullRequest on an unknown environment returned 404 environment_not_found.
  • pnpm exec turbo run test typecheck lint --filter=@bb/sdk --filter=@bb/plugin-build passes (sdk 137 tests, plugin-build 262). @bb/server typecheck and lint pass, and the two caller tests in plugin-sdk.test.ts pass. Full suites are left to CI.

AGENT GENERATED

🤖 Generated with Claude Code

ymichael and others added 3 commits November 6, 2026 15:32
… the GitHub PR Status plugin

#6125 deleted bb.sdk.environments.pullRequest, markPullRequestReady,
markPullRequestDraft and mergePullRequest outright, so published plugins
that still call them (genui, linear) throw a TypeError. Retire them the
way the Git reads were retired: runtime adapters with the old result
shapes that forward to bb--github-pr-status, a build warning naming the
replacement RPC call, and an api_to_audit entry.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A plugin's bb.sdk replaced plugins.callRpc with the caller-token SDK, but
sdk.environments still came from the shared base SDK, so the retired
adapters reached bb--github-pr-status as an anonymous client. The plugin
answers client reads from its saved row, which for a long-merged PR can
still say open while markReady (a fresh read) finds no PR. Build the
retired environment members on the caller-token callRpc in
wrapSdkForPlugin so pullRequest waits for a fresh row, as the old route
and a direct plugin callRpc do.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…types

Exporting it from environments.ts pulled the plugins-area types into
bundled-types, changing @get-bb/plugin-sdk's published surface. Its own
module stays outside the type graph the plugin SDK bundles.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ymichael
ymichael force-pushed the bb/restore-runtime-shims-for-removed-pr-sdk-methods-thr_jjr3pxi44d branch from 08688e4 to 0acad6b Compare November 6, 2026 23:33
@ymichael
ymichael merged commit be2bf8a into main Nov 6, 2026
52 checks passed
@ymichael
ymichael deleted the bb/restore-runtime-shims-for-removed-pr-sdk-methods-thr_jjr3pxi44d branch November 6, 2026 23:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant