From 2cf7d1a2feb923e2d25d129b1b4c47139ca39f4f Mon Sep 17 00:00:00 2001 From: sidreyas Date: Sat, 7 Nov 2026 04:10:07 +0530 Subject: [PATCH 1/3] fix(github): explain rejected pull request base branches --- .../GitHubSourceControlProvider.test.ts | 48 ++++++++++++++++++ .../src/server/GitHubSourceControlProvider.ts | 49 +++++++++++++------ 2 files changed, 82 insertions(+), 15 deletions(-) diff --git a/packages/source-control-github/src/server/GitHubSourceControlProvider.test.ts b/packages/source-control-github/src/server/GitHubSourceControlProvider.test.ts index a5a08fcfc2cc4..82853504c5a2f 100644 --- a/packages/source-control-github/src/server/GitHubSourceControlProvider.test.ts +++ b/packages/source-control-github/src/server/GitHubSourceControlProvider.test.ts @@ -552,6 +552,54 @@ describe("GitHubSourceControlProvider writes", () => { }).pipe(Effect.provide(Layer.merge(layer, NodeServices.layer)), Effect.scoped); }); + it.effect.each([ + { host: "github.com", status: 422, field: "base", rejectedBase: true }, + { host: "code.example.test", status: 422, field: "base", rejectedBase: true }, + { host: "github.com", status: 422, field: "head", rejectedBase: false }, + { host: "github.com", status: 500, field: "base", rejectedBase: false }, + ])( + "explains a rejected PR base without replacing other API failures: $host $status $field", + ({ host, status, field, rejectedBase }) => { + const cause = new GitHubRequestPolicy.GitHubApiResponseError({ + host, + operation: "createPullRequest", + status, + githubErrors: ["Validation Failed", `${field} invalid`], + }); + const { layer } = harness({ + remotes: remotesOutput( + ["origin", `git@${host}:me/web.git`], + ["upstream", `git@${host}:acme/web.git`], + ), + api: { rest: () => Effect.fail(cause) }, + }); + return Effect.gen(function* () { + const fs = yield* FileSystem.FileSystem; + const bodyFile = yield* fs.makeTempFileScoped({ suffix: ".md" }); + yield* fs.writeFileString(bodyFile, "Body"); + const gh = yield* GitHubSourceControlProvider.make; + const error = yield* gh + .createChangeRequest({ + cwd: "/repo", + context: githubContext(host), + baseRefName: "stack/parent", + headSelector: "me:child", + title: "Title", + bodyFile, + }) + .pipe(Effect.flip); + assert.strictEqual(error.operation, "createChangeRequest"); + assert.strictEqual(error.cause, cause); + assert.strictEqual( + error.detail, + rejectedBase + ? `GitHub rejected base branch "stack/parent" for ${host}/acme/web. Push the intended base branch to that repository, or choose an existing base branch and retry.` + : cause.message, + ); + }).pipe(Effect.provide(layer), Effect.scoped); + }, + ); + it.effect("creates a repository under an organization the viewer is not", () => { const requests: Array = []; const { layer } = harness({ diff --git a/packages/source-control-github/src/server/GitHubSourceControlProvider.ts b/packages/source-control-github/src/server/GitHubSourceControlProvider.ts index 4abb3d8d6669f..a67854c254c03 100644 --- a/packages/source-control-github/src/server/GitHubSourceControlProvider.ts +++ b/packages/source-control-github/src/server/GitHubSourceControlProvider.ts @@ -985,21 +985,40 @@ export const make = Effect.gen(function* () { failure("The pull request description could not be read.", cause), ), ); - yield* rest({ - host: locator.host, - operation: "createPullRequest", - method: "POST", - allowReserve: true, - path: `repos/${encodeURIComponent(locator.owner)}/${encodeURIComponent(locator.name)}/pulls`, - // Explicitly allow maintainer edits to match gh; the API default is undocumented. - body: { - base: input.baseRefName, - head: input.headSelector, - title: input.title, - body, - maintainer_can_modify: true, - }, - }); + yield* api + .rest({ + host: locator.host, + operation: "createPullRequest", + method: "POST", + allowReserve: true, + path: `repos/${encodeURIComponent(locator.owner)}/${encodeURIComponent(locator.name)}/pulls`, + // Explicitly allow maintainer edits to match gh; the API default is undocumented. + body: { + base: input.baseRefName, + head: input.headSelector, + title: input.title, + body, + maintainer_can_modify: true, + }, + }) + .pipe( + Effect.mapError((error) => { + if ( + error._tag === "GitHubApiResponseError" && + error.status === 422 && + error.githubErrors?.includes("base invalid") + ) { + const base = SourceControlProvider.transportSafeSourceControlErrorValue( + input.baseRefName, + ); + return failure( + `GitHub rejected base branch ${JSON.stringify(base)} for ${locator.host}/${locator.owner}/${locator.name}. Push the intended base branch to that repository, or choose an existing base branch and retry.`, + error, + ); + } + return fromGitHubApiError(error); + }), + ); }, (effect, input) => effect.pipe( From c86c65df7655b3dba85fa1cc7912a89539eb2042 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sun, 15 Nov 2026 04:47:54 +0000 Subject: [PATCH 2/3] fix(client): show the server's git action failure to the user Web and mobile toasts showed only "Source control action 'create_pr' failed during pr.", dropping the server's diagnostic (such as GitHub's rejected base branch). The client error now carries the server message as a Redacted field: logs and serialization still see only the generic message, and vcsActionFailureDescription gives clients the text to show. Co-Authored-By: Claude Opus 5.5 --- .../src/features/threads/DraftThreadHeader.tsx | 6 +++++- .../src/state/use-selected-thread-git-actions.ts | 3 ++- apps/web/src/components/GitActionsControl.tsx | 3 ++- .../client-runtime/src/state/vcsAction.test.ts | 11 ++++++----- packages/client-runtime/src/state/vcsAction.ts | 15 +++++++++++++-- 5 files changed, 28 insertions(+), 10 deletions(-) diff --git a/apps/mobile/src/features/threads/DraftThreadHeader.tsx b/apps/mobile/src/features/threads/DraftThreadHeader.tsx index 043273ee79bec..921604e83eaa2 100644 --- a/apps/mobile/src/features/threads/DraftThreadHeader.tsx +++ b/apps/mobile/src/features/threads/DraftThreadHeader.tsx @@ -12,6 +12,7 @@ import { useEnvironmentQuery } from "../../state/query"; import { useEnvironmentScope } from "../../state/session"; import { useAtomCommand } from "../../state/use-atom-command"; import { vcsActionManager, vcsEnvironment } from "../../state/vcs"; +import { vcsActionFailureDescription } from "@t3tools/client-runtime/state/vcs"; import { useVcsActionState } from "../../state/use-vcs-action-state"; import { ThreadHeader } from "./ThreadHeader"; @@ -84,7 +85,10 @@ export function DraftThreadHeader(props: { actionId: uuidv4(), }); if (AsyncResult.isFailure(result)) { - Dialog.alert("Git action failed", String(Cause.squash(result.cause))); + Dialog.alert( + "Git action failed", + vcsActionFailureDescription(Cause.squash(result.cause), "Git action failed."), + ); return null; } return result.value; diff --git a/apps/mobile/src/state/use-selected-thread-git-actions.ts b/apps/mobile/src/state/use-selected-thread-git-actions.ts index 7ecc10d0b6d85..04115b145e6bb 100644 --- a/apps/mobile/src/state/use-selected-thread-git-actions.ts +++ b/apps/mobile/src/state/use-selected-thread-git-actions.ts @@ -24,6 +24,7 @@ import { AsyncResult } from "effect/reactivity"; import { useBranches } from "./queries"; import { threadEnvironment } from "./threads"; import { vcsActionManager, vcsEnvironment } from "./vcs"; +import { vcsActionFailureDescription } from "@t3tools/client-runtime/state/vcs"; import { uuidv4 } from "../lib/uuid"; import { appAtomRegistry } from "./atom-registry"; import { readEnvironmentScope, useEnvironmentScope } from "./session"; @@ -199,7 +200,7 @@ export function useSelectedThreadGitActions() { : await vcsActionManager.track(appAtomRegistry, target, { operation, label }, run); if (AsyncResult.isFailure(result)) { const error = Cause.squash(result.cause); - const message = error instanceof Error ? error.message : "Git action failed."; + const message = vcsActionFailureDescription(error, "Git action failed."); setPendingConnectionError(message); showGitActionResult({ type: "error", title: "Git action failed", description: message }); return null; diff --git a/apps/web/src/components/GitActionsControl.tsx b/apps/web/src/components/GitActionsControl.tsx index 77ab241966e3f..5a44fffb450a5 100644 --- a/apps/web/src/components/GitActionsControl.tsx +++ b/apps/web/src/components/GitActionsControl.tsx @@ -110,6 +110,7 @@ import { sourceControlEnvironment } from "~/state/sourceControl"; import { threadEnvironment } from "~/state/threads"; import { useAtomCommand } from "~/state/use-atom-command"; import { vcsActionManager, vcsEnvironment, vcsStatusRevalidation } from "~/state/vcs"; +import { vcsActionFailureDescription } from "@t3tools/client-runtime/state/vcs"; import { randomUUID } from "~/lib/utils"; import { resolvePathLinkTarget } from "@t3tools/shared/fileLinks"; import { type DraftId, useComposerDraftStore } from "~/composerDraftStore"; @@ -1273,7 +1274,7 @@ export default function GitActionsControl({ stackedThreadToast({ type: "error", title: "Action failed", - description: error instanceof Error ? error.message : "An error occurred.", + description: vcsActionFailureDescription(error, "An error occurred."), timeout: errorToastTiming.timeout, ...(scopedToastData !== undefined ? { data: scopedToastData } : {}), }), diff --git a/packages/client-runtime/src/state/vcsAction.test.ts b/packages/client-runtime/src/state/vcsAction.test.ts index 67e9253cba4f3..785a5fca5fbdd 100644 --- a/packages/client-runtime/src/state/vcsAction.test.ts +++ b/packages/client-runtime/src/state/vcsAction.test.ts @@ -42,6 +42,7 @@ import { parseVcsActionTargetKey, VcsActionMissingTerminalEventError, VcsActionRemoteFailureError, + vcsActionFailureDescription, VcsActionTargetKeyParseError, } from "./vcsAction.ts"; import { vcsRefsCacheStateAtom } from "./vcsRefInvalidation.ts"; @@ -299,11 +300,12 @@ describe("vcsActionState", () => { }), ); - it.effect("retains structural remote failure context without copying the remote payload", () => + it.effect("shows the remote failure to the user without putting it in logged fields", () => Effect.gen(function* () { const target = { environmentId, cwd }; const transportActionId = createVcsActionTransportId(target, actionId); - const remoteMessage = "The remote rejected the push with credential=do-not-log."; + const remoteMessage = + 'GitHub rejected base branch "stack/parent" for github.com/acme/web. Push the intended base branch to that repository, or choose an existing base branch and retry.'; const error = yield* consumeVcsActionProgress( Stream.fromIterable([ { @@ -332,11 +334,10 @@ describe("vcsActionState", () => { environmentId, cwd, phase: "push", - remoteMessageLength: remoteMessage.length, }); - expect(error).not.toHaveProperty("detail"); expect(error.message).toBe("Source control action 'commit_push' failed during push."); - expect(error.message).not.toContain(remoteMessage); + expect(JSON.stringify(error)).not.toContain("stack/parent"); + expect(vcsActionFailureDescription(error, "fallback")).toBe(remoteMessage); }), ); diff --git a/packages/client-runtime/src/state/vcsAction.ts b/packages/client-runtime/src/state/vcsAction.ts index 5382e61164472..1c25ca2849cba 100644 --- a/packages/client-runtime/src/state/vcsAction.ts +++ b/packages/client-runtime/src/state/vcsAction.ts @@ -13,6 +13,7 @@ import { import * as Cause from "effect/Cause"; import * as DateTime from "effect/DateTime"; import * as Effect from "effect/Effect"; +import * as Redacted from "effect/Redacted"; import * as Schema from "effect/Schema"; import * as Stream from "effect/Stream"; import { AsyncResult, Atom, type AtomRegistry } from "effect/reactivity"; @@ -106,7 +107,7 @@ export class VcsActionRemoteFailureError extends Schema.TaggedError()( "VcsActionMissingTerminalEventError", { @@ -299,7 +310,7 @@ export function consumeVcsActionProgress( environmentId: input.target.environmentId, cwd: input.target.cwd, phase: terminalEvent.phase, - remoteMessageLength: terminalEvent.message.length, + remoteMessage: Redacted.make(terminalEvent.message), }), ); } From 38cbdcb08bf14e39d7b2d833c6b90e7eab90f75a Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sun, 15 Nov 2026 04:53:20 +0000 Subject: [PATCH 3/3] Revert "fix(client): show the server's git action failure to the user" The server fails the gitRunStackedAction stream with the typed provider error after emitting action_failed, so the client already receives the rejected-base diagnostic as that error's message (verified live on the PR's original head). The generic VcsActionRemoteFailureError only covers a stream that ends without failing, which this server does not produce. Co-Authored-By: Claude Opus 5.5 --- .../src/features/threads/DraftThreadHeader.tsx | 6 +----- .../src/state/use-selected-thread-git-actions.ts | 3 +-- apps/web/src/components/GitActionsControl.tsx | 3 +-- .../client-runtime/src/state/vcsAction.test.ts | 11 +++++------ packages/client-runtime/src/state/vcsAction.ts | 15 ++------------- 5 files changed, 10 insertions(+), 28 deletions(-) diff --git a/apps/mobile/src/features/threads/DraftThreadHeader.tsx b/apps/mobile/src/features/threads/DraftThreadHeader.tsx index 921604e83eaa2..043273ee79bec 100644 --- a/apps/mobile/src/features/threads/DraftThreadHeader.tsx +++ b/apps/mobile/src/features/threads/DraftThreadHeader.tsx @@ -12,7 +12,6 @@ import { useEnvironmentQuery } from "../../state/query"; import { useEnvironmentScope } from "../../state/session"; import { useAtomCommand } from "../../state/use-atom-command"; import { vcsActionManager, vcsEnvironment } from "../../state/vcs"; -import { vcsActionFailureDescription } from "@t3tools/client-runtime/state/vcs"; import { useVcsActionState } from "../../state/use-vcs-action-state"; import { ThreadHeader } from "./ThreadHeader"; @@ -85,10 +84,7 @@ export function DraftThreadHeader(props: { actionId: uuidv4(), }); if (AsyncResult.isFailure(result)) { - Dialog.alert( - "Git action failed", - vcsActionFailureDescription(Cause.squash(result.cause), "Git action failed."), - ); + Dialog.alert("Git action failed", String(Cause.squash(result.cause))); return null; } return result.value; diff --git a/apps/mobile/src/state/use-selected-thread-git-actions.ts b/apps/mobile/src/state/use-selected-thread-git-actions.ts index 04115b145e6bb..7ecc10d0b6d85 100644 --- a/apps/mobile/src/state/use-selected-thread-git-actions.ts +++ b/apps/mobile/src/state/use-selected-thread-git-actions.ts @@ -24,7 +24,6 @@ import { AsyncResult } from "effect/reactivity"; import { useBranches } from "./queries"; import { threadEnvironment } from "./threads"; import { vcsActionManager, vcsEnvironment } from "./vcs"; -import { vcsActionFailureDescription } from "@t3tools/client-runtime/state/vcs"; import { uuidv4 } from "../lib/uuid"; import { appAtomRegistry } from "./atom-registry"; import { readEnvironmentScope, useEnvironmentScope } from "./session"; @@ -200,7 +199,7 @@ export function useSelectedThreadGitActions() { : await vcsActionManager.track(appAtomRegistry, target, { operation, label }, run); if (AsyncResult.isFailure(result)) { const error = Cause.squash(result.cause); - const message = vcsActionFailureDescription(error, "Git action failed."); + const message = error instanceof Error ? error.message : "Git action failed."; setPendingConnectionError(message); showGitActionResult({ type: "error", title: "Git action failed", description: message }); return null; diff --git a/apps/web/src/components/GitActionsControl.tsx b/apps/web/src/components/GitActionsControl.tsx index 5a44fffb450a5..77ab241966e3f 100644 --- a/apps/web/src/components/GitActionsControl.tsx +++ b/apps/web/src/components/GitActionsControl.tsx @@ -110,7 +110,6 @@ import { sourceControlEnvironment } from "~/state/sourceControl"; import { threadEnvironment } from "~/state/threads"; import { useAtomCommand } from "~/state/use-atom-command"; import { vcsActionManager, vcsEnvironment, vcsStatusRevalidation } from "~/state/vcs"; -import { vcsActionFailureDescription } from "@t3tools/client-runtime/state/vcs"; import { randomUUID } from "~/lib/utils"; import { resolvePathLinkTarget } from "@t3tools/shared/fileLinks"; import { type DraftId, useComposerDraftStore } from "~/composerDraftStore"; @@ -1274,7 +1273,7 @@ export default function GitActionsControl({ stackedThreadToast({ type: "error", title: "Action failed", - description: vcsActionFailureDescription(error, "An error occurred."), + description: error instanceof Error ? error.message : "An error occurred.", timeout: errorToastTiming.timeout, ...(scopedToastData !== undefined ? { data: scopedToastData } : {}), }), diff --git a/packages/client-runtime/src/state/vcsAction.test.ts b/packages/client-runtime/src/state/vcsAction.test.ts index 785a5fca5fbdd..67e9253cba4f3 100644 --- a/packages/client-runtime/src/state/vcsAction.test.ts +++ b/packages/client-runtime/src/state/vcsAction.test.ts @@ -42,7 +42,6 @@ import { parseVcsActionTargetKey, VcsActionMissingTerminalEventError, VcsActionRemoteFailureError, - vcsActionFailureDescription, VcsActionTargetKeyParseError, } from "./vcsAction.ts"; import { vcsRefsCacheStateAtom } from "./vcsRefInvalidation.ts"; @@ -300,12 +299,11 @@ describe("vcsActionState", () => { }), ); - it.effect("shows the remote failure to the user without putting it in logged fields", () => + it.effect("retains structural remote failure context without copying the remote payload", () => Effect.gen(function* () { const target = { environmentId, cwd }; const transportActionId = createVcsActionTransportId(target, actionId); - const remoteMessage = - 'GitHub rejected base branch "stack/parent" for github.com/acme/web. Push the intended base branch to that repository, or choose an existing base branch and retry.'; + const remoteMessage = "The remote rejected the push with credential=do-not-log."; const error = yield* consumeVcsActionProgress( Stream.fromIterable([ { @@ -334,10 +332,11 @@ describe("vcsActionState", () => { environmentId, cwd, phase: "push", + remoteMessageLength: remoteMessage.length, }); + expect(error).not.toHaveProperty("detail"); expect(error.message).toBe("Source control action 'commit_push' failed during push."); - expect(JSON.stringify(error)).not.toContain("stack/parent"); - expect(vcsActionFailureDescription(error, "fallback")).toBe(remoteMessage); + expect(error.message).not.toContain(remoteMessage); }), ); diff --git a/packages/client-runtime/src/state/vcsAction.ts b/packages/client-runtime/src/state/vcsAction.ts index 1c25ca2849cba..5382e61164472 100644 --- a/packages/client-runtime/src/state/vcsAction.ts +++ b/packages/client-runtime/src/state/vcsAction.ts @@ -13,7 +13,6 @@ import { import * as Cause from "effect/Cause"; import * as DateTime from "effect/DateTime"; import * as Effect from "effect/Effect"; -import * as Redacted from "effect/Redacted"; import * as Schema from "effect/Schema"; import * as Stream from "effect/Stream"; import { AsyncResult, Atom, type AtomRegistry } from "effect/reactivity"; @@ -107,7 +106,7 @@ export class VcsActionRemoteFailureError extends Schema.TaggedError()( "VcsActionMissingTerminalEventError", { @@ -310,7 +299,7 @@ export function consumeVcsActionProgress( environmentId: input.target.environmentId, cwd: input.target.cwd, phase: terminalEvent.phase, - remoteMessage: Redacted.make(terminalEvent.message), + remoteMessageLength: terminalEvent.message.length, }), ); }