Skip to content

Commit cef6fd6

Browse files
committed
merge: sync main into provider retry wording fix
2 parents 7ed9bd1 + 3ddd398 commit cef6fd6

45 files changed

Lines changed: 1246 additions & 260 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/mobile/src/features/pull-requests/PullRequestMergeControls.tsx‎

Lines changed: 76 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@ import {
1616
allowedMergeMethods,
1717
canPerformPullRequestAction,
1818
mergeUnavailableReason,
19-
MERGE_CONFLICT_REASON,
2019
MERGE_METHODS,
20+
PR_ACTION_ICONS,
2121
pullRequestActionLabel,
2222
} from "./pullRequestActions";
2323
import { pullRequestStackMerge, singlePullRequestMergeAllowed } from "./pullRequestStack";
2424
import { pullRequestTarget, type PullRequestParams } from "./usePullRequestDiff";
25+
import { usePullRequestAction } from "./usePullRequestAction";
2526
import { usePullRequestPermissions } from "./usePullRequestPermissions";
2627
import { PullRequestGlyph } from "./pullRequestGlyphs";
28+
import type { AppSymbolName } from "../../components/ui/AppSymbol";
2729
import type { PullRequestStackState } from "./usePullRequestStack";
2830

2931
export function PullRequestMergeControls(props: {
@@ -35,6 +37,7 @@ export function PullRequestMergeControls(props: {
3537
const terminology = sourceControlClients.get(pr.provider).changeRequest;
3638
const target = pullRequestTarget(props.params);
3739
const permissions = usePullRequestPermissions(props.params, pr);
40+
const stateAction = usePullRequestAction(props.params, pr);
3841
const preferences = useAtomValue(mobilePreferencesAtom);
3942
const savePreferences = useAtomSet(updateMobilePreferencesAtom);
4043
const runAction = useAtomCommand(composerPullRequests.runAction, { reportFailure: false });
@@ -82,6 +85,39 @@ export function PullRequestMergeControls(props: {
8285
? `${MERGE_METHODS[method].title} stack (${scope.layers.length})`
8386
: MERGE_METHODS[method].title
8487
: "Merge unavailable";
88+
const nextAction =
89+
pr.state === "closed" ? "reopen" : pr.state === "open" && pr.isDraft ? "ready" : null;
90+
// States the button itself names, instead of a reason line under it. Draft and
91+
// closed offer their way forward when the viewer can take it.
92+
const status: {
93+
label: string;
94+
icon: AppSymbolName;
95+
final?: boolean;
96+
action?: "ready" | "reopen";
97+
} | null =
98+
nextAction && stateAction.available(nextAction)
99+
? {
100+
label: pullRequestActionLabel(nextAction, terminology),
101+
icon: PR_ACTION_ICONS[nextAction],
102+
final: nextAction === "reopen",
103+
action: nextAction,
104+
}
105+
: pr.state === "merged"
106+
? { label: "Merged", icon: PullRequestGlyph.merged, final: true }
107+
: pr.state === "closed"
108+
? { label: "Closed", icon: PullRequestGlyph.closed, final: true }
109+
: pr.isDraft
110+
? { label: "Draft", icon: PullRequestGlyph.draft }
111+
: pr.mergeability === "conflicting"
112+
? { label: "Resolve conflicts to merge", icon: PullRequestGlyph.conflicting }
113+
: pr.autoMergeEnabled
114+
? {
115+
label: `Auto-merge pending${pr.autoMergeMethod ? ` (${pr.autoMergeMethod})` : ""}`,
116+
icon: "clock",
117+
}
118+
: checkingStack && !busy
119+
? { label: "Checking stack…", icon: PullRequestGlyph.merged }
120+
: null;
85121
const autoAction = pr.autoMergeEnabled ? "disable-auto-merge" : "enable-auto-merge";
86122
const canAutoMerge =
87123
!busy &&
@@ -167,32 +203,48 @@ export function PullRequestMergeControls(props: {
167203
return (
168204
<View className="gap-2 border-t border-border-subtle p-3">
169205
<SplitButton
170-
label={busy ? "Working…" : !permissions.connected ? "Reconnect to merge" : label}
206+
label={
207+
busy || stateAction.busy
208+
? "Working…"
209+
: !permissions.connected
210+
? "Reconnect to merge"
211+
: (status?.label ?? label)
212+
}
171213
accessibilityLabel={
172-
scope ? `${label}, ${scope.layers.length} stack layers through #${pr.number}` : label
214+
status
215+
? status.label
216+
: scope
217+
? `${label}, ${scope.layers.length} stack layers through #${pr.number}`
218+
: label
219+
}
220+
icon={status?.icon ?? PullRequestGlyph.merged}
221+
disabled={status?.action ? stateAction.busy : !canMerge || status !== null}
222+
loading={busy || stateAction.busy || (!status?.action && checkingStack)}
223+
onPress={() =>
224+
status?.action ? void stateAction.perform(status.action) : confirm("merge")
173225
}
174-
icon={PullRequestGlyph.merged}
175-
disabled={!canMerge}
176-
loading={busy || checkingStack}
177-
onPress={() => confirm("merge")}
178226
menuTitle="Merge options"
179-
actions={[
180-
...methods.map((id) => ({
181-
id,
182-
title: MERGE_METHODS[id].title,
183-
state: id === method ? ("on" as const) : ("off" as const),
184-
attributes: { disabled: !canMerge && !canAutoMerge },
185-
})),
186-
...(canAutoMerge
187-
? [
188-
{
189-
id: autoAction,
190-
title: pr.autoMergeEnabled ? "Disable auto-merge" : "Enable auto-merge",
191-
image: "clock",
192-
},
227+
actions={
228+
status?.final
229+
? []
230+
: [
231+
...methods.map((id) => ({
232+
id,
233+
title: MERGE_METHODS[id].title,
234+
state: id === method ? ("on" as const) : ("off" as const),
235+
attributes: { disabled: !canMerge && !canAutoMerge },
236+
})),
237+
...(canAutoMerge
238+
? [
239+
{
240+
id: autoAction,
241+
title: pr.autoMergeEnabled ? "Disable auto-merge" : "Enable auto-merge",
242+
image: "clock",
243+
},
244+
]
245+
: []),
193246
]
194-
: []),
195-
]}
247+
}
196248
onPressAction={(id) => {
197249
const selected = methods.find((method) => method === id);
198250
if (selected) {
@@ -201,18 +253,9 @@ export function PullRequestMergeControls(props: {
201253
} else if (id === autoAction && canAutoMerge) confirm(autoAction);
202254
}}
203255
/>
204-
{permissions.connected &&
205-
reason &&
206-
reason !== MERGE_CONFLICT_REASON &&
207-
reason !== "Checking stack membership…" &&
208-
!(checkingStack && reason === "Refresh the stack before merging.") ? (
256+
{permissions.connected && !status && reason ? (
209257
<Text className="px-1 text-xs text-foreground-muted">{reason}</Text>
210258
) : null}
211-
{pr.autoMergeEnabled ? (
212-
<Text className="px-1 text-xs text-foreground-muted">
213-
Auto-merge is enabled{pr.autoMergeMethod ? ` · ${pr.autoMergeMethod}` : ""}
214-
</Text>
215-
) : null}
216259
{stack.error && stack.supportsStackActions ? (
217260
<Button label="Retry stack lookup" tone="text" onPress={stack.refresh} />
218261
) : null}

‎apps/mobile/src/features/pull-requests/pullRequestActions.ts‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,6 @@ export function canPerformPullRequestAction(pr: ActionDetail, action: PullReques
117117
}
118118
}
119119

120-
export const MERGE_CONFLICT_REASON = "Resolve the branch conflicts before merging.";
121-
122120
export function mergeUnavailableReason(
123121
pr: ActionDetail,
124122
connectionAllowsWrites: boolean,
@@ -132,7 +130,7 @@ export function mergeUnavailableReason(
132130
if (!pr.viewerPermissions.actions.includes("merge"))
133131
return `Your account cannot merge this ${terminology.singular}.`;
134132
if (pr.isDraft) return "Mark this draft ready for review before merging.";
135-
if (pr.mergeability === "conflicting") return MERGE_CONFLICT_REASON;
133+
if (pr.mergeability === "conflicting") return "Resolve the branch conflicts before merging.";
136134
if (!allowedMergeMethods(pr).length) return "This repository has no available merge methods.";
137135
return null;
138136
}

‎apps/server/src/environment/DirectEndpoints.test.ts‎

Lines changed: 75 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import * as NodeServices from "@effect/platform-node/NodeServices";
22
import { it as effectIt } from "@effect/vitest";
33
import type * as NodeOS from "node:os";
44
import * as Effect from "effect/Effect";
5+
import * as Deferred from "effect/Deferred";
6+
import * as Fiber from "effect/Fiber";
7+
import * as Ref from "effect/Ref";
58
import * as Layer from "effect/Layer";
69
import * as Sink from "effect/Sink";
710
import * as Stream from "effect/Stream";
@@ -255,25 +258,27 @@ const layerServeProbe = (status: number) =>
255258
),
256259
);
257260

258-
const layerServeConfig = Layer.effect(
259-
ServerConfig.ServerConfig,
260-
Effect.map(ServerConfig.ServerConfig, (config) => ({
261-
...config,
262-
host: "127.0.0.1",
263-
tailscaleServeEnabled: true,
264-
tailscaleServePort: 443,
265-
})),
266-
).pipe(
267-
Layer.provide(ServerConfig.layerTest(process.cwd(), { prefix: "t3-direct-" })),
268-
Layer.provide(NodeServices.layer),
269-
);
261+
const layerServeConfig = (host = "127.0.0.1") =>
262+
Layer.effect(
263+
ServerConfig.ServerConfig,
264+
Effect.map(ServerConfig.ServerConfig, (config) => ({
265+
...config,
266+
host,
267+
port: 3773,
268+
tailscaleServeEnabled: true,
269+
tailscaleServePort: 443,
270+
})),
271+
).pipe(
272+
Layer.provide(ServerConfig.layerTest(process.cwd(), { prefix: "t3-direct-" })),
273+
Layer.provide(NodeServices.layer),
274+
);
270275

271276
const resolveWithServe = (probeStatus: number) =>
272277
Effect.flatMap(DirectEndpoints.DirectEndpoints, (service) => service.resolve()).pipe(
273278
Effect.provide(
274279
DirectEndpoints.layer.pipe(
275280
Layer.provide(
276-
Layer.mergeAll(layerServeConfig, layerTailscaleUp, layerServeProbe(probeStatus)),
281+
Layer.mergeAll(layerServeConfig(), layerTailscaleUp, layerServeProbe(probeStatus)),
277282
),
278283
),
279284
),
@@ -288,6 +293,63 @@ describe("DirectEndpoints Tailscale Serve", () => {
288293
}),
289294
);
290295

296+
effectIt.effect(
297+
"returns bound endpoints during validation and reuses only a completed Serve result",
298+
() =>
299+
Effect.gen(function* () {
300+
const status = yield* Ref.make(200);
301+
const finishProbe = yield* Deferred.make<void>();
302+
const probeStarted = yield* Deferred.make<void>();
303+
const revalidationStarted = yield* Deferred.make<void>();
304+
const finishRevalidation = yield* Deferred.make<void>();
305+
const service = yield* DirectEndpoints.make.pipe(
306+
Effect.provide(
307+
Layer.mergeAll(
308+
layerServeConfig("192.168.1.10"),
309+
layerTailscaleUp,
310+
Layer.succeed(
311+
HttpClient.HttpClient,
312+
HttpClient.make((request) =>
313+
Deferred.succeed(probeStarted, undefined).pipe(
314+
Effect.andThen(Deferred.await(finishProbe)),
315+
Effect.andThen(Ref.get(status)),
316+
Effect.tap((status) =>
317+
status === 502
318+
? Deferred.succeed(revalidationStarted, undefined).pipe(
319+
Effect.andThen(Deferred.await(finishRevalidation)),
320+
)
321+
: Effect.void,
322+
),
323+
Effect.map((status) =>
324+
HttpClientResponse.fromWeb(request, new Response(null, { status })),
325+
),
326+
),
327+
),
328+
),
329+
),
330+
),
331+
);
332+
const resolving = yield* Effect.forkScoped(service.resolve());
333+
yield* Deferred.await(probeStarted);
334+
const bound = { kind: "lan", httpBaseUrl: "http://192.168.1.10:3773/" };
335+
expect(yield* service.resolveAvailable()).toEqual([bound]);
336+
yield* Deferred.succeed(finishProbe, undefined);
337+
const validated = yield* Fiber.join(resolving);
338+
expect(validated).toEqual([
339+
bound,
340+
{ kind: "tailnet", httpBaseUrl: "https://bb-1.tail1234.ts.net/" },
341+
]);
342+
expect(yield* service.resolveAvailable()).toEqual(validated);
343+
yield* Ref.set(status, 502);
344+
const revalidating = yield* Effect.forkScoped(service.resolve());
345+
yield* Deferred.await(revalidationStarted);
346+
expect(yield* service.resolveAvailable()).toEqual(validated);
347+
yield* Deferred.succeed(finishRevalidation, undefined);
348+
expect(yield* Fiber.join(revalidating)).toEqual([bound]);
349+
expect(yield* service.resolveAvailable()).toEqual([bound]);
350+
}).pipe(Effect.scoped),
351+
);
352+
291353
effectIt.effect("leaves the tailnet name out when Serve is not forwarding", () =>
292354
Effect.gen(function* () {
293355
expect(yield* resolveWithServe(502)).toEqual([]);

‎apps/server/src/environment/DirectEndpoints.ts‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import * as Duration from "effect/Duration";
99
import * as Effect from "effect/Effect";
1010
import * as Layer from "effect/Layer";
1111
import * as Option from "effect/Option";
12+
import * as Ref from "effect/Ref";
1213
import { HttpClient } from "effect/http";
1314
import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
1415
import * as NodeNet from "node:net";
@@ -34,6 +35,7 @@ const TAILSCALE_ENDPOINT_TIMEOUT = Duration.seconds(3);
3435
export class DirectEndpoints extends Context.Service<
3536
DirectEndpoints,
3637
{
38+
readonly resolveAvailable: () => Effect.Effect<ReadonlyArray<ServerDirectEndpoint>>;
3739
readonly resolve: () => Effect.Effect<ReadonlyArray<ServerDirectEndpoint>>;
3840
}
3941
>()("t3/environment/DirectEndpoints") {}
@@ -128,7 +130,8 @@ export const make = Effect.gen(function* () {
128130
: Effect.succeed(false);
129131
yield* Effect.forkDetach(onCloudVm);
130132

131-
const resolve = Effect.gen(function* () {
133+
const servedEndpoint = yield* Ref.make<Option.Option<string>>(Option.none());
134+
const resolveAvailable = Effect.fn("DirectEndpoints.resolveAvailable")(function* () {
132135
const endpoints = [
133136
...resolveBoundEndpoints({
134137
platform,
@@ -138,6 +141,12 @@ export const make = Effect.gen(function* () {
138141
onCloudVm: yield* onCloudVm,
139142
}),
140143
];
144+
const servedUrl = yield* Ref.get(servedEndpoint);
145+
if (Option.isSome(servedUrl)) endpoints.push({ kind: "tailnet", httpBaseUrl: servedUrl.value });
146+
return endpoints;
147+
});
148+
149+
const resolve = Effect.gen(function* () {
141150
// Serve setup can fail without stopping startup; advertise only after it answers as this server.
142151
if (config.tailscaleServeEnabled) {
143152
const servedUrl = yield* readTailscaleStatus.pipe(
@@ -158,14 +167,13 @@ export const make = Effect.gen(function* () {
158167
Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
159168
Effect.provideService(HttpClient.HttpClient, httpClient),
160169
);
161-
if (Option.isSome(servedUrl)) {
162-
endpoints.push({ kind: "tailnet", httpBaseUrl: servedUrl.value });
163-
}
170+
yield* Ref.set(servedEndpoint, servedUrl);
164171
}
165-
return endpoints;
172+
return yield* resolveAvailable();
166173
});
167174

168175
return DirectEndpoints.of({
176+
resolveAvailable,
169177
resolve: Effect.fn("DirectEndpoints.resolve")(function () {
170178
return resolve;
171179
}),

‎apps/server/src/provider/CodexDeveloperInstructions.test.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ describe("Codex orchestration context", () => {
6565

6666
NodeAssert.ok(orchestration.includes("use your native tool when the child uses your provider"));
6767
NodeAssert.ok(orchestration.includes("`run_in_background:false`"));
68-
NodeAssert.ok(orchestration.includes("A native type running another provider's model"));
68+
NodeAssert.ok(orchestration.includes("A native type on another provider's model"));
69+
NodeAssert.ok(
70+
orchestration.includes("Background agent: `delegate_task`, never a background `Agent`."),
71+
);
6972
NodeAssert.ok(
7073
orchestration.includes("Every new delegate review or re-check is a new `delegate_task`"),
7174
);

0 commit comments

Comments
 (0)