pi-hypercharm-provider 1.3.40 → 1.3.41

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/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.3.41
4
+
5
+ - `/login` while the session-start catalog revalidation is still in flight now fetches the new account's catalog right away: the forced refresh aborts the old-credential revalidation and waits for it to release the sync lock instead of skipping as "locked" until the next session start.
6
+
3
7
  ## 1.3.40
4
8
 
5
9
  - Quiet startup sync: background `/v1/provider` revalidation runs only with credentials, only when the disk cache is older than 1 hour (`PI_PROVIDER_SYNC_TTL_MS`, `0` = always), missing, or fetched with different credentials, and only in one pi process at a time (lock file next to the cache). Failed refreshes back off for 5 minutes; sessions that skip adopt a cache refreshed by another process. A completed `/login` forces a revalidation.
package/index.ts CHANGED
@@ -526,6 +526,8 @@ let cachedApiKey: string | undefined;
526
526
  // Stable identity behind cachedApiKey for the quiet-sync fingerprints.
527
527
  let cachedSyncIdentity: string | undefined;
528
528
  let revalidateAbort: AbortController | null = null;
529
+ // The in-flight catalog revalidation (session start or /login); it never rejects.
530
+ let modelSync: Promise<void> = Promise.resolve();
529
531
 
530
532
  const AUTH_PATH = path.join(getAgentDir(), "auth.json");
531
533
 
@@ -1338,7 +1340,12 @@ export default function (pi: ExtensionAPI) {
1338
1340
  lastCreditsFetchAt = 0;
1339
1341
  const epoch = statusEpoch;
1340
1342
  setTimeout(() => {
1341
- void syncModels(epoch, revalidateAbort?.signal, true).catch(() => {});
1343
+ // The new credentials supersede an in-flight revalidation, which must
1344
+ // release its sync lock first, or this forced refresh would skip as "locked".
1345
+ revalidateAbort?.abort();
1346
+ revalidateAbort = new AbortController();
1347
+ const signal = revalidateAbort.signal;
1348
+ modelSync = modelSync.then(() => (signal.aborted ? undefined : syncModels(epoch, signal, true))).catch(() => {});
1342
1349
  }, 0);
1343
1350
  };
1344
1351
 
@@ -1370,7 +1377,7 @@ export default function (pi: ExtensionAPI) {
1370
1377
  // the provider API. Nothing is awaited and every rejection is swallowed.
1371
1378
  // A key-resolution failure is surfaced (it used to vanish), then we keep
1372
1379
  // serving the embedded/cached catalog.
1373
- void resolveApiKey(ctx.modelRegistry)
1380
+ modelSync = resolveApiKey(ctx.modelRegistry)
1374
1381
  .catch((err) => {
1375
1382
  notifier.warn(`Unable to resolve HyperCharm credentials: ${describeError(err)} — serving cached/embedded models.`);
1376
1383
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-hypercharm-provider",
3
- "version": "1.3.40",
3
+ "version": "1.3.41",
4
4
  "description": "HyperCharm provider extension for pi - Access DeepSeek, GLM, Kimi, Qwen, MiniMax, Gemma, and GPT-OSS models through the Charm Hyper API",
5
5
  "type": "module",
6
6
  "main": "index.ts",
@@ -363,6 +363,33 @@ describe("HyperCharm quiet sync variants", () => {
363
363
  expect(new Headers(fetch.mock.calls[0][1]?.headers).get("Authorization")).toBe("Bearer fresh-access");
364
364
  });
365
365
 
366
+ it("fetches the new account's catalog when /login races the session revalidation holding the lock", async () => {
367
+ setupHome();
368
+ writeCache(2 * HOUR);
369
+ vi.doMock("../oauth", () => ({
370
+ USER_AGENT: "pi-hypercharm-provider/test",
371
+ loginHypercharm: async () => ({ type: "oauth", refresh: "fresh-refresh", access: "fresh-access", expires: Date.now() + HOUR }),
372
+ refreshHypercharmToken: async (c: unknown) => c,
373
+ }));
374
+ let release!: () => void;
375
+ const fetch = stubFetch((_url, init) => new Promise<Response>((resolve, reject) => {
376
+ const signal = init?.signal;
377
+ signal?.addEventListener("abort", () => reject(signal.reason));
378
+ release = () => resolve(liveModelsResponse());
379
+ }));
380
+ const ext = await loadExtension();
381
+ await ext.startSession();
382
+ await vi.waitFor(() => expect(catalogCalls(fetch)).toHaveLength(1)); // session sync in flight, lock held
383
+
384
+ await ext.registrations[0].oauth.login({});
385
+ await vi.waitFor(() => expect(catalogCalls(fetch)).toHaveLength(2));
386
+ release();
387
+ await vi.waitFor(() => expect(hasLiveModel(ext.registrations.at(-1))).toBe(true));
388
+ expect(new Headers(catalogCalls(fetch)[1][1]?.headers).get("Authorization")).toBe("Bearer fresh-access");
389
+ expect(JSON.parse(fs.readFileSync(syncMetaPath(cachePath), "utf8")).keyFingerprint).toBe(keyFingerprint("oauth:fresh-refresh"));
390
+ expect(fs.existsSync(syncLockPath(cachePath))).toBe(false);
391
+ });
392
+
366
393
  it("skips the startup account poll without a UI (print mode, child agents)", async () => {
367
394
  setupHome();
368
395
  writeCache(10 * 60 * 1000);