GeezerVison is showing github.com — feat(labs): send failed commit/push/PR actions to the agent by wSedlacek · Pull Request #32024 · pingdotgg/t3code
feat(labs): send failed commit/push/PR actions to the agent
#32024
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and
privacy statement . We’ll occasionally send you account related emails.
Already on GitHub?
Sign in
to your account
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter
Filter by extension
.md
(1)
.ts
(5)
.tsx
(2)
All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Hide whitespace
Diff view
Hide whitespace
There are no files selected for viewing
Original file line number
Diff line number
Diff line change
Expand Up
@@ -57,6 +57,12 @@ export function SettingsLabsRouteScreen() {
setting="fastWorktreeCheckout"
description="On a Mac, clone new worktrees from a checkout cached in the T3 home folder instead of writing every file. Uses Git’s normal checkout when it can’t. Turning it off deletes the cache."
/>
<MachineBetaSection
title="Send git action failures to agent"
icon="arrow.branch"
setting="sendGitActionFailuresToAgent"
description="When Commit, Push, or Create PR fails from a thread, send the error to that thread's agent so it can fix and retry."
/>
</ScrollView>
</SettingsScreen>
);
Expand Down
Expand Up
@@ -238,7 +244,10 @@ export function NewThreadSettingsSection() {
);
}
type MachineBetaSetting = "linkedEnvironmentsEnabled" | "fastWorktreeCheckout";
type MachineBetaSetting =
| "linkedEnvironmentsEnabled"
| "fastWorktreeCheckout"
| "sendGitActionFailuresToAgent";
/** One switch per connected machine that offers the beta, since each machine's own setting decides. */
function MachineBetaSection({
Expand All
@@ -250,15 +259,17 @@ function MachineBetaSection({
}: {
readonly title: string;
readonly icon: ComponentProps<typeof SettingsSwitchRow>["icon"];
readonly capability: "peerLinks" | "fastWorktreeCheckout";
readonly capability? : "peerLinks" | "fastWorktreeCheckout";
readonly setting: MachineBetaSetting;
readonly description: string;
}) {
const { environments } = useEnvironments();
const supported = environments.filter(
(environment) =>
environment.connection.phase === "connected" &&
environment.serverConfig?.environment.capabilities[capability] === true,
environment.serverConfig !== null &&
(capability === undefined ||
environment.serverConfig.environment.capabilities[capability] === true),
);
const writable = useEnvironmentsWithScope(supported, AuthSettingsWriteScope);
const updateSettings = useAtomCommand(serverEnvironment.updateSettings, {
Expand Down
Expand Up
@@ -287,7 +298,9 @@ function MachineBetaSection({
patch:
setting === "linkedEnvironmentsEnabled"
? { linkedEnvironmentsEnabled: value }
: { fastWorktreeCheckout: value },
: setting === "fastWorktreeCheckout"
? { fastWorktreeCheckout: value }
: { sendGitActionFailuresToAgent: value },
},
})
}
Expand Down
Original file line number
Diff line number
Diff line change
@@ -0,0 +1,209 @@
import {
CommandId,
ProjectId,
ProviderInstanceId,
ThreadId,
type OrchestrationV2ServerCommand as OrchestrationCommand,
} from "@t3tools/contracts";
import { describe, expect, it } from "@effect/vitest";
import * as SecureRandom from "effect/crypto/SecureRandom";
import * as Effect from "effect/Effect";
import * as Layer from "effect/Layer";
import * as Ref from "effect/Ref";
import * as Orchestrator from "../orchestration-v2/Orchestrator.ts";
import {
type PullRequestTestThread,
v2PullRequestThread,
} from "../orchestration-v2/testkit/pullRequestFixtures.ts";
import * as ServerSettings from "../serverSettings.ts";
import {
gitActionFailureMessage,
sendGitActionFailureToAgent,
} from "./sendGitActionFailureToAgent.ts";
const testCrypto = SecureRandom.make((size) => new Uint8Array(size).fill(1));
const PROJECT_ID = ProjectId.make("project-1");
const THREAD_ID = ThreadId.make("thread-1");
const commandId = Effect.succeed(CommandId.make("server:git-action-failure:test"));
const thread: PullRequestTestThread = {
id: THREAD_ID,
projectId: PROJECT_ID,
title: "Thread",
modelSelection: { instanceId: ProviderInstanceId.make("codex"), model: "gpt-5" },
runtimeMode: "full-access",
interactionMode: "default",
branch: null,
worktreePath: null,
pullRequests: [],
createdAt: "2026-08-01T00:00:00.000Z",
updatedAt: "2026-08-20T00:00:00.000Z",
archivedAt: null,
settledOverride: null,
settledAt: null,
latestUserMessageAt: "2026-08-20T00:00:00.000Z",
};
const recordingDispatch = Effect.fn("recordingDispatch")(function* () {
const commands = yield* Ref.make<ReadonlyArray<OrchestrationCommand>>([]);
const dispatch: Orchestrator.OrchestratorV2Shape["dispatch"] = (command) =>
Ref.update(commands, (recorded) => [...recorded, command]).pipe(
Effect.as({ sequence: 1, storedEvents: [] }),
);
return { commands, dispatch };
});
const layerDependenciesFor = (
dispatch: Orchestrator.OrchestratorV2Shape["dispatch"],
options?: {
readonly threadShell?: PullRequestTestThread | null;
readonly sendGitActionFailuresToAgent?: boolean;
},
) => {
const threadShell = options?.threadShell === undefined ? thread : options.threadShell;
return Layer.mergeAll(
Layer.mock(Orchestrator.OrchestratorV2)({
getThreadShell: () =>
Effect.succeed(threadShell === null ? null : v2PullRequestThread(threadShell)),
dispatch,
}),
ServerSettings.ServerSettingsService.layerTest({
sendGitActionFailuresToAgent: options?.sendGitActionFailuresToAgent ?? true,
}),
Layer.succeed(SecureRandom.SecureRandom, testCrypto),
);
};
describe("gitActionFailureMessage", () => {
it("names the action, phase, and error detail", () => {
expect(
gitActionFailureMessage({
action: "commit_push_pr",
phase: "push",
detail: "Permission denied (publickey).",
}),
).toEqual({
text: [
"The Commit, push & PR action failed while pushing:",
"",
"Permission denied (publickey).",
"",
"Fix the issue and retry the action.",
].join("\n"),
notification: {
source: { kind: "system" },
outcome: "failed",
summary: "Commit, push & PR failed",
},
});
});
it("omits the phase clause when none was recorded", () => {
expect(
gitActionFailureMessage({
action: "commit",
phase: null,
detail: " nothing to commit ",
}).text,
).toBe(
[
"The Commit action failed:",
"",
"nothing to commit",
"",
"Fix the issue and retry the action.",
].join("\n"),
);
});
});
describe("sendGitActionFailureToAgent", () => {
it.effect("dispatches a queued wake when the Labs setting is on", () =>
Effect.gen(function* () {
const { commands, dispatch } = yield* recordingDispatch();
yield* sendGitActionFailureToAgent({
threadId: THREAD_ID,
action: "push",
phase: "push",
detail: "rejected (non-fast-forward)",
commandId,
}).pipe(Effect.provide(layerDependenciesFor(dispatch)));
const recorded = yield* Ref.get(commands);
expect(recorded).toHaveLength(1);
const command = recorded[0];
expect(command).toMatchObject({
type: "message.dispatch",
commandId: "server:git-action-failure:test",
threadId: THREAD_ID,
text: gitActionFailureMessage({
action: "push",
phase: "push",
detail: "rejected (non-fast-forward)",
}).text,
notification: {
source: { kind: "system" },
outcome: "failed",
summary: "Push failed",
},
attachments: [],
dispatchMode: { type: "queue_after_active" },
createdBy: "agent",
creationSource: "server",
});
expect(command?.type === "message.dispatch" && command.messageId).toMatch(
/^message:git-action-failure:/,
);
}),
);
it.effect("does nothing when the Labs setting is off", () =>
Effect.gen(function* () {
const { commands, dispatch } = yield* recordingDispatch();
yield* sendGitActionFailureToAgent({
threadId: THREAD_ID,
action: "commit",
phase: "commit",
detail: "hook failed",
commandId,
}).pipe(
Effect.provide(layerDependenciesFor(dispatch, { sendGitActionFailuresToAgent: false })),
);
expect(yield* Ref.get(commands)).toEqual([]);
}),
);
it.effect("does nothing when the thread is missing", () =>
Effect.gen(function* () {
const { commands, dispatch } = yield* recordingDispatch();
yield* sendGitActionFailureToAgent({
threadId: THREAD_ID,
action: "create_pr",
phase: "pr",
detail: "gh not authenticated",
commandId,
}).pipe(Effect.provide(layerDependenciesFor(dispatch, { threadShell: null })));
expect(yield* Ref.get(commands)).toEqual([]);
}),
);
it.effect(
"swallows a dispatch failure so the stacked-action error still reaches the client",
() =>
Effect.gen(function* () {
const dispatch: Orchestrator.OrchestratorV2Shape["dispatch"] = () =>
Effect.die("dispatch unavailable");
yield* sendGitActionFailureToAgent({
threadId: THREAD_ID,
action: "commit_push",
phase: null,
detail: "index.lock",
commandId,
}).pipe(Effect.provide(layerDependenciesFor(dispatch)));
}),
);
});
Original file line number
Diff line number
Diff line change
@@ -0,0 +1,117 @@
import {
type CommandId,
type GitActionProgressPhase,
type GitStackedAction,
MessageId,
type OrchestrationV2Notification,
type ThreadId,
} from "@t3tools/contracts";
import * as Cause from "effect/Cause";
import * as SecureRandom from "effect/crypto/SecureRandom";
import * as Effect from "effect/Effect";
import * as Option from "effect/Option";
import * as Orchestrator from "../orchestration-v2/Orchestrator.ts";
import * as ServerSettings from "../serverSettings.ts";
const ACTION_LABEL: Record<GitStackedAction, string> = {
commit: "Commit",
push: "Push",
create_pr: "Create pull request",
commit_push: "Commit & push",
commit_push_pr: "Commit, push & PR",
};
const PHASE_LABEL: Record<GitActionProgressPhase, string> = {
branch: "creating the branch",
commit: "committing",
push: "pushing",
pr: "creating the pull request",
};
export function gitActionFailureMessage(input: {
readonly action: GitStackedAction;
readonly phase: GitActionProgressPhase | null;
readonly detail: string;
}): { readonly text: string; readonly notification: OrchestrationV2Notification } {
const actionLabel = ACTION_LABEL[input.action];
const during = input.phase === null ? "" : ` while ${PHASE_LABEL[input.phase] ?? input.phase}`;
const detail = input.detail.trim() || "Source control action failed.";
return {
text: [
`The ${actionLabel} action failed${during}:`,
"",
detail,
"",
"Fix the issue and retry the action.",
].join("\n"),
notification: {
source: { kind: "system" },
outcome: "failed",
summary: `${actionLabel} failed`,
},
};
}
/**
* Never fails the caller: the stacked action already failed and the client is getting that error,
* so a wake that cannot be made is logged and dropped. Callers must require orchestration-operate;
* source-control write alone must not reach this path.
*/
export const sendGitActionFailureToAgent: <E>(input: {
readonly threadId: ThreadId;
readonly action: GitStackedAction;
readonly phase: GitActionProgressPhase | null;
readonly detail: string;
readonly commandId: Effect.Effect<CommandId, E>;
}) => Effect.Effect<
void,
never,
Orchestrator.OrchestratorV2 | ServerSettings.ServerSettingsService | SecureRandom.SecureRandom
> = Effect.fn("sendGitActionFailureToAgent")(
function* <E>(input: {
readonly threadId: ThreadId;
readonly action: GitStackedAction;
readonly phase: GitActionProgressPhase | null;
readonly detail: string;
readonly commandId: Effect.Effect<CommandId, E>;
}) {
const settings = yield* ServerSettings.ServerSettingsService;
if (!(yield* settings.getSettings).sendGitActionFailuresToAgent) return;
const engine = yield* Orchestrator.OrchestratorV2;
const thread = yield* engine
.getThreadShell(input.threadId)
.pipe(Effect.map(Option.fromNullishOr));
if (Option.isNone(thread)) return;
const random = yield* SecureRandom.SecureRandom;
const uuid = yield* random.uuidV4();
const commandId = yield* input.commandId;
const wake = gitActionFailureMessage(input);
yield* engine
.dispatch({
type: "message.dispatch",
commandId,
threadId: input.threadId,
messageId: MessageId.make(`message:git-action-failure:${uuid}`),
text: wake.text,
notification: wake.notification,
attachments: [],
dispatchMode: { type: "queue_after_active" },
createdBy: "agent",
creationSource: "server",
})
.pipe(Effect.asVoid);
},
(effect, input) =>
effect.pipe(
Effect.catchCause((cause) =>
Cause.hasInterruptsOnly(cause)
? Effect.failCause(cause as Cause.Cause<never>)
: Effect.logWarning("failed to send git action failure to agent", {
threadId: input.threadId,
}),
),
),
);
Loading
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Loading
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.