Skip to content

Commit 86680b5

Browse files
Merge branch 'main' into fix/git-status-real-paths
2 parents 3450b0b + cfafb4b commit 86680b5

10 files changed

Lines changed: 152 additions & 32 deletions

File tree

‎apps/mobile/src/features/threads/git/GitOverviewSheet.tsx‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,11 @@ function GitOverviewSheetContent(props: GitOverviewSheetProps) {
375375
</View>
376376
) : null}
377377
{chain.layers.map((link, index) => (
378-
<View key={threadPullRequestKeyOf(link)}>
378+
<View
379+
key={threadPullRequestKeyOf(link)}
380+
// Steps in per layer like the web list, capped so deep stacks keep their width.
381+
style={{ paddingLeft: Math.min(chain.depths[index]!, 3) * 16 }}
382+
>
379383
{index > 0 && Platform.OS !== "android" ? (
380384
<View className="ml-12 h-px bg-border" />
381385
) : null}

‎apps/server/src/mcp/toolkits/pullRequests/handlers.test.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,22 @@ describe("listThreadPullRequests", () => {
574574
]);
575575
expect(result.chains).toEqual([{ kind: "native", numbers: [1, 2] }]);
576576
});
577+
578+
it("gives pull requests built on the same one the same position", () => {
579+
const result = listThreadPullRequests({
580+
pullRequests: [
581+
makeLink(1, { headBranch: "feat-a", baseBranch: "main" }),
582+
makeLink(2, { headBranch: "feat-b", baseBranch: "feat-a" }),
583+
makeLink(3, { headBranch: "feat-c", baseBranch: "feat-a" }),
584+
],
585+
});
586+
expect(result.pullRequests.map((entry) => [entry.number, entry.stack])).toEqual([
587+
[1, { kind: "derived", position: 1, size: 3 }],
588+
[2, { kind: "derived", position: 2, size: 3 }],
589+
[3, { kind: "derived", position: 2, size: 3 }],
590+
]);
591+
expect(result.chains).toEqual([{ kind: "derived", numbers: [1, 2, 3] }]);
592+
});
577593
});
578594

579595
describe("pull request guide tools", () => {

‎apps/server/src/mcp/toolkits/pullRequests/handlers.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ function entryOf(
114114
if (chain.layers.length < 2) continue;
115115
const index = chain.layers.findIndex((layer) => threadPullRequestKeyOf(layer) === key);
116116
if (index !== -1) {
117-
stack = { kind: chain.kind, position: index + 1, size: chain.layers.length };
117+
stack = { kind: chain.kind, position: chain.depths[index]! + 1, size: chain.layers.length };
118118
break;
119119
}
120120
}

‎apps/server/src/mcp/toolkits/pullRequests/tools.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ export const ThreadPullRequestEntry = Schema.Struct({
250250
stack: Schema.NullOr(
251251
Schema.Struct({
252252
kind: Schema.Literals(["native", "derived"]),
253-
/** 1-based, bottom of the stack first. */
253+
/** 1-based layer, bottom of the stack first. Pull requests built on the same one share it. */
254254
position: Schema.Int,
255255
size: Schema.Int,
256256
}),
@@ -263,7 +263,7 @@ export const ListThreadPullRequestsResult = Schema.Struct({
263263
chains: Schema.Array(
264264
Schema.Struct({
265265
kind: Schema.Literals(["native", "derived"]),
266-
/** Bottom to top. */
266+
/** Bottom to top; each pull request comes before the ones built on it. */
267267
numbers: Schema.Array(Schema.Int),
268268
}),
269269
),

‎apps/server/src/provider/CodexProvider.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ import {
3636
import { resolveSpawnCommand } from "@t3tools/shared/shell";
3737
import { codexAppServerArgs, resolveCodexLaunchArgs } from "./codexLaunchArgs.ts";
3838
import {
39-
AUTH_PROBE_TIMEOUT_MS,
4039
buildServerProvider,
4140
COMPACT_SLASH_COMMAND,
4241
providerModelsFromSettings,
@@ -71,6 +70,11 @@ const CODEX_APP_SERVER_PROBE_FORCE_KILL_AFTER = "2 seconds" as const;
7170
const CODEX_CATALOG_REFRESH_TIMEOUT = "3 seconds" as const;
7271
const CODEX_CATALOG_REFRESH_POLL = "100 millis" as const;
7372
const CODEX_CLIENT_NAME = "T3 Code";
73+
// Codex's probe does a full handshake plus account, models, and skills requests, which can
74+
// legitimately run past the shared 10s AUTH_PROBE_TIMEOUT_MS on a loaded or slow machine
75+
// (most often reported on Windows). Give Codex its own longer budget instead of raising the
76+
// timeout for every provider.
77+
const CODEX_AUTH_PROBE_TIMEOUT_MS = 20_000;
7478

7579
const CODEX_PRESENTATION = {
7680
displayName: "Codex",
@@ -660,7 +664,7 @@ export const checkCodexProviderStatus = Effect.fn("checkCodexProviderStatus")(fu
660664
...(managedAuth ? { skipNativeUsage: true } : {}),
661665
}).pipe(
662666
Effect.scoped,
663-
Effect.timeoutOption(Duration.millis(AUTH_PROBE_TIMEOUT_MS)),
667+
Effect.timeoutOption(Duration.millis(CODEX_AUTH_PROBE_TIMEOUT_MS)),
664668
Effect.result,
665669
);
666670

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,22 @@ it.layer(
588588
}),
589589
);
590590

591+
it.effect(
592+
"does not time out a healthy probe slower than the shared 10s auth-probe timeout (#7513)",
593+
() =>
594+
Effect.gen(function* () {
595+
const statusFiber = yield* checkCodexProviderStatus(defaultCodexSettings, () =>
596+
Effect.sleep("15 seconds").pipe(Effect.as(makeCodexProbeSnapshot())),
597+
).pipe(Effect.forkChild);
598+
599+
yield* Effect.yieldNow;
600+
yield* TestClock.adjust("15 seconds");
601+
602+
const status = yield* Fiber.join(statusFiber);
603+
assert.strictEqual(status.status, "ready");
604+
}),
605+
);
606+
591607
it.effect("closes the app-server probe scope when provider status times out", () =>
592608
Effect.gen(function* () {
593609
const killCalls = yield* Ref.make(0);
@@ -597,7 +613,7 @@ it.layer(
597613
);
598614

599615
yield* Effect.yieldNow;
600-
yield* TestClock.adjust("11 seconds");
616+
yield* TestClock.adjust("21 seconds");
601617
yield* Effect.yieldNow;
602618

603619
const status = yield* Fiber.join(statusFiber);

‎apps/web/src/components/chat/ComposerBannerStack.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ function ComposerBannerStackAlert({
345345
variant={item.variant}
346346
density="comfortable"
347347
>
348-
<ComposerBanner.Row layout="wrap-actions">
348+
<ComposerBanner.Row layout={item.priority === "activity" ? "inline" : "wrap-actions"}>
349349
<ComposerBanner.Icon className="h-(--composer-banner-icon-column) self-start">
350350
{item.icon}
351351
</ComposerBanner.Icon>

‎apps/web/src/components/pullRequest/pullRequestListLines.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ export function pullRequestListLines(
2727
);
2828
return ordered.flatMap((chain) => {
2929
const chainKey = chainKeyOf(chain);
30-
return chain.layers.map((link, depth) => ({
30+
return chain.layers.map((link, index) => ({
3131
link,
32-
depth,
32+
depth: chain.depths[index]!,
3333
chainKey,
3434
stack:
35-
depth === 0 && chain.layers.length > 1
35+
index === 0 && chain.layers.length > 1
3636
? { kind: chain.kind, size: chain.layers.length }
3737
: null,
3838
}));

‎packages/shared/src/threadPullRequests.test.ts‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,51 @@ describe("resolveThreadPullRequestChains", () => {
270270
]);
271271
});
272272

273+
it("keeps every link built on the same parent under it", () => {
274+
const links = [
275+
link(3, { snapshot: snapshot({ headBranch: "c", baseBranch: "a" }) }),
276+
link(5, { snapshot: snapshot({ headBranch: "p", baseBranch: "main" }) }),
277+
link(6, { snapshot: snapshot({ headBranch: "q", baseBranch: "p" }) }),
278+
link(1, { snapshot: snapshot({ headBranch: "a", baseBranch: "p" }) }),
279+
link(2, { snapshot: snapshot({ headBranch: "b", baseBranch: "a" }) }),
280+
link(9, { snapshot: snapshot({ headBranch: "solo", baseBranch: "main" }) }),
281+
];
282+
const chains = resolveThreadPullRequestChains(links);
283+
expect(
284+
chains.map((chain) => [chain.layers.map((layer) => layer.number), chain.depths]),
285+
).toEqual([
286+
// #6 and #1 both build on #5; #3 and #2 both build on #1.
287+
[
288+
[5, 6, 1, 3, 2],
289+
[0, 1, 1, 2, 2],
290+
],
291+
[[9], [0]],
292+
]);
293+
expect(resolveThreadPullRequestBadge(links.slice(0, 5))).toEqual({
294+
kind: "stack",
295+
layers: 5,
296+
state: "open",
297+
});
298+
});
299+
300+
it("points at the highest layer of a branched stack, not the last sibling listed", () => {
301+
// #1 → #2 → #3, and #4 also builds on #1.
302+
const branched = (state: ThreadPullRequestSnapshot["state"]) => [
303+
link(1, { snapshot: snapshot({ state, headBranch: "a" }) }),
304+
link(2, { snapshot: snapshot({ state, headBranch: "b", baseBranch: "a" }) }),
305+
link(3, { snapshot: snapshot({ state, headBranch: "c", baseBranch: "b" }) }),
306+
link(4, { snapshot: snapshot({ state, headBranch: "d", baseBranch: "a" }) }),
307+
];
308+
const open = resolveThreadCurrentPullRequest(branched("open"));
309+
expect(open?.kind === "stack" ? open.open.map((entry) => entry.number) : null).toEqual([
310+
3, 4, 2, 1,
311+
]);
312+
expect(resolveThreadCurrentPullRequest(branched("merged"))).toMatchObject({
313+
kind: "single",
314+
link: { number: 3 },
315+
});
316+
});
317+
273318
it("uses the native stack order when the host provides one", () => {
274319
const stack = {
275320
kind: "native" as const,
@@ -432,6 +477,17 @@ describe("chain selection and badge state", () => {
432477
});
433478
});
434479

480+
it("lists a pull request once when two links share its identity", () => {
481+
const links = [
482+
link(1, { snapshot: snapshot({ headBranch: "a" }) }),
483+
link(1, { snapshot: snapshot({ headBranch: "b", baseBranch: "a" }) }),
484+
link(1, { snapshot: snapshot({ headBranch: "c" }) }),
485+
];
486+
expect(resolveThreadPullRequestChains(links).map((chain) => chain.layers)).toEqual([
487+
[links[0]],
488+
]);
489+
});
490+
435491
it("does not guess a parent when a head branch was reused", () => {
436492
const links = [
437493
link(1, { snapshot: snapshot({ state: "merged", headBranch: "reused" }) }),

‎packages/shared/src/threadPullRequests.ts‎

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,15 @@ export type ThreadCurrentPullRequest =
100100
readonly top: ThreadPullRequestLink;
101101
};
102102

103+
function layersFromTop(chain: ThreadPullRequestChain): Array<ThreadPullRequestLink> {
104+
// `.sort()` on a fresh array, not `.toSorted()`: this runs on Hermes, which has no ES2023
105+
// array methods, and a TypeError here is fatal on every mobile launch that renders a stack.
106+
return chain.layers
107+
.map((link, index) => ({ link, index, depth: chain.depths[index]! }))
108+
.sort((left, right) => right.depth - left.depth || right.index - left.index)
109+
.map((entry) => entry.link);
110+
}
111+
103112
export function resolveThreadCurrentPullRequest(
104113
links: ReadonlyArray<ThreadPullRequestLink>,
105114
): ThreadCurrentPullRequest | null {
@@ -109,10 +118,8 @@ export function resolveThreadCurrentPullRequest(
109118
if (open.length === 1) return { kind: "single", link: open[0]! };
110119
const chains = resolveThreadPullRequestChains(visible);
111120
if (open.length > 1) {
112-
// `.reverse()` on a copy, not `.toReversed()`: this runs on Hermes, which has no ES2023
113-
// array methods, and a TypeError here is fatal on every mobile launch that renders a stack.
114121
const openChains = chains
115-
.map((chain) => [...chain.layers].reverse().filter(isOpen))
122+
.map((chain) => layersFromTop(chain).filter(isOpen))
116123
.filter((layers) => layers.length > 0)
117124
.sort(
118125
(left, right) =>
@@ -123,7 +130,7 @@ export function resolveThreadCurrentPullRequest(
123130
return { kind: "stack", open: ordered, top: ordered[0]! };
124131
}
125132
if (chains.length === 1) {
126-
return { kind: "single", link: chains[0]!.layers.at(-1)! };
133+
return { kind: "single", link: layersFromTop(chains[0]!)[0]! };
127134
}
128135
const terminal = [...visible].sort(
129136
(left, right) => latestUpdatedAt(right) - latestUpdatedAt(left),
@@ -189,6 +196,8 @@ export function legacyLinkedPullRequestOf(
189196
export interface ThreadPullRequestChain {
190197
readonly kind: "native" | "derived";
191198
readonly layers: ReadonlyArray<ThreadPullRequestLink>;
199+
/** One per layer: 0 for the base, parent's depth + 1 above it. Siblings share a depth. */
200+
readonly depths: ReadonlyArray<number>;
192201
}
193202

194203
export function resolveThreadPullRequestChains(
@@ -211,7 +220,7 @@ export function resolveThreadPullRequestChains(
211220
const order = new Map(members[0]!.stack!.layers.map((layer, index) => [layer.number, index]));
212221
members.sort((left, right) => (order.get(left.number) ?? 0) - (order.get(right.number) ?? 0));
213222
for (const member of members) placed.add(threadPullRequestKeyOf(member));
214-
chains.push({ kind: "native", layers: members });
223+
chains.push({ kind: "native", layers: members, depths: members.map((_, index) => index) });
215224
}
216225

217226
const remaining = visible.filter((link) => !placed.has(threadPullRequestKeyOf(link)));
@@ -225,29 +234,44 @@ export function resolveThreadPullRequestChains(
225234
const key = branchKey(link, link.snapshot.headBranch);
226235
byHead.set(key, byHead.has(key) ? null : link);
227236
}
228-
const hasChild = new Set<string>();
229-
for (const link of remaining) {
230-
if (link.snapshot === null) continue;
237+
const parentOf = (link: ThreadPullRequestLink) => {
238+
if (link.snapshot === null) return undefined;
231239
const parent = byHead.get(branchKey(link, link.snapshot.baseBranch));
232-
if (parent != null && parent !== link) hasChild.add(threadPullRequestKeyOf(parent));
240+
return parent == null || parent === link ? undefined : parent;
241+
};
242+
const children = new Map<string, Array<ThreadPullRequestLink>>();
243+
for (const link of remaining) {
244+
const parent = parentOf(link);
245+
if (parent === undefined) continue;
246+
const key = threadPullRequestKeyOf(parent);
247+
const siblings = children.get(key) ?? [];
248+
siblings.push(link);
249+
children.set(key, siblings);
233250
}
234-
for (const top of remaining) {
235-
if (hasChild.has(threadPullRequestKeyOf(top))) continue;
251+
for (const base of remaining) {
252+
if (parentOf(base) !== undefined) continue;
236253
const layers: Array<ThreadPullRequestLink> = [];
237-
let cursor: ThreadPullRequestLink | undefined = top;
238-
while (cursor !== undefined && !placed.has(threadPullRequestKeyOf(cursor))) {
239-
placed.add(threadPullRequestKeyOf(cursor));
240-
layers.unshift(cursor);
241-
cursor =
242-
cursor.snapshot === null
243-
? undefined
244-
: (byHead.get(branchKey(cursor, cursor.snapshot.baseBranch)) ?? undefined);
254+
const depths: Array<number> = [];
255+
const pending: Array<{ readonly link: ThreadPullRequestLink; readonly depth: number }> = [
256+
{ link: base, depth: 0 },
257+
];
258+
for (let next = pending.pop(); next !== undefined; next = pending.pop()) {
259+
const key = threadPullRequestKeyOf(next.link);
260+
// Two links with one identity would otherwise share a child list and expand forever.
261+
if (placed.has(key)) continue;
262+
placed.add(key);
263+
layers.push(next.link);
264+
depths.push(next.depth);
265+
const below = children.get(key) ?? [];
266+
for (let index = below.length - 1; index >= 0; index -= 1) {
267+
pending.push({ link: below[index]!, depth: next.depth + 1 });
268+
}
245269
}
246-
if (layers.length > 0) chains.push({ kind: "derived", layers });
270+
if (layers.length > 0) chains.push({ kind: "derived", layers, depths });
247271
}
248272
for (const link of remaining) {
249273
if (!placed.has(threadPullRequestKeyOf(link))) {
250-
chains.push({ kind: "derived", layers: [link] });
274+
chains.push({ kind: "derived", layers: [link], depths: [0] });
251275
}
252276
}
253277
return chains;

0 commit comments

Comments
 (0)