Skip to content

Commit 6421c4d

Browse files
donjor-agent[bot]rsi-pr-agent
authored andcommitted
fix(web): align group title generation budgets (#1769)
Bound complete server group-title generation to 180 seconds, including OpenCode 1.x. Give the client five extra seconds for the server response; preserve upstream-owned adapter timeouts. Squashes: - be3b72e fix(web): align group title generation budgets (#1769) (#1769) - 6192a40 fixup! fix(web): align group title generation budgets (#1769) (#1769) - bb57c48 fix(web): align group title generation budgets (#1769) (#1769) - e6b801a fixup! fix(web): align group title generation budgets (#1769) (#1769) Fork-Domain: thread-ordering Fork-Tier: bugfix Fork-Upstreamable: no
1 parent 22e1a1e commit 6421c4d

8 files changed

Lines changed: 159 additions & 17 deletions

File tree

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { expect, it } from "@effect/vitest";
2+
import { ProviderInstanceId, TEXT_GENERATION_TIMEOUT_MS_FORK } from "@t3tools/contracts";
3+
import * as Effect from "effect/Effect";
4+
import * as Fiber from "effect/Fiber";
5+
import * as TestClock from "effect/testing/TestClock";
6+
7+
import { TextGeneration } from "../textGeneration/TextGeneration.ts";
8+
import { generateThreadGroupTitle } from "./ThreadGroupTitles.ts";
9+
10+
const unused = () => Effect.die("Unexpected text generation operation");
11+
12+
it.effect("bounds an unbounded group title and names its budget in the failure", () =>
13+
Effect.gen(function* () {
14+
let interrupted = false;
15+
const provider = TextGeneration.of({
16+
generateCommitMessage: unused,
17+
generatePrContent: unused,
18+
generateBranchName: unused,
19+
generateReviewGuide: unused,
20+
generateThreadTitle: () =>
21+
Effect.never.pipe(
22+
Effect.onInterrupt(() =>
23+
Effect.sync(() => {
24+
interrupted = true;
25+
}),
26+
),
27+
),
28+
});
29+
const pending = yield* generateThreadGroupTitle(provider, {
30+
cwd: "/repo",
31+
memberTitles: ["Manual ordering", "Visual groups"],
32+
modelSelection: {
33+
instanceId: ProviderInstanceId.make("opencode"),
34+
model: "zai/glm-5.3-flash",
35+
},
36+
}).pipe(Effect.flip, Effect.forkChild);
37+
yield* TestClock.adjust(TEXT_GENERATION_TIMEOUT_MS_FORK - 1);
38+
expect(interrupted).toBe(false);
39+
yield* TestClock.adjust(1);
40+
expect(yield* Fiber.join(pending)).toMatchObject({
41+
_tag: "TextGenerationError",
42+
detail: "The text generation model did not answer within 180 seconds.",
43+
});
44+
expect(interrupted).toBe(true);
45+
}),
46+
);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { TEXT_GENERATION_TIMEOUT_MS_FORK, TextGenerationError } from "@t3tools/contracts";
2+
import * as Effect from "effect/Effect";
3+
4+
/** Covers the whole group request, including OpenCode 1.x's unbounded runner. */
5+
export const withThreadGroupTitleBudgetFork = <A, E, R>(request: Effect.Effect<A, E, R>) =>
6+
request.pipe(
7+
Effect.timeoutOrElse({
8+
duration: TEXT_GENERATION_TIMEOUT_MS_FORK,
9+
orElse: () =>
10+
Effect.fail(
11+
new TextGenerationError({
12+
operation: "generateThreadTitle",
13+
detail: `The text generation model did not answer within ${TEXT_GENERATION_TIMEOUT_MS_FORK / 1000} seconds.`,
14+
}),
15+
),
16+
}),
17+
);

‎apps/server/src/orchestration-v2/ThreadGroupTitles.ts‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
import { ServerSettingsService } from "../serverSettings.ts";
1515
import { TextGeneration } from "../textGeneration/TextGeneration.ts";
1616
import type { ProjectStoreV2 } from "./ProjectStore.ts";
17+
import { withThreadGroupTitleBudgetFork } from "./ThreadGroupTitles.timeout.fork.ts"; // fork-hook: thread-ordering/title-budget-import
1718

1819
// The thread-title prompt titles whatever the user asked for, so an
1920
// instruction here becomes the title ("Name Sidebar Thread Group"). Each
@@ -32,12 +33,14 @@ export function generateThreadGroupTitle(
3233
readonly modelSelection: ModelSelection;
3334
},
3435
) {
35-
return textGeneration.generateThreadTitle({
36-
cwd: input.cwd,
37-
message: buildThreadGroupTitleMessage(input.memberTitles),
38-
...(input.previousTitle === undefined ? {} : { previousTitle: input.previousTitle }),
39-
modelSelection: input.modelSelection,
40-
});
36+
return textGeneration
37+
.generateThreadTitle({
38+
cwd: input.cwd,
39+
message: buildThreadGroupTitleMessage(input.memberTitles),
40+
...(input.previousTitle === undefined ? {} : { previousTitle: input.previousTitle }),
41+
modelSelection: input.modelSelection,
42+
})
43+
.pipe(withThreadGroupTitleBudgetFork); // fork-hook: thread-ordering/title-budget
4144
}
4245

4346
const failTitleGeneration = (cause: unknown) =>

‎apps/web/src/components/SidebarThreadGroup.title.test.ts‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { EnvironmentInternalError } from "@t3tools/contracts";
1+
import {
2+
EnvironmentInternalError,
3+
THREAD_GROUP_TITLE_CLIENT_TIMEOUT_MS_FORK,
4+
} from "@t3tools/contracts";
25
import { RemoteEnvironmentAuthTimeoutError } from "@t3tools/client-runtime/rpc";
36
import type { AtomCommandResult } from "@t3tools/client-runtime/state/runtime";
47
import * as Cause from "effect/Cause";
@@ -17,15 +20,15 @@ const timeout = (): TitleResult =>
1720
Cause.fail(
1821
new RemoteEnvironmentAuthTimeoutError(
1922
"https://environment.example.test/api/orchestration/thread-group-title",
20-
60_000,
23+
THREAD_GROUP_TITLE_CLIENT_TIMEOUT_MS_FORK,
2124
),
2225
),
2326
);
2427

2528
describe("threadGroupTitleFailureDescription", () => {
2629
it("names the budget a timed-out request ran out of", () => {
2730
expect(threadGroupTitleFailureDescription(timeout())).toBe(
28-
"The text generation model did not answer within 60 seconds.",
31+
"The text generation model did not answer within 185 seconds.",
2932
);
3033
});
3134

@@ -108,9 +111,16 @@ function harness() {
108111
},
109112
});
110113
mount();
114+
// The request publishes its in-flight set from `finally`, after it has handled the result.
111115
const settle = async (result: TitleResult) => {
116+
const handled = new Promise<void>((resolve) => {
117+
const unsubscribe = owner.subscribe(() => {
118+
unsubscribe();
119+
resolve();
120+
});
121+
});
112122
pending.shift()!(result);
113-
await new Promise((resolve) => setTimeout(resolve, 0));
123+
await handled;
114124
};
115125
const clickRetry = () => {
116126
const [toast] = open.values();
@@ -159,7 +169,7 @@ describe("createThreadGroupTitleOwner", () => {
159169
const [toast] = h.open.values();
160170
expect(toast).toMatchObject({
161171
title: 'Failed to name "New group" (2 threads)',
162-
description: "The text generation model did not answer within 60 seconds.",
172+
description: "The text generation model did not answer within 185 seconds.",
163173
timeout: 0,
164174
});
165175
expect(h.groups().A![0]!.title).toBe("New group");
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { expect, it } from "@effect/vitest";
2+
import {
3+
EnvironmentId,
4+
ProjectId,
5+
TEXT_GENERATION_TIMEOUT_MS_FORK,
6+
THREAD_GROUP_TITLE_CLIENT_TIMEOUT_MS_FORK,
7+
} from "@t3tools/contracts";
8+
import * as Effect from "effect/Effect";
9+
import * as Fiber from "effect/Fiber";
10+
import * as Option from "effect/Option";
11+
import * as TestClock from "effect/testing/TestClock";
12+
import { HttpClient } from "effect/http";
13+
14+
import { PrimaryConnectionTarget } from "../connection/model.ts";
15+
import { fetchEnvironmentThreadGroupTitle } from "./threadGroupTitleHttp.ts";
16+
17+
it.effect("gives the server time to report its group-title deadline before the client aborts", () =>
18+
Effect.gen(function* () {
19+
let interrupted = false;
20+
const client = HttpClient.make(() =>
21+
Effect.never.pipe(
22+
Effect.onInterrupt(() =>
23+
Effect.sync(() => {
24+
interrupted = true;
25+
}),
26+
),
27+
),
28+
);
29+
const target = new PrimaryConnectionTarget({
30+
environmentId: EnvironmentId.make("environment-1"),
31+
label: "Test environment",
32+
httpBaseUrl: "https://environment.example.test",
33+
wsBaseUrl: "wss://environment.example.test",
34+
});
35+
const pending = yield* fetchEnvironmentThreadGroupTitle({
36+
prepared: {
37+
environmentId: target.environmentId,
38+
label: target.label,
39+
httpBaseUrl: target.httpBaseUrl,
40+
socketUrl: "wss://environment.example.test/ws",
41+
httpAuthorization: null,
42+
target,
43+
},
44+
signer: Option.none(),
45+
request: { projectId: ProjectId.make("project-1"), memberTitles: ["Ordering", "Groups"] },
46+
}).pipe(Effect.provideService(HttpClient.HttpClient, client), Effect.flip, Effect.forkChild);
47+
yield* TestClock.adjust(TEXT_GENERATION_TIMEOUT_MS_FORK);
48+
expect(interrupted).toBe(false);
49+
yield* TestClock.adjust(
50+
THREAD_GROUP_TITLE_CLIENT_TIMEOUT_MS_FORK - TEXT_GENERATION_TIMEOUT_MS_FORK,
51+
);
52+
expect(yield* Fiber.join(pending)).toMatchObject({
53+
_tag: "RemoteEnvironmentAuthTimeoutError",
54+
timeoutMs: THREAD_GROUP_TITLE_CLIENT_TIMEOUT_MS_FORK,
55+
});
56+
expect(interrupted).toBe(true);
57+
}),
58+
);

‎packages/client-runtime/src/state/threadGroupTitleHttp.ts‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { THREAD_GROUP_TITLE_CLIENT_TIMEOUT_MS_FORK as DEFAULT_THREAD_GROUP_TITLE_TIMEOUT_MS } from "@t3tools/contracts"; // fork-hook: thread-ordering/title-budget
12
import type {
23
ThreadGroupTitleGenerationInput,
34
ThreadGroupTitleGenerationResult,
@@ -14,8 +15,6 @@ import { ManagedRelayDpopSigner } from "../relay/managedRelay.ts";
1415
import type { RemoteEnvironmentRequestError } from "../rpc/http.ts";
1516
import { executeAuthenticatedEnvironmentHttpRequest } from "./environmentHttpAuth.ts";
1617

17-
const DEFAULT_THREAD_GROUP_TITLE_TIMEOUT_MS = 60_000;
18-
1918
export const fetchEnvironmentThreadGroupTitle = Effect.fn(
2019
"clientRuntime.state.fetchEnvironmentThreadGroupTitle",
2120
)(function* (input: {
@@ -61,10 +60,14 @@ export const threadGroupTitleLoaderLayer: Layer.Layer<
6160
RemoteEnvironmentAuthorization.RemoteEnvironmentAuthorization,
6261
);
6362
return ThreadGroupTitleLoader.of({
64-
generate: (prepared, request) =>
65-
fetchEnvironmentThreadGroupTitle({ prepared, request, signer, remoteAuthorization }).pipe(
66-
Effect.provideService(HttpClient.HttpClient, httpClient),
67-
),
63+
generate: Effect.fn("ThreadGroupTitleLoader.generate")(function (prepared, request) {
64+
return fetchEnvironmentThreadGroupTitle({
65+
prepared,
66+
request,
67+
signer,
68+
remoteAuthorization,
69+
}).pipe(Effect.provideService(HttpClient.HttpClient, httpClient));
70+
}),
6871
});
6972
}),
7073
);

‎packages/contracts/src/index.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export { wsRpcsFork } from "./rpc.fork.ts"; // fork-hook: upstream-fixes/ws-rpcs
7878
export * from "./worktreeSetup.ts";
7979
export * from "./secretRequest.ts";
8080
export * from "./clientRpcPermissions.ts";
81+
export * from "./textGeneration.fork.ts"; // fork-hook: thread-ordering/title-budget-export
8182
export * from "./voiceInput.fork.ts"; // fork-hook: voice-input/contracts-export
8283
export * from "./voiceDucking.fork.ts"; // fork-hook: voice-input/ducking-contracts
8384
export * from "./terminalSession.fork.ts"; // fork-hook: zmux-estate/terminal-session-export
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/** Whole server group-title budget, matching the providers' existing text-generation limit. */
2+
export const TEXT_GENERATION_TIMEOUT_MS_FORK = 180_000;
3+
/** Allow the server's failure response to arrive before the client aborts. */
4+
export const THREAD_GROUP_TITLE_CLIENT_TIMEOUT_MS_FORK = TEXT_GENERATION_TIMEOUT_MS_FORK + 5_000;

0 commit comments

Comments
 (0)