@devries-cameron20 / t3code Mirror · read-only / commits / 4b7a347ca9
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 13:15 UTC

fix(composer): retry expired catalogs after failed discovery (#23174)

Co-authored-by: GPT-6.1 Sol <noreply@openai.com> Co-authored-by: maria-rcks <maria@kuuro.net>

Victor Vogel committed Oct 29, 2026 at 12:57 UTC 4b7a347ca9372aea7e2cc93d8b2835cdf34f69eb
2 files changed +73 -5
packages/client-runtime/src/providerSkills.test.ts
+57
@@ -199,6 +199,63 @@ describe("provider workspace snapshot refresh atom", () => {
199 unmount();
200 });
201
202 + it.each(["already expired", "expires during discovery"])(
203 + "retries an unchanged catalog that %s after the short cooldown",
204 + async (expiry) => {
205 + const start = Date.parse("2026-01-01T00:05:00.000Z");
206 + vi.useFakeTimers({ now: expiry === "expires during discovery" ? start - 1 : start });
207 + const stale = withSnapshot("2026-01-01T00:00:00.000Z");
208 + const { registry, atom, responses, run, unmount } = setup(
209 + expiry === "expires during discovery"
210 + ? withSnapshot("2026-01-01T00:00:00.000Z", true)
211 + : stale,
212 + [
213 + () => {
214 + if (expiry === "expires during discovery") vi.setSystemTime(start + 1);
215 + return stale;
216 + },
217 + ],
218 + );
219 + await vi.advanceTimersByTimeAsync(0);
220 + await vi.advanceTimersByTimeAsync(9_999);
221 + registry.refresh(atom);
222 + expect(run).toHaveBeenCalledTimes(1);
223 + responses.push(() => withSnapshot("2026-01-01T00:05:10.000Z"));
224 + await vi.advanceTimersByTimeAsync(1);
225 + registry.refresh(atom);
226 + expect(run).toHaveBeenCalledTimes(2);
227 + unmount();
228 + },
229 + );
230 +
231 + it("keeps the TTL guard for a newly scanned catalog when the client clock is ahead", async () => {
232 + vi.useFakeTimers({ now: Date.parse("2026-01-01T01:00:00.000Z") });
233 + const { registry, atom, run, unmount } = setup(withSnapshot("2026-01-01T00:00:00.000Z"), [
234 + () => withSnapshot("2026-01-01T00:01:00.000Z"),
235 + ]);
236 + await vi.advanceTimersByTimeAsync(10_000);
237 + registry.refresh(atom);
238 + expect(run).toHaveBeenCalledTimes(1);
239 + unmount();
240 + });
241 +
242 + it("bounds retries when discovery repeatedly returns the same expired catalog", async () => {
243 + vi.useFakeTimers({ now: Date.parse("2026-01-01T00:05:00.000Z") });
244 + const stale = withSnapshot("2026-01-01T00:00:00.000Z");
245 + const { registry, atom, run, unmount } = setup(stale, [() => stale, () => stale, () => stale]);
246 + await vi.advanceTimersByTimeAsync(0);
247 + await vi.advanceTimersByTimeAsync(10_000);
248 + registry.refresh(atom);
249 + await vi.advanceTimersByTimeAsync(0);
250 + await vi.advanceTimersByTimeAsync(10_000);
251 + registry.refresh(atom);
252 + await vi.advanceTimersByTimeAsync(0);
253 + await vi.advanceTimersByTimeAsync(10_000);
254 + registry.refresh(atom);
255 + expect(run).toHaveBeenCalledTimes(3);
256 + unmount();
257 + });
258 +
259 it("does not rescan a current snapshot, and rescans once it ages past the TTL", () => {
260 vi.useFakeTimers({ now: Date.parse("2026-01-01T00:01:00.000Z") });
261 const { registry, atom, run, unmount } = setup(withSnapshot("2026-01-01T00:00:00.000Z"));
packages/client-runtime/src/providerSkills.ts
+16 -5
@@ -144,7 +144,7 @@ interface ProviderWorkspaceSnapshotRefreshState {
144 readonly requestedAt: number | null;
145 /** A failed scan is not retried before this time. */
146 readonly retryNotBefore: number | null;
147 - /** Scans in a row that ended without a complete snapshot. */
147 + /** Failed scans within the current request TTL. */
148 readonly failedAttempts: number;
149 readonly hadSnapshot: boolean;
150 }
@@ -183,8 +183,10 @@ function planProviderWorkspaceSnapshotRefresh(
183 const state = {
184 requestedAt,
185 retryNotBefore,
186 - // A complete snapshot ends the run of failures.
187 - failedAttempts: hasSnapshot ? 0 : previous.failedAttempts,
186 + failedAttempts:
187 + lost || (requestedAt !== null && now - requestedAt >= PROVIDER_WORKSPACE_SNAPSHOT_TTL_MS)
188 + ? 0
189 + : previous.failedAttempts,
190 hadSnapshot: hasSnapshot,
191 };
192 const refresh =
@@ -305,9 +307,18 @@ export function createProviderWorkspaceSnapshotRefreshAtomFamily(input: {
307 { environmentId, input: { instanceId, cwd } },
308 { reportFailure: false },
309 ).then((result) => {
310 + const refreshedProvider =
311 + result._tag === "Success" ? findProvider(result.value.providers) : undefined;
312 + const snapshot =
313 + refreshedProvider && resolveProviderWorkspaceSnapshot(refreshedProvider, cwd);
314 + // A new server timestamp proves progress even when the client clock is ahead.
315 + // @effect-diagnostics-next-line globalDate:off
316 + const completedAt = Date.now();
317 const refreshed =
309 - result._tag === "Success" &&
310 - hasCompleteProviderWorkspaceSnapshot(findProvider(result.value.providers), cwd);
318 + hasCompleteProviderWorkspaceSnapshot(refreshedProvider, cwd) &&
319 + (hasCurrentProviderWorkspaceSnapshot(refreshedProvider, cwd, completedAt) ||
320 + snapshot?.checkedAt !==
321 + (provider && resolveProviderWorkspaceSnapshot(provider, cwd))?.checkedAt);
322 if (!refreshed) retryLater();
323 }, retryLater);
324 return plan.state;