@usine/engine 0.7.1-next.596.gcfd02df.1.1 → 0.7.1-next.604.g34f71e5.1.1

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/README.md CHANGED
@@ -40,7 +40,9 @@ restart. Older events return `None`. Repeated submissions and retries preserve
40
40
  the original requirement and reason.
41
41
 
42
42
  - Approval-gated runs wait for an approval event before their first attempt.
43
- - Infrastructure and provider capacity failures retry automatically, up to three attempts. Capacity retries wait two minutes after attempt 1 and five minutes after attempt 2, without reserving a worker slot. The persisted attempt end time determines the deadline across restarts. Retries resume from the newest pushed salvage, and cancellation stops the wait. Agent, defect, and guard failures wait for an operator retry. A defect escaping `StepExecutor` is saved as `DefectFailure` with its original cause.
43
+ - Infrastructure failures retry automatically, up to three attempts, without counting attempts that a provider refused for capacity. Agent, defect, and guard failures wait for an operator retry. A defect escaping `StepExecutor` is saved as `DefectFailure` with its original cause.
44
+ - A provider capacity refusal always retries and never fails the run. `ProviderCapacity` marks the capacity group of the refused Attempt, its child harness and model on its Worker (`CapacityGroup`), as at capacity. The run driver starts each Attempt through `ProviderCapacity.gate`: a Run that needs a group at capacity releases its Worker slot and waits without an Attempt. After the backoff of `capacityBackoff`, or at the latest reset time that the refusals report, one waiting Run's Attempt tests the group. A refusal of an Attempt that started after the previous one ended lengthens the backoff. A child's `ProviderAnswered` in that Attempt, or the Attempt's end without a capacity refusal, releases the other Runs; an infrastructure failure or a defect lets another waiting Run test the group. The rules are pure transitions in `engine/capacity/state.ts`. Each time a Run waits, including after a restart, it registers its consecutive refusals in the group of the newest one (`capacityRefusalStreak`) from the persisted Attempts, so a refusal on another Worker neither moves its wait nor lengthens that group's backoff. A Run that the claim of its slot made wait for another group keeps waiting for that group. `RunEngine.capacityWaits` lists the groups at capacity. `RunEngine.retry` of a Run that waits for a group, with or without a refused Attempt, starts its next Attempt now. Retries resume from the newest pushed salvage, and cancellation stops the wait.
45
+ - `RunEngine.retry` of a Run that waits after a capacity refusal starts its next Attempt now, and that Attempt tests the group.
44
46
  - `RunEngine.retry(runId, request)` takes a `RetryRequest`: the operator login and the task and agent that an edit-and-retry changes.
45
47
  - `Attempt.start` records why each attempt started: the event, an operator retry or edit-and-retry with its login, an infrastructure or provider capacity retry, or a restart. A reattached attempt keeps its reason and records `reattachedAt`.
46
48
 
@@ -0,0 +1,68 @@
1
+ import type { BrainSpec } from "@usine/core/agent/brain";
2
+ import { type Attempt } from "@usine/core/attempt";
3
+ import type * as AttemptChannel from "@usine/core/attempt/channel";
4
+ import type { AttemptFailure } from "@usine/core/attempt/failure";
5
+ import type { LoopName } from "@usine/core/loop";
6
+ import type { RunId } from "@usine/core/run";
7
+ import type { StepCompletion } from "@usine/core/step/result";
8
+ import type { WorkerName } from "@usine/core/worker";
9
+ import { Context, Effect, Layer, Option, Result } from "effect";
10
+ import * as Capacity from "./state.ts";
11
+ export { CapacityGroup, capacityGroupKey, CapacityWait, type CapacityTurn } from "./state.ts";
12
+ /** An Attempt that ran under `ProviderCapacity.gate`, and its executor result. */
13
+ export interface EndedAttempt {
14
+ readonly attempt: Attempt;
15
+ readonly result: Result.Result<StepCompletion, AttemptFailure>;
16
+ }
17
+ /** The claim of a Run's new Attempt on its capacity group. */
18
+ export interface CapacityClaimRequest<E, R> {
19
+ readonly loop: LoopName;
20
+ readonly worker: WorkerName;
21
+ readonly turn: Capacity.CapacityTurn;
22
+ /** Reads the brain of the Run's Agent; it runs only while a group is at capacity. */
23
+ readonly brain: Effect.Effect<Pick<BrainSpec, "harness" | "model">, E, R>;
24
+ }
25
+ /** Reports one transcript envelope of a running Attempt to `ProviderCapacity`. */
26
+ export type CapacityObserver = (attempt: Attempt, envelope: AttemptChannel.Envelope) => Effect.Effect<void>;
27
+ declare const ProviderCapacity_base: Context.ServiceClass<ProviderCapacity, "@usine/engine/engine/capacity/capacity/ProviderCapacity", {
28
+ /**
29
+ * Registers the consecutive capacity refusals that end `attempts`, the Attempts of the Run
30
+ * `runId` of `loop` from oldest to newest, in the group of the newest refusal, unless the
31
+ * claim of the Run's slot made it wait for another group. Then waits for the Run's turn: until
32
+ * the group it waits for is free, or until no Attempt tests the group and its next try has
33
+ * come. Returns `Forced` when an operator retry ends the wait, and `Due` otherwise.
34
+ */
35
+ readonly awaitTurn: (run: {
36
+ readonly runId: RunId;
37
+ readonly loop: LoopName;
38
+ readonly attempts: ReadonlyArray<Attempt>;
39
+ }) => Effect.Effect<Capacity.CapacityTurn>;
40
+ /**
41
+ * Runs `attempt` of the Run `runId`, unless `claim`, the claim of a new Attempt, finds the
42
+ * Run's group at capacity when it isn't the Run's turn: then the Run waits for the group, and
43
+ * `gate` returns `None`. `attempt` passes each transcript envelope to the observer it receives, and a
44
+ * child's `ProviderAnswered` releases the group. An Attempt that ended settles the group: a
45
+ * success or a failure that the provider answered releases it, and an infrastructure failure
46
+ * or a defect ends the Run's test of it. A capacity refusal is registered when the Run waits.
47
+ */
48
+ readonly gate: <A, E, R, E2 = never, R2 = never>(runId: RunId, claim: Option.Option<CapacityClaimRequest<E2, R2>>, attempt: (observe: CapacityObserver) => Effect.Effect<Result.Result<EndedAttempt, A>, E, R>) => Effect.Effect<Option.Option<Result.Result<EndedAttempt, A>>, E | E2, R | R2>;
49
+ /**
50
+ * Ends the next or current wait of `runId` for an operator retry. Returns whether a waiting
51
+ * fiber of the Run was woken.
52
+ */
53
+ readonly force: (runId: RunId) => Effect.Effect<boolean>;
54
+ /** Removes `runId` from the waiting Runs, the testing Attempts, and the forced retries. */
55
+ readonly leave: (runId: RunId) => Effect.Effect<void>;
56
+ /** The groups at capacity, ordered by when they started refusing. */
57
+ readonly waits: Effect.Effect<ReadonlyArray<Capacity.CapacityWait>>;
58
+ }>;
59
+ /**
60
+ * Tracks the capacity groups whose provider refuses requests, in this process. A refusal marks
61
+ * the group; Runs that need it wait without an Attempt, one Attempt at a time tests it after the
62
+ * backoff, and the first answer from its provider releases the waiting Runs. After a restart, each
63
+ * Run that waits registers its refusals again. The rules are in `state.ts`.
64
+ */
65
+ export declare class ProviderCapacity extends ProviderCapacity_base {
66
+ static readonly layer: Layer.Layer<ProviderCapacity, never, never>;
67
+ }
68
+ //# sourceMappingURL=capacity.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capacity.d.ts","sourceRoot":"","sources":["../../../src/engine/capacity/capacity.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,KAAK,OAAO,EAAyB,MAAM,qBAAqB,CAAC;AAC1E,OAAO,KAAK,KAAK,cAAc,MAAM,6BAA6B,CAAC;AACnE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAElE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,OAAO,EAAgC,MAAM,EAAE,KAAK,EAAE,MAAM,EAAO,MAAM,EAAE,MAAM,QAAQ,CAAC;AACnG,OAAO,KAAK,QAAQ,MAAM,YAAY,CAAC;AAEvC,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,YAAY,EAAE,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAE9F,kFAAkF;AAClF,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,cAAc,EAAE,cAAc,CAAC,CAAC;CAChE;AAED,8DAA8D;AAC9D,MAAM,WAAW,oBAAoB,CAAC,CAAC,EAAE,CAAC;IACxC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,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KAAK,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC;IACxD,2FAA2F;oBAC3E,CAAC,KAAK,EAAE,KAAK,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;IACrD,qEAAqE;oBACrD,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;;AA1CvE;;;;;GAKG;AACH,qBAAa,gBAAiB,SAAQ,qBAsCwB;IAC5D,MAAM,CAAC,QAAQ,CAAC,KAAK,8CAyUnB;CACH"}
@@ -0,0 +1,257 @@
1
+ import { InstanceScope } from "@usine/core/access";
2
+ import { capacityRefusalStreak } from "@usine/core/attempt";
3
+ import { ChangeBus } from "@usine/core/changes";
4
+ import { Context, DateTime, Deferred, Duration, Effect, Layer, Option, Ref, Result } from "effect";
5
+ import * as Capacity from "./state.js";
6
+ export { CapacityGroup, capacityGroupKey, CapacityWait } from "./state.js";
7
+ /** Returns whether `envelope` reports the first answer of a child session's model provider. */
8
+ const providerAnswered = (envelope) => envelope._tag === "OutboundEnvelope" &&
9
+ envelope.payload._tag === "SessionEvent" &&
10
+ envelope.payload.event._tag === "ProviderAnswered" &&
11
+ envelope.payload.event.session._tag === "ChildSession";
12
+ const groupFields = (group) => ({
13
+ worker: group.worker,
14
+ harness: group.harness,
15
+ model: group.model,
16
+ });
17
+ const waitFields = (wait) => ({
18
+ ...groupFields(wait.group),
19
+ message: wait.message,
20
+ refusals: wait.refusals,
21
+ since: DateTime.formatIso(wait.since),
22
+ nextTryAt: DateTime.formatIso(wait.nextTryAt),
23
+ probes: wait.probes,
24
+ waitingRuns: wait.runIds.length,
25
+ });
26
+ /**
27
+ * Tracks the capacity groups whose provider refuses requests, in this process. A refusal marks
28
+ * the group; Runs that need it wait without an Attempt, one Attempt at a time tests it after the
29
+ * backoff, and the first answer from its provider releases the waiting Runs. After a restart, each
30
+ * Run that waits registers its refusals again. The rules are in `state.ts`.
31
+ */
32
+ export class ProviderCapacity extends Context.Service()("@usine/engine/engine/capacity/capacity/ProviderCapacity") {
33
+ static layer = Layer.effect(ProviderCapacity, Effect.gen(function* () {
34
+ const bus = yield* ChangeBus;
35
+ const state = yield* Ref.make(Capacity.emptyCapacity);
36
+ const initial = yield* Deferred.make();
37
+ const changed = yield* Ref.make(initial);
38
+ // The waiting fiber of each Run, which an operator retry wakes.
39
+ const wakes = yield* Ref.make(new Map());
40
+ /** Wakes every waiting Run, and refreshes the attention view and the views of `runs`. */
41
+ const announce = Effect.fn("ProviderCapacity.announce")(function* (runs) {
42
+ const next = yield* Deferred.make();
43
+ const previous = yield* Ref.getAndSet(changed, next);
44
+ yield* Deferred.succeed(previous, undefined);
45
+ const changes = [
46
+ { audience: InstanceScope.make(), target: { kind: "attention", id: "instance" } },
47
+ ...runs.map(([runId, loop]) => ({
48
+ audience: { _tag: "Loop", loop },
49
+ target: { kind: "run", id: runId },
50
+ })),
51
+ ];
52
+ yield* bus.publish(changes);
53
+ });
54
+ /** Announces a change of the groups `keys` to the Runs that wait for them. */
55
+ const announceGroups = (keys) => Ref.get(state).pipe(Effect.flatMap((current) => announce(keys.flatMap((key) => Capacity.waitersOf(current, key)))));
56
+ const refused = Effect.fn("ProviderCapacity.refused")(function* (attempt, loop) {
57
+ const fields = { runId: attempt.runId, attemptId: attempt.id };
58
+ yield* Effect.annotateCurrentSpan(fields);
59
+ const refusal = Capacity.refusalOf(attempt, loop);
60
+ if (Option.isNone(refusal)) {
61
+ yield* Effect.logInfo("The capacity refusal has no end time; the Run waits for no group after it", fields);
62
+ return;
63
+ }
64
+ const group = refusal.value.group;
65
+ const key = Capacity.capacityGroupKey(group);
66
+ const recorded = yield* Ref.modify(state, (current) => Capacity.refused(current, refusal.value));
67
+ const groupLog = { ...fields, ...groupFields(group) };
68
+ if (recorded === "Stale") {
69
+ yield* Effect.logInfo("The capacity refusal ended before the provider last answered in its group; the Run doesn't wait for it", groupLog);
70
+ return recorded;
71
+ }
72
+ if (recorded === "Known")
73
+ return recorded;
74
+ const current = yield* Ref.get(state);
75
+ if (recorded === "Elsewhere") {
76
+ yield* Effect.logInfo("The Run keeps waiting for the group that the claim of its slot put it in; its capacity refusal in another group doesn't move it", { ...groupLog, waitsFor: current.waiting.get(attempt.runId)?.key });
77
+ return recorded;
78
+ }
79
+ const wait = Option.getOrUndefined(Capacity.waitFor(current, key));
80
+ const logged = wait === undefined ? groupLog : { ...fields, ...waitFields(wait) };
81
+ if (recorded === "Marked")
82
+ yield* Effect.logWarning("The provider refused the Attempt for capacity; Runs that need its group wait, and one Attempt at a time tests it", {
83
+ ...logged,
84
+ resetsAt: Option.getOrUndefined(Option.map(refusal.value.resetsAt, DateTime.formatIso)),
85
+ });
86
+ else
87
+ yield* Effect.logInfo("The Run waits again for its group after a capacity refusal recorded before", logged);
88
+ yield* announceGroups([key]);
89
+ return recorded;
90
+ });
91
+ /** Settles the group of `attempt` after it ended with `end`, and logs what changed. */
92
+ const settle = Effect.fn("ProviderCapacity.settle")(function* (attempt, end) {
93
+ const group = Capacity.capacityGroupOf(attempt.brain, attempt.worker);
94
+ const fields = { runId: attempt.runId, attemptId: attempt.id, end, ...groupFields(group) };
95
+ yield* Effect.annotateCurrentSpan(fields);
96
+ const now = yield* DateTime.now;
97
+ const outcome = yield* Ref.modify(state, (current) => Capacity.settled(current, {
98
+ runId: attempt.runId,
99
+ group,
100
+ startedAt: attempt.startedAt,
101
+ end,
102
+ now,
103
+ }));
104
+ switch (outcome._tag) {
105
+ case "Free":
106
+ case "Refused":
107
+ return;
108
+ case "Earlier":
109
+ return yield* Effect.logInfo("The provider answered an Attempt that started before its group's latest refusal; the group stays at capacity", fields);
110
+ case "Released":
111
+ yield* Effect.logInfo("The provider answered in a group at capacity; the Runs waiting for it start", { ...fields, releasedRunIds: outcome.runs.map(([runId]) => runId) });
112
+ return yield* announce(outcome.runs);
113
+ case "Left":
114
+ if (outcome.groups.length === 0)
115
+ return;
116
+ yield* Effect.logInfo("The Attempt that tested a group at capacity ended without showing whether the provider answered; another waiting Run tests the group", { ...fields, groups: outcome.groups });
117
+ return yield* announceGroups(outcome.groups);
118
+ }
119
+ });
120
+ /** Settles the group of `attempt` while it is at capacity; a free group needs nothing. */
121
+ const settleAtCapacity = (attempt, end) => Ref.get(state).pipe(Effect.flatMap((current) => current.groups.size > 0 ? settle(attempt, end) : Effect.void));
122
+ const observe = (attempt, envelope) => providerAnswered(envelope) ? settleAtCapacity(attempt, "Succeeded") : Effect.void;
123
+ const leave = Effect.fn("ProviderCapacity.leave")(function* (runId) {
124
+ yield* Effect.annotateCurrentSpan({ runId });
125
+ const keys = yield* Ref.modify(state, (current) => Capacity.leave(current, runId));
126
+ if (keys.length === 0)
127
+ return;
128
+ yield* Effect.logInfo("The Run no longer waits for or tests a group at capacity; a group that no Run needs is dropped", { runId, groups: keys });
129
+ yield* announceGroups(keys);
130
+ });
131
+ const claim = Effect.fn("ProviderCapacity.claim")(function* (runId, request) {
132
+ const { loop, worker } = request;
133
+ yield* Effect.annotateCurrentSpan({ runId, worker });
134
+ if ((yield* Ref.get(state)).groups.size === 0) {
135
+ // Nothing is at capacity, so the Run's group is free and needs no read of its brain.
136
+ yield* Ref.update(state, (current) => Capacity.leave(current, runId)[1]);
137
+ return "Free";
138
+ }
139
+ const brain = yield* request.brain;
140
+ const group = Capacity.capacityGroupOf(brain, worker);
141
+ const now = yield* DateTime.now;
142
+ const claimed = yield* Ref.modify(state, (current) => Capacity.claim(current, { runId, loop, group, turn: request.turn, now }));
143
+ const fields = { runId, ...groupFields(group) };
144
+ const current = yield* Ref.get(state);
145
+ const others = claimed.left.flatMap((other) => Capacity.waitersOf(current, other));
146
+ if (claimed.left.length > 0)
147
+ yield* Effect.logInfo("The Run elected to test a group at capacity got a slot for another group; the Runs waiting for the first group elect another", { ...fields, left: claimed.left });
148
+ const wait = Capacity.waitFor(current, Capacity.capacityGroupKey(group));
149
+ if (claimed.claim === "Free" || Option.isNone(wait)) {
150
+ if (others.length > 0)
151
+ yield* announce(others);
152
+ return claimed.claim;
153
+ }
154
+ const logged = { ...fields, ...waitFields(wait.value) };
155
+ if (claimed.claim === "Wait")
156
+ yield* Effect.logInfo("The Run's group is at capacity; it frees its Worker slot and waits without an Attempt", logged);
157
+ else
158
+ yield* Effect.logInfo(claimed.forced
159
+ ? "An operator retry tests the group at capacity"
160
+ : "The Run's Attempt tests the group at capacity; the other Runs that need it keep waiting", logged);
161
+ yield* announce([
162
+ ...Capacity.waitersOf(current, Capacity.capacityGroupKey(group)),
163
+ ...others,
164
+ ]);
165
+ return claimed.claim;
166
+ });
167
+ const gate = Effect.fn("ProviderCapacity.gate")(function* (runId, request, attempt) {
168
+ yield* Effect.annotateCurrentSpan({ runId });
169
+ if (Option.isSome(request) && (yield* claim(runId, request.value)) === "Wait")
170
+ return Option.none();
171
+ const ran = yield* attempt(observe);
172
+ if (Result.isSuccess(ran)) {
173
+ const { attempt: ended, result } = ran.success;
174
+ yield* Effect.annotateCurrentSpan({ attemptId: ended.id });
175
+ yield* settleAtCapacity(ended, Result.match(result, {
176
+ onSuccess: () => "Succeeded",
177
+ onFailure: ({ _tag }) => _tag,
178
+ }));
179
+ }
180
+ return Option.some(ran);
181
+ });
182
+ /** Waits until the Run's turn comes, and returns how its wait ended. */
183
+ const waitTurn = Effect.fn("ProviderCapacity.waitTurn")(function* (runId) {
184
+ const wake = yield* Deferred.make();
185
+ yield* Ref.update(wakes, (current) => new Map(current).set(runId, wake));
186
+ // Whether the Run's wait was logged, so a long wait logs once.
187
+ let logged = false;
188
+ return yield* Effect.gen(function* () {
189
+ while (true) {
190
+ const signal = yield* Ref.get(changed);
191
+ const now = yield* DateTime.now;
192
+ const step = yield* Ref.modify(state, (current) => Capacity.turn(current, runId, now));
193
+ switch (step._tag) {
194
+ case "Forced":
195
+ yield* Effect.logInfo("An operator retry ends the Run's wait for its group", {
196
+ runId,
197
+ });
198
+ return "Forced";
199
+ case "Free":
200
+ case "Due":
201
+ if (step._tag === "Due" && step.elected)
202
+ yield* Effect.logInfo("The Run's next Attempt tests its group at capacity", {
203
+ runId,
204
+ ...groupFields(step.group),
205
+ });
206
+ return "Due";
207
+ case "Sleep": {
208
+ const delayMillis = DateTime.toEpochMillis(step.until) - DateTime.toEpochMillis(now);
209
+ if (!logged)
210
+ yield* Effect.logInfo("The Run waits for its group at capacity", {
211
+ runId,
212
+ ...groupFields(step.group),
213
+ nextTryAt: DateTime.formatIso(step.until),
214
+ delayMillis,
215
+ });
216
+ logged = true;
217
+ yield* Effect.raceFirst(Deferred.await(wake), Effect.raceFirst(Deferred.await(signal), Effect.sleep(Duration.millis(delayMillis))));
218
+ break;
219
+ }
220
+ case "AwaitProbe":
221
+ if (!logged)
222
+ yield* Effect.logInfo("The Run waits while another Attempt tests its group at capacity", { runId, ...groupFields(step.group) });
223
+ logged = true;
224
+ yield* Effect.raceFirst(Deferred.await(wake), Deferred.await(signal));
225
+ break;
226
+ }
227
+ }
228
+ }).pipe(Effect.ensuring(Ref.update(wakes, (current) => {
229
+ if (current.get(runId) !== wake)
230
+ return current;
231
+ const next = new Map(current);
232
+ next.delete(runId);
233
+ return next;
234
+ })));
235
+ });
236
+ const awaitTurn = Effect.fn("ProviderCapacity.awaitTurn")(function* (run) {
237
+ yield* Effect.annotateCurrentSpan({ runId: run.runId });
238
+ // The streak is in one group, so a Run that waits for another group skips all of it.
239
+ for (const attempt of capacityRefusalStreak(run.attempts))
240
+ if ((yield* refused(attempt, run.loop)) === "Elsewhere")
241
+ break;
242
+ return yield* waitTurn(run.runId);
243
+ });
244
+ const force = Effect.fn("ProviderCapacity.force")(function* (runId) {
245
+ yield* Effect.annotateCurrentSpan({ runId });
246
+ yield* Ref.update(state, (current) => Capacity.force(current, runId));
247
+ const wake = (yield* Ref.get(wakes)).get(runId);
248
+ if (wake !== undefined && (yield* Deferred.succeed(wake, undefined)))
249
+ return true;
250
+ yield* Effect.logInfo("An operator retry applies at the Run's next claim of its group, as the Run doesn't wait now", { runId });
251
+ return false;
252
+ });
253
+ const waits = Ref.get(state).pipe(Effect.map(Capacity.waitsOf), Effect.withSpan("ProviderCapacity.waits"));
254
+ return { awaitTurn, gate, force, leave, waits };
255
+ }));
256
+ }
257
+ //# sourceMappingURL=capacity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capacity.js","sourceRoot":"","sources":["../../../src/engine/capacity/capacity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,OAAO,EAAgB,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAG1E,OAAO,EAAE,SAAS,EAAqB,MAAM,qBAAqB,CAAC;AAKnE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACnG,OAAO,KAAK,QAAQ,MAAM,YAAY,CAAC;AAEvC,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,YAAY,EAAqB,MAAM,YAAY,CAAC;AAuB9F,+FAA+F;AAC/F,MAAM,gBAAgB,GAAG,CAAC,QAAiC,EAAW,EAAE,CACtE,QAAQ,CAAC,IAAI,KAAK,kBAAkB;IACpC,QAAQ,CAAC,OAAO,CAAC,IAAI,KAAK,cAAc;IACxC,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,kBAAkB;IAClD,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,KAAK,cAAc,CAAC;AAEzD,MAAM,WAAW,GAAG,CAAC,KAA6B,EAAE,EAAE,CAAC,CAAC;IACtD,MAAM,EAAE,KAAK,CAAC,MAAM;IACpB,OAAO,EAAE,KAAK,CAAC,OAAO;IACtB,KAAK,EAAE,KAAK,CAAC,KAAK;CACnB,CAAC,CAAC;AAEH,MAAM,UAAU,GAAG,CAAC,IAA2B,EAAE,EAAE,CAAC,CAAC;IACnD,GAAG,WAAW,CAAC,IAAI,CAAC,KAAK,CA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,CAAC,CAAC;QAEH,MAAM,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,IAAI,CAC/B,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,EAC5B,MAAM,CAAC,QAAQ,CAAC,wBAAwB,CAAC,CAC1C,CAAC;QAEF,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;IAClD,CAAC,CAAC,CACH,CAAC;CACH"}
@@ -0,0 +1,209 @@
1
+ import { type BrainSpec } from "@usine/core/agent/brain";
2
+ import { type Attempt, type AttemptId } from "@usine/core/attempt";
3
+ import type { AttemptFailure } from "@usine/core/attempt/failure";
4
+ import type { LoopName } from "@usine/core/loop";
5
+ import { RunId } from "@usine/core/run";
6
+ import { WorkerName } from "@usine/core/worker";
7
+ import { Array as EffectArray, type Brand, DateTime, Option, Schema } from "effect";
8
+ declare const CapacityGroup_base: Schema.Class<CapacityGroup, Schema.Struct<{
9
+ /** The harness of the Attempt's child sessions. */
10
+ readonly harness: Schema.brand<Schema.String, "Harness">;
11
+ /** The model of the Attempt's child sessions. */
12
+ readonly model: Schema.brand<Schema.String, "ModelId">;
13
+ /** The Worker whose credential the harness used. */
14
+ readonly worker: Schema.brand<Schema.String, "WorkerName">;
15
+ }>, Brand.Brand<"@usine/engine/engine/capacity/state/CapacityGroup">>;
16
+ /**
17
+ * The harness and model of an Attempt's child sessions on one Worker, which a provider capacity
18
+ * refusal applies to. The Worker holds the harness credential, and a model can have its own usage
19
+ * limit.
20
+ */
21
+ export declare class CapacityGroup extends CapacityGroup_base {
22
+ }
23
+ /** Returns the capacity group of `brain` on `worker`. */
24
+ export declare const capacityGroupOf: (brain: Pick<BrainSpec, "harness" | "model">, worker: WorkerName) => CapacityGroup;
25
+ /** Identifies `group` in the capacity state and in the operator's attention entries. */
26
+ export declare const capacityGroupKey: (group: CapacityGroup) => string;
27
+ declare const CapacityWait_base: Schema.Class<CapacityWait, Schema.Struct<{
28
+ readonly group: typeof CapacityGroup;
29
+ /** The provider's latest refusal. */
30
+ readonly message: Schema.NonEmptyString;
31
+ /** The end of the first refusal since the provider last answered in the group. */
32
+ readonly since: Schema.DateTimeUtcFromString;
33
+ /** The refusals that each lengthened the wait: one per Attempt that tested the group. */
34
+ readonly refusals: Schema.Int;
35
+ /** The earliest time that the next Attempt tests the group. */
36
+ readonly nextTryAt: Schema.DateTimeUtcFromString;
37
+ /** The Runs whose Attempt tests the group now. */
38
+ readonly probes: Schema.$Array<Schema.brand<Schema.NonEmptyString, "RunId">>;
39
+ /** The Runs that wait for the group without an Attempt. */
40
+ readonly runIds: Schema.$Array<Schema.brand<Schema.NonEmptyString, "RunId">>;
41
+ }>, Brand.Brand<"@usine/engine/engine/capacity/state/CapacityWait">>;
42
+ /** A capacity group whose provider refuses requests, and the Runs that wait for it. */
43
+ export declare class CapacityWait extends CapacityWait_base {
44
+ }
45
+ /** A capacity refusal that ended an Attempt of a Run of `loop`. */
46
+ export interface CapacityRefusal {
47
+ readonly runId: RunId;
48
+ readonly loop: LoopName;
49
+ readonly group: CapacityGroup;
50
+ readonly attemptId: AttemptId;
51
+ readonly startedAt: DateTime.Utc;
52
+ readonly endedAt: DateTime.Utc;
53
+ readonly message: string;
54
+ readonly resetsAt: Option.Option<DateTime.Utc>;
55
+ }
56
+ /** Returns the capacity refusal that ended `attempt`, or `None` without one or an end time. */
57
+ export declare const refusalOf: (attempt: Attempt, loop: LoopName) => Option.Option<CapacityRefusal>;
58
+ interface GroupState {
59
+ readonly group: CapacityGroup;
60
+ /** Ordered by end time. */
61
+ readonly refusals: EffectArray.NonEmptyReadonlyArray<CapacityRefusal>;
62
+ readonly probes: ReadonlySet<RunId>;
63
+ }
64
+ interface Waiter {
65
+ readonly key: string;
66
+ readonly loop: LoopName;
67
+ }
68
+ /** The capacity groups at capacity in this process, and the Runs that wait for them. */
69
+ export interface CapacityState {
70
+ readonly groups: ReadonlyMap<string, GroupState>;
71
+ readonly waiting: ReadonlyMap<RunId, Waiter>;
72
+ /** The time the provider last answered in each group; older refusals are stale. */
73
+ readonly answered: ReadonlyMap<string, DateTime.Utc>;
74
+ /** The Runs whose next claim or wait an operator retry ends. */
75
+ readonly forced: ReadonlySet<RunId>;
76
+ }
77
+ export declare const emptyCapacity: CapacityState;
78
+ /** Returns the Runs that wait for the group `key`, with their Loops. */
79
+ export declare const waitersOf: (state: CapacityState, key: string) => (readonly [string & Brand.Brand<"RunId">, string & Brand.Brand<"LoopName">])[];
80
+ /** Returns the wait of the group `key`, or `None` if it isn't at capacity. */
81
+ export declare const waitFor: (state: CapacityState, key: string) => Option.Option<CapacityWait>;
82
+ /** Returns the groups at capacity, ordered by when they started refusing. */
83
+ export declare const waitsOf: (state: CapacityState) => ReadonlyArray<CapacityWait>;
84
+ /**
85
+ * How `refused` recorded a refusal: `Stale` if it ended before the provider last answered in its
86
+ * group, `Elsewhere` if its Run waits for another group, `Known` if it was recorded before and its
87
+ * Run still waits, `Rejoined` if it was recorded before and its Run waits for its group again, and
88
+ * `Marked` if it marked the group.
89
+ */
90
+ export type Refused = "Stale" | "Elsewhere" | "Known" | "Rejoined" | "Marked";
91
+ /**
92
+ * Records `refusal` and that its Run waits for the refused group, unless it is stale or the Run
93
+ * waits for another group: the claim of its slot made it wait there after the refusal, so it keeps
94
+ * that group.
95
+ */
96
+ export declare const refused: (state: CapacityState, refusal: CapacityRefusal) => readonly [Refused, CapacityState];
97
+ /**
98
+ * What `answered` did: nothing because the group isn't at capacity (`Free`) or the Attempt started
99
+ * before the group's latest refusal (`Earlier`), or it released the group and its waiting Runs.
100
+ */
101
+ export type Answered = {
102
+ readonly _tag: "Free";
103
+ } | {
104
+ readonly _tag: "Earlier";
105
+ } | {
106
+ readonly _tag: "Released";
107
+ readonly runs: ReadonlyArray<readonly [RunId, LoopName]>;
108
+ };
109
+ /**
110
+ * Records that the provider answered the Attempt of `runId` that started at `startedAt` in
111
+ * `group`. It releases the group and its waiting Runs if the Attempt tests the group or started
112
+ * after the group's latest refusal; an Attempt that started earlier was already running when the
113
+ * provider refused.
114
+ */
115
+ export declare const answered: (state: CapacityState, answer: {
116
+ readonly runId: RunId;
117
+ readonly group: CapacityGroup;
118
+ readonly startedAt: DateTime.Utc;
119
+ readonly now: DateTime.Utc;
120
+ }) => readonly [Answered, CapacityState];
121
+ /**
122
+ * What a Run may do in a group: start an Attempt because the group isn't at capacity (`Free`),
123
+ * start the Attempt that tests it (`Probe`), or wait without an Attempt (`Wait`).
124
+ */
125
+ type CapacityClaim = "Free" | "Probe" | "Wait";
126
+ /**
127
+ * How a Run's wait for its capacity group ended: its turn came or it waited for no group (`Due`),
128
+ * or an operator retry ended it (`Forced`).
129
+ */
130
+ export type CapacityTurn = "Due" | "Forced";
131
+ /** What `claim` decided, whether an operator retry forced it, and the groups the Run left. */
132
+ export interface Claimed {
133
+ readonly claim: CapacityClaim;
134
+ readonly forced: boolean;
135
+ /** The groups that the Run stopped testing because it got a slot for another group. */
136
+ readonly left: ReadonlyArray<string>;
137
+ }
138
+ /**
139
+ * Decides whether the Run `runId` of `loop` starts an Attempt in `group` at `now`. A Run tests a
140
+ * group at capacity when it was elected to, when no Attempt tests the group and its next try has
141
+ * come, or when an operator retry forced its turn. Otherwise it waits for the group.
142
+ */
143
+ export declare const claim: (state: CapacityState, request: {
144
+ readonly runId: RunId;
145
+ readonly loop: LoopName;
146
+ readonly group: CapacityGroup;
147
+ readonly turn: CapacityTurn;
148
+ readonly now: DateTime.Utc;
149
+ }) => readonly [Claimed, CapacityState];
150
+ /**
151
+ * The next step of a Run's wait for its group: an operator retry ended it (`Forced`), the Run
152
+ * waits for no group (`Free`), its Attempt tests the group (`Due`), it waits until the group's
153
+ * next try (`Sleep`), or it waits while another Attempt tests the group (`AwaitProbe`).
154
+ */
155
+ export type TurnStep = {
156
+ readonly _tag: "Forced";
157
+ } | {
158
+ readonly _tag: "Free";
159
+ } | {
160
+ readonly _tag: "Due";
161
+ readonly elected: boolean;
162
+ readonly group: CapacityGroup;
163
+ } | {
164
+ readonly _tag: "Sleep";
165
+ readonly until: DateTime.Utc;
166
+ readonly group: CapacityGroup;
167
+ } | {
168
+ readonly _tag: "AwaitProbe";
169
+ readonly group: CapacityGroup;
170
+ };
171
+ /**
172
+ * Returns the next step of the wait of `runId` at `now`. When no Attempt tests its group and the
173
+ * next try has come, it elects the Run to test the group, so only one waiting Run does.
174
+ */
175
+ export declare const turn: (state: CapacityState, runId: RunId, now: DateTime.Utc) => readonly [TurnStep, CapacityState];
176
+ /** How an Attempt ended, for `settled`: it succeeded, or failed with the failure's tag. */
177
+ export type AttemptEnd = "Succeeded" | AttemptFailure["_tag"];
178
+ /**
179
+ * What `settled` did to the group of an Attempt that ended: what `answered` did, nothing for a
180
+ * capacity refusal (`Refused`), or the groups that the Run stopped testing (`Left`).
181
+ */
182
+ export type Settled = Answered | {
183
+ readonly _tag: "Refused";
184
+ } | {
185
+ readonly _tag: "Left";
186
+ readonly groups: ReadonlyArray<string>;
187
+ };
188
+ /**
189
+ * Settles the group of the Attempt of `runId` that started at `startedAt` and ended with `end`.
190
+ * A success, or a failure that the provider answered, counts as an answer. A capacity refusal
191
+ * changes nothing; the Run registers it when it waits. An infrastructure failure or a defect
192
+ * doesn't show whether the provider answered, so the Run only stops testing the group.
193
+ */
194
+ export declare const settled: (state: CapacityState, ended: {
195
+ readonly runId: RunId;
196
+ readonly group: CapacityGroup;
197
+ readonly startedAt: DateTime.Utc;
198
+ readonly end: AttemptEnd;
199
+ readonly now: DateTime.Utc;
200
+ }) => readonly [Settled, CapacityState];
201
+ /** Records that an operator retry ends the next or current wait of `runId`. */
202
+ export declare const force: (state: CapacityState, runId: RunId) => CapacityState;
203
+ /**
204
+ * Removes `runId` from the waiting Runs, the testing Attempts, and the forced retries, and
205
+ * returns the groups it waited for or tested.
206
+ */
207
+ export declare const leave: (state: CapacityState, runId: RunId) => readonly [ReadonlyArray<string>, CapacityState];
208
+ export {};
209
+ //# sourceMappingURL=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