Back off checkpoint capture after repeated failures #4517
Closedyashranaway(GitHub profile, opens in a new tab)wants to merge 5 commits into
main fromrefs/pull/4517/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/server/src/checkpointing/CaptureBackoff.ts lines 66 to 70OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +50,21 @@50+}51+52+interface WorkspaceRecord<E> {53+ consecutiveFailures: number;54+ skipUntilMs: number;55+ lastError: E;56+}57+58+/**59+ * Tracks capture health per workspace. Callers ask whether to skip, then60+ * report the outcome of any capture they actually ran.61+ */62+export function makeCaptureBackoff<E>() {63+ const recordByCwd = new Map<string, WorkspaceRecord<E>>();64+65+ return {66+ evaluate(cwd: string, nowMs: number): CaptureBackoffDecision<E> {67+ const record = recordByCwd.get(cwd);68+ if (!record || nowMs >= record.skipUntilMs) {69+ return { skip: false, remainingMs: 0, lastError: null };70+ }apps/server/src/checkpointing/CaptureBackoff.ts line 68OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +48,21 @@48+ const scale = 2 ** Math.min(doublings, 10);49+ return Math.min(BASE_COOLDOWN_MS * scale, MAX_COOLDOWN_MS);50+}51+52+interface WorkspaceRecord<E> {53+ consecutiveFailures: number;54+ skipUntilMs: number;55+ lastError: E;56+}57+58+/**59+ * Tracks capture health per workspace. Callers ask whether to skip, then60+ * report the outcome of any capture they actually ran.61+ */62+export function makeCaptureBackoff<E>() {63+ const recordByCwd = new Map<string, WorkspaceRecord<E>>();64+65+ return {66+ evaluate(cwd: string, nowMs: number): CaptureBackoffDecision<E> {67+ const record = recordByCwd.get(cwd);68+ if (!record || nowMs >= record.skipUntilMs) {
- apps/server/src/checkpointing/CheckpointStore.ts line 138Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -122,3 +125,14 @@122125 const captureCheckpoint: CheckpointStore["Service"]["captureCheckpoint"] = Effect.fn(123126 "captureCheckpoint",124127 )(function* (input) {128+ const startedAt = yield* Clock.currentTimeMillis;129+ const decision = captureBackoff.evaluate(input.cwd, startedAt);130+ if (decision.skip && decision.lastError) {131+ // Spawning git here would repeat a capture that cannot succeed, so132+ // replay the failure the caller already handles instead of burning a133+ // CPU core and leaving another orphaned tmp_pack behind.134+ yield* Effect.logDebug("Skipping checkpoint capture during failure cooldown", {135+ cwdLength: input.cwd.length,136+ remainingMs: decision.remainingMs,137+ });138+ return yield* Effect.fail(decision.lastError);
- apps/server/src/checkpointing/CaptureBackoff.ts line 117Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -0,0 +90,21 @@90+ * released past an expired cooldown reserves the attempt, and any read91+ * refreshes eviction recency so a workspace being actively skipped is not92+ * evicted by churn from unrelated workspaces.93+ */94+ beginAttempt(cwd: string, nowMs: number): CaptureBackoffDecision<E> {95+ const record = recordByCwd.get(cwd);96+ if (!record) {97+ return { skip: false, remainingMs: 0, lastError: null };98+ }99+100+ touch(cwd, record);101+ if (nowMs < record.skipUntilMs) {102+ return {103+ skip: true,104+ remainingMs: record.skipUntilMs - nowMs,105+ lastError: record.lastError,106+ };107+ }108+109+ record.skipUntilMs = nowMs + ATTEMPT_RESERVATION_MS;110+ return { skip: false, remainingMs: 0, lastError: null };apps/server/src/checkpointing/CheckpointStore.ts line 156Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -125,2 +132,20 @@132+ // replay the failure the caller already handles instead of burning a133+ // CPU core and leaving another orphaned tmp_pack behind.134+ yield* Effect.logDebug("Skipping checkpoint capture during failure cooldown", {135+ cwdLength: input.cwd.length,136+ remainingMs: decision.remainingMs,137+ });138+ return yield* Effect.fail(decision.lastError);139+ }140+125141 const checkpoints = yield* resolveCheckpoints("CheckpointStore.captureCheckpoint", input.cwd);126- return yield* checkpoints.captureCheckpoint(input);142+ return yield* checkpoints.captureCheckpoint(input).pipe(143+ Effect.tap(() => Effect.sync(() => captureBackoff.recordSuccess(input.cwd))),144+ Effect.tapError((error) =>145+ Effect.gen(function* () {146+ const failedAt = yield* Clock.currentTimeMillis;147+ const outcome = captureBackoff.recordFailure(input.cwd, failedAt, error);148+ yield* Effect.logWarning("Checkpoint capture failed", {149+ cwdLength: input.cwd.length,150+ consecutiveFailures: outcome.consecutiveFailures,151+ cooldownMs: outcome.cooldownMs,
t3dotgg(GitHub profile, opens in a new tab) added labelsvouch:trusted
t3dotgg(GitHub profile, opens in a new tab) removed labelsvouch:unvouched
Sign in to join this conversation.


Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
15b00203-5b08-41fe-9987-cfe2de42dcb7You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share