Commit a3eec5d
fix: skip expired snapshots and fallback to fresh sandbox (#412)
* fix: skip expired snapshots and fallback to fresh sandbox on failure
Accounts with expired Vercel snapshots caused Sandbox.create() to throw
"Status code 400 is not ok" with no recovery path.
Changes:
- Extract getValidSnapshotId to its own lib file (SRP)
- Both processCreateSandbox and createSandboxFromSnapshot use it
- Add fallback: if snapshot creation fails, create a fresh sandbox
- DRY: processCreateSandbox uses createSandboxWithFallback helper
so createSandbox({}) is only called once
- Add tests for getValidSnapshotId (5 tests)
- Add snapshot expiry and fallback tests to existing test files
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* refactor: DRY createSandbox({}) in createSandboxFromSnapshot
Single createSandbox({}) call path instead of duplicating it in
both the catch block and the else branch.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* refactor: extract createSandboxWithFallback to own lib file, add error logging
- Extract createSandboxWithFallback to lib/sandbox/createSandboxWithFallback.ts (SRP)
- processCreateSandbox and createSandboxFromSnapshot use it / follow same pattern
- Log snapshot creation errors before falling back to fresh sandbox
- Add 4 unit tests for createSandboxWithFallback
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* refactor: DRY createSandboxFromSnapshot via shared createSandboxWithFallback
- createSandboxFromSnapshot now delegates to createSandboxWithFallback
instead of duplicating snapshot/fresh fallback logic
- createSandboxWithFallback returns full SandboxCreateResult + fromSnapshot
- Update tests to match new delegation pattern
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* refactor: consolidate processCreateSandbox to use createSandboxFromSnapshot
processCreateSandbox now delegates sandbox creation to
createSandboxFromSnapshot instead of calling getValidSnapshotId,
createSandboxWithFallback, and insertAccountSandbox directly.
This eliminates the duplicated snapshot lookup + fallback + DB insert
logic between the two functions. processCreateSandbox adds only
the prompt-triggering behavior on top.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* fix: treat exact-expiry and unparsable timestamps as invalid snapshots
Use <= instead of < so snapshots expiring exactly now are treated as
expired. Add NaN check so unparsable expires_at values don't slip
through as valid.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>1 parent f010076 commit a3eec5d
File tree
9 files changed
+328
-514
lines changed- lib/sandbox
- __tests__
9 files changed
+328
-514
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
9 | 9 | | |
10 | | - | |
11 | | - | |
| 10 | + | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
15 | | - | |
| 14 | + | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
| 31 | + | |
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| 39 | + | |
39 | 40 | | |
40 | 41 | | |
41 | 42 | | |
42 | 43 | | |
43 | 44 | | |
44 | 45 | | |
45 | 46 | | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
| 47 | + | |
| 48 | + | |
50 | 49 | | |
51 | 50 | | |
52 | 51 | | |
53 | | - | |
54 | | - | |
55 | | - | |
| 52 | + | |
56 | 53 | | |
57 | 54 | | |
58 | | - | |
59 | | - | |
| 55 | + | |
| 56 | + | |
60 | 57 | | |
61 | 58 | | |
62 | 59 | | |
63 | | - | |
| 60 | + | |
64 | 61 | | |
65 | 62 | | |
66 | 63 | | |
67 | | - | |
| 64 | + | |
68 | 65 | | |
69 | 66 | | |
70 | 67 | | |
| |||
74 | 71 | | |
75 | 72 | | |
76 | 73 | | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
81 | 86 | | |
82 | 87 | | |
83 | 88 | | |
84 | 89 | | |
85 | 90 | | |
86 | 91 | | |
87 | 92 | | |
88 | | - | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
89 | 121 | | |
90 | 122 | | |
91 | 123 | | |
| |||
0 commit comments