Repository navigation
Commit a6014b9
committed
fix(codex): serialize native-main refresh on the CODEX_HOME claim
Reimplements #3000 (author @MarcTCruz) for the #2999 lock-scope half.
The refresh lock is keyed on the grant fingerprint and lives under
OPENCODEX_HOME (src/codex/account-store.ts:420-422, via getConfigDir).
The file it protects is auth.json under CODEX_HOME, which every OpenCodex
install on the machine shares regardless of its own home. Two proxies with
distinct OPENCODEX_HOMEs therefore took two unrelated locks and refreshed the
one credential concurrently; the loser published its rotated grant over the
winner's and the provider then rejected it.
The outer lock is now withNativeMainExclusiveClaim on
resolveNativeProfileContext(), which is the CODEX_HOME coordination the other
native-main paths already use (.opencodex-native-main.claim.sqlite). No new
primitive, no FFI.
Why not #3000's approach: it introduces
src/lib/atomic-file-preserving-replace.ts, which dlopens libc.so.6 /
libSystem.B.dylib / kernel32.dll for renameat2 / renamex_np / ReplaceFileW and
throws "No rename fallback is safe" on anything else. musl names its libc
libc.so, not libc.so.6, so publication would crash on Alpine. It also throws
MainAccountTokenRefreshError("transient") on an aborted signal BEFORE
persistRefreshedMainAuthJson, so a late cancel discards a grant the provider
has already rotated -- the only live refresh token, dropped.
The existing check-then-rename guard is left as it is: atomicWriteFile with
assertMainAuthJsonSnapshotUnchanged in both beforeRename and
validateBeforeRename refuses rather than overwrites, and the covering test
(refuses to overwrite an external auth writer after refresh) already passes.
Lock order is claim (machine-wide) then fingerprint lock (per-grant), never the
reverse: two processes holding different fingerprint locks and then reaching
for the same claim would deadlock.
Mutation-checked: dropping the claim wrapper fails exactly the new test
(3 pass / 1 fail), restored to 4/0.
Closes #2999.1 parent 6123be3 commit a6014b9
2 files changed
Lines changed: 88 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
| 23 | + | |
22 | 24 | | |
23 | 25 | | |
24 | 26 | | |
| |||
191 | 193 | | |
192 | 194 | | |
193 | 195 | | |
194 | | - | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
195 | 211 | | |
196 | 212 | | |
197 | 213 | | |
| |||
221 | 237 | | |
222 | 238 | | |
223 | 239 | | |
224 | | - | |
| 240 | + | |
| 241 | + | |
225 | 242 | | |
226 | 243 | | |
227 | 244 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
122 | 122 | | |
123 | 123 | | |
124 | 124 | | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
125 | 194 | | |
0 commit comments