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, 16:00 UTC
perf(relay): lighter Postgres load and PS-160 cluster (#36442)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Nov 13, 2026 at 15:56 UTC
770028f965e0639e4eefb639f25f2b211d5ccdfc
4 files changed
+80
-12
infra/relay/src/agentActivity/AgentActivityPublisher.test.ts
+67
@@ -207,6 +207,73 @@ describe("AgentActivityPublisher", () => {
207
);
208
});
209
210
+ it.effect.each([
211
+ {
212
+ name: "skips the activity query without a running iOS Live Activity",
213
+ activityToken: null,
214
+ listCalls: 0,
215
+ },
216
+ {
217
+ name: "aggregates activity for a running iOS Live Activity",
218
+ activityToken: "activity-token",
219
+ listCalls: 1,
220
+ },
221
+ ])("$name", ({ activityToken, listCalls }) => {
222
+ const android = { ...target("android"), platform: "android" as const, ios_major_version: null };
223
+ const ios = { ...target("ios"), activity_push_token: activityToken };
224
+ let listed = 0;
225
+ const hasAggregate: boolean[] = [];
226
+ return Effect.gen(function* () {
227
+ const publisher = yield* AgentActivityPublisher.AgentActivityPublisher;
228
+ yield* publisher.publish({
229
+ environmentId: state.environmentId,
230
+ environmentPublicKey: "key",
231
+ threadId: state.threadId,
232
+ state,
233
+ });
234
+ expect(listed).toBe(listCalls);
235
+ expect(hasAggregate).toEqual([listCalls > 0]);
236
+ }).pipe(
237
+ Effect.provide(
238
+ AgentActivityPublisher.layer.pipe(
239
+ Layer.provide(
240
+ Layer.mergeAll(
241
+ Layer.succeed(
242
+ AgentActivityRows.AgentActivityRows,
243
+ makeAgentActivityRows({
244
+ listForUser: () =>
245
+ Effect.sync(() => {
246
+ listed += 1;
247
+ return [state];
248
+ }),
249
+ }),
250
+ ),
251
+ Layer.succeed(EnvironmentLinks.EnvironmentLinks, makeEnvironmentLinks()),
252
+ Layer.succeed(
253
+ LiveActivities.LiveActivities,
254
+ makeLiveActivities({ listTargets: () => Effect.succeed([android, ios]) }),
255
+ ),
256
+ Layer.succeed(
257
+ ApnsDeliveries.ApnsDeliveries,
258
+ makeApnsDeliveries({
259
+ sendForTarget: (input) =>
260
+ Effect.sync(() => {
261
+ hasAggregate.push(input.aggregate !== null);
262
+ return null;
263
+ }),
264
+ }),
265
+ ),
266
+ Layer.succeed(FcmDeliveries.FcmDeliveries, {
267
+ enqueue: () => Effect.succeed(null),
268
+ process: () => Effect.void,
269
+ }),
270
+ ),
271
+ ),
272
+ ),
273
+ ),
274
+ );
275
+ });
276
+
277
it.effect("replays the latest aggregate when a Live Activity token registers", () => {
278
const registeredTarget: LiveActivities.TargetRow = {
279
...target("device-1"),
infra/relay/src/agentActivity/AgentActivityPublisher.ts
+11
-10
@@ -63,17 +63,18 @@ const make = Effect.gen(function* () {
63
readonly state: RelayAgentActivityState | null;
64
readonly nowMs: number;
65
}) {
66
- const activeStates = input.deliveryUser.liveActivitiesEnabled
67
- ? yield* rows.listForUser({ userId: input.deliveryUser.userId })
68
- : [];
69
- const liveActivityAggregate = input.deliveryUser.liveActivitiesEnabled
70
- ? makeAggregateState({
71
- activeStates,
72
- terminalState: input.state && isTerminalPhase(input.state) ? input.state : null,
73
- nowMs: input.nowMs,
74
- })
75
- : null;
66
const targets = yield* liveActivities.listTargets({ userId: input.deliveryUser.userId });
67
+ // Only iOS targets with a running Live Activity read the aggregate, and few users have one,
68
+ // so skip the per-user activity query otherwise.
69
+ const liveActivityAggregate =
70
+ input.deliveryUser.liveActivitiesEnabled &&
71
+ targets.some((target) => target.platform !== "android" && target.activity_push_token)
72
+ ? makeAggregateState({
73
+ activeStates: yield* rows.listForUser({ userId: input.deliveryUser.userId }),
74
+ terminalState: input.state && isTerminalPhase(input.state) ? input.state : null,
75
+ nowMs: input.nowMs,
76
+ })
77
+ : null;
78
return yield* Effect.forEach(
79
targets,
80
Effect.fnUntraced(function* (target) {
infra/relay/src/agentActivity/DeliveryAttempts.ts
+1
-1
@@ -68,7 +68,7 @@ export class DeliveryAttempts extends Context.Service<
68
>()("t3code-relay/agentActivity/DeliveryAttempts") {}
69
70
const SOURCE_JOB_CLAIM_LEASE_MINUTES = 10;
71
-export const DELIVERY_ATTEMPT_RETENTION_DAYS = 7;
71
+export const DELIVERY_ATTEMPT_RETENTION_DAYS = 1;
72
export const DELIVERY_ATTEMPT_PRUNE_BATCH_SIZE = 5_000;
73
// Caps each cron run so draining the pre-retention backlog cannot monopolize the database.
74
export const DELIVERY_ATTEMPT_PRUNE_MAX_BATCHES = 4;
infra/relay/src/db.ts
+1
-1
@@ -49,7 +49,7 @@ export const PlanetscaleDatabase = Effect.gen(function* () {
49
? yield* Planetscale.PostgresDatabase("RelayPostgresDatabase", {
50
name: "t3coderelay",
51
region: { slug: "us-west" },
52
- clusterSize: "PS_80",
52
+ clusterSize: "PS_160",
53
migrations: { dir: schema.out, table: "relay_migrations" },
54
replicas: 2,
55
}).pipe(RemovalPolicy.retain())