@intentic/sandbox-contract 1.427.0 → 1.428.0

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.
Files changed (171) hide show
  1. package/README.md +22 -5
  2. package/dist/contracts/accounts.contract.d.ts +4 -0
  3. package/dist/contracts/accounts.contract.d.ts.map +1 -1
  4. package/dist/contracts/agent.contract.d.ts +60 -0
  5. package/dist/contracts/agent.contract.d.ts.map +1 -1
  6. package/dist/contracts/agents.contract.d.ts +617 -0
  7. package/dist/contracts/agents.contract.d.ts.map +1 -1
  8. package/dist/contracts/agents.contract.js +11 -0
  9. package/dist/contracts/agents.contract.js.map +1 -1
  10. package/dist/contracts/bases.contract.d.ts +43 -0
  11. package/dist/contracts/bases.contract.d.ts.map +1 -0
  12. package/dist/contracts/bases.contract.js +33 -0
  13. package/dist/contracts/bases.contract.js.map +1 -0
  14. package/dist/contracts/ci.contract.d.ts +17 -0
  15. package/dist/contracts/ci.contract.d.ts.map +1 -1
  16. package/dist/contracts/loops.contract.d.ts +2 -0
  17. package/dist/contracts/loops.contract.d.ts.map +1 -1
  18. package/dist/contracts/needs.contract.d.ts +52 -0
  19. package/dist/contracts/needs.contract.d.ts.map +1 -1
  20. package/dist/contracts/offload.contract.d.ts +14 -14
  21. package/dist/contracts/runner.contract.d.ts +62 -14
  22. package/dist/contracts/runner.contract.d.ts.map +1 -1
  23. package/dist/contracts/seal.contract.d.ts +10 -0
  24. package/dist/contracts/seal.contract.d.ts.map +1 -1
  25. package/dist/contracts/sessions.contract.d.ts +6 -0
  26. package/dist/contracts/sessions.contract.d.ts.map +1 -1
  27. package/dist/contracts/settings.contract.d.ts +4 -0
  28. package/dist/contracts/settings.contract.d.ts.map +1 -1
  29. package/dist/contracts/system.contract.d.ts +370 -4
  30. package/dist/contracts/system.contract.d.ts.map +1 -1
  31. package/dist/contracts/system.contract.js +45 -0
  32. package/dist/contracts/system.contract.js.map +1 -1
  33. package/dist/contracts/translator.contract.d.ts +8 -0
  34. package/dist/contracts/translator.contract.d.ts.map +1 -1
  35. package/dist/contracts/usage.contract.d.ts +110 -0
  36. package/dist/contracts/usage.contract.d.ts.map +1 -1
  37. package/dist/contracts/usage.contract.js +18 -0
  38. package/dist/contracts/usage.contract.js.map +1 -1
  39. package/dist/contracts/workflows.contract.d.ts +3 -0
  40. package/dist/contracts/workflows.contract.d.ts.map +1 -1
  41. package/dist/events/agent-events.d.ts +26 -0
  42. package/dist/events/agent-events.d.ts.map +1 -1
  43. package/dist/events/agent-events.js +4 -0
  44. package/dist/events/agent-events.js.map +1 -1
  45. package/dist/events/agent-transcript.d.ts +6 -0
  46. package/dist/events/agent-transcript.d.ts.map +1 -1
  47. package/dist/events/system-events.d.ts +222 -0
  48. package/dist/events/system-events.d.ts.map +1 -1
  49. package/dist/events/system-events.js +6 -0
  50. package/dist/events/system-events.js.map +1 -1
  51. package/dist/events/transcript.d.ts +30 -0
  52. package/dist/events/transcript.d.ts.map +1 -1
  53. package/dist/index.d.ts +2 -0
  54. package/dist/index.d.ts.map +1 -1
  55. package/dist/index.js +2 -0
  56. package/dist/index.js.map +1 -1
  57. package/dist/models/plan-pools.d.ts +8 -7
  58. package/dist/models/plan-pools.d.ts.map +1 -1
  59. package/dist/models/plan-pools.js +63 -40
  60. package/dist/models/plan-pools.js.map +1 -1
  61. package/dist/models/verdict/current-windows.d.ts +9 -0
  62. package/dist/models/verdict/current-windows.d.ts.map +1 -0
  63. package/dist/models/verdict/current-windows.js +60 -0
  64. package/dist/models/verdict/current-windows.js.map +1 -0
  65. package/dist/models/verdict/refusal-verdict.d.ts +6 -3
  66. package/dist/models/verdict/refusal-verdict.d.ts.map +1 -1
  67. package/dist/models/verdict/refusal-verdict.js +71 -18
  68. package/dist/models/verdict/refusal-verdict.js.map +1 -1
  69. package/dist/models/verdict/window-period.d.ts +7 -1
  70. package/dist/models/verdict/window-period.d.ts.map +1 -1
  71. package/dist/models/verdict/window-period.js +21 -2
  72. package/dist/models/verdict/window-period.js.map +1 -1
  73. package/dist/protocol/raw/raw-routes.d.ts +13 -0
  74. package/dist/protocol/raw/raw-routes.d.ts.map +1 -1
  75. package/dist/protocol/raw/raw-routes.js +4 -0
  76. package/dist/protocol/raw/raw-routes.js.map +1 -1
  77. package/dist/schemas/agents-list.d.ts +4 -0
  78. package/dist/schemas/agents-list.d.ts.map +1 -1
  79. package/dist/schemas/agents.d.ts +6 -0
  80. package/dist/schemas/agents.d.ts.map +1 -1
  81. package/dist/schemas/agents.js +2 -0
  82. package/dist/schemas/agents.js.map +1 -1
  83. package/dist/schemas/bases.d.ts +52 -0
  84. package/dist/schemas/bases.d.ts.map +1 -0
  85. package/dist/schemas/bases.js +31 -0
  86. package/dist/schemas/bases.js.map +1 -0
  87. package/dist/schemas/ci.d.ts +35 -0
  88. package/dist/schemas/ci.d.ts.map +1 -1
  89. package/dist/schemas/ci.js +25 -0
  90. package/dist/schemas/ci.js.map +1 -1
  91. package/dist/schemas/context-continues.d.ts +5 -0
  92. package/dist/schemas/context-continues.d.ts.map +1 -0
  93. package/dist/schemas/context-continues.js +17 -0
  94. package/dist/schemas/context-continues.js.map +1 -0
  95. package/dist/schemas/device-stacks.d.ts +161 -0
  96. package/dist/schemas/device-stacks.d.ts.map +1 -0
  97. package/dist/schemas/device-stacks.js +65 -0
  98. package/dist/schemas/device-stacks.js.map +1 -0
  99. package/dist/schemas/hosts.d.ts +2 -0
  100. package/dist/schemas/hosts.d.ts.map +1 -1
  101. package/dist/schemas/hosts.js +2 -0
  102. package/dist/schemas/hosts.js.map +1 -1
  103. package/dist/schemas/loops.d.ts +4 -0
  104. package/dist/schemas/loops.d.ts.map +1 -1
  105. package/dist/schemas/loops.js +7 -0
  106. package/dist/schemas/loops.js.map +1 -1
  107. package/dist/schemas/needs.d.ts +50 -1
  108. package/dist/schemas/needs.d.ts.map +1 -1
  109. package/dist/schemas/needs.js +16 -2
  110. package/dist/schemas/needs.js.map +1 -1
  111. package/dist/schemas/proceed-without-asking.d.ts +9 -0
  112. package/dist/schemas/proceed-without-asking.d.ts.map +1 -0
  113. package/dist/schemas/proceed-without-asking.js +17 -0
  114. package/dist/schemas/proceed-without-asking.js.map +1 -0
  115. package/dist/schemas/providers/capacity.d.ts +291 -0
  116. package/dist/schemas/providers/capacity.d.ts.map +1 -0
  117. package/dist/schemas/providers/capacity.js +64 -0
  118. package/dist/schemas/providers/capacity.js.map +1 -0
  119. package/dist/schemas/providers/plan-limits.d.ts +14 -0
  120. package/dist/schemas/providers/plan-limits.d.ts.map +1 -1
  121. package/dist/schemas/providers/plan-limits.js +9 -2
  122. package/dist/schemas/providers/plan-limits.js.map +1 -1
  123. package/dist/schemas/providers/provider-oauth.d.ts +4 -0
  124. package/dist/schemas/providers/provider-oauth.d.ts.map +1 -1
  125. package/dist/schemas/providers/refusals.d.ts +8 -0
  126. package/dist/schemas/providers/refusals.d.ts.map +1 -1
  127. package/dist/schemas/providers/refusals.js +8 -0
  128. package/dist/schemas/providers/refusals.js.map +1 -1
  129. package/dist/schemas/run-targets.d.ts +1 -0
  130. package/dist/schemas/run-targets.d.ts.map +1 -1
  131. package/dist/schemas/run-targets.js +2 -1
  132. package/dist/schemas/run-targets.js.map +1 -1
  133. package/dist/schemas/settings.d.ts +4 -0
  134. package/dist/schemas/settings.d.ts.map +1 -1
  135. package/dist/schemas/settings.js +6 -8
  136. package/dist/schemas/settings.js.map +1 -1
  137. package/dist/schemas/workflows.d.ts +5 -0
  138. package/dist/schemas/workflows.d.ts.map +1 -1
  139. package/dist/state/definition.d.ts +8 -0
  140. package/dist/state/definition.d.ts.map +1 -1
  141. package/package.json +5 -5
  142. package/src/contracts/agents.contract.ts +13 -0
  143. package/src/contracts/bases.contract.ts +38 -0
  144. package/src/contracts/system.contract.ts +66 -0
  145. package/src/contracts/usage.contract.ts +21 -0
  146. package/src/events/agent-events.ts +8 -0
  147. package/src/events/system-events.ts +11 -0
  148. package/src/index.ts +3 -0
  149. package/src/models/plan-pools.test.ts +271 -39
  150. package/src/models/plan-pools.ts +132 -70
  151. package/src/models/verdict/current-windows.ts +95 -0
  152. package/src/models/verdict/refusal-verdict.ts +124 -30
  153. package/src/models/verdict/window-period.ts +53 -6
  154. package/src/protocol/raw/raw-routes.ts +9 -0
  155. package/src/schemas/agents.ts +2 -0
  156. package/src/schemas/bases.ts +48 -0
  157. package/src/schemas/ci.ts +35 -0
  158. package/src/schemas/context-continues.ts +40 -0
  159. package/src/schemas/device-stacks.ts +126 -0
  160. package/src/schemas/hosts.ts +4 -0
  161. package/src/schemas/loops.ts +10 -0
  162. package/src/schemas/needs.ts +25 -2
  163. package/src/schemas/proceed-without-asking.ts +37 -0
  164. package/src/schemas/providers/capacity.ts +91 -0
  165. package/src/schemas/providers/plan-limits.ts +20 -3
  166. package/src/schemas/providers/refusals.ts +17 -0
  167. package/src/schemas/run-targets.ts +4 -3
  168. package/src/schemas/settings.ts +6 -14
  169. package/src/state/daemon-floor.test.ts +2 -0
  170. package/src/state/workspace-state.test.ts +3 -3
  171. package/src/state/workspace-state.ts +1 -1
@@ -12,8 +12,11 @@ import {
12
12
  preferredAccount,
13
13
  refusalVerdict,
14
14
  refusedInstant,
15
+ refusedPoolOf,
15
16
  refusedPoolReset,
17
+ stampedRefusal,
16
18
  bestWithRoom,
19
+ capacityValidUntil,
17
20
  NEARLY_OUT_ROOM,
18
21
  renewalOf,
19
22
  scopedWindow,
@@ -110,6 +113,38 @@ test("a window's length is read off the provider's own key, and off its name whe
110
113
  expect(period("model:Fable", "Fable")).toBeUndefined();
111
114
  });
112
115
 
116
+ // 2026-11-19: the reader states the length where the provider's answer says it (UsageWindow.periodSeconds), once, and
117
+ // every judgement reads that rather than the words. A window filed before then keeps being read off its words.
118
+ test("a window's stated length outranks its key and its name, and is named as the words would name it", () => {
119
+ // A key that says one length and a statement that says another: the statement is the provider's word.
120
+ expect(windowPeriod({ kind: "five_hour", periodSeconds: 86_400 })).toEqual({ seconds: 86_400, short: "24h" });
121
+ // Claude's model slice, named only by its model, has a length once its reader states the week its key named.
122
+ expect(windowPeriod({ kind: "model:Fable", label: "Fable", periodSeconds: 604_800 })).toEqual({ seconds: 604_800, short: "wk" });
123
+ expect(windowPeriod({ kind: "model:Fable", label: "Fable" })).toBeUndefined();
124
+ const stated = (periodSeconds: number) => windowPeriod({ kind: "claude:tangelo", periodSeconds })?.short;
125
+ expect(stated(18_000)).toBe("5h");
126
+ expect(stated(43_200)).toBe("12h");
127
+ expect(stated(86_400)).toBe("24h");
128
+ expect(stated(3 * 86_400)).toBe("3d");
129
+ expect(stated(604_800)).toBe("wk");
130
+ expect(stated(28 * 86_400)).toBe("mo");
131
+ expect(stated(30 * 86_400)).toBe("mo");
132
+ expect(stated(31 * 86_400)).toBe("mo");
133
+ expect(stated(32 * 86_400)).toBe("32d");
134
+ expect(stated(1_800)).toBe("30m");
135
+ expect(stated(90)).toBe("90s");
136
+
137
+ // It is what a reading with no published reset is trusted for, and what the renewal a pick weighs is judged by.
138
+ const NOW = 1_700_000_000_000;
139
+ const DAY = 86_400_000;
140
+ const slice = window({ kind: "model:Fable", label: "Fable", utilization: 40, periodSeconds: 604_800 });
141
+ expect(windowLive(slice, NOW - 6 * DAY, NOW)).toBe(true);
142
+ expect(windowLive(slice, NOW - 8 * DAY, NOW)).toBe(false);
143
+ const fiveHour = window({ kind: "five_hour", resetsAt: 100 });
144
+ expect(renewalOf([fiveHour, window({ kind: "model:Fable", label: "Fable", resetsAt: 900, periodSeconds: 604_800 })])).toBe(900);
145
+ expect(renewalOf([fiveHour, window({ kind: "model:Fable", label: "Fable", resetsAt: 900 })])).toBe(100);
146
+ });
147
+
113
148
  test("a reading is live until its reset, or, with none published, for one window's length after it was taken", () => {
114
149
  const NOW = 1_700_000_000_000;
115
150
  const HOUR = 3_600_000;
@@ -164,6 +199,10 @@ test("a pool whose window closed since its reading stays on the account, at the
164
199
 
165
200
  const at = (measuredAt: number, ...windows: UsageWindow[]): AccountUsage => ({ windows, measuredAt });
166
201
  const refusal = (over: Partial<ProviderRefusal> & Pick<ProviderRefusal, "kind">): ProviderRefusal => ({ at: 1_000, message: "no.", ...over });
202
+ // An instant inside every window the fixtures below read in the first seconds of the epoch (a five-hour pool measured at
203
+ // 500 ms is current until 18,000,500 ms): the rule takes each reading as it stands at the instant it judges, so a fixture
204
+ // judged by today's clock would read every such window long closed.
205
+ const SOON = 10_000;
167
206
 
168
207
  test("spent is the contract's one line: 99.5% still has room, 100% is spent until its last full pool reopens", () => {
169
208
  expect(readingHeadroom(usage(window({ kind: "five_hour", utilization: 99.5 })))).toEqual({ kind: "ready", room: 0.5 });
@@ -188,8 +227,8 @@ test("a pool read at 100 in whole percents is at the line with no room, until a
188
227
  // The provider refused it: spent until the pool reopens, and a reading still at the line does not answer that.
189
228
  const facts = { account: "a", usage: { ...atLine, measuredAt: 2_000 } };
190
229
  const refused = refusal({ kind: "limit", account: "a" });
191
- expect(refusalVerdict(refused, [facts])).toBe("standing");
192
- expect(serviceStates([facts], [refused]).get("a")).toEqual({ kind: "spent", reopensAt: 900 });
230
+ expect(refusalVerdict(refused, [facts], SOON)).toBe("standing");
231
+ expect(serviceStates([facts], [refused], undefined, SOON).get("a")).toEqual({ kind: "spent", reopensAt: 900 });
193
232
  });
194
233
 
195
234
  test("with no model named, an account is spent only when no model can run on it", () => {
@@ -214,75 +253,75 @@ test("with no model named, an account is spent only when no model can run on it"
214
253
 
215
254
  test("a revoked sign-in outranks a lost seat, which outranks a bench, whatever the meters say", () => {
216
255
  const facts = { account: "a", usage: usage(window({ kind: "five_hour", utilization: 0 })) };
217
- expect(serviceState({ ...facts, needsReauth: true, seatRefusal: "no seat" })).toEqual({ kind: "blocked", fix: "reconnect", reason: "sign-in expired" });
218
- expect(serviceState({ ...facts, seatRefusal: "Your org disabled Claude Code." })).toEqual({
256
+ expect(serviceState({ ...facts, needsReauth: true, seatRefusal: "no seat" }, [], undefined, Date.now())).toEqual({ kind: "blocked", fix: "reconnect", reason: "sign-in expired" });
257
+ expect(serviceState({ ...facts, seatRefusal: "Your org disabled Claude Code." }, [], undefined, Date.now())).toEqual({
219
258
  kind: "blocked",
220
259
  fix: "admin",
221
260
  reason: "Your org disabled Claude Code.",
222
261
  });
223
- expect(serviceState({ ...facts, cooling: { reason: "no project" } })).toEqual({ kind: "blocked", fix: "reconnect", reason: "no project" });
224
- expect(serviceState({ ...facts, cooling: { until: 2_000 } }, undefined, undefined, 1_000_000)).toEqual({
262
+ expect(serviceState({ ...facts, cooling: { reason: "no project" } }, [], undefined, Date.now())).toEqual({ kind: "blocked", fix: "reconnect", reason: "no project" });
263
+ expect(serviceState({ ...facts, cooling: { until: 2_000 } }, [], undefined, 1_000_000)).toEqual({
225
264
  kind: "blocked",
226
265
  fix: "wait",
227
266
  reason: "cooling down",
228
267
  until: 2_000,
229
268
  });
230
269
  // One Google wants its owner to verify: neither waiting nor reconnecting lifts it, and the row carries the page.
231
- expect(serviceState({ ...facts, cooling: { reason: "Verify your account to continue.", verify: "https://accounts.google.com/v" } })).toEqual({
270
+ expect(serviceState({ ...facts, cooling: { reason: "Verify your account to continue.", verify: "https://accounts.google.com/v" } }, [], undefined, Date.now())).toEqual({
232
271
  kind: "blocked",
233
272
  fix: "verify",
234
273
  reason: "Verify your account to continue.",
235
274
  url: "https://accounts.google.com/v",
236
275
  });
237
276
  // A bench whose instant has passed is over.
238
- expect(serviceState({ ...facts, cooling: { until: 999 } }, undefined, undefined, 1_000_000)).toEqual({ kind: "ready", room: 100 });
277
+ expect(serviceState({ ...facts, cooling: { until: 999 } }, [], undefined, 1_000_000)).toEqual({ kind: "ready", room: 100 });
239
278
  });
240
279
 
241
280
  test("a standing refusal blocks by its kind, and a limit refusal pins only the pool its model spends", () => {
242
281
  const facts = { account: "a", usage: CLAUDE };
243
- expect(serviceState(facts, [refusal({ kind: "auth" })])).toEqual({ kind: "blocked", fix: "reconnect", reason: "no." });
244
- expect(serviceState(facts, [refusal({ kind: "entitlement" })])).toEqual({ kind: "blocked", fix: "admin", reason: "no." });
282
+ expect(serviceState(facts, [refusal({ kind: "auth" })], undefined, SOON)).toEqual({ kind: "blocked", fix: "reconnect", reason: "no." });
283
+ expect(serviceState(facts, [refusal({ kind: "entitlement" })], undefined, SOON)).toEqual({ kind: "blocked", fix: "admin", reason: "no." });
245
284
  // Refused on Haiku: the 5-hour/weekly binding pool (seven_day, 30%) reads full, so Haiku is spent too.
246
- expect(serviceState(facts, [refusal({ kind: "limit", model: "claude-haiku-4-5" })], { id: "claude-haiku-4-5" })).toEqual({ kind: "spent" });
285
+ expect(serviceState(facts, [refusal({ kind: "limit", model: "claude-haiku-4-5" })], { id: "claude-haiku-4-5" }, SOON)).toEqual({ kind: "spent" });
247
286
  // Refused on Opus: its own slice was already full; Haiku keeps the room its pools show.
248
- expect(serviceState(facts, [refusal({ kind: "limit", model: "claude-opus-4-6" })], { id: "claude-haiku-4-5" })).toEqual({ kind: "ready", room: 70 });
287
+ expect(serviceState(facts, [refusal({ kind: "limit", model: "claude-opus-4-6" })], { id: "claude-haiku-4-5" }, SOON)).toEqual({ kind: "ready", room: 70 });
249
288
  // No reading at all: the refusal is the evidence, unless it was about another model.
250
- expect(serviceState({ account: "a" }, [refusal({ kind: "limit" })])).toEqual({ kind: "spent" });
251
- expect(serviceState({ account: "a" }, [refusal({ kind: "limit", model: "opus" })], { id: "haiku" })).toEqual({ kind: "unknown" });
289
+ expect(serviceState({ account: "a" }, [refusal({ kind: "limit" })], undefined, SOON)).toEqual({ kind: "spent" });
290
+ expect(serviceState({ account: "a" }, [refusal({ kind: "limit", model: "opus" })], { id: "haiku" }, SOON)).toEqual({ kind: "unknown" });
252
291
  });
253
292
 
254
293
  test("a refusal stands until a later reading contradicts it, and never past its account's disconnection", () => {
255
294
  const room = at(2_000, window({ kind: "five_hour", utilization: 40 }));
256
295
  const full = at(2_000, window({ kind: "five_hour", utilization: 100 }));
257
296
  const before = at(500, window({ kind: "five_hour", utilization: 40 }));
258
- expect(refusalVerdict(refusal({ kind: "limit", account: "a" }), [{ account: "a", usage: room }])).toBe("answered");
259
- expect(refusalVerdict(refusal({ kind: "limit", account: "a" }), [{ account: "a", usage: full }])).toBe("standing");
260
- expect(refusalVerdict(refusal({ kind: "limit", account: "a" }), [{ account: "a", usage: before }])).toBe("standing");
297
+ expect(refusalVerdict(refusal({ kind: "limit", account: "a" }), [{ account: "a", usage: room }], SOON)).toBe("answered");
298
+ expect(refusalVerdict(refusal({ kind: "limit", account: "a" }), [{ account: "a", usage: full }], SOON)).toBe("standing");
299
+ expect(refusalVerdict(refusal({ kind: "limit", account: "a" }), [{ account: "a", usage: before }], SOON)).toBe("standing");
261
300
  // Another account's room proves nothing about the one refused.
262
- expect(refusalVerdict(refusal({ kind: "limit", account: "a" }), [{ account: "a", usage: before }, { account: "b", usage: room }])).toBe("standing");
301
+ expect(refusalVerdict(refusal({ kind: "limit", account: "a" }), [{ account: "a", usage: before }, { account: "b", usage: room }], SOON)).toBe("standing");
263
302
  // A refusal naming no account is answered on each account by that account's own reading: b's room frees b, not a.
264
303
  const nameless = refusal({ kind: "limit" });
265
- expect(refusalVerdict(nameless, [{ account: "a", usage: before }, { account: "b", usage: room }])).toBe("standing");
266
- expect(Object.fromEntries(serviceStates([{ account: "a", usage: before }, { account: "b", usage: room }], [nameless]))).toEqual({
304
+ expect(refusalVerdict(nameless, [{ account: "a", usage: before }, { account: "b", usage: room }], SOON)).toBe("standing");
305
+ expect(Object.fromEntries(serviceStates([{ account: "a", usage: before }, { account: "b", usage: room }], [nameless], undefined, SOON))).toEqual({
267
306
  a: { kind: "spent" },
268
307
  b: { kind: "ready", room: 60 },
269
308
  });
270
- expect(refusalVerdict(nameless, [{ account: "a", usage: room }, { account: "b", usage: room }])).toBe("answered");
271
- expect(refusalVerdict(refusal({ kind: "auth", account: "a" }), [{ account: "a", usage: full }])).toBe("answered");
272
- expect(refusalVerdict(refusal({ kind: "auth", account: "a" }), [{ account: "a", usage: full, needsReauth: true }])).toBe("standing");
273
- expect(refusalVerdict(refusal({ kind: "entitlement", account: "a" }), [{ account: "a", usage: room }])).toBe("standing");
274
- expect(refusalVerdict(refusal({ kind: "limit", account: "gone" }), [{ account: "a", usage: room }])).toBe("gone");
275
- expect(refusalVerdict(refusal({ kind: "limit", account: "a" }), [])).toBe("standing");
309
+ expect(refusalVerdict(nameless, [{ account: "a", usage: room }, { account: "b", usage: room }], SOON)).toBe("answered");
310
+ expect(refusalVerdict(refusal({ kind: "auth", account: "a" }), [{ account: "a", usage: full }], SOON)).toBe("answered");
311
+ expect(refusalVerdict(refusal({ kind: "auth", account: "a" }), [{ account: "a", usage: full, needsReauth: true }], SOON)).toBe("standing");
312
+ expect(refusalVerdict(refusal({ kind: "entitlement", account: "a" }), [{ account: "a", usage: room }], SOON)).toBe("standing");
313
+ expect(refusalVerdict(refusal({ kind: "limit", account: "gone" }), [{ account: "a", usage: room }], SOON)).toBe("gone");
314
+ expect(refusalVerdict(refusal({ kind: "limit", account: "a" }), [], SOON)).toBe("standing");
276
315
  });
277
316
 
278
317
  // An admin's allowance (Cursor's team spend limit) is one the refused account's own reading does not measure.
279
318
  test("an allowance no reading measures stands against its own account's reading, until the provider's own reset", () => {
280
319
  const room = at(Date.now() + 60_000, window({ kind: "seven_day", utilization: 43 }));
281
320
  const credit = refusal({ kind: "limit", unmetered: true, at: Date.now(), resetsAt: Math.floor(Date.now() / 1000) + 3_600 });
282
- expect(refusalVerdict({ ...credit, account: "a" }, [{ account: "a", usage: room }, { account: "b", usage: room }])).toBe("standing");
283
- expect(refusalVerdict(credit, [{ account: "a", usage: room }])).toBe("standing");
284
- expect(refusalVerdict({ ...credit, account: "a", resetsAt: Math.floor(Date.now() / 1000) - 1 }, [{ account: "a", usage: room }])).toBe("answered");
285
- expect(refusalVerdict({ ...credit, resetsAt: undefined }, [{ account: "a", usage: room }])).toBe("standing");
321
+ expect(refusalVerdict({ ...credit, account: "a" }, [{ account: "a", usage: room }, { account: "b", usage: room }], Date.now())).toBe("standing");
322
+ expect(refusalVerdict(credit, [{ account: "a", usage: room }], Date.now())).toBe("standing");
323
+ expect(refusalVerdict({ ...credit, account: "a", resetsAt: Math.floor(Date.now() / 1000) - 1 }, [{ account: "a", usage: room }], Date.now())).toBe("answered");
324
+ expect(refusalVerdict({ ...credit, resetsAt: undefined }, [{ account: "a", usage: room }], Date.now())).toBe("standing");
286
325
  });
287
326
 
288
327
  // 2026-10-19: one routed refusal ("try again at 1:53 PM", filed a day out, as an admin's credit) named no account and
@@ -379,8 +418,9 @@ test("a stamped reset ends a refusal only where no reading since it says the poo
379
418
  expect(unstampedVerdict).toEqual({ kind: "spent", reopensAt: weeklyReset });
380
419
  expect(serviceStates([{ account: "a", usage: weeklyFull }], [stamped], undefined, now).get("a")).toEqual(unstampedVerdict);
381
420
  expect(fleetCapacity([{ account: "a", usage: weeklyFull }], [stamped], undefined, now)).toMatchObject({ kind: "spent", reopensAt: weeklyReset });
382
- // Nothing read since the stamp: it ends there. Read with room since: over.
383
- expect(serviceStates([{ account: "a", usage: refusedIn }], [stamped], undefined, now).get("a")).toEqual({ kind: "ready", room: 2, renewsAt: weeklyReset });
421
+ // Nothing read since the stamp: it ends there. Read with room since: over. The five-hour pool the refusal came in
422
+ // reset 700 s before `now`, so it reads lapsed at the floor and the weekly pool at 97 binds.
423
+ expect(serviceStates([{ account: "a", usage: refusedIn }], [stamped], undefined, now).get("a")).toEqual({ kind: "ready", room: 3, renewsAt: weeklyReset });
384
424
  const roomSince = at((fiveHourReset + 600) * 1000, window({ kind: "five_hour", utilization: 4, resetsAt: fiveHourReset + 18_000 }), window({ kind: "seven_day", utilization: 60, resetsAt: weeklyReset }));
385
425
  expect(refusalVerdict(stamped, [{ account: "a", usage: roomSince }], now)).toBe("answered");
386
426
  });
@@ -415,9 +455,9 @@ test("nothing is stamped where a pool's reset cannot speak for the refusal", ()
415
455
 
416
456
  test("a provider's accounts are judged together: a standing refusal lands only on the account it names", () => {
417
457
  const room = at(500, window({ kind: "five_hour", utilization: 40 }));
418
- const states = serviceStates([{ account: "a", usage: room }, { account: "b", usage: room }], [refusal({ kind: "entitlement", account: "a" })]);
458
+ const states = serviceStates([{ account: "a", usage: room }, { account: "b", usage: room }], [refusal({ kind: "entitlement", account: "a" })], undefined, SOON);
419
459
  expect(Object.fromEntries(states)).toEqual({ a: { kind: "blocked", fix: "admin", reason: "no." }, b: { kind: "ready", room: 60 } });
420
- const answered = serviceStates([{ account: "a", usage: at(2_000, window({ kind: "five_hour", utilization: 40 })) }], [refusal({ kind: "limit", account: "a" })]);
460
+ const answered = serviceStates([{ account: "a", usage: at(2_000, window({ kind: "five_hour", utilization: 40 })) }], [refusal({ kind: "limit", account: "a" })], undefined, SOON);
421
461
  expect(answered.get("a")).toEqual({ kind: "ready", room: 60 });
422
462
  });
423
463
 
@@ -439,8 +479,9 @@ test("each account answers to the newest refusal on file that still stands over
439
479
  });
440
480
  // Only the provider's last one: the first account is back at the line, no room but not proven spent.
441
481
  expect(serviceStates(accounts, [elsewhere], undefined, 9_999).get("a")).toEqual({ kind: "ready", room: 0, renewsAt: 20 });
442
- // Past the instant the provider named, its refusal is over and the reading speaks alone.
443
- expect(serviceStates(accounts, [elsewhere, own], undefined, 20_000).get("a")).toEqual({ kind: "ready", room: 0, renewsAt: 20 });
482
+ // Past the instant the provider named, its refusal is over, and so is the window the reading at the line was taken
483
+ // in, which reset at that same instant: nothing measures the account until it is read again.
484
+ expect(serviceStates(accounts, [elsewhere, own], undefined, 20_000).get("a")).toEqual({ kind: "unknown" });
444
485
  // A newer refusal on the same account outranks the older one.
445
486
  const revoked = refusal({ kind: "auth", account: "a", at: 6_000 });
446
487
  expect(serviceStates(accounts, [own, revoked], undefined, 9_999).get("a")).toEqual({ kind: "blocked", fix: "reconnect", reason: "no." });
@@ -455,9 +496,9 @@ test("a reading answers a spent allowance only in the pool the refused model spe
455
496
  );
456
497
  const flash = refusal({ kind: "limit", account: "a", model: "gemini-3.8-flash-high" });
457
498
  // Claude spent, Gemini open: room where Flash spends answers it, the full Claude pool notwithstanding.
458
- expect(refusalVerdict(flash, [{ account: "a", usage: pools(100, 40) }])).toBe("answered");
499
+ expect(refusalVerdict(flash, [{ account: "a", usage: pools(100, 40) }], Date.now())).toBe("answered");
459
500
  // Claude open, Gemini full: room in a pool Flash never spends answers nothing.
460
- expect(refusalVerdict(flash, [{ account: "a", usage: pools(0, 100) }])).toBe("standing");
501
+ expect(refusalVerdict(flash, [{ account: "a", usage: pools(0, 100) }], Date.now())).toBe("standing");
461
502
  });
462
503
 
463
504
  // 2026-11-08 (ci-fix-intentic-42395805126-attempt2): the translator tried five of 31 Google accounts per send, all
@@ -701,6 +742,128 @@ test("a refusal's instant is judged against the pools a reading since publishes:
701
742
  expect(serviceState({ account: "a", usage: { ...unnamed, measuredAt: filed - 1 } }, [sol], { id: "gpt-6-luna" }, now)).toMatchObject({ kind: "spent" });
702
743
  });
703
744
 
745
+ // 2026-11-19: which pool a refusal's instant belongs to is resolved once, by the ledger as it files the refusal, from the
746
+ // reading beside it (refusedPoolOf), and every judgement after reads that stamp. Re-inferring it on each judgement from
747
+ // whatever reading it held was rejected: a reading taken once the pool had moved said something else.
748
+ describe("a spent allowance resolved to its pool as it was filed", () => {
749
+ const DAY = 86_400;
750
+ const filed = Date.parse("2026-11-12T20:59:22Z");
751
+ const instant = Date.parse("2026-11-18T14:21:08Z") / 1000;
752
+ const now = Date.parse("2026-11-14T09:00:00Z");
753
+ const sol = refusal({ kind: "limit", account: "a", model: "gpt-6.1-sol", resetsAt: instant, at: filed });
754
+ const codex = (measuredAt: number, weekly: number, utilization = 30) =>
755
+ at(
756
+ measuredAt,
757
+ window({ kind: "five_hour", utilization: 36, resetsAt: Math.floor(measuredAt / 1000) + 3_600 }),
758
+ window({ kind: "seven_day", utilization, resetsAt: weekly }),
759
+ );
760
+ // The reading beside the refusal as it is filed: taken a minute before it, as a polled one is.
761
+ const filing = (weekly: number) => [{ account: "a", usage: codex(filed - 60_000, weekly) }];
762
+ const since = (weekly: number, utilization = 30) => codex(now - 60_000, weekly, utilization);
763
+
764
+ test("is the pool its instant was the reset of, from a reading taken before the refusal that no later judgement could read", () => {
765
+ const accounts = filing(instant + 60);
766
+ expect(refusedPoolOf(sol, accounts)).toEqual({ pool: "seven_day" });
767
+ // The reading beside it predates the refusal, so judged afterwards it says nothing of the instant.
768
+ expect(refusedInstant(sol, accounts[0]?.usage)).toBe("unjudged");
769
+ expect(stampedRefusal(sol, accounts)).toEqual({ ...sol, pool: "seven_day" });
770
+ });
771
+
772
+ test("pins exactly that pool however far a reading since puts its reset from the instant, where an unstamped one is guessed again", () => {
773
+ const stamped = { ...sol, pool: "seven_day" };
774
+ // Read since with the weekly reset 40 minutes past the instant: outside the half hour that names one reset.
775
+ const later = since(instant + 40 * 60);
776
+ expect(refusedInstant(sol, later)).toBe("unpublished");
777
+ expect(judgedReading(later, [stamped])?.windows.map((entry) => [entry.kind, entry.utilization, entry.resetsAt])).toEqual([
778
+ ["five_hour", 36, Math.floor(now / 1000) - 60 + 3_600],
779
+ ["seven_day", 100, instant],
780
+ ]);
781
+ expect(refusalVerdict(stamped, [{ account: "a", usage: later }], now)).toBe("standing");
782
+ expect(serviceState({ account: "a", usage: later }, [stamped], { id: "gpt-6-luna" }, now)).toEqual({ kind: "spent", reopensAt: instant });
783
+ // Unstamped, the same reading reads it as a pool of its own, holding Sol alone, as before.
784
+ expect(serviceState({ account: "a", usage: later }, [sol], { id: "gpt-6-luna" }, now)).toEqual({ kind: "ready", room: 64, renewsAt: instant + 40 * 60 });
785
+ expect(serviceState({ account: "a", usage: later }, [sol], { id: "gpt-6.1-sol" }, now)).toEqual({ kind: "spent", reopensAt: instant, pool: "GPT 6.1 Sol" });
786
+ });
787
+
788
+ test("is a pool of its own where its instant was no published pool's reset, whatever a reading since says", () => {
789
+ const accounts = filing(Math.floor(filed / 1000) + 5 * DAY);
790
+ expect(refusedPoolOf(sol, accounts)).toEqual({ poolUnpublished: true });
791
+ const unpublished = { ...sol, poolUnpublished: true as const };
792
+ // A reading since whose weekly reset happens to fall on the instant: unstamped, the refusal would be read as that
793
+ // window's and hold every model; stamped, it holds Sol alone until its instant.
794
+ const later = since(instant + 60);
795
+ expect(refusedInstant(sol, later)).toBe("published");
796
+ expect(serviceState({ account: "a", usage: later }, [sol], { id: "gpt-6-luna" }, now)).toEqual({ kind: "spent", reopensAt: instant });
797
+ expect(serviceState({ account: "a", usage: later }, [unpublished], { id: "gpt-6-luna" }, now)).toEqual({ kind: "ready", room: 64, renewsAt: instant + 60 });
798
+ expect(serviceState({ account: "a", usage: later }, [unpublished], { id: "gpt-6.1-sol" }, now)).toEqual({ kind: "spent", reopensAt: instant, pool: "GPT 6.1 Sol" });
799
+ expect(refusalVerdict(unpublished, [{ account: "a", usage: later }], now)).toBe("standing");
800
+ });
801
+
802
+ test("is answered early once its pool has renewed since with room, and not while it is full again or no reading names it", () => {
803
+ const stamped = { ...sol, pool: "seven_day" };
804
+ const renewedAt = Math.floor(now / 1000) + 6 * DAY;
805
+ expect(refusalVerdict(stamped, [{ account: "a", usage: since(renewedAt) }], now)).toBe("answered");
806
+ expect(serviceStates([{ account: "a", usage: since(renewedAt) }], [stamped], { id: "gpt-6.1-sol" }, now).get("a")).toEqual({
807
+ kind: "ready",
808
+ room: 64,
809
+ renewsAt: renewedAt,
810
+ });
811
+ expect(refusalVerdict(stamped, [{ account: "a", usage: since(renewedAt, 100) }], now)).toBe("standing");
812
+ // A pool the reading no longer names cannot say it renewed: the provider's instant stands.
813
+ expect(refusalVerdict({ ...sol, pool: "seven_day_retired" }, [{ account: "a", usage: since(renewedAt) }], now)).toBe("standing");
814
+ // A pool of its own is answered as an unstamped one is: every window that could have held it renewed since.
815
+ expect(refusalVerdict({ ...sol, poolUnpublished: true }, [{ account: "a", usage: since(renewedAt) }], now)).toBe("answered");
816
+ expect(refusalVerdict({ ...sol, poolUnpublished: true }, [{ account: "a", usage: since(renewedAt, 100) }], now)).toBe("standing");
817
+ });
818
+
819
+ test("is the fullest of the pools resetting at its instant, so a model's own slice holds that model alone", () => {
820
+ const weekly = 1_800_000_000;
821
+ const claude = at(
822
+ filed - 60_000,
823
+ window({ kind: "five_hour", utilization: 20, resetsAt: Math.floor(filed / 1000) + 3_600 }),
824
+ window({ kind: "seven_day", utilization: 60, resetsAt: weekly }),
825
+ window({ kind: "model:Opus", label: "Opus", utilization: 100, resetsAt: weekly, periodSeconds: 7 * DAY, gates: { models: ["Opus"] } }),
826
+ );
827
+ const opus = refusal({ kind: "limit", account: "a", model: "claude-opus-5-5", resetsAt: weekly + 120, at: filed });
828
+ expect(refusedPoolOf(opus, [{ account: "a", usage: claude }])).toEqual({ pool: "model:Opus" });
829
+ const stamped = { ...opus, pool: "model:Opus" };
830
+ expect(serviceState({ account: "a", usage: claude }, [stamped], { id: "claude-haiku-5" }, filed)).toEqual({ kind: "ready", room: 40, renewsAt: weekly });
831
+ expect(serviceState({ account: "a", usage: claude }, [stamped], { id: "claude-opus-5-5" }, filed)).toEqual({ kind: "spent", reopensAt: weekly + 120, pool: "Opus" });
832
+ });
833
+
834
+ test("is left unresolved where the reading beside it cannot say, and judged as it stands then", () => {
835
+ const accounts = filing(instant + 60);
836
+ // A refusal naming no instant takes its pool's reset instead; one no reading measures, and a person's mark, nothing.
837
+ const noInstant = refusal({ kind: "limit", account: "a", model: "gpt-6.1-sol", at: filed });
838
+ expect(refusedPoolOf(noInstant, accounts)).toEqual({});
839
+ expect(stampedRefusal(noInstant, accounts)).toEqual({ ...noInstant, poolResetsAt: Math.floor(filed / 1000) - 60 + 3_600 });
840
+ expect(refusedPoolOf({ ...sol, unmetered: true }, accounts)).toEqual({});
841
+ expect(refusedPoolOf({ ...sol, byHand: true }, accounts)).toEqual({});
842
+ expect(refusedPoolOf({ ...sol, kind: "entitlement" }, accounts)).toEqual({});
843
+ // Naming no account: resolved where the provider has only the one, never across several whose pools may differ.
844
+ const nameless = refusal({ kind: "limit", model: "gpt-6.1-sol", resetsAt: instant, at: filed });
845
+ expect(refusedPoolOf(nameless, accounts)).toEqual({ pool: "seven_day" });
846
+ expect(refusedPoolOf(nameless, [...accounts, { account: "b", usage: codex(filed - 60_000, instant + 60) }])).toEqual({});
847
+ // An account with no reading, or another account's.
848
+ expect(refusedPoolOf(sol, [{ account: "a" }])).toEqual({});
849
+ expect(refusedPoolOf({ ...sol, account: "gone" }, accounts)).toEqual({});
850
+ // A pool the model spends that publishes no reset, or no length, or whose window closed before the refusal came:
851
+ // the instant may be that pool's, so no pool of its own is concluded. One resetting at the instant still is it.
852
+ const idle = at(filed - 60_000, window({ kind: "five_hour", utilization: 0 }), window({ kind: "seven_day", utilization: 30, resetsAt: instant - 2 * DAY }));
853
+ expect(refusedPoolOf(sol, [{ account: "a", usage: idle }])).toEqual({});
854
+ const unnamedLength = at(filed - 60_000, window({ kind: "claude:tangelo", utilization: 30, resetsAt: instant - 2 * DAY }));
855
+ expect(refusedPoolOf(sol, [{ account: "a", usage: unnamedLength }])).toEqual({});
856
+ const idleAtInstant = at(filed - 60_000, window({ kind: "five_hour", utilization: 0 }), window({ kind: "seven_day", utilization: 30, resetsAt: instant }));
857
+ expect(refusedPoolOf(sol, [{ account: "a", usage: idleAtInstant }])).toEqual({ pool: "seven_day" });
858
+ const closed = at(
859
+ filed - 6 * 3_600_000,
860
+ window({ kind: "five_hour", utilization: 90, resetsAt: Math.floor(filed / 1000) - 600 }),
861
+ window({ kind: "seven_day", utilization: 30, resetsAt: instant - 2 * DAY }),
862
+ );
863
+ expect(refusedPoolOf(sol, [{ account: "a", usage: closed }])).toEqual({});
864
+ });
865
+ });
866
+
704
867
  // 2026-10-09/10-20: a routed model's bench (model-cooldowns.json) and the provider's last refusal were two copies of one
705
868
  // refusal, and the picker greyed by one while the rail judged by the other. One ledger: every refusal standing over an
706
869
  // account is laid on its reading, so two models refused on two pools both read spent.
@@ -747,7 +910,7 @@ test("a provider's capacity for a model is spent only when no account can serve
747
910
  // An account nothing has measured may still answer: it keeps the model servable.
748
911
  expect(fleetCapacity([...accounts, { account: "c" }], [a, b], { id: "sol" }, 6_000_000)).toEqual({ kind: "serving", serving: 1, accounts: 3, roomMeasuredAt: undefined });
749
912
  // No account at all says nothing either way.
750
- expect(fleetCapacity([], [a], { id: "sol" })).toEqual({ kind: "unknown" });
913
+ expect(fleetCapacity([], [a], { id: "sol" }, Date.now())).toEqual({ kind: "unknown" });
751
914
  // A plan that publishes no reading (Cursor's) is spent for a model every account refused, and only that model.
752
915
  const cursor = [{ account: "x" }, { account: "y" }];
753
916
  const refused = [refusal({ kind: "limit", account: "x", model: "composer-2.5" }), refusal({ kind: "limit", account: "y", model: "composer-2.5" })];
@@ -757,6 +920,32 @@ test("a provider's capacity for a model is spent only when no account can serve
757
920
  expect(fleetCapacity([{ account: "x" }], [refusal({ kind: "entitlement", account: "x" })], { id: "gpt-6" }, 2_000).kind).toBe("spent");
758
921
  });
759
922
 
923
+ test("an account whose plan does not include a model is outside that model's fleet, and only that model's", () => {
924
+ // 2026-11-19: two ChatGPT Free sign-ins back from their monthly reset, and the Team one, the only one running Sol, spent.
925
+ const free = at(5_000, window({ kind: "monthly", utilization: 0, resetsAt: 9_000_000 }));
926
+ const spentTeam = at(5_000, window({ kind: "five_hour", utilization: 100, resetsAt: 9_000 }));
927
+ const freeModels = ["gpt-6-luna", "gpt-6.1-terra"];
928
+ const accounts: ServiceFacts[] = [
929
+ { account: "free-a", usage: free, models: freeModels },
930
+ { account: "free-b", usage: free, models: freeModels },
931
+ { account: "team", usage: spentTeam, models: ["gpt-6.2-sol", ...freeModels] },
932
+ ];
933
+ const sol = serviceStates(accounts, [], { id: "gpt-6.2-sol", label: "GPT-6.2-Sol" }, 6_000_000);
934
+ expect(sol.get("free-a")).toEqual({ kind: "blocked", fix: "plan", reason: "GPT-6.2-Sol is not on this account's plan" });
935
+ expect(sol.get("team")?.kind).toBe("spent");
936
+ // Sol is back when the Team account is, and the Free ones are not counted toward it.
937
+ expect(fleetCapacity(accounts, [], { id: "gpt-6.2-sol" }, 6_000_000)).toEqual({ kind: "spent", accounts: 1, reopensAt: 9_000, pool: undefined });
938
+ // Every account runs Luna: the Free ones' room serves it.
939
+ expect(fleetCapacity(accounts, [], { id: "gpt-6-luna" }, 6_000_000)).toEqual({ kind: "serving", serving: 2, accounts: 3, roomMeasuredAt: 5_000 });
940
+ // With no model asked about, nothing is off any plan.
941
+ expect(serviceStates(accounts, [], undefined, 6_000_000).get("free-a")?.kind).toBe("ready");
942
+ // A model no account lists under this id (an alias, a suffix) judges nobody off plan, and neither does a missing list.
943
+ expect(serviceStates(accounts, [], { id: "gpt-6.2-sol-high" }, 6_000_000).get("free-a")?.kind).toBe("ready");
944
+ const unlisted = [{ account: "fresh", usage: free }, ...accounts];
945
+ expect(serviceStates(unlisted, [], { id: "gpt-6.2-sol" }, 6_000_000).get("fresh")?.kind).toBe("ready");
946
+ expect(fleetCapacity(unlisted, [], { id: "gpt-6.2-sol" }, 6_000_000)).toMatchObject({ kind: "serving", serving: 1, accounts: 2 });
947
+ });
948
+
760
949
  test("an answer on one model covers another only where every pool the other spends gates it too", () => {
761
950
  const codex = usage(window({ kind: "five_hour", utilization: 0 }), window({ kind: "seven_day", utilization: 0 }));
762
951
  expect(answerCovers(codex, { id: "gpt-6-luna" }, { id: "gpt-6.1-sol" })).toBe(true);
@@ -780,3 +969,46 @@ test("an account switched off twice within the week flaps; once, or twice a week
780
969
  expect([...flappingAccounts(offs, now + FLAPPING_WINDOW_MS)]).toEqual([]);
781
970
  expect([...flappingAccounts(undefined, now)]).toEqual([]);
782
971
  });
972
+
973
+ // 2026-11-19: the daemon lapsed a window past its reset as it read its store, the rule did not, and an editor holding
974
+ // the facts it had been sent judged the same account spent, "back at 12:00", five minutes after 12:00, while the daemon
975
+ // judged it ready. The rule now takes every reading as it stands at the instant it judges, so both sides agree.
976
+ test("a reading judged after its window resets reads the same whether or not anyone lapsed it first", () => {
977
+ const reset = Date.parse("2026-11-19T12:00:00Z") / 1000;
978
+ const read = (reset - 30 * 60) * 1000;
979
+ const held = at(
980
+ read,
981
+ window({ kind: "five_hour", label: "5-hour", utilization: 100, resetsAt: reset }),
982
+ window({ kind: "seven_day", label: "Weekly", utilization: 40, resetsAt: reset + 4 * 86_400 }),
983
+ );
984
+ const refused = refusal({ kind: "limit", account: "a", model: "gpt-x", at: read + 60_000, resetsAt: reset });
985
+ const after = (reset + 5 * 60) * 1000;
986
+ const asSent = serviceStates([{ account: "a", usage: held }], [refused], { id: "gpt-x" }, after).get("a");
987
+ const asStored = serviceStates([{ account: "a", usage: { ...held, windows: currentWindows(held, after) } }], [refused], { id: "gpt-x" }, after).get("a");
988
+ expect(asSent).toEqual({ kind: "ready", room: 60, renewsAt: reset + 4 * 86_400 });
989
+ expect(asStored).toEqual(asSent);
990
+ expect(fleetCapacity([{ account: "a", usage: held }], [refused], { id: "gpt-x" }, after)).toEqual({ kind: "serving", serving: 1, accounts: 1, roomMeasuredAt: read });
991
+ // A second before the reset the same facts read spent until it.
992
+ expect(serviceStates([{ account: "a", usage: held }], [refused], { id: "gpt-x" }, reset * 1000 - 1000).get("a")).toEqual({ kind: "spent", reopensAt: reset });
993
+ // A reading whose every window has closed says nothing about now: the account reads as unmeasured.
994
+ expect(serviceState({ account: "a", usage: at(read, window({ kind: "five_hour", utilization: 100, resetsAt: reset })) }, [], undefined, after)).toEqual({ kind: "unknown" });
995
+ });
996
+
997
+ test("a provider's picture is valid until the soonest instant the clock alone changes any of it", () => {
998
+ const now = Date.parse("2026-11-19T12:00:00Z");
999
+ const s = Math.floor(now / 1000);
1000
+ const reading = at(now - 60_000, window({ kind: "five_hour", utilization: 30, resetsAt: s + 7_200 }), window({ kind: "seven_day", utilization: 20, resetsAt: s + 86_400 }));
1001
+ const facts: ServiceFacts[] = [{ account: "a", usage: reading }];
1002
+ const states = serviceStates(facts, [], undefined, now);
1003
+ // The five-hour pool resetting is the first change.
1004
+ expect(capacityValidUntil(facts, states, [], undefined, now)).toBe((s + 7_200) * 1000);
1005
+ // A refusal's own instant, a bench's end and a switch-off ageing out each come sooner when they do.
1006
+ const refused = refusal({ kind: "limit", account: "a", at: now - 1_000, resetsAt: s + 600 });
1007
+ expect(capacityValidUntil(facts, serviceStates(facts, [refused], undefined, now), [refused], undefined, now)).toBe((s + 600) * 1000);
1008
+ const benched: ServiceFacts[] = [{ account: "a", usage: reading, cooling: { until: s + 300 } }];
1009
+ expect(capacityValidUntil(benched, serviceStates(benched, [], undefined, now), [], undefined, now)).toBe((s + 300) * 1000);
1010
+ const switchedOff = now - FLAPPING_WINDOW_MS + 120_000;
1011
+ expect(capacityValidUntil(facts, states, [], { a: [switchedOff] }, now)).toBe(switchedOff + FLAPPING_WINDOW_MS);
1012
+ // Instants already past are judged; nothing ahead is nothing to wait for.
1013
+ expect(capacityValidUntil([{ account: "a" }], new Map(), [refusal({ kind: "limit", resetsAt: s - 1 })], undefined, now)).toBeUndefined();
1014
+ });