Skip to content

Commit 22095c2

Browse files
sweetmantechclaude
andcommitted
fix(sandbox): actually delegate getLifecycleDueAtMs to the extracted helpers
In the previous SRP refactor I created computeInactivityDueAtMs.ts and computeExpiryDueAtMs.ts but the Write to update getLifecycleDueAtMs.ts errored on "File has not been read yet" and I missed it in the batch output. The two helper files were left as orphans while the original file kept its inline copies — visible by the SANDBOX_*_MS imports + both functions still inlined. Now properly imports computeInactivityDueAtMs / computeExpiryDueAtMs and the parent file just composes them. No behavior change. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 30ef641 commit 22095c2

1 file changed

Lines changed: 4 additions & 29 deletions

File tree

‎lib/sandbox/getLifecycleDueAtMs.ts‎

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,11 @@
1-
import{
2-
SANDBOX_EXPIRES_BUFFER_MS,
3-
SANDBOX_INACTIVITY_TIMEOUT_MS,
4-
}from"@/lib/sandbox/sandboxLifecycleConfig";
5-
import{isoToEpochMs}from"@/lib/sandbox/isoToEpochMs";
1+
import{computeExpiryDueAtMs}from"@/lib/sandbox/computeExpiryDueAtMs";
2+
import{computeInactivityDueAtMs}from"@/lib/sandbox/computeInactivityDueAtMs";
63
importtype{Tables}from"@/types/database.types";
74

85
/**
96
* Computes when the lifecycle workflow should next wake up for a
10-
* session. Returns the earlier of:
11-
* - inactivity due — `last_activity_at` (or `updated_at`) +
12-
* SANDBOX_INACTIVITY_TIMEOUT_MS, overridden by `hibernate_after`
13-
* if set
14-
* - expiry due — `sandbox_expires_at` minus
15-
* SANDBOX_EXPIRES_BUFFER_MS, so we pause before Vercel hard-stops
16-
*
17-
* Output is epoch milliseconds. Used by both the workflow (for
7+
* session. Returns the earlier of the inactivity-due time and the
8+
* expiry-due time. Used by both the workflow (for
189
* `sleep(new Date(wakeAtMs))`) and the stale-run detector in the
1910
* kick logic.
2011
*
@@ -32,19 +23,3 @@ export function getLifecycleDueAtMs(
3223
if(expiryDue===null)returninactivityDue;
3324
returnMath.min(inactivityDue,expiryDue);
3425
}
35-
36-
functioncomputeInactivityDueAtMs(
37-
row: Pick<Tables<"sessions">,"hibernate_after"|"last_activity_at"|"updated_at">,
38-
): number{
39-
consthibernateAfter=isoToEpochMs(row.hibernate_after);
40-
if(hibernateAfter!==null)returnhibernateAfter;
41-
constlastActivity=isoToEpochMs(row.last_activity_at);
42-
constfallback=lastActivity??isoToEpochMs(row.updated_at)??Date.now();
43-
returnfallback+SANDBOX_INACTIVITY_TIMEOUT_MS;
44-
}
45-
46-
functioncomputeExpiryDueAtMs(row: Pick<Tables<"sessions">,"sandbox_expires_at">): number|null{
47-
constexpiresAt=isoToEpochMs(row.sandbox_expires_at);
48-
if(expiresAt===null)returnnull;
49-
returnexpiresAt-SANDBOX_EXPIRES_BUFFER_MS;
50-
}

0 commit comments

Comments
 (0)