Skip to content

Commit 941452f

Browse files
Merge remote-tracking branch 'origin/main' into fix/issue-29534
2 parents 5dd8733 + 6f41364 commit 941452f

9 files changed

Lines changed: 382 additions & 27 deletions

File tree

‎apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.test.ts‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,22 @@ it.layer(McpProviderSessions.layer)("OpenCode2 adapter", (it) => {
563563
status: 429,
564564
},
565565
},
566+
{
567+
name: "a Claude limit without a reset timestamp",
568+
failureClass: "usage_limit",
569+
error: {
570+
type: "provider.unknown",
571+
message: "You've hit your session limit · resets 5:20pm (Europe/Berlin)",
572+
},
573+
},
574+
{
575+
name: "an unrelated provider.unknown failure",
576+
failureClass: "provider_error",
577+
error: {
578+
type: "provider.unknown",
579+
message: "Request failed. Resets at 2026-11-02T20:00:00Z.",
580+
},
581+
},
566582
] as const)("classifies $name as $failureClass", ({ error, failureClass }) =>
567583
Effect.gen(function* () {
568584
const { runtime, thread } = yield* resumed([
@@ -583,6 +599,35 @@ it.layer(McpProviderSessions.layer)("OpenCode2 adapter", (it) => {
583599
}).pipe(Effect.scoped),
584600
);
585601

602+
// regression: #29289 Claude weekly limits through claude-agent lost their usage-limit reset
603+
it.effect(
604+
"classifies a Claude weekly limit as a usage limit that resets at its reported time",
605+
() =>
606+
Effect.gen(function* () {
607+
const message =
608+
"You've hit your weekly limit · resets 9pm (Europe/Paris) Resets at 2026-11-02T20:00:00.000Z.";
609+
const { runtime, thread } = yield* resumed([
610+
out("session.prompt", { sessionID: SESSION, text: "<any>" }),
611+
promptAccepted,
612+
event("session.execution.failed", {
613+
sessionID: SESSION,
614+
error: { type: "provider.unknown", message },
615+
}),
616+
]);
617+
const terminal = yield* terminalOf(runtime).pipe(Effect.forkScoped);
618+
yield* runtime.startTurn(turnInput(thread));
619+
const ended = yield* Fiber.join(terminal);
620+
assert.equal(ended?.status, "failed");
621+
assert.deepEqual(ended?.failure, {
622+
class: "usage_limit",
623+
code: "provider.unknown",
624+
message,
625+
retryable: null,
626+
resetAt: "2026-11-02T20:00:00.000Z",
627+
});
628+
}).pipe(Effect.scoped),
629+
);
630+
586631
it.effect("ends the turn when its terminal event is one this build cannot decode", () =>
587632
Effect.gen(function* () {
588633
const { runtime, thread } = yield* resumed([

‎apps/server/src/relay/AgentAwarenessRelay.test.ts‎

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,113 @@ describe("AgentAwarenessRelay", () => {
482482
}),
483483
);
484484

485+
it.effect("publishes a cleared thread's tombstone once while it stays cleared", () =>
486+
Effect.gen(function* () {
487+
const { relay, currentShell, publications } = yield* makeTestRelay();
488+
yield* relay.publishThread(THREAD_ID);
489+
const completed = shell({ status: "completed" });
490+
yield* Ref.set(currentShell, completed);
491+
yield* relay.publishThread(THREAD_ID);
492+
yield* TestClock.adjust("5 seconds");
493+
yield* relay.drain;
494+
yield* Ref.set(currentShell, {
495+
...completed,
496+
settledOverride: "settled",
497+
settledAt: yield* DateTime.now,
498+
lastVisitedAt: null,
499+
});
500+
yield* relay.publishThread(THREAD_ID);
501+
yield* TestClock.adjust("5 seconds");
502+
yield* relay.drain;
503+
assert.deepEqual(
504+
publications.map((publication) => publication.state?.phase ?? null),
505+
["running", "completed", null],
506+
);
507+
508+
for (let i = 0; i < 3; i++) {
509+
yield* relay.publishThread(THREAD_ID);
510+
yield* TestClock.adjust("5 seconds");
511+
yield* relay.drain;
512+
}
513+
assert.deepEqual(
514+
publications.map((publication) => publication.state?.phase ?? null),
515+
["running", "completed", null],
516+
);
517+
}),
518+
);
519+
520+
it.effect("does not alert an old completion after publishing its thread's tombstone", () =>
521+
Effect.gen(function* () {
522+
const oldCompleted = shell({
523+
status: "completed",
524+
latestRunCompletedAt: DateTime.makeUnsafe("2026-09-04T11:59:00.000Z"),
525+
});
526+
yield* TestClock.setTime(DateTime.toEpochMillis(DateTime.makeUnsafe(NOW)));
527+
const { relay, currentShell, publications } = yield* makeTestRelay();
528+
yield* Ref.set(currentShell, {
529+
...oldCompleted,
530+
settledOverride: "settled",
531+
settledAt: DateTime.makeUnsafe(NOW),
532+
lastVisitedAt: null,
533+
});
534+
yield* relay.publishThread(THREAD_ID);
535+
yield* TestClock.adjust("5 seconds");
536+
yield* relay.drain;
537+
assert.deepEqual(
538+
publications.map((publication) => publication.state),
539+
[null],
540+
);
541+
542+
yield* Ref.set(currentShell, oldCompleted);
543+
yield* relay.publishThread(THREAD_ID);
544+
yield* TestClock.adjust("5 seconds");
545+
yield* relay.drain;
546+
assert.deepEqual(
547+
publications.map((publication) => publication.state),
548+
[null],
549+
);
550+
}),
551+
);
552+
553+
it.effect("alerts a completion settled during its hold after an earlier tombstone", () =>
554+
Effect.gen(function* () {
555+
yield* TestClock.setTime(DateTime.toEpochMillis(DateTime.makeUnsafe(NOW)));
556+
const { relay, currentShell, publications } = yield* makeTestRelay();
557+
const settledAt = DateTime.makeUnsafe(NOW);
558+
yield* Ref.set(currentShell, {
559+
...shell({ status: "completed" }),
560+
settledOverride: "settled",
561+
settledAt,
562+
lastVisitedAt: null,
563+
});
564+
yield* relay.publishThread(THREAD_ID);
565+
yield* TestClock.adjust("5 seconds");
566+
yield* relay.drain;
567+
568+
const completed = shell({
569+
status: "completed",
570+
latestRunCompletedAt: DateTime.makeUnsafe("2026-09-04T12:00:06.000Z"),
571+
});
572+
yield* Ref.set(currentShell, completed);
573+
yield* relay.publishThread(THREAD_ID);
574+
yield* Ref.set(currentShell, {
575+
...completed,
576+
settledOverride: "settled",
577+
settledAt,
578+
lastVisitedAt: null,
579+
});
580+
yield* relay.publishThread(THREAD_ID);
581+
yield* TestClock.adjust("5 seconds");
582+
yield* relay.drain;
583+
yield* TestClock.adjust("5 seconds");
584+
yield* relay.drain;
585+
assert.deepEqual(
586+
publications.map((publication) => publication.state?.phase ?? null),
587+
[null, "completed", null],
588+
);
589+
}),
590+
);
591+
485592
it.effect("drops a held completion when a queued continuation hides the thread", () =>
486593
Effect.gen(function* () {
487594
const { relay, currentShell, publications } = yield* makeTestRelay();

‎apps/server/src/relay/AgentAwarenessRelay.ts‎

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,17 @@ function agentAwarenessPublishIdentity(state: RelayAgentActivityState | null): s
165165
return JSON.stringify(meaningfulState);
166166
}
167167

168+
const CLEARED_PUBLISH_IDENTITY = agentAwarenessPublishIdentity(null);
169+
170+
// A published tombstone stays recorded so repeats are skipped, but it is not live state.
171+
function hasLivePublishedState(
172+
publishedStateByThread: ReadonlyMap<ThreadId, string>,
173+
threadId: ThreadId,
174+
): boolean {
175+
const identity = publishedStateByThread.get(threadId);
176+
return identity !== undefined && identity !== CLEARED_PUBLISH_IDENTITY;
177+
}
178+
168179
function resolveAgentActivityPublishingStartupState(input: {
169180
readonly relayConfigured: boolean;
170181
readonly publishEnabled: boolean;
@@ -517,7 +528,7 @@ export const make = Effect.gen(function* () {
517528
if (
518529
threadShell !== null &&
519530
!isListedThreadLineage(threadShell.lineage) &&
520-
!(yield* Ref.get(publishedStateByThreadRef)).has(threadId)
531+
!hasLivePublishedState(yield* Ref.get(publishedStateByThreadRef), threadId)
521532
) {
522533
// Subagents and side chats have no relay rows to clear; per-event tombstones would needlessly redeliver user aggregates.
523534
return;
@@ -538,11 +549,15 @@ export const make = Effect.gen(function* () {
538549
const publishedStateByThread = yield* Ref.get(publishedStateByThreadRef);
539550
if (
540551
(snapshot.state?.phase === "completed" || snapshot.state?.phase === "failed") &&
541-
!publishedStateByThread.has(threadId)
552+
!hasLivePublishedState(publishedStateByThread, threadId)
542553
) {
543554
if (Option.isNone(thread) || !terminalWorkSinceStart(thread.value, startedAt)) return;
544555
}
545-
if (publishedStateByThread.get(threadId) === publishIdentity) {
556+
if (
557+
publishedStateByThread.get(threadId) === publishIdentity &&
558+
// A held completion settled after an earlier clear still has to alert.
559+
!(snapshot.state === null && heldCompletions.has(threadId))
560+
) {
546561
// Clear moot deadlines so later transient nulls cannot skip their deferral window.
547562
publishConfirmDeadlines.delete(threadId);
548563
heldCompletions.delete(threadId);
@@ -557,10 +572,7 @@ export const make = Effect.gen(function* () {
557572
// Confirm tombstones over live state to avoid removing active cards.
558573
// Confirm completion: a run can end moments before its continuation starts, and the relay
559574
// alerts on every move into completed.
560-
const requiresConfirmation =
561-
(snapshot.state === null &&
562-
publishedStateByThread.get(threadId) !== agentAwarenessPublishIdentity(null)) ||
563-
snapshot.state?.phase === "completed";
575+
const requiresConfirmation = snapshot.state === null || snapshot.state?.phase === "completed";
564576
if (requiresConfirmation) {
565577
if (snapshot.state?.phase === "completed") heldCompletions.add(threadId);
566578
const nowMs = (yield* DateTime.now).epochMilliseconds;
@@ -640,15 +652,9 @@ export const make = Effect.gen(function* () {
640652
}).pipe(withRelayClientTracing);
641653
publishConfirmDeadlines.delete(threadId);
642654
heldCompletions.delete(threadId);
643-
yield* Ref.update(publishedStateByThreadRef, (publishedStates) => {
644-
const nextPublishedStates = new Map(publishedStates);
645-
if (snapshot.state === null) {
646-
nextPublishedStates.delete(threadId);
647-
} else {
648-
nextPublishedStates.set(threadId, publishIdentity);
649-
}
650-
return nextPublishedStates;
651-
});
655+
yield* Ref.update(publishedStateByThreadRef, (publishedStates) =>
656+
new Map(publishedStates).set(threadId, publishIdentity),
657+
);
652658
});
653659

654660
const processThreadPublish = Effect.fnUntraced(function* (threadId: ThreadId) {

‎apps/web/src/components/settings/ProviderSettingsPanel.environment.browser.test.tsx‎

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const state = vi.hoisted(() => ({
3636
updateModelPreferences: vi.fn(),
3737
toggleFavorite: vi.fn(),
3838
mutateProviderInstance: vi.fn(),
39+
confirm: vi.fn<() => Promise<boolean>>(),
3940
}));
4041

4142
vi.mock(import("../../state/server"), async (original) => {
@@ -80,6 +81,14 @@ vi.mock(import("../../state/use-atom-command"), async (original) => ({
8081
"accept-url-auth": state.acceptUrlAuth,
8182
})[command.label ?? ""] ?? vi.fn()) as never,
8283
}));
84+
vi.mock(import("~/localApi"), async (original) => {
85+
const api = { dialogs: { confirm: state.confirm } };
86+
return {
87+
...(await original()),
88+
readLocalApi: (() => api) as never,
89+
ensureLocalApi: (() => api) as never,
90+
};
91+
});
8392
vi.mock(import("../../state/query"), async (original) => ({
8493
...(await original()),
8594
useEnvironmentQuery: ((query: unknown) => ({
@@ -231,6 +240,7 @@ async function setup() {
231240
state.updateModelPreferences.mockReset();
232241
state.toggleFavorite.mockReset();
233242
state.mutateProviderInstance.mockReset().mockResolvedValue(AsyncResult.success({}));
243+
state.confirm.mockReset().mockResolvedValue(false);
234244
state.refresh.mockReset().mockResolvedValue(AsyncResult.success(undefined));
235245
state.updateProvider.mockReset().mockResolvedValue(AsyncResult.success(undefined));
236246
state.uninstall.mockReset().mockResolvedValue(AsyncResult.success({}));
@@ -359,6 +369,90 @@ describe("EnvironmentProviderSettings routing", () => {
359369
});
360370
});
361371

372+
describe("EnvironmentProviderSettings instance removal", () => {
373+
it("resets a configured default instance only once the user confirms", async () => {
374+
await setup();
375+
state.settings = {
376+
...DEFAULT_UNIFIED_SETTINGS,
377+
providerInstances: {
378+
[codexId]: {
379+
driver: ProviderDriverKind.make("codex"),
380+
enabled: true,
381+
config: { binaryPath: "/opt/codex/bin/codex" },
382+
},
383+
},
384+
};
385+
await setProviders([provider()]);
386+
await using _screen = await render(panel({ targetInstanceId: codexId }));
387+
const reset = page.getByRole("button", { name: "Reset Codex provider settings to default" });
388+
await userEvent.click(reset);
389+
390+
expect(state.mutateProviderInstance).not.toHaveBeenCalled();
391+
expect(state.confirm).toHaveBeenCalledOnce();
392+
393+
state.confirm.mockResolvedValue(true);
394+
await userEvent.click(reset);
395+
await vi.waitFor(() =>
396+
expect(state.mutateProviderInstance).toHaveBeenCalledWith({
397+
operation: "remove",
398+
instanceId: codexId,
399+
}),
400+
);
401+
});
402+
403+
it("warns that resetting an enabled default-off provider turns it off", async () => {
404+
await setup();
405+
const antigravityId = ProviderInstanceId.make("antigravity");
406+
const antigravity = ProviderDriverKind.make("antigravity");
407+
state.settings = {
408+
...DEFAULT_UNIFIED_SETTINGS,
409+
providerInstances: {
410+
[antigravityId]: {
411+
driver: antigravity,
412+
enabled: true,
413+
config: { binaryPath: "/opt/antigravity/bin/agy" },
414+
},
415+
},
416+
};
417+
await setProviders([{ ...provider(), instanceId: antigravityId, driver: antigravity }]);
418+
await using _screen = await render(panel({ targetInstanceId: antigravityId }));
419+
await userEvent.click(page.getByRole("button", { name: /^Reset .* provider settings/ }));
420+
421+
expect(state.confirm).toHaveBeenCalledWith(
422+
expect.stringContaining("It will also be turned off."),
423+
{
424+
variant: "destructive",
425+
},
426+
);
427+
expect(state.mutateProviderInstance).not.toHaveBeenCalled();
428+
});
429+
430+
it("deletes a custom instance only once the user confirms", async () => {
431+
await setup();
432+
state.settings = {
433+
...DEFAULT_UNIFIED_SETTINGS,
434+
providerInstances: {
435+
[customId]: { driver: ProviderDriverKind.make("codex"), enabled: true },
436+
},
437+
};
438+
await using _screen = await render(panel({ targetInstanceId: customId }));
439+
const remove = page.getByRole("button", { name: `Delete instance ${customId}` });
440+
await userEvent.click(remove);
441+
442+
expect(state.mutateProviderInstance).not.toHaveBeenCalled();
443+
expect(state.confirm).toHaveBeenCalledOnce();
444+
445+
state.confirm.mockResolvedValue(true);
446+
await userEvent.click(remove);
447+
await vi.waitFor(() =>
448+
expect(state.mutateProviderInstance).toHaveBeenCalledWith({
449+
operation: "remove",
450+
instanceId: customId,
451+
}),
452+
);
453+
});
454+
});
455+
362456
describe("EnvironmentProviderSettings health check interval", () => {
363457
it("commits interval drafts and allows retrying rejected edits", async () => {
364458
await setup();

0 commit comments

Comments
 (0)