@devries-cameron20 / t3code Mirror · read-only / commits / 990f31cac2
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 21, 04:45 UTC

fix(server): host sleep no longer times out an Antigravity turn (#39395)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

Omar Espinosa committed Nov 19, 2026 at 17:36 UTC 990f31cac2567163a15c7fa603abfebe5bdcdb9e
2 files changed +72 -3
apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts
+60
@@ -45,6 +45,7 @@ import * as Effect from "effect/Effect";
45 import * as Exit from "effect/Exit";
46 import * as FileSystem from "effect/FileSystem";
47 import * as Fiber from "effect/Fiber";
48 +import * as Latch from "effect/Latch";
49 import * as Layer from "effect/Layer";
50 import * as Option from "effect/Option";
51 import * as Path from "effect/Path";
@@ -5531,6 +5532,65 @@ describe("AcpAdapterV2", () => {
5532 }).pipe(Effect.provide(layerTest)),
5533 );
5534
5535 + // regression: #34160 a turn failed as silent right after the computer woke from sleep
5536 + it.effect.each([
5537 + { label: "a timer due during sleep fires on wake", timerCountsSleep: true, asleep: "2 hours" },
5538 + { label: "the host wakes before the deadline", timerCountsSleep: true, asleep: "9 minutes" },
5539 + {
5540 + label: "timers pause while only wall time jumps",
5541 + timerCountsSleep: false,
5542 + asleep: "2 hours",
5543 + },
5544 + ] as const)(
5545 + "does not count host sleep as prompt inactivity when $label",
5546 + ({ timerCountsSleep, asleep }) =>
5547 + Effect.gen(function* () {
5548 + const testClock = yield* TestClock.testClockWith(Effect.succeed);
5549 + const awake = yield* Latch.make(true);
5550 + let wallJumpMillis = 0;
5551 + // macOS and Windows timers count sleep and fire on the first tick after wake; on Linux
5552 + // timers pause while the wall clock jumps.
5553 + const hostClock: TestClock.TestClock = {
5554 + ...testClock,
5555 + currentTimeMillisUnsafe: () => testClock.currentTimeMillisUnsafe() + wallJumpMillis,
5556 + currentTimeMillis: Effect.sync(
5557 + () => testClock.currentTimeMillisUnsafe() + wallJumpMillis,
5558 + ),
5559 + sleep: (duration) => testClock.sleep(duration).pipe(Effect.andThen(awake.await)),
5560 + };
5561 + yield* Effect.gen(function* () {
5562 + const harness = yield* makePromptInactivityHarness({
5563 + environment: (runtimeOrdinal) =>
5564 + runtimeOrdinal === 1 ? { T3_ACP_HANG_PROMPT_FOREVER: "1" } : {},
5565 + });
5566 + yield* harness.startTurn(1);
5567 + yield* TestClock.adjust("5 minutes");
5568 + yield* harness.emitUpdate({
5569 + sessionId: "mock-session-1",
5570 + update: {
5571 + sessionUpdate: "agent_thought_chunk",
5572 + content: { type: "text", text: "Still working." },
5573 + },
5574 + });
5575 + if (timerCountsSleep) {
5576 + yield* awake.close;
5577 + yield* TestClock.adjust(asleep);
5578 + yield* awake.open;
5579 + } else {
5580 + wallJumpMillis = Duration.toMillis(asleep);
5581 + }
5582 + yield* TestClock.adjust(Duration.millis(15 * 60_000 - 1));
5583 + assert.isTrue(yield* harness.nextTurnRejected(2));
5584 +
5585 + yield* TestClock.adjust("2 minutes");
5586 + yield* harness.startTurn(2);
5587 + const [silent, next] = yield* harness.terminals(2);
5588 + assert.equal(silent?.status, "failed");
5589 + assert.equal(next?.status, "completed");
5590 + }).pipe(Effect.provideService(Clock.Clock, hostClock));
5591 + }).pipe(Effect.provide(layerTest)),
5592 + );
5593 +
5594 it.effect(
5595 "holds the inactivity timeout while a tool runs and restarts it when the tool ends",
5596 () =>
packages/provider-acp/src/server/adapter.ts
+12 -3
@@ -147,6 +147,8 @@ const ACP_DEFERRED_FINALIZE_DEBOUNCE: Duration.Input = "3000 millis";
147 // A model can stay silent this long before the first token of a reply the agent started itself.
148 const ACP_OPEN_REPLY_QUIET_LIMIT: Duration.Input = "2 minutes";
149 const ACP_BUSY_PROMPT_RETRY_INTERVAL: Duration.Input = "1 second";
150 +const ACP_PROMPT_INACTIVITY_SLICE_MILLIS = 60_000;
151 +const ACP_HOST_SLEEP_TOLERANCE_MILLIS = 10_000;
152
153 // pi-agent-core agents (oh-my-pi) end a turn while background work runs and reject
154 // prompts until it finishes; the prompt is resent rather than failing the turn.
@@ -8767,10 +8769,17 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
8769 yield* Deferred.await(context.promptDispatched);
8770 context.lastProgressAt = yield* Clock.currentTimeMillis;
8771 while (true) {
8770 - const remaining =
8771 - context.lastProgressAt + timeoutMillis - (yield* Clock.currentTimeMillis);
8772 + const sliceStartedAt = yield* Clock.currentTimeMillis;
8773 + const remaining = context.lastProgressAt + timeoutMillis - sliceStartedAt;
8774 if (remaining > 0) {
8773 - yield* Effect.sleep(Duration.millis(remaining));
8775 + const slice = Math.min(remaining, ACP_PROMPT_INACTIVITY_SLICE_MILLIS);
8776 + yield* Effect.sleep(Duration.millis(slice));
8777 + // Host sleep is not agent silence. Timers either fire late on wake (macOS, Windows)
8778 + // or pause while the wall clock jumps (Linux); both overrun a short slice.
8779 + const now = yield* Clock.currentTimeMillis;
8780 + if (now - sliceStartedAt > slice + ACP_HOST_SLEEP_TOLERANCE_MILLIS) {
8781 + context.lastProgressAt = now;
8782 + }
8783 continue;
8784 }
8785 const outcome = yield* runtimeTransitionPermit.withPermit(