Skip to content

Commit b50d739

Browse files
d-csTrigger.dev RepoOps
authored andcommitted
fix(webapp): keep finished runs' Redis snapshot state for 4 days instead of 14
Finished runs' execution snapshot state in the Redis snapshot store now expires after 4 days instead of 14, keeping the store's memory bounded to a few days of completions. Runs that are still active are unaffected, and runs that finished before this change keep their existing expiry. Mono-RevId: 6609ff96d5f3872e964e73072f0465e5fba4f1db
1 parent 59597ac commit b50d739

5 files changed

Lines changed: 6 additions & 6 deletions

File tree

‎apps/webapp/app/v3/utils/snapshotStoreConnection.server.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { RedisSnapshotStore, type SnapshotStoreMetrics } from "@internal/run-sto
44
const COMMAND_TIMEOUT_MS = 500;
55
const CONNECT_TIMEOUT_MS = 500;
66
const POLICY_CHECK_INTERVAL_MS = 30_000;
7-
const COMPLETED_TTL_MS = 14 * 24 * 60 * 60 * 1_000;
7+
const COMPLETED_TTL_MS = 4 * 24 * 60 * 60 * 1_000;
88

99
/** Infrastructure only. Rollout modes belong to the existing polled flags, not this URL. */
1010
export function snapshotClusterOptions(endpoint: string) {

‎internal-packages/run-store/src/redisSnapshotStore.residencyMarker.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Item 8d: a terminal MIRRORED run's residency marker expires WITH its state (its Postgres copy is
2-
// authoritative after 14 days, so no permanent per-run marker accumulates), while a REDIS-PRIMARY marker
2+
// authoritative once the completed TTL passes, so no permanent per-run marker accumulates), while a REDIS-PRIMARY marker
33
// is kept forever so an expired redis-primary run resolves to expired/fail-closed rather than empty
44
// Postgres. Proven against REAL Redis (testcontainers, no mocks).
55
import { describe, expect } from "vitest";

‎internal-packages/run-store/src/redisSnapshotStore.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1483,7 +1483,7 @@ export class RedisSnapshotStore {
14831483
for i = 1, high do
14841484
redis.call('PEXPIRE', wpKey(i), ttlMs)
14851485
end
1486-
-- A MIRRORED run's residency marker expires WITH its state: after 14 days the terminal keys are
1486+
-- A MIRRORED run's residency marker expires WITH its state: once the completed TTL passes the terminal keys are
14871487
-- gone and its complete Postgres copy is authoritative, so a read cleanly misses to Postgres and
14881488
-- no permanent per-run marker accumulates. A REDIS-PRIMARY marker is kept forever (no PEXPIRE):
14891489
-- it is the only record the run was ever redis-primary, so an expired redis-primary run resolves

‎internal-packages/run-store/src/snapshotKeys.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export function snapshotKeys(runId: string): SnapshotKeys {
4141

4242
/**
4343
* The Redis-primary residency marker key. Shares the run's partition tag but is a SEPARATE physical
44-
* key: it has no TTL ever, so it outlives the run-state keys once they take the terminal 14-day TTL.
44+
* key: it has no TTL ever, so it outlives the run-state keys once they take the terminal completed TTL.
4545
*/
4646
export function residencyKey(runId: string): string {
4747
return `${SNAPSHOT_NAMESPACE}:res:{${partitionTag(runToPartition(runId))}}:${runId}`;

‎scripts/compare-snapshot-stores.mts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,8 @@ function emptySkipped(): SkippedRuns {
255255
return { postgres: 0, redisPrimary: 0, noSnapshots: 0, unknown: 0, expired: 0 };
256256
}
257257

258-
/** Finished runs keep their MemoryDB keys for this long, then the whole keyspace expires. */
259-
export const FINISHED_RUN_RETENTION_MS = 14 * 24 * 60 * 60 * 1000;
258+
/** Finished runs keep their MemoryDB keys for this long, then the whole keyspace expires. Matches the webapp's completed TTL. */
259+
export const FINISHED_RUN_RETENTION_MS = 4 * 24 * 60 * 60 * 1000;
260260

261261
function isExpired(
262262
rows: PostgresSnapshotRow[],

0 commit comments

Comments
 (0)