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 23, 03:00 UTC
fix(web,mobile): keep reporting client activity after an interrupted report (#15738)
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>
Sky Hong committed
Oct 19, 2026 at 13:08 UTC
7c367e88d39ac8d9c3c609a45303dc8baa88e867
3 files changed
+59
-3
apps/mobile/src/connection/background-activity.ts
+3
-1
@@ -81,7 +81,9 @@ export const layerReporter = Layer.effectDiscard(
81
observedAt: DateTime.makeUnsafe(observedAtMs),
82
}),
83
)
84
- .pipe(Effect.ignore),
84
+ // Not `ignore`: tearing down an environment mid-request interrupts its report,
85
+ // and an interrupt leaking out here would end the reporting loop for good.
86
+ .pipe(Effect.ignoreCause),
87
{ concurrency: "unbounded", discard: true },
88
);
89
}).pipe(Effect.withSpan("mobile.backgroundActivity.report"));
apps/web/src/lib/backgroundActivityReporter.test.ts
+53
-1
@@ -1,8 +1,15 @@
1
+import { EnvironmentRegistry } from "@t3tools/client-runtime/connection";
2
import { EnvironmentId, WS_METHODS } from "@t3tools/contracts";
2
-import { describe, expect, it } from "@effect/vitest";
3
+import { afterEach, beforeEach, describe, expect, it } from "@effect/vitest";
4
+import * as Cause from "effect/Cause";
5
import * as Effect from "effect/Effect";
6
+import * as Layer from "effect/Layer";
7
+import * as SubscriptionRef from "effect/SubscriptionRef";
8
+import * as TestClock from "effect/testing/TestClock";
9
+import { vi } from "vite-plus/test";
10
11
import {
12
+ layer,
13
observeBackgroundActivitySubscription,
14
retainedBackgroundScopes,
15
wasRecentlyInteracted,
@@ -70,3 +77,48 @@ describe("wasRecentlyInteracted", () => {
77
}),
78
);
79
});
80
+
81
+describe("layer", () => {
82
+ beforeEach(() => {
83
+ const target = new EventTarget();
84
+ const listeners = {
85
+ addEventListener: target.addEventListener.bind(target),
86
+ removeEventListener: target.removeEventListener.bind(target),
87
+ };
88
+ vi.stubGlobal("window", {
89
+ ...listeners,
90
+ localStorage: { getItem: () => "client", setItem: () => undefined },
91
+ });
92
+ vi.stubGlobal("document", { ...listeners, visibilityState: "visible", hasFocus: () => true });
93
+ });
94
+
95
+ afterEach(() => {
96
+ vi.unstubAllGlobals();
97
+ });
98
+
99
+ // As when an environment's connection is torn down while its report is in flight.
100
+ it.effect("keeps reporting after a report is interrupted", () =>
101
+ Effect.gen(function* () {
102
+ const entries = yield* SubscriptionRef.make(
103
+ new Map([[EnvironmentId.make("environment-reporter-test"), {}]]),
104
+ );
105
+ let calls = 0;
106
+ const registry = EnvironmentRegistry.EnvironmentRegistry.of({
107
+ entries,
108
+ run: () => {
109
+ calls += 1;
110
+ return calls === 1 ? Effect.failCause(Cause.interrupt()) : Effect.void;
111
+ },
112
+ } as unknown as EnvironmentRegistry.EnvironmentRegistry["Service"]);
113
+
114
+ yield* Layer.build(
115
+ layer.pipe(Layer.provide(Layer.succeed(EnvironmentRegistry.EnvironmentRegistry, registry))),
116
+ );
117
+ yield* TestClock.adjust("1 second");
118
+ expect(calls).toBe(1);
119
+
120
+ yield* TestClock.adjust("25 seconds");
121
+ expect(calls).toBe(2);
122
+ }).pipe(Effect.scoped),
123
+ );
124
+});
apps/web/src/lib/backgroundActivityReporter.ts
+3
-1
@@ -205,7 +205,9 @@ export const layer = Layer.effectDiscard(
205
createActivityReport(environmentId, lastInteractionAtMs, observedAtMs),
206
),
207
)
208
- .pipe(Effect.ignore),
208
+ // Not `ignore`: tearing down an environment mid-request interrupts its report,
209
+ // and an interrupt leaking out here would end the reporting loop for good.
210
+ .pipe(Effect.ignoreCause),
211
{ concurrency: "unbounded", discard: true },
212
);
213
}).pipe(Effect.withSpan("web.backgroundActivity.report"));