@@ -784,6 +784,36 @@ describe("acpRegistrySnapshotReadiness", () => { |
784 | 784 | expect(entitled.models.map((m) => m.slug)).toEqual(["gmodel"]); |
785 | 785 | expect(entitled.models.find((m) => m.slug === "gmodel")?.isDefault).toBe(true); |
786 | 786 |
|
| 787 | + const afterProvisional = applyAcpRegistryLiveConfiguration( |
| 788 | + entitled, |
| 789 | + { |
| 790 | + models: [{ id: "placeholder", name: "Placeholder", description: null }], |
| 791 | + currentModelId: "placeholder", |
| 792 | + configOptions: [], |
| 793 | + modelsFromModelSelect: false, |
| 794 | + }, |
| 795 | + [], |
| 796 | + entitled.models, |
| 797 | + { preserveSingleModelCatalog: true }, |
| 798 | + ); |
| 799 | + expect(afterProvisional.models.map((m) => m.slug)).toEqual(["gmodel"]); |
| 800 | + expect(afterProvisional.models.find((m) => m.slug === "gmodel")?.isDefault).toBe(true); |
| 801 | + |
| 802 | + const replacedExplicit = applyAcpRegistryLiveConfiguration( |
| 803 | + entitled, |
| 804 | + { |
| 805 | + models: [{ id: "hmodel", name: "Haiku-Only", description: null }], |
| 806 | + currentModelId: "hmodel", |
| 807 | + configOptions: [], |
| 808 | + modelsFromModelSelect: true, |
| 809 | + }, |
| 810 | + [], |
| 811 | + entitled.models, |
| 812 | + { preserveSingleModelCatalog: true }, |
| 813 | + ); |
| 814 | + expect(replacedExplicit.models.map((m) => m.slug)).toEqual(["hmodel"]); |
| 815 | + expect(replacedExplicit.models.find((m) => m.slug === "hmodel")?.isDefault).toBe(true); |
| 816 | + |
787 | 817 | const narrowed = applyAcpRegistryLiveConfiguration( |
788 | 818 | provider, |
789 | 819 | { |
@@ -831,6 +861,31 @@ describe("acpRegistryEnrichmentCache", () => { |
831 | 861 |
|
832 | 862 | expect(replayed).toBe(cache); |
833 | 863 | expect(replayed.entry?.expiresAt).toBe(1_000); |
| 864 | + |
| 865 | + const explicitSingletonCache = { |
| 866 | + generation: 1, |
| 867 | + entry: { |
| 868 | + provider: providerWithModels( |
| 869 | + [{ id: "gmodel", name: "GPT-Pro", description: null }], |
| 870 | + "gmodel", |
| 871 | + ), |
| 872 | + expiresAt: 1_000, |
| 873 | + }, |
| 874 | + }; |
| 875 | + const provisionalUpdate = updateAcpRegistryEnrichmentCache({ |
| 876 | + cache: explicitSingletonCache, |
| 877 | + configuration: { |
| 878 | + models: [{ id: "placeholder", name: "Placeholder", description: null }], |
| 879 | + currentModelId: "placeholder", |
| 880 | + configOptions: [], |
| 881 | + modelsFromModelSelect: false, |
| 882 | + }, |
| 883 | + customModels: [], |
| 884 | + now: 2_000, |
| 885 | + preserveSingleModelCatalog: true, |
| 886 | + }); |
| 887 | + expect(provisionalUpdate).toBe(explicitSingletonCache); |
| 888 | + expect(provisionalUpdate.entry?.provider.models.map((m) => m.slug)).toEqual(["gmodel"]); |
834 | 889 | }); |
835 | 890 |
|
836 | 891 | it("updates the cache and promotes the expiry when live configuration discovers a catalog", () => { |
@@ -1036,6 +1091,13 @@ createInterface({ input: process.stdin }).on("line", (line) => { |
1036 | 1091 | }); |
1037 | 1092 | return; |
1038 | 1093 | } |
| 1094 | + if (payload && !Array.isArray(payload) && typeof payload.fail === "string") { |
| 1095 | + send({ |
| 1096 | + id, |
| 1097 | + error: { code: payload.code ?? -32603, message: payload.fail }, |
| 1098 | + }); |
| 1099 | + return; |
| 1100 | + } |
1039 | 1101 | const availableModels = payload.map((entry) => |
1040 | 1102 | typeof entry === "string" ? { modelId: entry, name: entry } : entry, |
1041 | 1103 | ); |
@@ -1492,6 +1554,56 @@ it.layer(driverLayer)("AcpRegistryDriver periodic refresh", (it) => { |
1492 | 1554 | Option.getOrThrow(yield* Fiber.join(afterProvisional)).models.map((model) => model.slug), |
1493 | 1555 | ).toEqual(["new-model", "old-model", "other-model"]); |
1494 | 1556 |
|
| 1557 | + // A provisional probe must still use the short retry TTL even when it retains a multi-model catalog. |
| 1558 | + yield* fileSystem.writeFileString( |
| 1559 | + modelsPath, |
| 1560 | + JSON.stringify(["new-model", "old-model", "other-model", "settled-model"]), |
| 1561 | + ); |
| 1562 | + yield* TestClock.adjust("1 minute"); |
| 1563 | + const afterProvisionalRetry = yield* waitForEnriched().pipe( |
| 1564 | + Effect.forkScoped({ startImmediately: true }), |
| 1565 | + ); |
| 1566 | + yield* instance.snapshot.refresh; |
| 1567 | + expect( |
| 1568 | + Option.getOrThrow(yield* Fiber.join(afterProvisionalRetry)).models.map( |
| 1569 | + (model) => model.slug, |
| 1570 | + ), |
| 1571 | + ).toEqual(["new-model", "old-model", "other-model", "settled-model"]); |
| 1572 | + |
| 1573 | + // A transient discovery failure after TTL expiry must surface warning status without |
| 1574 | + // dropping the accepted catalog to synthetic default, and must stay uncached for retry. |
| 1575 | + yield* fileSystem.writeFileString( |
| 1576 | + modelsPath, |
| 1577 | + JSON.stringify({ fail: "Temporary discovery outage" }), |
| 1578 | + ); |
| 1579 | + yield* TestClock.adjust("16 minutes"); |
| 1580 | + const failedProbe = yield* instance.snapshot.streamChanges.pipe( |
| 1581 | + Stream.filter((snapshot) => snapshot.status === "warning"), |
| 1582 | + Stream.runHead, |
| 1583 | + Effect.forkScoped({ startImmediately: true }), |
| 1584 | + ); |
| 1585 | + yield* instance.snapshot.refresh; |
| 1586 | + const warned = Option.getOrThrow(yield* Fiber.join(failedProbe)); |
| 1587 | + expect(warned.status).toBe("warning"); |
| 1588 | + expect(warned.models.map((model) => model.slug)).toEqual([ |
| 1589 | + "new-model", |
| 1590 | + "old-model", |
| 1591 | + "other-model", |
| 1592 | + "settled-model", |
| 1593 | + ]); |
| 1594 | + |
| 1595 | + yield* fileSystem.writeFileString( |
| 1596 | + modelsPath, |
| 1597 | + JSON.stringify(["new-model", "old-model", "other-model", "settled-model"]), |
| 1598 | + ); |
| 1599 | + const recovered = yield* waitForEnriched().pipe( |
| 1600 | + Effect.forkScoped({ startImmediately: true }), |
| 1601 | + ); |
| 1602 | + yield* instance.snapshot.refresh; |
| 1603 | + expect( |
| 1604 | + Option.getOrThrow(yield* Fiber.join(recovered)).models.map((model) => model.slug), |
| 1605 | + ).toEqual(["new-model", "old-model", "other-model", "settled-model"]); |
| 1606 | + |
1495 | 1607 | // Readiness must keep the last accepted catalog when enrichment is skipped during foreground startup, |
1496 | 1608 | // and drop that fallback once caches are invalidated. |
1497 | 1609 | const startupEntered = yield* Deferred.make<void>(); |
@@ -1511,6 +1623,7 @@ it.layer(driverLayer)("AcpRegistryDriver periodic refresh", (it) => { |
1511 | 1623 | "new-model", |
1512 | 1624 | "old-model", |
1513 | 1625 | "other-model", |
| 1626 | + "settled-model", |
1514 | 1627 | ]); |
1515 | 1628 |
|
1516 | 1629 | yield* instance.invalidateCaches ?? Effect.void; |
@@ -1615,6 +1728,55 @@ it.layer(driverLayer)("AcpRegistryDriver periodic refresh", (it) => { |
1615 | 1728 | (config) => config.currentModelId, |
1616 | 1729 | ), |
1617 | 1730 | ).toEqual(Option.some("entitled-model")); |
| 1731 | + |
| 1732 | + // A subsequent provisional single-model live update must not replace the explicit singleton |
| 1733 | + // catalog or downgrade its provenance. |
| 1734 | + const provisionalProcessed = yield* instance.snapshot.streamChanges.pipe( |
| 1735 | + Stream.filter( |
| 1736 | + (snapshot) => |
| 1737 | + snapshot.models |
| 1738 | + .find((model) => model.slug === "entitled-model") |
| 1739 | + ?.capabilities?.optionDescriptors?.some((option) => option.id === "effort") === true, |
| 1740 | + ), |
| 1741 | + Stream.runHead, |
| 1742 | + Effect.forkScoped({ startImmediately: true }), |
| 1743 | + ); |
| 1744 | + yield* coordinator.publishLiveConfiguration(identity.instanceId, { |
| 1745 | + models: [{ id: "live-placeholder", name: "Live Placeholder", description: null }], |
| 1746 | + currentModelId: "live-placeholder", |
| 1747 | + configOptions: [ |
| 1748 | + { |
| 1749 | + id: "effort", |
| 1750 | + label: "Effort", |
| 1751 | + type: "select", |
| 1752 | + currentValue: "high", |
| 1753 | + options: [ |
| 1754 | + { id: "low", label: "Low" }, |
| 1755 | + { id: "high", label: "High" }, |
| 1756 | + ], |
| 1757 | + }, |
| 1758 | + ], |
| 1759 | + modelsFromModelSelect: false, |
| 1760 | + }); |
| 1761 | + expect( |
| 1762 | + Option.getOrThrow(yield* Fiber.join(provisionalProcessed)).models.map( |
| 1763 | + (model) => model.slug, |
| 1764 | + ), |
| 1765 | + ).toEqual(["entitled-model"]); |
| 1766 | + |
| 1767 | + yield* fileSystem.writeFileString(modelsPath, JSON.stringify({ provisional: "placeholder" })); |
| 1768 | + yield* TestClock.adjust("16 minutes"); |
| 1769 | + const afterProvisionalProbe = yield* instance.snapshot.streamChanges.pipe( |
| 1770 | + Stream.filter((snapshot) => snapshot.nativeSessions !== undefined), |
| 1771 | + Stream.runHead, |
| 1772 | + Effect.forkScoped({ startImmediately: true }), |
| 1773 | + ); |
| 1774 | + yield* instance.snapshot.refresh; |
| 1775 | + expect( |
| 1776 | + Option.getOrThrow(yield* Fiber.join(afterProvisionalProbe)).models.map( |
| 1777 | + (model) => model.slug, |
| 1778 | + ), |
| 1779 | + ).toEqual(["entitled-model"]); |
1618 | 1780 | }), |
1619 | 1781 | ); |
1620 | 1782 |
|
@@ -1636,6 +1798,9 @@ it.layer(driverLayer)("AcpRegistryDriver periodic refresh", (it) => { |
1636 | 1798 | const staleCallbackEntered = yield* Deferred.make<void>(); |
1637 | 1799 | const releaseStaleCallback = yield* Deferred.make<void>(); |
1638 | 1800 | const staleCallbackDone = yield* Deferred.make<void>(); |
| 1801 | + const newerCallbackEntered = yield* Deferred.make<void>(); |
| 1802 | + const releaseNewerCallback = yield* Deferred.make<void>(); |
| 1803 | + const newerCallbackDone = yield* Deferred.make<void>(); |
1639 | 1804 | const secondWatcherSubscribed = yield* Deferred.make<void>(); |
1640 | 1805 | let postTtlLiveReads = 0; |
1641 | 1806 | let armed = false; |
@@ -1672,7 +1837,14 @@ it.layer(driverLayer)("AcpRegistryDriver periodic refresh", (it) => { |
1672 | 1837 | Effect.andThen(Deferred.succeed(staleCallbackDone, undefined)), |
1673 | 1838 | Effect.asVoid, |
1674 | 1839 | ) |
1675 | | - : onUpdate(configuration, revision), |
| 1840 | + : configuration.currentModelId === "newer-live-model" |
| 1841 | + ? Deferred.succeed(newerCallbackEntered, undefined).pipe( |
| 1842 | + Effect.andThen(Deferred.await(releaseNewerCallback)), |
| 1843 | + Effect.andThen(onUpdate(configuration, revision)), |
| 1844 | + Effect.andThen(Deferred.succeed(newerCallbackDone, undefined)), |
| 1845 | + Effect.asVoid, |
| 1846 | + ) |
| 1847 | + : onUpdate(configuration, revision), |
1676 | 1848 | options, |
1677 | 1849 | ); |
1678 | 1850 | }), |
@@ -1746,6 +1918,19 @@ it.layer(driverLayer)("AcpRegistryDriver periodic refresh", (it) => { |
1746 | 1918 | Option.getOrThrow(yield* Fiber.join(probed)).models.map((model) => model.slug), |
1747 | 1919 | ).toEqual(["old-model", "other-model", "new-model"]); |
1748 | 1920 |
|
| 1921 | + // Publish a newer live revision while the stale callback is still paused so currentLive is |
| 1922 | + // Option.some(newer) when the stale callback resumes, specifically exercising the |
| 1923 | + // clearedThroughRevision watermark. |
| 1924 | + yield* coordinator.publishLiveConfiguration(identity.instanceId, { |
| 1925 | + models: [ |
| 1926 | + { id: "old-model", name: "old-model", description: null }, |
| 1927 | + { id: "newer-live-model", name: "newer-live-model", description: null }, |
| 1928 | + ], |
| 1929 | + currentModelId: "newer-live-model", |
| 1930 | + configOptions: [], |
| 1931 | + modelsFromModelSelect: true, |
| 1932 | + }); |
| 1933 | + |
1749 | 1934 | // Releasing the delayed watcher callback must not overwrite the snapshot, cache, or accepted catalog. |
1750 | 1935 | yield* Deferred.succeed(releaseStaleCallback, undefined); |
1751 | 1936 | yield* Deferred.await(staleCallbackDone); |
@@ -1755,6 +1940,15 @@ it.layer(driverLayer)("AcpRegistryDriver periodic refresh", (it) => { |
1755 | 1940 | "new-model", |
1756 | 1941 | ]); |
1757 | 1942 |
|
| 1943 | + // The newer live revision queued behind it must still be applied. |
| 1944 | + yield* Deferred.await(newerCallbackEntered); |
| 1945 | + yield* Deferred.succeed(releaseNewerCallback, undefined); |
| 1946 | + yield* Deferred.await(newerCallbackDone); |
| 1947 | + expect((yield* instance.snapshot.getSnapshot).models.map((model) => model.slug)).toEqual([ |
| 1948 | + "old-model", |
| 1949 | + "newer-live-model", |
| 1950 | + ]); |
| 1951 | + |
1758 | 1952 | yield* fileSystem.writeFileString( |
1759 | 1953 | modelsPath, |
1760 | 1954 | JSON.stringify(["unexpected-reprobe", "other-model"]), |
@@ -1763,7 +1957,7 @@ it.layer(driverLayer)("AcpRegistryDriver periodic refresh", (it) => { |
1763 | 1957 | yield* instance.snapshot.refresh; |
1764 | 1958 | expect( |
1765 | 1959 | Option.getOrThrow(yield* Fiber.join(cached)).models.map((model) => model.slug), |
1766 | | - ).toEqual(["old-model", "other-model", "new-model"]); |
| 1960 | + ).toEqual(["old-model", "newer-live-model"]); |
1767 | 1961 | }), |
1768 | 1962 | ); |
1769 | 1963 | }); |