@aiwayds/dsh-model-sync 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/remote-catalog.d.ts +87 -5
- package/lib/remote-catalog.js +123 -20
- package/lib/remote-catalog.js.map +1 -1
- package/lib/writer.js +26 -34
- package/lib/writer.js.map +1 -1
- package/package.json +1 -1
- package/src/remote-catalog.ts +190 -23
- package/src/writer.ts +27 -34
package/lib/remote-catalog.d.ts
CHANGED
|
@@ -40,11 +40,28 @@ export interface ModelsStoreEntry {
|
|
|
40
40
|
* User `modelOverrides` folded out of settings and unset there (the dsh
|
|
41
41
|
* llm-pi-ai validation refuses a models list beside non-empty
|
|
42
42
|
* modelOverrides). Replayed into the translated target on every later
|
|
43
|
-
* round so the user's values survive
|
|
44
|
-
* field
|
|
43
|
+
* round so the user's values survive. The catalog refresh must NOT carry
|
|
44
|
+
* this field forward from its own snapshot — the queue-internal seed
|
|
45
|
+
* merge keeps whatever overrides the route currently holds, so a
|
|
46
|
+
* concurrent round's stage cannot be clobbered by a fetch write (C1 fix).
|
|
45
47
|
*/
|
|
46
48
|
overrides?: Record<string, Record<string, unknown>>;
|
|
47
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* Patch surface for `update()`. The fetch side typically only names
|
|
52
|
+
* fetch-owned fields (`models` / `checkedAt` / `lastModified` / `etag`),
|
|
53
|
+
* but `overrides` is part of the type so the same seed formula works for
|
|
54
|
+
* callers that need to patch out-of-band fields too (and so TS doesn't
|
|
55
|
+
* reject `patch.overrides` in the seed). The merge is a field-level seed
|
|
56
|
+
* inside the accessor's write queue: concurrent stages (the writer's
|
|
57
|
+
* `persistOverridesToStore`, a sibling route's fetch, etc.) see a
|
|
58
|
+
* consistent read-modify-write and never overwrite each other's
|
|
59
|
+
* out-of-band fields. The seed also guarantees the entry shape invariant
|
|
60
|
+
* — every persisted entry carries models (default []), checkedAt (default
|
|
61
|
+
* Date.now()), lastModified (default 0), etag, and overrides — so a
|
|
62
|
+
* subsequent read never sees an incomplete shape (B1 fix).
|
|
63
|
+
*/
|
|
64
|
+
export type ModelsStoreEntryPatch = Partial<Pick<ModelsStoreEntry, 'models' | 'checkedAt' | 'lastModified' | 'etag' | 'overrides'>>;
|
|
48
65
|
/** Top-level shape of ~/.dsh/models-store.json. */
|
|
49
66
|
export interface ModelsStore {
|
|
50
67
|
[route: string]: ModelsStoreEntry;
|
|
@@ -62,10 +79,48 @@ export interface FetchRemoteCatalogResult {
|
|
|
62
79
|
* pi.dev may return: a plain array, `{ models: [...] }`, or an object of arrays.
|
|
63
80
|
*/
|
|
64
81
|
export declare function parseRemoteCatalog(providerId: string, value: unknown): RemoteCatalogEntry[];
|
|
65
|
-
/**
|
|
82
|
+
/**
|
|
83
|
+
* Serialized read/write accessor for ~/.dsh/models-store.json.
|
|
84
|
+
*
|
|
85
|
+
* Every mutation method funnels through the same promise queue so
|
|
86
|
+
* concurrent updates serialize cleanly. `update` / `updateOverrides` use
|
|
87
|
+
* a queue-internal field-level seed (B1 fix) that gives every persisted
|
|
88
|
+
* entry the unconditional shape { models, checkedAt, lastModified, etag,
|
|
89
|
+
* overrides } — patch missing → fall through to current → fall back to a
|
|
90
|
+
* per-field default. The `write` method is the legacy whole-entry
|
|
91
|
+
* replacement path (kept for tests / seeders); production callers prefer
|
|
92
|
+
* the targeted merge so concurrent stages (the writer's
|
|
93
|
+
* `persistOverridesToStore`, a sibling route's fetch, etc.) never
|
|
94
|
+
* overwrite each other's out-of-band fields.
|
|
95
|
+
*/
|
|
66
96
|
export interface ModelsStoreAccessor {
|
|
67
97
|
read(providerId?: string): Promise<ModelsStoreEntry | undefined>;
|
|
98
|
+
/**
|
|
99
|
+
* Whole-entry replacement. Still available for tests / seeders; production
|
|
100
|
+
* code paths prefer the targeted `update` / `updateOverrides` so the queue
|
|
101
|
+
* can preserve out-of-band fields.
|
|
102
|
+
*/
|
|
68
103
|
write(providerId: string, entry: ModelsStoreEntry): Promise<void>;
|
|
104
|
+
/**
|
|
105
|
+
* Field-level seed merge: the route's current entry is re-read inside
|
|
106
|
+
* the write queue (so it sees every prior queue task's committed
|
|
107
|
+
* state), the patch's fields override the current's where present, and
|
|
108
|
+
* missing fields fall back to per-field defaults (models: [],
|
|
109
|
+
* checkedAt: Date.now(), lastModified: 0, etag: undefined, overrides:
|
|
110
|
+
* undefined). The result is an unconditional entry shape — a
|
|
111
|
+
* subsequent read never sees an incomplete `{overrides}-only` entry.
|
|
112
|
+
* Used by `fetchRemoteCatalog` for every status path.
|
|
113
|
+
*/
|
|
114
|
+
update(providerId: string, patch: ModelsStoreEntryPatch): Promise<void>;
|
|
115
|
+
/**
|
|
116
|
+
* Replace the route's `overrides` field only; the same field-level
|
|
117
|
+
* seed as `update` guarantees the rest of the entry (models /
|
|
118
|
+
* checkedAt / lastModified / etag) lands with sensible defaults when
|
|
119
|
+
* the route is new / the doc is corrupt, or is preserved verbatim
|
|
120
|
+
* from the current entry otherwise. Used by `persistOverridesToStore`
|
|
121
|
+
* so its stage survives a concurrent fetch write.
|
|
122
|
+
*/
|
|
123
|
+
updateOverrides(providerId: string, overrides: Record<string, Record<string, unknown>>): Promise<void>;
|
|
69
124
|
delete(providerId: string): Promise<void>;
|
|
70
125
|
}
|
|
71
126
|
/**
|
|
@@ -84,11 +139,38 @@ export declare function resetModelsStoreCache(): void;
|
|
|
84
139
|
* Fetch one route's model list from pi.dev with ETag/304 revalidation.
|
|
85
140
|
*
|
|
86
141
|
* Behavior mirrors the original withRemoteCatalog.refreshModels:
|
|
87
|
-
* - 304 →
|
|
88
|
-
* - 404/501 →
|
|
142
|
+
* - 304 → refresh checkedAt only (everything else falls through to current via the seed)
|
|
143
|
+
* - 404/501 → empty overlay, return empty
|
|
89
144
|
* - transient failure → keep cached entries, return error message
|
|
90
145
|
* - success → parse + store + return entries
|
|
91
146
|
*
|
|
147
|
+
* C1 fix (2026-09-04): the four write paths used to spread the route's
|
|
148
|
+
* pre-fetch snapshot into the written entry — most notably re-attaching
|
|
149
|
+
* `overrides: stored?.overrides` — which clobbered any out-of-band field
|
|
150
|
+
* staged by a concurrent round (e.g. an overlapping auto-refresh whose
|
|
151
|
+
* `persistOverridesToStore` ran between this round's `store.read(route)`
|
|
152
|
+
* and `store.write(...)`). Every status path now calls
|
|
153
|
+
* `effectiveStore.update(route, patch)` with a fetch-owned patch — the
|
|
154
|
+
* queue-internal field-level seed re-reads the route's current entry
|
|
155
|
+
* inside the queue and only overrides the fields the patch names
|
|
156
|
+
* (`models` / `checkedAt` / `lastModified` / `etag`; the 304 path
|
|
157
|
+
* narrows this to just `checkedAt`). Out-of-band fields — notably
|
|
158
|
+
* `overrides`, plus anything a future caller stages — are preserved
|
|
159
|
+
* verbatim because the seed only writes fields the patch actually
|
|
160
|
+
* supplies. The pre-fetch `stored` snapshot stays in scope only for
|
|
161
|
+
* conditional checks (304 ETag match, 4h throttle) and to seed the
|
|
162
|
+
* fall-back models/lastModified/etag values on error paths — it never
|
|
163
|
+
* participates in the write payload.
|
|
164
|
+
*
|
|
165
|
+
* B1 fix: the seed gives every persisted entry an unconditional shape
|
|
166
|
+
* — models / checkedAt / lastModified / etag / overrides (the last
|
|
167
|
+
* three may be undefined, but models is always an array and checkedAt
|
|
168
|
+
* is always a number). A `updateOverrides` stage on an ENOENT / corrupt
|
|
169
|
+
* doc now lands an entry the next round can consume; the previous
|
|
170
|
+
* `{...current, ...patch}` spread left the entry incomplete
|
|
171
|
+
* (`{overrides}-only`) and crashed `fetchRemoteCatalog` on the stale
|
|
172
|
+
* read because `stored.models` was undefined.
|
|
173
|
+
*
|
|
92
174
|
* @param route The provider route id (e.g. 'opencode-go')
|
|
93
175
|
* @param timeout Abort budget in ms (default 30s)
|
|
94
176
|
* @param store Optional override for the models-store accessor (testing)
|
package/lib/remote-catalog.js
CHANGED
|
@@ -133,6 +133,75 @@ export function loadModelsStore(storePath) {
|
|
|
133
133
|
doc[providerId] = entry;
|
|
134
134
|
await writeDoc(doc);
|
|
135
135
|
}),
|
|
136
|
+
update: (providerId, patch) => enqueue(async () => {
|
|
137
|
+
// Queue-internal read-modify-write: the read sees every prior
|
|
138
|
+
// queue task's committed state. The merge is field-level seeded —
|
|
139
|
+
// a field is taken from the patch when present, otherwise from
|
|
140
|
+
// the current entry, otherwise from a per-field default. This
|
|
141
|
+
// makes the entry shape unconditional: every persisted entry
|
|
142
|
+
// carries models/checkedAt/lastModified/etag/overrides (the
|
|
143
|
+
// last three may be undefined, but the first two always have
|
|
144
|
+
// values). Field-level seed closes the C1 bug: a stage via
|
|
145
|
+
// `updateOverrides` on an ENOENT/corrupt doc now lands an entry
|
|
146
|
+
// shape the next round's fetch can consume (`stored.models` is
|
|
147
|
+
// `[]`, never undefined) — the previous `{...current, ...patch}`
|
|
148
|
+
// spread left the entry incomplete and crashed `fetchRemoteCatalog`
|
|
149
|
+
// on the stale read.
|
|
150
|
+
//
|
|
151
|
+
// Fields outside the patch (notably `overrides`) survive any
|
|
152
|
+
// concurrent stage of out-of-band data: patch field is undefined
|
|
153
|
+
// → fall through to current → preserved. A stale pre-fetch
|
|
154
|
+
// snapshot can no longer clobber an out-of-band stage because
|
|
155
|
+
// the patch only names fields the call site intends to write.
|
|
156
|
+
//
|
|
157
|
+
// Read failure → treat the doc as empty and let the atomic
|
|
158
|
+
// writeDoc heal the file (same self-heal contract as `write`).
|
|
159
|
+
let doc;
|
|
160
|
+
try {
|
|
161
|
+
doc = await readDoc();
|
|
162
|
+
}
|
|
163
|
+
catch {
|
|
164
|
+
doc = {};
|
|
165
|
+
}
|
|
166
|
+
const current = doc[providerId] ?? {};
|
|
167
|
+
doc[providerId] = {
|
|
168
|
+
models: patch.models ?? current.models ?? [],
|
|
169
|
+
checkedAt: patch.checkedAt ?? current.checkedAt ?? Date.now(),
|
|
170
|
+
lastModified: patch.lastModified ?? current.lastModified ?? 0,
|
|
171
|
+
etag: patch.etag ?? current.etag,
|
|
172
|
+
overrides: patch.overrides ?? current.overrides,
|
|
173
|
+
};
|
|
174
|
+
await writeDoc(doc);
|
|
175
|
+
}),
|
|
176
|
+
updateOverrides: (providerId, overrides) => enqueue(async () => {
|
|
177
|
+
// Queue-internal RMW: same field-level seed as `update`. The
|
|
178
|
+
// patch is `{ overrides }`; the seed fills every other field
|
|
179
|
+
// with a sensible default (models: [], checkedAt: Date.now(),
|
|
180
|
+
// lastModified: 0, etag: undefined) when current is missing, and
|
|
181
|
+
// preserves current's value when present. The result: an
|
|
182
|
+
// overrides-only stage on an ENOENT / corrupt doc still produces
|
|
183
|
+
// a well-formed entry the fetch side can consume, and an
|
|
184
|
+
// overrides-only stage on a populated entry keeps the fetch's
|
|
185
|
+
// models / etag / checkedAt intact. This is what the writer's
|
|
186
|
+
// `persistOverridesToStore` calls — its previous read-then-write
|
|
187
|
+
// raced the fetch side because the read ran outside the queue.
|
|
188
|
+
let doc;
|
|
189
|
+
try {
|
|
190
|
+
doc = await readDoc();
|
|
191
|
+
}
|
|
192
|
+
catch {
|
|
193
|
+
doc = {};
|
|
194
|
+
}
|
|
195
|
+
const current = doc[providerId] ?? {};
|
|
196
|
+
doc[providerId] = {
|
|
197
|
+
models: current.models ?? [],
|
|
198
|
+
checkedAt: current.checkedAt ?? Date.now(),
|
|
199
|
+
lastModified: current.lastModified ?? 0,
|
|
200
|
+
etag: current.etag,
|
|
201
|
+
overrides,
|
|
202
|
+
};
|
|
203
|
+
await writeDoc(doc);
|
|
204
|
+
}),
|
|
136
205
|
delete: (providerId) => enqueue(async () => {
|
|
137
206
|
let doc;
|
|
138
207
|
try {
|
|
@@ -164,11 +233,38 @@ export function resetModelsStoreCache() {
|
|
|
164
233
|
* Fetch one route's model list from pi.dev with ETag/304 revalidation.
|
|
165
234
|
*
|
|
166
235
|
* Behavior mirrors the original withRemoteCatalog.refreshModels:
|
|
167
|
-
* - 304 →
|
|
168
|
-
* - 404/501 →
|
|
236
|
+
* - 304 → refresh checkedAt only (everything else falls through to current via the seed)
|
|
237
|
+
* - 404/501 → empty overlay, return empty
|
|
169
238
|
* - transient failure → keep cached entries, return error message
|
|
170
239
|
* - success → parse + store + return entries
|
|
171
240
|
*
|
|
241
|
+
* C1 fix (2026-09-04): the four write paths used to spread the route's
|
|
242
|
+
* pre-fetch snapshot into the written entry — most notably re-attaching
|
|
243
|
+
* `overrides: stored?.overrides` — which clobbered any out-of-band field
|
|
244
|
+
* staged by a concurrent round (e.g. an overlapping auto-refresh whose
|
|
245
|
+
* `persistOverridesToStore` ran between this round's `store.read(route)`
|
|
246
|
+
* and `store.write(...)`). Every status path now calls
|
|
247
|
+
* `effectiveStore.update(route, patch)` with a fetch-owned patch — the
|
|
248
|
+
* queue-internal field-level seed re-reads the route's current entry
|
|
249
|
+
* inside the queue and only overrides the fields the patch names
|
|
250
|
+
* (`models` / `checkedAt` / `lastModified` / `etag`; the 304 path
|
|
251
|
+
* narrows this to just `checkedAt`). Out-of-band fields — notably
|
|
252
|
+
* `overrides`, plus anything a future caller stages — are preserved
|
|
253
|
+
* verbatim because the seed only writes fields the patch actually
|
|
254
|
+
* supplies. The pre-fetch `stored` snapshot stays in scope only for
|
|
255
|
+
* conditional checks (304 ETag match, 4h throttle) and to seed the
|
|
256
|
+
* fall-back models/lastModified/etag values on error paths — it never
|
|
257
|
+
* participates in the write payload.
|
|
258
|
+
*
|
|
259
|
+
* B1 fix: the seed gives every persisted entry an unconditional shape
|
|
260
|
+
* — models / checkedAt / lastModified / etag / overrides (the last
|
|
261
|
+
* three may be undefined, but models is always an array and checkedAt
|
|
262
|
+
* is always a number). A `updateOverrides` stage on an ENOENT / corrupt
|
|
263
|
+
* doc now lands an entry the next round can consume; the previous
|
|
264
|
+
* `{...current, ...patch}` spread left the entry incomplete
|
|
265
|
+
* (`{overrides}-only`) and crashed `fetchRemoteCatalog` on the stale
|
|
266
|
+
* read because `stored.models` was undefined.
|
|
267
|
+
*
|
|
172
268
|
* @param route The provider route id (e.g. 'opencode-go')
|
|
173
269
|
* @param timeout Abort budget in ms (default 30s)
|
|
174
270
|
* @param store Optional override for the models-store accessor (testing)
|
|
@@ -177,8 +273,11 @@ export function resetModelsStoreCache() {
|
|
|
177
273
|
export async function fetchRemoteCatalog(route, timeout, store, options) {
|
|
178
274
|
const effectiveStore = store ?? loadModelsStore(options?.storePath);
|
|
179
275
|
const stored = await effectiveStore.read(route);
|
|
180
|
-
// I-5: throttle — return cached entries if checkedAt is within revalidation interval
|
|
181
|
-
|
|
276
|
+
// I-5: throttle — return cached entries if checkedAt is within revalidation interval.
|
|
277
|
+
// Optional chaining on `models` is defensive: the field-level seed (B1) always seeds
|
|
278
|
+
// `models: []` at minimum, so a missing field here means a legacy entry written
|
|
279
|
+
// before the seed landed — treat it as "no cached entries" rather than crashing.
|
|
280
|
+
if (!options?.force && stored !== undefined && (stored.models?.length ?? 0) > 0) {
|
|
182
281
|
const elapsed = Date.now() - stored.checkedAt;
|
|
183
282
|
if (elapsed >= 0 && elapsed < REMOTE_CATALOG_REFRESH_INTERVAL_MS) {
|
|
184
283
|
return { entries: stored.models, fromCache: true };
|
|
@@ -199,33 +298,39 @@ export async function fetchRemoteCatalog(route, timeout, store, options) {
|
|
|
199
298
|
signal: controller.signal,
|
|
200
299
|
});
|
|
201
300
|
const checkedAt = Date.now();
|
|
202
|
-
// 304: body unchanged, just refresh checkedAt
|
|
301
|
+
// 304: body unchanged, just refresh checkedAt. The patch is narrowed to
|
|
302
|
+
// { checkedAt }: the seed merge preserves models / lastModified / etag /
|
|
303
|
+
// overrides from the route's current entry, so re-naming them on a 304
|
|
304
|
+
// is unnecessary (and previously risked a clobber if a concurrent round
|
|
305
|
+
// had staged one of those fields between the snapshot read and the
|
|
306
|
+
// write — N1).
|
|
203
307
|
if (response.status === 304 && stored) {
|
|
204
|
-
await effectiveStore.
|
|
308
|
+
await effectiveStore.update(route, { checkedAt });
|
|
205
309
|
return { entries: stored.models, fromCache: true };
|
|
206
310
|
}
|
|
207
|
-
// 404/501: provider not found on pi.dev; store empty overlay
|
|
311
|
+
// 404/501: provider not found on pi.dev; store empty overlay. The
|
|
312
|
+
// patch omits `etag` (and `overrides`) so the seed preserves both
|
|
313
|
+
// from the route's current entry — the next round's conditional
|
|
314
|
+
// request still uses the cached etag, harmless if the resource is
|
|
315
|
+
// truly gone (server replies 404/501 again) and useful if it comes
|
|
316
|
+
// back (server replies 304). lastModified is zeroed so the catalog
|
|
317
|
+
// metadata reflects "no known server-side last-mod time".
|
|
208
318
|
if (response.status === 404 || response.status === 501) {
|
|
209
|
-
|
|
319
|
+
await effectiveStore.update(route, {
|
|
210
320
|
models: stored?.models ?? [],
|
|
211
321
|
checkedAt,
|
|
212
322
|
lastModified: 0,
|
|
213
|
-
|
|
214
|
-
overrides: stored?.overrides,
|
|
215
|
-
};
|
|
216
|
-
await effectiveStore.write(route, entry);
|
|
323
|
+
});
|
|
217
324
|
return { entries: [], fromCache: false };
|
|
218
325
|
}
|
|
219
326
|
// Transient failure: keep cached entries, report error
|
|
220
327
|
if (!response.ok) {
|
|
221
|
-
|
|
328
|
+
await effectiveStore.update(route, {
|
|
222
329
|
models: stored?.models ?? [],
|
|
223
330
|
checkedAt,
|
|
224
331
|
lastModified: stored?.lastModified ?? 0,
|
|
225
332
|
etag: stored?.etag,
|
|
226
|
-
|
|
227
|
-
};
|
|
228
|
-
await effectiveStore.write(route, entry);
|
|
333
|
+
});
|
|
229
334
|
return {
|
|
230
335
|
entries: stored?.models ?? [],
|
|
231
336
|
fromCache: false,
|
|
@@ -236,14 +341,12 @@ export async function fetchRemoteCatalog(route, timeout, store, options) {
|
|
|
236
341
|
const refreshed = parseRemoteCatalog(route, await response.json());
|
|
237
342
|
const lastModified = Date.parse(response.headers.get('last-modified') ?? '');
|
|
238
343
|
const etag = response.headers.get('etag') ?? undefined;
|
|
239
|
-
|
|
344
|
+
await effectiveStore.update(route, {
|
|
240
345
|
models: refreshed,
|
|
241
346
|
checkedAt,
|
|
242
347
|
lastModified: Number.isNaN(lastModified) ? 0 : lastModified,
|
|
243
348
|
etag,
|
|
244
|
-
|
|
245
|
-
};
|
|
246
|
-
await effectiveStore.write(route, storeEntry);
|
|
349
|
+
});
|
|
247
350
|
return { entries: refreshed, fromCache: false };
|
|
248
351
|
}
|
|
249
352
|
catch (err) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remote-catalog.js","sourceRoot":"","sources":["../src/remote-catalog.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAE5E;;;;;;;;;GASG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACjC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AACzC,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAErE,8EAA8E;AAC9E,yDAAyD;AACzD,8EAA8E;AAE9E,6CAA6C;AAC7C,MAAM,CAAC,MAAM,uBAAuB,GAAG,gBAAgB,CAAA;AAEvD,mEAAmE;AACnE,MAAM,CAAC,MAAM,kCAAkC,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAA;AAEpE,iDAAiD;AACjD,MAAM,CAAC,MAAM,iBAAiB,GAAG,IAAI,CAAC,OAAO,EAAE,EAAE,MAAM,EAAE,mBAAmB,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"remote-catalog.js","sourceRoot":"","sources":["../src/remote-catalog.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAE5E;;;;;;;;;GASG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACjC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AACzC,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAErE,8EAA8E;AAC9E,yDAAyD;AACzD,8EAA8E;AAE9E,6CAA6C;AAC7C,MAAM,CAAC,MAAM,uBAAuB,GAAG,gBAAgB,CAAA;AAEvD,mEA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,SAAS,EAAE,KAAK;YAChB,KAAK,EAAE,oBAAoB,KAAK,KAAK,OAAO,EAAE;SAC/C,CAAA;IACH,CAAC;YAAS,CAAC;QACT,IAAI,KAAK,KAAK,SAAS;YAAE,YAAY,CAAC,KAAK,CAAC,CAAA;IAC9C,CAAC;AACH,CAAC"}
|
package/lib/writer.js
CHANGED
|
@@ -144,46 +144,38 @@ async function resolveOverrides(desc, route, store) {
|
|
|
144
144
|
}
|
|
145
145
|
/**
|
|
146
146
|
* Stage overrides in the models-store BEFORE the mutate that unsets them
|
|
147
|
-
* from settings (store-first). The
|
|
148
|
-
* write queue
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
147
|
+
* from settings (store-first). The RMW runs inside the accessor's
|
|
148
|
+
* serialized write queue via `updateOverrides` — the previous read-then-
|
|
149
|
+
* write pattern read OUTSIDE the queue, which let the fetch side's
|
|
150
|
+
* `store.write` clobber any staged overrides that landed in the window
|
|
151
|
+
* between this read and the eventual write. The queue-internal field-
|
|
152
|
+
* level seed (B1) merges the stage with whatever the route currently
|
|
153
|
+
* holds: `overrides` is replaced by the new value, every other field
|
|
154
|
+
* (`models` / `checkedAt` / `lastModified` / `etag`) is preserved
|
|
155
|
+
* verbatim when present, otherwise seeded with a sensible default.
|
|
156
|
+
* A concurrent fetch write (the C1 race surface) can no longer wipe
|
|
157
|
+
* the stage: the fetch-side patch only names fetch-owned fields, so
|
|
158
|
+
* the seed leaves `overrides` alone. While the settings key is present
|
|
159
|
+
* it always wins over the store (resolveOverrides order); the stored
|
|
160
|
+
* copy is only ever replayed once the key is gone. Callers must treat
|
|
161
|
+
* a throw from here as "skip the mutate": unsetting without a staged
|
|
162
|
+
* copy is the v0.1.5 data loss.
|
|
154
163
|
*
|
|
155
|
-
* The store read may
|
|
156
|
-
*
|
|
157
|
-
* the
|
|
158
|
-
*
|
|
159
|
-
* entry
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
*
|
|
164
|
+
* The store read may fail on corruption / permission errors (the
|
|
165
|
+
* queue's internal read tolerates them by treating the doc as empty,
|
|
166
|
+
* then the atomic writeDoc replaces the bad file with a fresh,
|
|
167
|
+
* well-formed entry — the self-heal). The field-level seed keeps the
|
|
168
|
+
* resulting entry well-formed (models: [], checkedAt: Date.now(),
|
|
169
|
+
* lastModified: 0, etag: undefined, overrides: <stage>), so the fetch
|
|
170
|
+
* side can consume it on its next round. (A storeless call — store
|
|
171
|
+
* undefined — cannot stage anything and keeps the legacy
|
|
172
|
+
* unset-without-copy behavior; production wiring in index.ts always
|
|
163
173
|
* passes a store.)
|
|
164
174
|
*/
|
|
165
175
|
async function persistOverridesToStore(store, route, overrides) {
|
|
166
176
|
if (store === undefined)
|
|
167
177
|
return;
|
|
168
|
-
|
|
169
|
-
try {
|
|
170
|
-
stored = await store.read(route);
|
|
171
|
-
}
|
|
172
|
-
catch (readErr) {
|
|
173
|
-
// Cache lost — fall through with no cached metadata. The atomic
|
|
174
|
-
// writeDoc below replaces the bad file with a fresh entry carrying
|
|
175
|
-
// only the overrides. The fetch side re-populates the rest on its
|
|
176
|
-
// next round. The settings key remains the authoritative source of
|
|
177
|
-
// truth in the meantime.
|
|
178
|
-
void readErr;
|
|
179
|
-
}
|
|
180
|
-
await store.write(route, {
|
|
181
|
-
models: stored?.models ?? [],
|
|
182
|
-
checkedAt: stored?.checkedAt ?? Date.now(),
|
|
183
|
-
lastModified: stored?.lastModified ?? 0,
|
|
184
|
-
etag: stored?.etag,
|
|
185
|
-
overrides,
|
|
186
|
-
});
|
|
178
|
+
await store.updateOverrides(route, overrides);
|
|
187
179
|
}
|
|
188
180
|
// ---------------------------------------------------------------------------
|
|
189
181
|
// syncToSettings (§4)
|
package/lib/writer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"writer.js","sourceRoot":"","sources":["../src/writer.ts"],"names":[],"mappings":"AAAA,sFAAsF;AA6GtF,8EAA8E;AAC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C,CAAA;gBAC9D,CAAC;gBAAC,OAAO,UAAmB,EAAE,CAAC;oBAC7B,MAAM,CAAC,IAAI,CACT,8CAA8C,EAC9C,KAAK,EACL,UAAU,YAAY,KAAK,CAAC,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,CACtE,CAAA;oBACD,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,mBAAmB,EAAE,CAAA;gBACtD,CAAC;YACH,CAAC;YAED,MAAM,QAAQ,CAAC,MAAM,CAAC,WAAW,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAA;YAC9D,OAAO;gBACL,KAAK,EAAE,IAAI;gBACX,MAAM,EAAE,mBAAmB;gBAC3B,eAAe,EAAE,KAAK,CAAC,MAAM;gBAC7B,kBAAkB,EAAE,YAAY;aACjC,CAAA;QACH,CAAC;QAAC,OAAO,QAAiB,EAAE,CAAC;YAC3B,MAAM,CAAC,IAAI,CACT,wCAAwC,EACxC,KAAK,EACL,QAAQ,YAAY,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAChE,CAAA;YACD,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,uBAAuB,EAAE,CAAA;QAC1D,CAAC;IACH,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aiwayds/dsh-model-sync",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "dsh plugin: keep llm-pi-ai provider routes' model lists in step with the pi.dev gateway, written through the official settings seam",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
package/src/remote-catalog.ts
CHANGED
|
@@ -69,12 +69,32 @@ export interface ModelsStoreEntry {
|
|
|
69
69
|
* User `modelOverrides` folded out of settings and unset there (the dsh
|
|
70
70
|
* llm-pi-ai validation refuses a models list beside non-empty
|
|
71
71
|
* modelOverrides). Replayed into the translated target on every later
|
|
72
|
-
* round so the user's values survive
|
|
73
|
-
* field
|
|
72
|
+
* round so the user's values survive. The catalog refresh must NOT carry
|
|
73
|
+
* this field forward from its own snapshot — the queue-internal seed
|
|
74
|
+
* merge keeps whatever overrides the route currently holds, so a
|
|
75
|
+
* concurrent round's stage cannot be clobbered by a fetch write (C1 fix).
|
|
74
76
|
*/
|
|
75
77
|
overrides?: Record<string, Record<string, unknown>>
|
|
76
78
|
}
|
|
77
79
|
|
|
80
|
+
/**
|
|
81
|
+
* Patch surface for `update()`. The fetch side typically only names
|
|
82
|
+
* fetch-owned fields (`models` / `checkedAt` / `lastModified` / `etag`),
|
|
83
|
+
* but `overrides` is part of the type so the same seed formula works for
|
|
84
|
+
* callers that need to patch out-of-band fields too (and so TS doesn't
|
|
85
|
+
* reject `patch.overrides` in the seed). The merge is a field-level seed
|
|
86
|
+
* inside the accessor's write queue: concurrent stages (the writer's
|
|
87
|
+
* `persistOverridesToStore`, a sibling route's fetch, etc.) see a
|
|
88
|
+
* consistent read-modify-write and never overwrite each other's
|
|
89
|
+
* out-of-band fields. The seed also guarantees the entry shape invariant
|
|
90
|
+
* — every persisted entry carries models (default []), checkedAt (default
|
|
91
|
+
* Date.now()), lastModified (default 0), etag, and overrides — so a
|
|
92
|
+
* subsequent read never sees an incomplete shape (B1 fix).
|
|
93
|
+
*/
|
|
94
|
+
export type ModelsStoreEntryPatch = Partial<
|
|
95
|
+
Pick<ModelsStoreEntry, 'models' | 'checkedAt' | 'lastModified' | 'etag' | 'overrides'>
|
|
96
|
+
>
|
|
97
|
+
|
|
78
98
|
/** Top-level shape of ~/.dsh/models-store.json. */
|
|
79
99
|
export interface ModelsStore {
|
|
80
100
|
[route: string]: ModelsStoreEntry
|
|
@@ -132,10 +152,51 @@ export function parseRemoteCatalog(
|
|
|
132
152
|
|
|
133
153
|
let modelsStoreCache: ModelsStoreAccessor | undefined
|
|
134
154
|
|
|
135
|
-
/**
|
|
155
|
+
/**
|
|
156
|
+
* Serialized read/write accessor for ~/.dsh/models-store.json.
|
|
157
|
+
*
|
|
158
|
+
* Every mutation method funnels through the same promise queue so
|
|
159
|
+
* concurrent updates serialize cleanly. `update` / `updateOverrides` use
|
|
160
|
+
* a queue-internal field-level seed (B1 fix) that gives every persisted
|
|
161
|
+
* entry the unconditional shape { models, checkedAt, lastModified, etag,
|
|
162
|
+
* overrides } — patch missing → fall through to current → fall back to a
|
|
163
|
+
* per-field default. The `write` method is the legacy whole-entry
|
|
164
|
+
* replacement path (kept for tests / seeders); production callers prefer
|
|
165
|
+
* the targeted merge so concurrent stages (the writer's
|
|
166
|
+
* `persistOverridesToStore`, a sibling route's fetch, etc.) never
|
|
167
|
+
* overwrite each other's out-of-band fields.
|
|
168
|
+
*/
|
|
136
169
|
export interface ModelsStoreAccessor {
|
|
137
170
|
read(providerId?: string): Promise<ModelsStoreEntry | undefined>
|
|
171
|
+
/**
|
|
172
|
+
* Whole-entry replacement. Still available for tests / seeders; production
|
|
173
|
+
* code paths prefer the targeted `update` / `updateOverrides` so the queue
|
|
174
|
+
* can preserve out-of-band fields.
|
|
175
|
+
*/
|
|
138
176
|
write(providerId: string, entry: ModelsStoreEntry): Promise<void>
|
|
177
|
+
/**
|
|
178
|
+
* Field-level seed merge: the route's current entry is re-read inside
|
|
179
|
+
* the write queue (so it sees every prior queue task's committed
|
|
180
|
+
* state), the patch's fields override the current's where present, and
|
|
181
|
+
* missing fields fall back to per-field defaults (models: [],
|
|
182
|
+
* checkedAt: Date.now(), lastModified: 0, etag: undefined, overrides:
|
|
183
|
+
* undefined). The result is an unconditional entry shape — a
|
|
184
|
+
* subsequent read never sees an incomplete `{overrides}-only` entry.
|
|
185
|
+
* Used by `fetchRemoteCatalog` for every status path.
|
|
186
|
+
*/
|
|
187
|
+
update(providerId: string, patch: ModelsStoreEntryPatch): Promise<void>
|
|
188
|
+
/**
|
|
189
|
+
* Replace the route's `overrides` field only; the same field-level
|
|
190
|
+
* seed as `update` guarantees the rest of the entry (models /
|
|
191
|
+
* checkedAt / lastModified / etag) lands with sensible defaults when
|
|
192
|
+
* the route is new / the doc is corrupt, or is preserved verbatim
|
|
193
|
+
* from the current entry otherwise. Used by `persistOverridesToStore`
|
|
194
|
+
* so its stage survives a concurrent fetch write.
|
|
195
|
+
*/
|
|
196
|
+
updateOverrides(
|
|
197
|
+
providerId: string,
|
|
198
|
+
overrides: Record<string, Record<string, unknown>>,
|
|
199
|
+
): Promise<void>
|
|
139
200
|
delete(providerId: string): Promise<void>
|
|
140
201
|
}
|
|
141
202
|
|
|
@@ -219,6 +280,78 @@ export function loadModelsStore(storePath?: string): ModelsStoreAccessor {
|
|
|
219
280
|
doc[providerId] = entry
|
|
220
281
|
await writeDoc(doc)
|
|
221
282
|
}),
|
|
283
|
+
update: (providerId: string, patch: ModelsStoreEntryPatch): Promise<void> =>
|
|
284
|
+
enqueue(async () => {
|
|
285
|
+
// Queue-internal read-modify-write: the read sees every prior
|
|
286
|
+
// queue task's committed state. The merge is field-level seeded —
|
|
287
|
+
// a field is taken from the patch when present, otherwise from
|
|
288
|
+
// the current entry, otherwise from a per-field default. This
|
|
289
|
+
// makes the entry shape unconditional: every persisted entry
|
|
290
|
+
// carries models/checkedAt/lastModified/etag/overrides (the
|
|
291
|
+
// last three may be undefined, but the first two always have
|
|
292
|
+
// values). Field-level seed closes the C1 bug: a stage via
|
|
293
|
+
// `updateOverrides` on an ENOENT/corrupt doc now lands an entry
|
|
294
|
+
// shape the next round's fetch can consume (`stored.models` is
|
|
295
|
+
// `[]`, never undefined) — the previous `{...current, ...patch}`
|
|
296
|
+
// spread left the entry incomplete and crashed `fetchRemoteCatalog`
|
|
297
|
+
// on the stale read.
|
|
298
|
+
//
|
|
299
|
+
// Fields outside the patch (notably `overrides`) survive any
|
|
300
|
+
// concurrent stage of out-of-band data: patch field is undefined
|
|
301
|
+
// → fall through to current → preserved. A stale pre-fetch
|
|
302
|
+
// snapshot can no longer clobber an out-of-band stage because
|
|
303
|
+
// the patch only names fields the call site intends to write.
|
|
304
|
+
//
|
|
305
|
+
// Read failure → treat the doc as empty and let the atomic
|
|
306
|
+
// writeDoc heal the file (same self-heal contract as `write`).
|
|
307
|
+
let doc: ModelsStore
|
|
308
|
+
try {
|
|
309
|
+
doc = await readDoc()
|
|
310
|
+
} catch {
|
|
311
|
+
doc = {}
|
|
312
|
+
}
|
|
313
|
+
const current = doc[providerId] ?? {}
|
|
314
|
+
doc[providerId] = {
|
|
315
|
+
models: patch.models ?? current.models ?? [],
|
|
316
|
+
checkedAt: patch.checkedAt ?? current.checkedAt ?? Date.now(),
|
|
317
|
+
lastModified: patch.lastModified ?? current.lastModified ?? 0,
|
|
318
|
+
etag: patch.etag ?? current.etag,
|
|
319
|
+
overrides: patch.overrides ?? current.overrides,
|
|
320
|
+
}
|
|
321
|
+
await writeDoc(doc)
|
|
322
|
+
}),
|
|
323
|
+
updateOverrides: (
|
|
324
|
+
providerId: string,
|
|
325
|
+
overrides: Record<string, Record<string, unknown>>,
|
|
326
|
+
): Promise<void> =>
|
|
327
|
+
enqueue(async () => {
|
|
328
|
+
// Queue-internal RMW: same field-level seed as `update`. The
|
|
329
|
+
// patch is `{ overrides }`; the seed fills every other field
|
|
330
|
+
// with a sensible default (models: [], checkedAt: Date.now(),
|
|
331
|
+
// lastModified: 0, etag: undefined) when current is missing, and
|
|
332
|
+
// preserves current's value when present. The result: an
|
|
333
|
+
// overrides-only stage on an ENOENT / corrupt doc still produces
|
|
334
|
+
// a well-formed entry the fetch side can consume, and an
|
|
335
|
+
// overrides-only stage on a populated entry keeps the fetch's
|
|
336
|
+
// models / etag / checkedAt intact. This is what the writer's
|
|
337
|
+
// `persistOverridesToStore` calls — its previous read-then-write
|
|
338
|
+
// raced the fetch side because the read ran outside the queue.
|
|
339
|
+
let doc: ModelsStore
|
|
340
|
+
try {
|
|
341
|
+
doc = await readDoc()
|
|
342
|
+
} catch {
|
|
343
|
+
doc = {}
|
|
344
|
+
}
|
|
345
|
+
const current = doc[providerId] ?? {}
|
|
346
|
+
doc[providerId] = {
|
|
347
|
+
models: current.models ?? [],
|
|
348
|
+
checkedAt: current.checkedAt ?? Date.now(),
|
|
349
|
+
lastModified: current.lastModified ?? 0,
|
|
350
|
+
etag: current.etag,
|
|
351
|
+
overrides,
|
|
352
|
+
}
|
|
353
|
+
await writeDoc(doc)
|
|
354
|
+
}),
|
|
222
355
|
delete: (providerId: string): Promise<void> =>
|
|
223
356
|
enqueue(async () => {
|
|
224
357
|
let doc: ModelsStore
|
|
@@ -254,11 +387,38 @@ export function resetModelsStoreCache(): void {
|
|
|
254
387
|
* Fetch one route's model list from pi.dev with ETag/304 revalidation.
|
|
255
388
|
*
|
|
256
389
|
* Behavior mirrors the original withRemoteCatalog.refreshModels:
|
|
257
|
-
* - 304 →
|
|
258
|
-
* - 404/501 →
|
|
390
|
+
* - 304 → refresh checkedAt only (everything else falls through to current via the seed)
|
|
391
|
+
* - 404/501 → empty overlay, return empty
|
|
259
392
|
* - transient failure → keep cached entries, return error message
|
|
260
393
|
* - success → parse + store + return entries
|
|
261
394
|
*
|
|
395
|
+
* C1 fix (2026-09-04): the four write paths used to spread the route's
|
|
396
|
+
* pre-fetch snapshot into the written entry — most notably re-attaching
|
|
397
|
+
* `overrides: stored?.overrides` — which clobbered any out-of-band field
|
|
398
|
+
* staged by a concurrent round (e.g. an overlapping auto-refresh whose
|
|
399
|
+
* `persistOverridesToStore` ran between this round's `store.read(route)`
|
|
400
|
+
* and `store.write(...)`). Every status path now calls
|
|
401
|
+
* `effectiveStore.update(route, patch)` with a fetch-owned patch — the
|
|
402
|
+
* queue-internal field-level seed re-reads the route's current entry
|
|
403
|
+
* inside the queue and only overrides the fields the patch names
|
|
404
|
+
* (`models` / `checkedAt` / `lastModified` / `etag`; the 304 path
|
|
405
|
+
* narrows this to just `checkedAt`). Out-of-band fields — notably
|
|
406
|
+
* `overrides`, plus anything a future caller stages — are preserved
|
|
407
|
+
* verbatim because the seed only writes fields the patch actually
|
|
408
|
+
* supplies. The pre-fetch `stored` snapshot stays in scope only for
|
|
409
|
+
* conditional checks (304 ETag match, 4h throttle) and to seed the
|
|
410
|
+
* fall-back models/lastModified/etag values on error paths — it never
|
|
411
|
+
* participates in the write payload.
|
|
412
|
+
*
|
|
413
|
+
* B1 fix: the seed gives every persisted entry an unconditional shape
|
|
414
|
+
* — models / checkedAt / lastModified / etag / overrides (the last
|
|
415
|
+
* three may be undefined, but models is always an array and checkedAt
|
|
416
|
+
* is always a number). A `updateOverrides` stage on an ENOENT / corrupt
|
|
417
|
+
* doc now lands an entry the next round can consume; the previous
|
|
418
|
+
* `{...current, ...patch}` spread left the entry incomplete
|
|
419
|
+
* (`{overrides}-only`) and crashed `fetchRemoteCatalog` on the stale
|
|
420
|
+
* read because `stored.models` was undefined.
|
|
421
|
+
*
|
|
262
422
|
* @param route The provider route id (e.g. 'opencode-go')
|
|
263
423
|
* @param timeout Abort budget in ms (default 30s)
|
|
264
424
|
* @param store Optional override for the models-store accessor (testing)
|
|
@@ -273,8 +433,11 @@ export async function fetchRemoteCatalog(
|
|
|
273
433
|
const effectiveStore = store ?? loadModelsStore(options?.storePath)
|
|
274
434
|
const stored = await effectiveStore.read(route)
|
|
275
435
|
|
|
276
|
-
// I-5: throttle — return cached entries if checkedAt is within revalidation interval
|
|
277
|
-
|
|
436
|
+
// I-5: throttle — return cached entries if checkedAt is within revalidation interval.
|
|
437
|
+
// Optional chaining on `models` is defensive: the field-level seed (B1) always seeds
|
|
438
|
+
// `models: []` at minimum, so a missing field here means a legacy entry written
|
|
439
|
+
// before the seed landed — treat it as "no cached entries" rather than crashing.
|
|
440
|
+
if (!options?.force && stored !== undefined && (stored.models?.length ?? 0) > 0) {
|
|
278
441
|
const elapsed = Date.now() - stored.checkedAt
|
|
279
442
|
if (elapsed >= 0 && elapsed < REMOTE_CATALOG_REFRESH_INTERVAL_MS) {
|
|
280
443
|
return { entries: stored.models, fromCache: true }
|
|
@@ -300,35 +463,41 @@ export async function fetchRemoteCatalog(
|
|
|
300
463
|
|
|
301
464
|
const checkedAt = Date.now()
|
|
302
465
|
|
|
303
|
-
// 304: body unchanged, just refresh checkedAt
|
|
466
|
+
// 304: body unchanged, just refresh checkedAt. The patch is narrowed to
|
|
467
|
+
// { checkedAt }: the seed merge preserves models / lastModified / etag /
|
|
468
|
+
// overrides from the route's current entry, so re-naming them on a 304
|
|
469
|
+
// is unnecessary (and previously risked a clobber if a concurrent round
|
|
470
|
+
// had staged one of those fields between the snapshot read and the
|
|
471
|
+
// write — N1).
|
|
304
472
|
if (response.status === 304 && stored) {
|
|
305
|
-
await effectiveStore.
|
|
473
|
+
await effectiveStore.update(route, { checkedAt })
|
|
306
474
|
return { entries: stored.models, fromCache: true }
|
|
307
475
|
}
|
|
308
476
|
|
|
309
|
-
// 404/501: provider not found on pi.dev; store empty overlay
|
|
477
|
+
// 404/501: provider not found on pi.dev; store empty overlay. The
|
|
478
|
+
// patch omits `etag` (and `overrides`) so the seed preserves both
|
|
479
|
+
// from the route's current entry — the next round's conditional
|
|
480
|
+
// request still uses the cached etag, harmless if the resource is
|
|
481
|
+
// truly gone (server replies 404/501 again) and useful if it comes
|
|
482
|
+
// back (server replies 304). lastModified is zeroed so the catalog
|
|
483
|
+
// metadata reflects "no known server-side last-mod time".
|
|
310
484
|
if (response.status === 404 || response.status === 501) {
|
|
311
|
-
|
|
485
|
+
await effectiveStore.update(route, {
|
|
312
486
|
models: stored?.models ?? [],
|
|
313
487
|
checkedAt,
|
|
314
488
|
lastModified: 0,
|
|
315
|
-
|
|
316
|
-
overrides: stored?.overrides,
|
|
317
|
-
}
|
|
318
|
-
await effectiveStore.write(route, entry)
|
|
489
|
+
})
|
|
319
490
|
return { entries: [], fromCache: false }
|
|
320
491
|
}
|
|
321
492
|
|
|
322
493
|
// Transient failure: keep cached entries, report error
|
|
323
494
|
if (!response.ok) {
|
|
324
|
-
|
|
495
|
+
await effectiveStore.update(route, {
|
|
325
496
|
models: stored?.models ?? [],
|
|
326
497
|
checkedAt,
|
|
327
498
|
lastModified: stored?.lastModified ?? 0,
|
|
328
499
|
etag: stored?.etag,
|
|
329
|
-
|
|
330
|
-
}
|
|
331
|
-
await effectiveStore.write(route, entry)
|
|
500
|
+
})
|
|
332
501
|
return {
|
|
333
502
|
entries: stored?.models ?? [],
|
|
334
503
|
fromCache: false,
|
|
@@ -341,14 +510,12 @@ export async function fetchRemoteCatalog(
|
|
|
341
510
|
const lastModified = Date.parse(response.headers.get('last-modified') ?? '')
|
|
342
511
|
const etag = response.headers.get('etag') ?? undefined
|
|
343
512
|
|
|
344
|
-
|
|
513
|
+
await effectiveStore.update(route, {
|
|
345
514
|
models: refreshed,
|
|
346
515
|
checkedAt,
|
|
347
516
|
lastModified: Number.isNaN(lastModified) ? 0 : lastModified,
|
|
348
517
|
etag,
|
|
349
|
-
|
|
350
|
-
}
|
|
351
|
-
await effectiveStore.write(route, storeEntry)
|
|
518
|
+
})
|
|
352
519
|
|
|
353
520
|
return { entries: refreshed, fromCache: false }
|
|
354
521
|
} catch (err: unknown) {
|
package/src/writer.ts
CHANGED
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
*/
|
|
45
45
|
|
|
46
46
|
import type { SettingsModelProfile } from './translate.ts'
|
|
47
|
-
import type { ModelsStoreAccessor
|
|
47
|
+
import type { ModelsStoreAccessor } from './remote-catalog.ts'
|
|
48
48
|
|
|
49
49
|
// ---------------------------------------------------------------------------
|
|
50
50
|
// Types
|
|
@@ -268,22 +268,32 @@ async function resolveOverrides(
|
|
|
268
268
|
|
|
269
269
|
/**
|
|
270
270
|
* Stage overrides in the models-store BEFORE the mutate that unsets them
|
|
271
|
-
* from settings (store-first). The
|
|
272
|
-
* write queue
|
|
273
|
-
*
|
|
274
|
-
*
|
|
275
|
-
*
|
|
276
|
-
*
|
|
277
|
-
*
|
|
271
|
+
* from settings (store-first). The RMW runs inside the accessor's
|
|
272
|
+
* serialized write queue via `updateOverrides` — the previous read-then-
|
|
273
|
+
* write pattern read OUTSIDE the queue, which let the fetch side's
|
|
274
|
+
* `store.write` clobber any staged overrides that landed in the window
|
|
275
|
+
* between this read and the eventual write. The queue-internal field-
|
|
276
|
+
* level seed (B1) merges the stage with whatever the route currently
|
|
277
|
+
* holds: `overrides` is replaced by the new value, every other field
|
|
278
|
+
* (`models` / `checkedAt` / `lastModified` / `etag`) is preserved
|
|
279
|
+
* verbatim when present, otherwise seeded with a sensible default.
|
|
280
|
+
* A concurrent fetch write (the C1 race surface) can no longer wipe
|
|
281
|
+
* the stage: the fetch-side patch only names fetch-owned fields, so
|
|
282
|
+
* the seed leaves `overrides` alone. While the settings key is present
|
|
283
|
+
* it always wins over the store (resolveOverrides order); the stored
|
|
284
|
+
* copy is only ever replayed once the key is gone. Callers must treat
|
|
285
|
+
* a throw from here as "skip the mutate": unsetting without a staged
|
|
286
|
+
* copy is the v0.1.5 data loss.
|
|
278
287
|
*
|
|
279
|
-
* The store read may
|
|
280
|
-
*
|
|
281
|
-
* the
|
|
282
|
-
*
|
|
283
|
-
* entry
|
|
284
|
-
*
|
|
285
|
-
*
|
|
286
|
-
*
|
|
288
|
+
* The store read may fail on corruption / permission errors (the
|
|
289
|
+
* queue's internal read tolerates them by treating the doc as empty,
|
|
290
|
+
* then the atomic writeDoc replaces the bad file with a fresh,
|
|
291
|
+
* well-formed entry — the self-heal). The field-level seed keeps the
|
|
292
|
+
* resulting entry well-formed (models: [], checkedAt: Date.now(),
|
|
293
|
+
* lastModified: 0, etag: undefined, overrides: <stage>), so the fetch
|
|
294
|
+
* side can consume it on its next round. (A storeless call — store
|
|
295
|
+
* undefined — cannot stage anything and keeps the legacy
|
|
296
|
+
* unset-without-copy behavior; production wiring in index.ts always
|
|
287
297
|
* passes a store.)
|
|
288
298
|
*/
|
|
289
299
|
async function persistOverridesToStore(
|
|
@@ -292,24 +302,7 @@ async function persistOverridesToStore(
|
|
|
292
302
|
overrides: Record<string, Record<string, unknown>>,
|
|
293
303
|
): Promise<void> {
|
|
294
304
|
if (store === undefined) return
|
|
295
|
-
|
|
296
|
-
try {
|
|
297
|
-
stored = await store.read(route)
|
|
298
|
-
} catch (readErr: unknown) {
|
|
299
|
-
// Cache lost — fall through with no cached metadata. The atomic
|
|
300
|
-
// writeDoc below replaces the bad file with a fresh entry carrying
|
|
301
|
-
// only the overrides. The fetch side re-populates the rest on its
|
|
302
|
-
// next round. The settings key remains the authoritative source of
|
|
303
|
-
// truth in the meantime.
|
|
304
|
-
void readErr
|
|
305
|
-
}
|
|
306
|
-
await store.write(route, {
|
|
307
|
-
models: stored?.models ?? [],
|
|
308
|
-
checkedAt: stored?.checkedAt ?? Date.now(),
|
|
309
|
-
lastModified: stored?.lastModified ?? 0,
|
|
310
|
-
etag: stored?.etag,
|
|
311
|
-
overrides,
|
|
312
|
-
})
|
|
305
|
+
await store.updateOverrides(route, overrides)
|
|
313
306
|
}
|
|
314
307
|
|
|
315
308
|
// ---------------------------------------------------------------------------
|