The best way to control Claude Code, Codex and more from any computer or phone
fix(client-runtime): Diagnostics Resource History keeps updating while open (#35116)
Julius Marminge committed
Nov 12, 2026 at 02:47 UTC
32f3d8b160a1a28fd9cb7add78064e3ed9042dce
2 files changed
+87
-76
packages/client-runtime/src/state/server.test.ts
+84
-76
@@ -1740,82 +1740,90 @@ describe("provider setup commands", () => {
1740
});
1741
1742
describe("resource telemetry history", () => {
1743
- it.effect("refreshes an initially empty history while mounted and stops after unmount", () =>
1744
- Effect.gen(function* () {
1745
- vi.useFakeTimers();
1746
- try {
1747
- yield* Effect.scoped(
1748
- Effect.gen(function* () {
1749
- let reads = 0;
1750
- const client = {
1751
- [WS_METHODS.serverGetResourceTelemetryHistory]: () =>
1752
- Effect.sync(() => ({
1753
- retainedSampleCount: reads++,
1754
- })),
1755
- } as unknown as WsRpcProtocolClient;
1756
- const supervisor = EnvironmentSupervisor.EnvironmentSupervisor.of({
1757
- target: TARGET,
1758
- state: yield* SubscriptionRef.make<SupervisorConnectionState>({
1759
- ...AVAILABLE_CONNECTION_STATE,
1760
- phase: "connected",
1761
- }),
1762
- session: yield* SubscriptionRef.make(Option.some(session(client))),
1763
- prepared: yield* SubscriptionRef.make(Option.none<PreparedConnection>()),
1764
- connect: Effect.void,
1765
- disconnect: Effect.void,
1766
- retryNow: Effect.void,
1767
- });
1768
- const environments = EnvironmentRegistry.EnvironmentRegistry.of({
1769
- run: (_id, effect) =>
1770
- Effect.provideService(
1771
- effect,
1772
- EnvironmentSupervisor.EnvironmentSupervisor,
1773
- supervisor,
1774
- ),
1775
- followStream: (_id, stream) =>
1776
- Stream.provideService(
1777
- stream,
1778
- EnvironmentSupervisor.EnvironmentSupervisor,
1779
- supervisor,
1743
+ it.effect.each([
1744
+ ["resourceTelemetryHistory", WS_METHODS.serverGetResourceTelemetryHistory],
1745
+ ["processResourceHistory", WS_METHODS.serverGetProcessResourceHistory],
1746
+ ] as const)(
1747
+ "%s refreshes an initially empty history while mounted and stops after unmount",
1748
+ ([atomKey, method]) =>
1749
+ Effect.gen(function* () {
1750
+ vi.useFakeTimers();
1751
+ try {
1752
+ yield* Effect.scoped(
1753
+ Effect.gen(function* () {
1754
+ let reads = 0;
1755
+ const client = {
1756
+ [method]: () =>
1757
+ Effect.sync(() => ({
1758
+ retainedSampleCount: reads++,
1759
+ })),
1760
+ } as unknown as WsRpcProtocolClient;
1761
+ const supervisor = EnvironmentSupervisor.EnvironmentSupervisor.of({
1762
+ target: TARGET,
1763
+ state: yield* SubscriptionRef.make<SupervisorConnectionState>({
1764
+ ...AVAILABLE_CONNECTION_STATE,
1765
+ phase: "connected",
1766
+ }),
1767
+ session: yield* SubscriptionRef.make(Option.some(session(client))),
1768
+ prepared: yield* SubscriptionRef.make(Option.none<PreparedConnection>()),
1769
+ connect: Effect.void,
1770
+ disconnect: Effect.void,
1771
+ retryNow: Effect.void,
1772
+ });
1773
+ const environments = EnvironmentRegistry.EnvironmentRegistry.of({
1774
+ run: (_id, effect) =>
1775
+ Effect.provideService(
1776
+ effect,
1777
+ EnvironmentSupervisor.EnvironmentSupervisor,
1778
+ supervisor,
1779
+ ),
1780
+ followStream: (_id, stream) =>
1781
+ Stream.provideService(
1782
+ stream,
1783
+ EnvironmentSupervisor.EnvironmentSupervisor,
1784
+ supervisor,
1785
+ ),
1786
+ } as EnvironmentRegistry.EnvironmentRegistry["Service"]);
1787
+ const runtime = Atom.runtime(
1788
+ Layer.merge(
1789
+ Layer.succeed(EnvironmentRegistry.EnvironmentRegistry, environments),
1790
+ Layer.succeed(Persistence.EnvironmentCacheStore, {
1791
+ loadServerConfig: () => Effect.succeedNone,
1792
+ } as unknown as Persistence.EnvironmentCacheStore["Service"]),
1793
),
1781
- } as EnvironmentRegistry.EnvironmentRegistry["Service"]);
1782
- const runtime = Atom.runtime(
1783
- Layer.merge(
1784
- Layer.succeed(EnvironmentRegistry.EnvironmentRegistry, environments),
1785
- Layer.succeed(Persistence.EnvironmentCacheStore, {
1786
- loadServerConfig: () => Effect.succeedNone,
1787
- } as unknown as Persistence.EnvironmentCacheStore["Service"]),
1788
- ),
1789
- );
1790
- const atoms = createServerEnvironmentAtoms(runtime, {
1791
- initialConfigValueAtom: () => Atom.make(CONFIG),
1792
- });
1793
- const registry = yield* Effect.acquireRelease(Effect.sync(AtomRegistry.make), (value) =>
1794
- Effect.sync(() => value.dispose()),
1795
- );
1796
- const history = atoms.resourceTelemetryHistory({
1797
- environmentId: TARGET.environmentId,
1798
- input: { windowMs: 900_000, bucketMs: 30_000 },
1799
- });
1800
- const unmount = registry.mount(history);
1801
- const initial = yield* AtomRegistry.getResult(registry, history, {
1802
- suspendOnWaiting: true,
1803
- });
1804
- expect(initial.retainedSampleCount).toBe(0);
1805
- yield* Effect.promise(() => vi.advanceTimersByTimeAsync(5_000));
1806
- expect(reads).toBe(2);
1807
- const updated = yield* AtomRegistry.getResult(registry, history, {
1808
- suspendOnWaiting: true,
1809
- });
1810
- expect(updated.retainedSampleCount).toBe(1);
1811
- unmount();
1812
- yield* Effect.promise(() => vi.advanceTimersByTimeAsync(10_000));
1813
- expect(reads).toBe(2);
1814
- }),
1815
- );
1816
- } finally {
1817
- vi.useRealTimers();
1818
- }
1819
- }),
1794
+ );
1795
+ const atoms = createServerEnvironmentAtoms(runtime, {
1796
+ initialConfigValueAtom: () => Atom.make(CONFIG),
1797
+ });
1798
+ const registry = yield* Effect.acquireRelease(
1799
+ Effect.sync(AtomRegistry.make),
1800
+ (value) => Effect.sync(() => value.dispose()),
1801
+ );
1802
+ const history: Atom.Atom<
1803
+ AsyncResult.AsyncResult<{ readonly retainedSampleCount: number }, Error>
1804
+ > = atoms[atomKey]({
1805
+ environmentId: TARGET.environmentId,
1806
+ input: { windowMs: 900_000, bucketMs: 30_000 },
1807
+ });
1808
+ const unmount = registry.mount(history);
1809
+ const initial = yield* AtomRegistry.getResult(registry, history, {
1810
+ suspendOnWaiting: true,
1811
+ });
1812
+ expect(initial.retainedSampleCount).toBe(0);
1813
+ yield* Effect.promise(() => vi.advanceTimersByTimeAsync(5_000));
1814
+ expect(reads).toBe(2);
1815
+ const updated = yield* AtomRegistry.getResult(registry, history, {
1816
+ suspendOnWaiting: true,
1817
+ });
1818
+ expect(updated.retainedSampleCount).toBe(1);
1819
+ unmount();
1820
+ yield* Effect.promise(() => vi.advanceTimersByTimeAsync(10_000));
1821
+ expect(reads).toBe(2);
1822
+ }),
1823
+ );
1824
+ } finally {
1825
+ vi.useRealTimers();
1826
+ }
1827
+ }),
1828
);
1829
});
packages/client-runtime/src/state/server.ts
+3
@@ -1389,6 +1389,9 @@ export function createServerEnvironmentAtoms<R, E>(
1389
processResourceHistory: createEnvironmentRpcQueryAtomFamily(runtime, {
1390
label: "environment-data:server:process-resource-history",
1391
tag: WS_METHODS.serverGetProcessResourceHistory,
1392
+ staleTimeMs: 5_000,
1393
+ refreshIntervalMs: 5_000,
1394
+ idleTtlMs: 0,
1395
}),
1396
scheduledTaskWebhookDeliveries: createEnvironmentRpcQueryAtomFamily(runtime, {
1397
label: "environment-data:server:scheduled-task:webhook-deliveries",