mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-29 15:52:36 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - When a run finishes but copying its files out of the sandbox fails, Paperclip holds the task and tries to recover the saved files. When recovery gives up, the task offers Retry. > - Some saved files can never be recovered: the sandbox that held them was destroyed, or Paperclip cannot prove which runs used a shared sandbox. Each Retry ran the same check again, failed again, and parked the Retry in a wait that never ends. > - The task told the person to press Retry again or to wait for a Paperclip update. That breaks the rule that recovery must work and that a Retry that is shown must work. > - This pull request makes Retry continue the task in a fresh session and a new workspace from the work that is recorded, when the saved files are provably unrecoverable or cannot be proven safe. The task says clearly that the unsaved files were not recovered. > - The benefit is that an offered Retry starts a run, and nobody waits for a fix that another click cannot bring. ## Linked Issues or Issue Description Refs #21315, #21295, #21267 **What happened?** On hosted staging, two blocked tasks offered Retry (`canRetry: true`). Each Retry was accepted, and within about 3 seconds it was parked in a wait. No run started. Every later Retry did the same. - Task A: the hold cause was `native_workspace_sync_out_retry_exhausted`. Recovery ended with `source_unavailable` (`use_alternative_strategy`). The sandbox that held the files had a signed absence proof and a `destroyed` termination receipt. Retry was parked with `saved_work_recovery_failed`: "Saving the agent's files failed. Retry to try again". - Task B: the same hold cause. Recovery ended with `allocation_ownership_ambiguous` (`service_required`), because the sandbox was a reusable sandbox that other runs also used. Each Retry opened a new recovery generation, ran the same check, and was parked with `saved_work_recovery_refused`: "Retry runs the same check again and succeeds only after Paperclip is updated." - In both tasks, the agent's turn had finished and its result was accepted. Its work was recorded outside the sandbox: a plan document and screenshot attachments for task A, and a pushed branch with an open pull request and an implementation document for task B. Root cause: admission had a branch for an accepted result whose files were not yet saved. When the recovery budget was spent, the branch always returned a `saved_work_recovery_*` wait. It did not check whether the files could ever be recovered, so the fresh-workspace path that admission already has was never reached. The automatic retained-source fallback did not help either, because it handles only the remote workspace v1 reference, and these runs use the native workspace sync v3 reference. Also, Retry opened a new recovery generation for an ownership refusal, which only repeated the same check. **Expected behavior** When the saved files are provably unrecoverable or cannot be proven safe, Retry continues the task in a fresh session and a new workspace from the recorded work. The old files are never applied and the source sandbox is not changed. No provider turn is replayed. The task says that the unsaved files could not be recovered. The Retry offer and admission agree. **Steps to reproduce** 1. Let a native run finish with an accepted result, and let its workspace copy-back fail (`native_workspace_sync_out_retry_exhausted`). 2. Let saved-work recovery end with `source_unavailable` (sandbox destroyed) or with `allocation_ownership_ambiguous` (shared reusable sandbox). 3. Press Retry. 4. Observe that the Retry receipt waits with `saved_work_recovery_failed` or `saved_work_recovery_refused`, and no run starts. Press Retry again and observe the same result. **Paperclip version or commit** Staging on `origin/master` after #21315 (`bbafa78fe2`). **Deployment mode** Hosted cloud (staging), remote Daytona sandbox runner. **Agent adapter(s) involved** `paperclip_runner` (native runtime runs). ## What Changed - `savedFilesUnrecoverable` and `unrecoverableSavedFilesFailure` (`system-recovery-state.ts`) are the one rule for saved files that no recovery can apply. The rule is true for a spent recovery whose failure is a permanent source refusal: `source_unavailable`, `allocation_ownership_ambiguous` or `historical_source_missing`. It is false for `source_binding_invalid`, because a new recovery generation can still verify that source. It is false for `archive_unsafe` and `snapshot_verification_failed`, because a fresh attempt still imports earlier saved snapshots and would fail before the agent starts. It is also false after a fresh attempt is recorded. - Admission (`explicit-native-continuation.ts`) no longer parks a Retry of an accepted result in `saved_work_recovery_*` when every live recovery of the run is unrecoverable. The Retry takes the existing fresh-workspace path (`fresh_isolated_workspace`). That path keeps all stop proofs, leaves the source sandbox and workspace untouched, and starts a fresh session. - When such a Retry starts, the task gets one system comment. The comment says that Paperclip could not recover the unsaved files, why, and that the task continues from its recorded work (comments, documents, attachments and pushed commits). The settled hold records the same text. - Retry (`task-retry.ts`) binds to an unrecoverable recovery generation. It does not open a new generation that repeats the same check. - The blocker text for unrecoverable files says that Retry continues the task in a new workspace from its recorded work. It no longer says that Retry succeeds only after an update. - `canAdoptNativeSourceRetention` and the permanent source-refusal lists moved into `system-recovery-state.ts`, so that admission, Retry and messages share them. The old modules re-export them. ## Verification - Red/green: `cd server && npx vitest run src/services/unrecoverable-saved-work-retry.test.ts`. The tests fail on `origin/master` sources (or on the earlier head for the snapshot case) and pass with this change. They are built from the two staging shapes (destroyed sandbox with `source_unavailable`, and a shared reusable sandbox with `allocation_ownership_ambiguous`): - offers a Retry that continues the task (blocker and task view agree, and the text names the fresh workspace) - starts a fresh run from the recorded work: the Retry receipt has no wait and a run, the strategy is `fresh_isolated_workspace`, the hold is settled with the fresh attempt, one system comment explains the lost files with no raw IDs, the source lease is unchanged, and no new recovery generation opens - keeps a Retry out of a fresh attempt that would import a succeeded snapshot whose archive is unsafe - `workspace-recovery-warm-handoff.test.ts` › "wakes physical preservation from HTTP Retry before passive history without replaying the provider" failed on an earlier head of this PR, which also treated `source_binding_invalid` as unrecoverable. It passes unchanged now. - Updated tests that pinned the old repeat-the-check behavior: `workspace-recovery-preparation-gates`, `task-retry`, `system-recovery-state`, `workspace-recovery-retry-copyback`. - Related suites pass: `system-recovery-state`, `workspace-recovery-preparation-gates`, `workspace-recovery-retry-copyback`, `workspace-recovery-warm-handoff`, `task-retry`, `saved-work-retry-eligibility`, `workspace-recovery-fallback`, `explicit-native-continuation`, `workspace-recovery-admission`, `task-interruption-query`, `native-workspace-sync-retention`. - `cd server && node scripts/typecheck-layers.mjs` passes (source and test layers). ## Risks - Medium-low. A Retry of an unrecoverable hold now starts a new agent turn in a new workspace instead of waiting. The turn starts only through the existing fresh-workspace admission, which keeps every stop and cleanup proof. - Unsaved files of the old run are not applied. That was already true; the change is that the task continues and says so. - `source_binding_invalid`, `snapshot_verification_failed` and `archive_unsafe` keep today's path. > For core feature work, check [`ROADMAP.md`](ROADMAP.md) first and discuss it in `#dev` before opening the PR. Feature PRs that overlap with planned core work may need to be redirected — check the roadmap first. See `CONTRIBUTING.md`. ## Model Used - Claude Opus 5.5 (`claude-opus-5-5`), Anthropic, used through Claude Code with tool use (shell, file edit, browser for read-only staging API reads). ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [ ] All Paperclip CI gates are green - [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
207 lines
14 KiB
TypeScript
207 lines
14 KiB
TypeScript
import { sql } from "drizzle-orm";
|
|
import { issueRecoveryActions } from "@paperclipai/db";
|
|
import { REMOTE_WORKSPACE_CAPTURE_POLICY_VERSION } from "./remote-workspace-snapshot-archive.js";
|
|
import { CAPTURE_POLICY_REARM_CODES, FINISHED_COORDINATOR_PHASES, PERMANENT_SOURCE_RETRY_CLASSES, UNVERIFIABLE_SOURCE_CODES, isExhaustedStopProofWait, STOP_PROOF_MAX_REARMS, STOP_PROOF_RECOVERY_KEY, STOP_PROOF_RECOVERY_SCHEMA, STOP_PROOF_WAIT_CODE,
|
|
stopProofRearmsSpent, type SystemRecoveryState } from "./system-recovery-state.js";
|
|
import { canonicalExecutionUuid } from "./execution-identity.js";
|
|
|
|
/** Source refusals that repeat on every retry (see workspace-recovery-fallback). */
|
|
export { PERMANENT_SOURCE_RETRY_CLASSES, UNVERIFIABLE_SOURCE_CODES };
|
|
export const RETAINED_SOURCE_FALLBACK_CHECK_KEY = "retainedSourceFallbackCheck";
|
|
/** Holds of an accepted result whose copy-back could not finish. */
|
|
export const EXPORT_HOLD_CAUSES = ["native_workspace_sync_out_unrecoverable", "native_workspace_sync_out_retry_exhausted"] as const;
|
|
/** A native run that failed before provider work keeps its files under a
|
|
* no-replay hold. It is recorded resolved-but-blocked: replay stays blocked
|
|
* until its files are recovered, or the task continues from the last save. */
|
|
export const NATIVE_NO_REPLAY_HOLD_CAUSE = "native_continuation_requires_reconciliation";
|
|
/** Marks the retained-file hold of a result retired as superseded while its
|
|
* workspace export failed. No result waits for those files, so once the
|
|
* bounded re-export is spent the task continues from its last save. */
|
|
export const SUPERSEDED_WORKSPACE_EXPORT_KEY = "supersededWorkspaceExport";
|
|
export const SUPERSEDED_WORKSPACE_EXPORT_SCHEMA = "paperclip.superseded-workspace-export.v1";
|
|
|
|
type HoldAction = { cause: string; status: string; outcome: string | null; evidence: Record<string, unknown> };
|
|
const list = (values: readonly string[]) => sql.join(values.map(value => sql`${value}`), sql`, `);
|
|
const field = (value: unknown, key: string) => value && typeof value === "object" ? (value as Record<string, unknown>)[key] : undefined;
|
|
|
|
/** Whether this recovery action is a retained-file hold the fallback may settle. */
|
|
export function isRetainedFileHold(action: HoldAction) {
|
|
if ((EXPORT_HOLD_CAUSES as readonly string[]).includes(action.cause)) return ["active", "escalated"].includes(action.status);
|
|
const automatic = action.evidence.automaticRecovery;
|
|
return action.cause === NATIVE_NO_REPLAY_HOLD_CAUSE
|
|
&& (["active", "escalated"].includes(action.status) || (action.status === "resolved" && action.outcome === "blocked"))
|
|
&& field(automatic, "policy") === "preserve_without_replay_v1" && field(automatic, "replay") === "blocked"
|
|
&& typeof action.evidence.runId === "string" && field(automatic, "runId") === action.evidence.runId;
|
|
}
|
|
|
|
/** SQL form of isRetainedFileHold. */
|
|
function retainedFileHoldCondition() {
|
|
return sql`((${issueRecoveryActions.cause} in (${list(EXPORT_HOLD_CAUSES)}) and ${issueRecoveryActions.status} in ('active', 'escalated'))
|
|
or (${issueRecoveryActions.cause} = ${NATIVE_NO_REPLAY_HOLD_CAUSE}
|
|
and (${issueRecoveryActions.status} in ('active', 'escalated')
|
|
or (${issueRecoveryActions.status} = 'resolved' and ${issueRecoveryActions.outcome} = 'blocked'))
|
|
and ${issueRecoveryActions.evidence}#>>'{automaticRecovery,policy}' = 'preserve_without_replay_v1'
|
|
and ${issueRecoveryActions.evidence}#>>'{automaticRecovery,replay}' = 'blocked'
|
|
and ${issueRecoveryActions.evidence}#>>'{automaticRecovery,runId}' = ${issueRecoveryActions.evidence}->>'runId'))`;
|
|
}
|
|
|
|
/** Whether a hold names the superseded export of its own source run. */
|
|
export function isSupersededWorkspaceExportHold(evidence: Record<string, unknown> | null | undefined) {
|
|
const marker = evidence?.[SUPERSEDED_WORKSPACE_EXPORT_KEY];
|
|
return field(marker, "schema") === SUPERSEDED_WORKSPACE_EXPORT_SCHEMA && typeof evidence?.runId === "string"
|
|
&& field(marker, "runId") === evidence.runId;
|
|
}
|
|
|
|
/** Whether an exhausted hold may continue from the last save: its source is
|
|
* refused permanently, its stop stayed unproven through every re-arm, or it
|
|
* holds the files of a superseded result whose bounded re-export is spent. */
|
|
export function retainedHoldFallbackEligible(evidence: Record<string, unknown> | null | undefined, state: SystemRecoveryState | null) {
|
|
if (!state || state.state !== "exhausted") return false;
|
|
if (isSupersededWorkspaceExportHold(evidence)) return true;
|
|
const failure = state.failure;
|
|
if (failure && (UNVERIFIABLE_SOURCE_CODES as readonly string[]).includes(failure.code)
|
|
&& (PERMANENT_SOURCE_RETRY_CLASSES as readonly string[]).includes(failure.retryClass)) return true;
|
|
return isExhaustedStopProofWait(state) && stopProofRearmsSpent(evidence);
|
|
}
|
|
|
|
// The source run's id as a uuid, or null when the saved text is not the
|
|
// canonical (lowercase) form. `run.id = sourceRunId` matches exactly the rows
|
|
// `run.id::text = evidence->>'runId'` matched, and it uses the run's primary
|
|
// key. The text comparison cannot, so each probe read every run (or
|
|
// finalizer, or lease) of the company.
|
|
const sourceRunId = canonicalExecutionUuid(sql`${issueRecoveryActions.evidence}->>'runId'`);
|
|
const stopProofMarker = sql`${issueRecoveryActions.evidence}->${STOP_PROOF_RECOVERY_KEY}`;
|
|
const stopProofRearms = sql`case when ${stopProofMarker}->>'schema' = ${STOP_PROOF_RECOVERY_SCHEMA}
|
|
and jsonb_typeof(${stopProofMarker}->'rearms') = 'number' then (${stopProofMarker}->>'rearms')::int else 0 end`;
|
|
const exhaustedStopProofWait = sql`(${issueRecoveryActions.evidence}#>>'{systemRecovery,state}' = 'exhausted'
|
|
and ${issueRecoveryActions.evidence}#>>'{systemRecovery,failure,code}' = ${STOP_PROOF_WAIT_CODE}
|
|
and ${issueRecoveryActions.evidence}#>>'{systemRecovery,failure,retryClass}' = 'recheck_evidence')`;
|
|
|
|
// A stale (lapsed or expiry-less) owner of an unfinished coordinator waits for
|
|
// the abandoned-owner settlement: the attempt would refuse it, and the passive
|
|
// sweep revisits the hold after it. The re-arm itself releases a lapsed owner
|
|
// of a finished coordinator (lapsedFinishedCoordinatorOwner), because no
|
|
// settlement ever would.
|
|
const staleUnfinishedFinalizerOwner = sql`exists (select 1 from native_run_finalizations finalizer
|
|
where finalizer.company_id = ${issueRecoveryActions.companyId} and finalizer.run_id = ${sourceRunId}
|
|
and finalizer.lease_owner is not null and coalesce(finalizer.lease_expires_at <= now(), true)
|
|
and finalizer.phase not in (${list(FINISHED_COORDINATOR_PHASES)}))`;
|
|
|
|
/** An exhausted unproven-stop hold whose next bounded re-arm is pending. Holds
|
|
* saved by older releases carry no marker and are due immediately. A live
|
|
* finalizer lease makes the re-arm due at its expiry (stopProofRearmDueAt). */
|
|
export function stopProofRearmPendingCondition() {
|
|
return sql`(${issueRecoveryActions.status} in ('active', 'escalated')
|
|
and ${exhaustedStopProofWait}
|
|
and not ${staleUnfinishedFinalizerOwner}
|
|
and ${issueRecoveryActions.evidence}->'retainedSourceFallback' is null
|
|
and ${issueRecoveryActions.evidence}->'executionReconciliation' is null
|
|
and ${stopProofRearms} < ${STOP_PROOF_MAX_REARMS})`;
|
|
}
|
|
|
|
/** When the next re-arm is due, in epoch milliseconds (0 = now): its backoff,
|
|
* and no earlier than the expiry of a controller or finalizer lease that the
|
|
* source run still holds, so a held run is checked at that deadline only. */
|
|
export function stopProofRearmDueAt() {
|
|
return sql`greatest(case when ${stopProofMarker}->>'schema' = ${STOP_PROOF_RECOVERY_SCHEMA}
|
|
and jsonb_typeof(${stopProofMarker}->'nextRearmAt') = 'number' then (${stopProofMarker}->>'nextRearmAt')::bigint else 0 end,
|
|
${sourceRunLeasesExpireAt()})`;
|
|
}
|
|
|
|
/** The latest expiry of a controller or finalizer lease the source run holds (0 = none). */
|
|
function sourceRunLeasesExpireAt() {
|
|
return sql`greatest(coalesce((select (extract(epoch from source.controller_lease_expires_at) * 1000)::bigint from heartbeat_runs source
|
|
where source.company_id = ${issueRecoveryActions.companyId} and source.id = ${sourceRunId}), 0),
|
|
coalesce((select max((extract(epoch from finalizer.lease_expires_at) * 1000)::bigint) from native_run_finalizations finalizer
|
|
where finalizer.company_id = ${issueRecoveryActions.companyId} and finalizer.run_id = ${sourceRunId}
|
|
and finalizer.lease_owner is not null), 0))`;
|
|
}
|
|
|
|
export function stopProofRearmDueCondition(now: number) {
|
|
return sql`(${stopProofRearmPendingCondition()} and ${stopProofRearmDueAt()} <= ${now}::bigint)`;
|
|
}
|
|
|
|
const capturePolicyVersion = sql`case when jsonb_typeof(${issueRecoveryActions.evidence}#>'{systemRecovery,capturePolicyVersion}') = 'number'
|
|
then (${issueRecoveryActions.evidence}#>>'{systemRecovery,capturePolicyVersion}')::int else 1 end`;
|
|
|
|
/** An exhausted save whose files a previous capture policy refused, not yet
|
|
* retried under the current policy (isCapturePolicyRearmable). Saves exhausted
|
|
* by older releases carry no version and are due at once, with no migration. */
|
|
export function capturePolicyRearmPendingCondition() {
|
|
return sql`(${issueRecoveryActions.status} in ('active', 'escalated')
|
|
and ${issueRecoveryActions.evidence}#>>'{systemRecovery,state}' = 'exhausted'
|
|
and ${issueRecoveryActions.evidence}#>>'{systemRecovery,phase}' = 'preserve_files'
|
|
and ${issueRecoveryActions.evidence}#>>'{systemRecovery,failure,code}' in (${list(CAPTURE_POLICY_REARM_CODES)})
|
|
and ${capturePolicyVersion} < ${REMOTE_WORKSPACE_CAPTURE_POLICY_VERSION}
|
|
and not ${staleUnfinishedFinalizerOwner}
|
|
and ${issueRecoveryActions.evidence}->'retainedSourceFallback' is null
|
|
and ${issueRecoveryActions.evidence}->'executionReconciliation' is null)`;
|
|
}
|
|
|
|
export function capturePolicyRearmDueAt() {
|
|
return sourceRunLeasesExpireAt();
|
|
}
|
|
|
|
export function capturePolicyRearmDueCondition(now: number) {
|
|
return sql`(${capturePolicyRearmPendingCondition()} and ${capturePolicyRearmDueAt()} <= ${now}::bigint)`;
|
|
}
|
|
|
|
const check = sql`${issueRecoveryActions.evidence}->${RETAINED_SOURCE_FALLBACK_CHECK_KEY}`;
|
|
// New stop evidence (any change to an allocation of the source run, such as a
|
|
// late provider stop receipt) after the last deferred check reconsiders the
|
|
// hold once, even after its bounded checks are spent.
|
|
const leaseChangedSinceCheck = sql`(jsonb_typeof(${check}->'checkedAt') = 'number' and exists (
|
|
select 1 from environment_leases lease where lease.company_id = ${issueRecoveryActions.companyId}
|
|
and lease.heartbeat_run_id = ${sourceRunId}
|
|
and lease.updated_at > to_timestamp((${check}->>'checkedAt')::bigint / 1000.0)))`;
|
|
|
|
/**
|
|
* An exhausted hold that the fallback may still settle: its source is refused
|
|
* permanently, or a sibling recovery action of the same run saved its files.
|
|
* The recovery worker discovers it like other unfinished work. A deferred
|
|
* check of the same generation waits for its recorded time; a bounded number of
|
|
* deferrals ends with no time, so the worker stops scheduling it (new input,
|
|
* Retry or a new generation reconsiders it).
|
|
*/
|
|
export function retainedSourceFallbackPendingCondition() {
|
|
return sql`((${issueRecoveryActions.status} in ('active', 'escalated') or ${retainedFileHoldCondition()})
|
|
and ${issueRecoveryActions.evidence}#>>'{systemRecovery,state}' = 'exhausted'
|
|
and ${issueRecoveryActions.evidence}->'retainedSourceFallback' is null
|
|
and ((${retainedFileHoldCondition()}
|
|
and ${issueRecoveryActions.evidence}#>>'{systemRecovery,failure,code}' in (${list(UNVERIFIABLE_SOURCE_CODES)})
|
|
and ${issueRecoveryActions.evidence}#>>'{systemRecovery,failure,retryClass}' in (${list(PERMANENT_SOURCE_RETRY_CLASSES)})
|
|
and exists (select 1 from heartbeat_runs source where source.company_id = ${issueRecoveryActions.companyId}
|
|
and source.id = ${sourceRunId}
|
|
and source.runner_profile_json#>>'{remoteWorkspace,state}' = 'prepared'))
|
|
or (${retainedFileHoldCondition()}
|
|
and ${issueRecoveryActions.evidence}#>>'{${sql.raw(SUPERSEDED_WORKSPACE_EXPORT_KEY)},schema}' = ${SUPERSEDED_WORKSPACE_EXPORT_SCHEMA}
|
|
and ${issueRecoveryActions.evidence}#>>'{${sql.raw(SUPERSEDED_WORKSPACE_EXPORT_KEY)},runId}' = ${issueRecoveryActions.evidence}->>'runId'
|
|
and exists (select 1 from heartbeat_runs source where source.company_id = ${issueRecoveryActions.companyId}
|
|
and source.id = ${sourceRunId}
|
|
and source.runner_profile_json#>>'{remoteWorkspace,state}' = 'prepared'))
|
|
or (${retainedFileHoldCondition()} and ${exhaustedStopProofWait} and ${stopProofRearms} >= ${STOP_PROOF_MAX_REARMS}
|
|
and exists (select 1 from heartbeat_runs source where source.company_id = ${issueRecoveryActions.companyId}
|
|
and source.id = ${sourceRunId}
|
|
and source.runner_profile_json#>>'{remoteWorkspace,state}' = 'prepared'))
|
|
or ((${issueRecoveryActions.status} in ('active', 'escalated') or ${retainedFileHoldCondition()})
|
|
and exists (select 1 from issue_recovery_actions sibling
|
|
where sibling.company_id = ${issueRecoveryActions.companyId} and sibling.source_issue_id = ${issueRecoveryActions.sourceIssueId}
|
|
and sibling.id <> ${issueRecoveryActions.id} and sibling.evidence->>'runId' = ${issueRecoveryActions.evidence}->>'runId'
|
|
and sibling.evidence#>>'{systemRecovery,state}' = 'complete'
|
|
and sibling.evidence#>>'{workspaceRecovery,status}' = 'recovered')))
|
|
and (${check} is null
|
|
or ${check}->>'generationId' is distinct from ${issueRecoveryActions.evidence}#>>'{systemRecovery,generationId}'
|
|
or ${leaseChangedSinceCheck}
|
|
or jsonb_typeof(${check}->'nextCheckAt') = 'number'))`;
|
|
}
|
|
|
|
/** When the pending fallback is next due, in epoch milliseconds (0 = now). */
|
|
export function retainedSourceFallbackDueAt() {
|
|
return sql`case when ${check}->>'generationId' = ${issueRecoveryActions.evidence}#>>'{systemRecovery,generationId}'
|
|
and jsonb_typeof(${check}->'nextCheckAt') = 'number' then (${check}->>'nextCheckAt')::bigint else 0 end`;
|
|
}
|
|
|
|
export function retainedSourceFallbackDueCondition(now: number) {
|
|
return sql`(${retainedSourceFallbackPendingCondition()} and ${retainedSourceFallbackDueAt()} <= ${now}::bigint)`;
|
|
}
|