Skip to content

Commit 43da771

Browse files
committed
refactor(run-store,run-engine,webapp): make redis-read reads org-gated, drop the percentage
Reads at redis-read were gated by a per-run hash percentage that production always pinned to 100, so the sampling never ran. The organisation is the ramp unit, so an org at redis-read now reads every one of its runs from Redis, with Postgres as the fallback on a miss or error. Removes the readPercent option, the hash sampling, and the tests that only exercised partial percentages.
1 parent 474405a commit 43da771

17 files changed

Lines changed: 51 additions & 178 deletions

‎apps/webapp/app/v3/snapshotStoreInstance.server.ts‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,7 @@ const instance = singleton<Instance | undefined>("snapshotStoreInstance", () =>
114114
store: redisSnapshotStore,
115115
modeResolver: snapshotStoreModeResolver,
116116
halted: snapshotStoreHalted,
117-
// Pinned: the field defaults to 0, which would mean no read ever reaches Redis. The
118-
// organisation is the ramp unit, so there is no percentage to ramp.
119-
readPercent: 100,
117+
// The organisation is the ramp unit.
120118
metrics: metrics.decorator,
121119
onAppendFailure: async (args) => {
122120
const enqueue = getSnapshotRepairEnqueuer();

‎internal-packages/run-engine/src/engine/tests/helpers/decoratedStore.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ export function buildDecoratedStore(opts: {
3232
prisma: PrismaClient;
3333
redisOptions: RedisOptions;
3434
mode: SnapshotStoreMode;
35-
readPercent?: number;
3635
faults?: SnapshotFaultInjector;
3736
onAppendFailure?: SnapshotRepairEnqueuer;
3837
}): DecoratedStoreHarness {
@@ -50,7 +49,6 @@ export function buildDecoratedStore(opts: {
5049
{
5150
store: redis,
5251
mode: opts.mode,
53-
readPercent: opts.readPercent ?? 100,
5452
...(opts.faults && { faults: opts.faults }),
5553
onAppendFailure: async (args) => {
5654
repairs.push(args);

‎internal-packages/run-engine/src/engine/tests/snapshotStoreChaos.test.ts‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ describe("snapshot store crash boundaries", () => {
112112
prisma,
113113
redisOptions,
114114
mode: "redis-read",
115-
readPercent: 100,
116115
faults: faults.hook,
117116
});
118117
const engine = new RunEngine(engineOptions(prisma, redisOptions, harness, 200) as never);
@@ -170,7 +169,6 @@ describe("snapshot store crash boundaries", () => {
170169
prisma,
171170
redisOptions,
172171
mode: "redis-read",
173-
readPercent: 100,
174172
faults: faults.hook,
175173
});
176174
const engine = new RunEngine(engineOptions(prisma, redisOptions, harness, 200) as never);
@@ -286,7 +284,6 @@ describe("snapshot store crash boundaries", () => {
286284
prisma,
287285
redisOptions,
288286
mode: "redis-read",
289-
readPercent: 100,
290287
faults: faults.hook,
291288
});
292289
const engine = new RunEngine(engineOptions(prisma, redisOptions, harness, 200) as never);

‎internal-packages/run-engine/src/engine/tests/snapshotStoreReadGate.test.ts‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ describe("snapshot store read gate", () => {
6060
prisma,
6161
redisOptions,
6262
mode: "redis-read",
63-
readPercent: 100,
6463
});
6564
const engine = new RunEngine(engineOptions(prisma, redisOptions, harness) as never);
6665

@@ -116,7 +115,6 @@ describe("snapshot store read gate", () => {
116115
prisma,
117116
redisOptions,
118117
mode: "redis-read",
119-
readPercent: 100,
120118
});
121119
const engine = new RunEngine(engineOptions(prisma, redisOptions, harness) as never);
122120

@@ -162,7 +160,6 @@ describe("snapshot store read gate", () => {
162160
prisma,
163161
redisOptions,
164162
mode: "redis-read",
165-
readPercent: 100,
166163
});
167164
const engine = new RunEngine(engineOptions(prisma, redisOptions, harness) as never);
168165

@@ -219,7 +216,6 @@ describe("snapshot store read gate", () => {
219216
prisma,
220217
redisOptions,
221218
mode: "redis-read",
222-
readPercent: 100,
223219
});
224220
const engine = new RunEngine(engineOptions(prisma, redisOptions, harness) as never);
225221

@@ -287,7 +283,6 @@ describe("snapshot store read gate", () => {
287283
prisma,
288284
redisOptions,
289285
mode: "redis-read",
290-
readPercent: 100,
291286
});
292287
const engineOn = new RunEngine(engineOptions(prisma, redisOptions, on) as never);
293288
try {

‎internal-packages/run-store/src/taskRunExecutionSnapshotStore.checkpoint.test.ts‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ describe("a checkpoint on a snapshot served from Redis", () => {
4444
const decorated = new TaskRunExecutionSnapshotStore(plain as unknown as RunStore, {
4545
store: redis,
4646
mode: "redis-read",
47-
readPercent: 100,
4847
});
4948
try {
5049
const env = await seedSnapshotEnvironment(prisma);
@@ -121,7 +120,6 @@ describe("a checkpoint on a snapshot served from Redis", () => {
121120
const decorated = new TaskRunExecutionSnapshotStore(store as unknown as RunStore, {
122121
store: redis,
123122
mode: "redis-only",
124-
readPercent: 100,
125123
});
126124
try {
127125
const env = await seedSnapshotEnvironment(prisma);
@@ -191,7 +189,6 @@ describe("a checkpoint on a snapshot served from Redis", () => {
191189
const decorated = new TaskRunExecutionSnapshotStore(plain as unknown as RunStore, {
192190
store: redis,
193191
mode: "redis-read",
194-
readPercent: 100,
195192
metrics: {
196193
recordWrite: () => {},
197194
recordAppendFailed: () => {},

‎internal-packages/run-store/src/taskRunExecutionSnapshotStore.hardStop.test.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ function storeWith(options: {
2222
mode: options.mode,
2323
...(options.resolver && { modeResolver: options.resolver }),
2424
...(options.halted !== undefined && { halted: () => options.halted === true }),
25-
readPercent: 100,
2625
});
2726
}
2827

‎internal-packages/run-store/src/taskRunExecutionSnapshotStore.hotPath.test.ts‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ describe("a Redis that stops answering", () => {
210210
const redis = new RedisSnapshotStore({ redisOptions, completedTtlMs: COMPLETED_TTL_MS });
211211
const decorated = new TaskRunExecutionSnapshotStore(
212212
new PostgresRunStore({ prisma, readOnlyPrisma: prisma }) as unknown as RunStore,
213-
{ store: redis, mode: "redis-read", readPercent: 100 }
213+
{ store: redis, mode: "redis-read" }
214214
);
215215
try {
216216
const env = await seedSnapshotEnvironment(prisma);
@@ -243,7 +243,7 @@ describe("a Redis that stops answering", () => {
243243
});
244244
const decorated = new TaskRunExecutionSnapshotStore(
245245
new PostgresRunStore({ prisma, readOnlyPrisma: prisma }) as unknown as RunStore,
246-
{ store: redis, mode: "redis-read", readPercent: 100 }
246+
{ store: redis, mode: "redis-read" }
247247
);
248248
try {
249249
const env = await seedSnapshotEnvironment(prisma);
@@ -285,7 +285,6 @@ describe("a Redis that stops answering", () => {
285285
const decorated = new TaskRunExecutionSnapshotStore(plain as unknown as RunStore, {
286286
store: redis,
287287
mode: "redis-read",
288-
readPercent: 100,
289288
});
290289
try {
291290
const env = await seedSnapshotEnvironment(prisma);
@@ -365,7 +364,6 @@ describe("a Redis that stops answering", () => {
365364
const decorated = new TaskRunExecutionSnapshotStore(plain as unknown as RunStore, {
366365
store: redis,
367366
mode: "redis-read",
368-
readPercent: 100,
369367
metrics: {
370368
recordWrite: () => {},
371369
recordAppendFailed: () => {},

‎internal-packages/run-store/src/taskRunExecutionSnapshotStore.orgReads.test.ts‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ function harness(opts: {
1616
globalMode: SnapshotStoreMode;
1717
readModeFor?: (runId: string, environmentId?: string) => SnapshotStoreMode;
1818
anyOrgReadEnabled?: () => boolean;
19-
readPercent?: number;
2019
}) {
2120
const redisTouched: string[] = [];
2221
const redis = new Proxy({} as RedisSnapshotStore, {
@@ -55,7 +54,6 @@ function harness(opts: {
5554
store: redis,
5655
mode: opts.globalMode,
5756
modeResolver,
58-
readPercent: opts.readPercent ?? 100,
5957
});
6058

6159
return {
@@ -133,25 +131,23 @@ describe("org-scoped read routing", () => {
133131
describe("resolver is transparent to routing when no per-org override applies", () => {
134132
const ids = Array.from({ length: 500 }, (_, n) => `run_cohort_${n}_${n * 7919}`);
135133

136-
function plain(mode: SnapshotStoreMode, readPercent: number): CohortProbe {
134+
function plain(mode: SnapshotStoreMode): CohortProbe {
137135
return new TaskRunExecutionSnapshotStore({} as unknown as RunStore, {
138136
store: {} as never,
139137
mode,
140-
readPercent,
141138
}) as unknown as CohortProbe;
142139
}
143140

144141
it("routes every run exactly as the global dial did before per-org reads existed", () => {
145142
// A resolver that always answers the global mode, with no org read-enabled. The short-circuit
146-
// does not fire (global IS a read position), effective === global, and the hash path is
147-
// untouched, so the population must route identically to a store with no resolver at all.
143+
// does not fire (global IS a read position) and effective === global, so the population must
144+
// route identically to a store with no resolver at all.
148145
const withResolver = harness({
149146
globalMode: "redis-read",
150-
readPercent: 50,
151147
anyOrgReadEnabled: () => false,
152148
readModeFor: () => "redis-read",
153149
}).probe;
154-
const withoutResolver = plain("redis-read", 50);
150+
const withoutResolver = plain("redis-read");
155151

156152
for (const id of ids) {
157153
expect(withResolver.readsFromRedis(id)).toBe(withoutResolver.readsFromRedis(id));

‎internal-packages/run-store/src/taskRunExecutionSnapshotStore.priming.test.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ function harness(opts: {
7070
store: redis,
7171
mode: opts.globalMode,
7272
modeResolver,
73-
readPercent: 100,
7473
});
7574

7675
return { decorated, runOrg, delegateTouched, dbReads: () => dbReads };

‎internal-packages/run-store/src/taskRunExecutionSnapshotStore.rampSites.test.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ function harness(global: SnapshotStoreMode, perOrg: SnapshotStoreMode) {
4545
store: redis,
4646
mode: global,
4747
modeResolver,
48-
readPercent: 100,
4948
});
5049

5150
return { decorated, appends };

0 commit comments

Comments
 (0)