audit-tools 0.32.10 → 0.32.12
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/dist/audit/cli/args.d.ts.map +1 -1
- package/dist/audit/cli/args.js +9 -8
- package/dist/audit/cli/args.js.map +1 -1
- package/dist/audit/cli/hybridDispatch.d.ts +3 -1
- package/dist/audit/cli/hybridDispatch.d.ts.map +1 -1
- package/dist/audit/cli/hybridDispatch.js +11 -2
- package/dist/audit/cli/hybridDispatch.js.map +1 -1
- package/dist/audit/cli/nextStepCommand.d.ts.map +1 -1
- package/dist/audit/cli/nextStepCommand.js +4 -0
- package/dist/audit/cli/nextStepCommand.js.map +1 -1
- package/dist/audit/cli/nextStepHelpers.d.ts +11 -0
- package/dist/audit/cli/nextStepHelpers.d.ts.map +1 -1
- package/dist/audit/cli/nextStepHelpers.js +21 -4
- package/dist/audit/cli/nextStepHelpers.js.map +1 -1
- package/dist/audit/validation/sessionConfig.d.ts.map +1 -1
- package/dist/audit/validation/sessionConfig.js +7 -1
- package/dist/audit/validation/sessionConfig.js.map +1 -1
- package/dist/remediate/index.d.ts +0 -1
- package/dist/remediate/index.d.ts.map +1 -1
- package/dist/remediate/index.js +0 -14
- package/dist/remediate/index.js.map +1 -1
- package/dist/remediate/steps/dispatch.d.ts +2 -0
- package/dist/remediate/steps/dispatch.d.ts.map +1 -1
- package/dist/remediate/steps/dispatch.js +40 -20
- package/dist/remediate/steps/dispatch.js.map +1 -1
- package/dist/remediate/steps/nextStep.d.ts.map +1 -1
- package/dist/remediate/steps/nextStep.js +41 -27
- package/dist/remediate/steps/nextStep.js.map +1 -1
- package/dist/shared/dispatch/rollingDispatch.d.ts.map +1 -1
- package/dist/shared/dispatch/rollingDispatch.js +9 -1
- package/dist/shared/dispatch/rollingDispatch.js.map +1 -1
- package/dist/shared/index.d.ts +2 -4
- package/dist/shared/index.d.ts.map +1 -1
- package/dist/shared/index.js +2 -3
- package/dist/shared/index.js.map +1 -1
- package/dist/shared/providers/openAiCompatibleProvider.d.ts.map +1 -1
- package/dist/shared/providers/openAiCompatibleProvider.js +42 -15
- package/dist/shared/providers/openAiCompatibleProvider.js.map +1 -1
- package/dist/shared/quota/apiPool.d.ts +29 -4
- package/dist/shared/quota/apiPool.d.ts.map +1 -1
- package/dist/shared/quota/apiPool.js +114 -25
- package/dist/shared/quota/apiPool.js.map +1 -1
- package/dist/shared/quota/hostSessionQuotaSource.d.ts +2 -3
- package/dist/shared/quota/hostSessionQuotaSource.d.ts.map +1 -1
- package/dist/shared/quota/hostSessionQuotaSource.js +2 -3
- package/dist/shared/quota/hostSessionQuotaSource.js.map +1 -1
- package/dist/shared/types/sessionConfig.d.ts +32 -0
- package/dist/shared/types/sessionConfig.d.ts.map +1 -1
- package/dist/shared/types/sessionConfig.js +26 -0
- package/dist/shared/types/sessionConfig.js.map +1 -1
- package/package.json +1 -1
- package/skills/audit-code/SKILL.md +11 -2
- package/wrapper/audit-code-wrapper-install-hosts.mjs +16 -8
- package/dist/shared/quota/rollingEngine.d.ts +0 -130
- package/dist/shared/quota/rollingEngine.d.ts.map +0 -1
- package/dist/shared/quota/rollingEngine.js +0 -153
- package/dist/shared/quota/rollingEngine.js.map +0 -1
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Rolling engine — provider-pool-change semantics (drop + re-route).
|
|
3
|
-
*
|
|
4
|
-
* Manages a mutable active provider pool across a dispatch run. When a provider
|
|
5
|
-
* signals quota exhaustion or disappears, the engine drops it from the active
|
|
6
|
-
* routing set, re-queues any in-flight packets that had been assigned to it, and
|
|
7
|
-
* re-routes those packets to the remaining active providers.
|
|
8
|
-
*
|
|
9
|
-
* NOTE: The empty-pool terminal (active_pools reaches zero → waiting_for_provider)
|
|
10
|
-
* is NOT handled here — that is N-S09's responsibility. When dropProvider is
|
|
11
|
-
* called on the last active pool it returns a state with active_pools: [] and
|
|
12
|
-
* the caller's engine loop detects and handles the empty-pool condition.
|
|
13
|
-
*/
|
|
14
|
-
import { computeDispatchCapacity, buildEmptyPoolTerminal } from "./capacity.js";
|
|
15
|
-
// ---------------------------------------------------------------------------
|
|
16
|
-
// dropProvider
|
|
17
|
-
// ---------------------------------------------------------------------------
|
|
18
|
-
/**
|
|
19
|
-
* Pure function: remove a provider from the active routing set.
|
|
20
|
-
*
|
|
21
|
-
* Given the current engine state and a pool_id to drop:
|
|
22
|
-
* 1. Moves the named pool from `active_pools` to `exhausted_pools`.
|
|
23
|
-
* 2. Identifies all in-flight packets assigned to the dropped pool.
|
|
24
|
-
* 3. Removes those packets from `in_flight_tokens`.
|
|
25
|
-
* 4. Appends those packets to `pending_tokens` (re-queued for re-routing).
|
|
26
|
-
* 5. Appends a `ProviderPoolEvent` to `event_log`.
|
|
27
|
-
*
|
|
28
|
-
* Returns a new `RollingEnginePoolState` — the input state is never mutated.
|
|
29
|
-
*
|
|
30
|
-
* When `active_pools` is already empty or the pool_id is not found in
|
|
31
|
-
* `active_pools`, the state is returned unchanged (idempotent).
|
|
32
|
-
*
|
|
33
|
-
* When this call reduces `active_pools` to `[]`, the caller (N-S09's engine
|
|
34
|
-
* loop) is responsible for detecting the empty-pool condition.
|
|
35
|
-
*/
|
|
36
|
-
export function dropProvider(state, pool_id, kind) {
|
|
37
|
-
const poolIndex = state.active_pools.findIndex((e) => e.pool.id === pool_id);
|
|
38
|
-
if (poolIndex === -1) {
|
|
39
|
-
// Pool not in active set — idempotent, return unchanged.
|
|
40
|
-
return state;
|
|
41
|
-
}
|
|
42
|
-
const dropped = state.active_pools[poolIndex];
|
|
43
|
-
// Identify in-flight packets assigned to the dropped pool.
|
|
44
|
-
const requeued = state.in_flight_tokens.filter((t) => t.assigned_pool_id === pool_id);
|
|
45
|
-
const stillInFlight = state.in_flight_tokens.filter((t) => t.assigned_pool_id !== pool_id);
|
|
46
|
-
const event = {
|
|
47
|
-
kind,
|
|
48
|
-
provider_id: pool_id,
|
|
49
|
-
timestamp: new Date().toISOString(),
|
|
50
|
-
in_flight_count: requeued.length,
|
|
51
|
-
requeued_count: requeued.length,
|
|
52
|
-
};
|
|
53
|
-
// Structured observability for pool drops/rerouting (OBS-d81a55ab). Emitted on
|
|
54
|
-
// its own line and wrapped so a logging failure can never abort a dispatch run.
|
|
55
|
-
try {
|
|
56
|
-
process.stderr.write(JSON.stringify({
|
|
57
|
-
ts: event.timestamp,
|
|
58
|
-
kind: "rolling_engine_drop_provider",
|
|
59
|
-
provider_id: pool_id,
|
|
60
|
-
drop_kind: kind,
|
|
61
|
-
in_flight_count: event.in_flight_count,
|
|
62
|
-
requeued_count: event.requeued_count,
|
|
63
|
-
}) + "\n");
|
|
64
|
-
}
|
|
65
|
-
catch {
|
|
66
|
-
// Observability must never abort a run.
|
|
67
|
-
}
|
|
68
|
-
return {
|
|
69
|
-
active_pools: [
|
|
70
|
-
...state.active_pools.slice(0, poolIndex),
|
|
71
|
-
...state.active_pools.slice(poolIndex + 1),
|
|
72
|
-
],
|
|
73
|
-
exhausted_pools: [...state.exhausted_pools, dropped],
|
|
74
|
-
in_flight_tokens: stillInFlight,
|
|
75
|
-
pending_tokens: [...state.pending_tokens, ...requeued],
|
|
76
|
-
event_log: [...state.event_log, event],
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Re-route pending packet tokens across the remaining active pools.
|
|
81
|
-
*
|
|
82
|
-
* The no-stranding guarantee (INV-QD-13 / SEAM-rolling-stranding): after ANY
|
|
83
|
-
* `dropProvider` — including simultaneous multi-pool drops where pending demand
|
|
84
|
-
* exceeds the survivors' slot capacity — this function leaves ZERO
|
|
85
|
-
* `pending_tokens` whose `assigned_pool_id` points at a dropped/exhausted (i.e.
|
|
86
|
-
* non-active) pool. Every pending packet is either reassigned to a pool still in
|
|
87
|
-
* `active_pools`, or removed from `pending_tokens` and surfaced in
|
|
88
|
-
* `terminal.stranded_ids`. `reroutePackets` is the SINGLE owner of this
|
|
89
|
-
* guarantee; consumers (audit-cli-commands, remediate-steps-dispatch) only
|
|
90
|
-
* consume `stranded_ids` and never implement their own reroute.
|
|
91
|
-
*
|
|
92
|
-
* Behaviour:
|
|
93
|
-
* - No pending tokens → state unchanged, `allocation` and `terminal` null.
|
|
94
|
-
* - `active_pools` empty but pending tokens exist → every pending packet is
|
|
95
|
-
* stranded (state pending cleared) and an `empty_pool` terminal is returned.
|
|
96
|
-
* - Otherwise → `computeDispatchCapacity` sizes the surviving pools; the largest
|
|
97
|
-
* pending packets are assigned to the surviving pools up to their slot counts,
|
|
98
|
-
* and any surplus that does not fit is stranded.
|
|
99
|
-
*
|
|
100
|
-
* Also returns the `DispatchCapacity` computed by `computeDispatchCapacity` so
|
|
101
|
-
* callers can inspect the allocation without re-computing it.
|
|
102
|
-
*/
|
|
103
|
-
export function reroutePackets(state, sessionConfig) {
|
|
104
|
-
if (state.pending_tokens.length === 0) {
|
|
105
|
-
return { state, allocation: null, terminal: null };
|
|
106
|
-
}
|
|
107
|
-
// No surviving pool: every pending packet is stranded. Clearing pending here
|
|
108
|
-
// is what guarantees ZERO pending_tokens remain pointed at a dead pool.
|
|
109
|
-
if (state.active_pools.length === 0) {
|
|
110
|
-
const strandedIds = state.pending_tokens.map((t) => t.id);
|
|
111
|
-
return {
|
|
112
|
-
state: { ...state, pending_tokens: [] },
|
|
113
|
-
allocation: null,
|
|
114
|
-
terminal: buildEmptyPoolTerminal(strandedIds),
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
const pendingItemTokens = state.pending_tokens.map((t) => t.estimated_tokens);
|
|
118
|
-
const pools = state.active_pools.map((e) => e.pool);
|
|
119
|
-
const activePoolIds = new Set(pools.map((p) => p.id));
|
|
120
|
-
const allocation = computeDispatchCapacity({ pools, sessionConfig, pendingItemTokens });
|
|
121
|
-
// Order pending packets largest-first so the survivors' slots carry the most
|
|
122
|
-
// expensive work, mirroring computeDispatchCapacity's own descending layout.
|
|
123
|
-
const ordered = [...state.pending_tokens].sort((a, b) => b.estimated_tokens - a.estimated_tokens);
|
|
124
|
-
// Re-assign pending tokens to surviving pools based on slot counts.
|
|
125
|
-
const reassigned = [];
|
|
126
|
-
let tokenCursor = 0;
|
|
127
|
-
for (const poolAlloc of allocation.pools) {
|
|
128
|
-
// Defensive: never assign to a pool that is not in the active set.
|
|
129
|
-
if (!activePoolIds.has(poolAlloc.pool_id))
|
|
130
|
-
continue;
|
|
131
|
-
const assignCount = Math.min(poolAlloc.slots, ordered.length - tokenCursor);
|
|
132
|
-
for (let i = 0; i < assignCount; i++) {
|
|
133
|
-
const original = ordered[tokenCursor + i];
|
|
134
|
-
reassigned.push({ ...original, assigned_pool_id: poolAlloc.pool_id });
|
|
135
|
-
}
|
|
136
|
-
tokenCursor += assignCount;
|
|
137
|
-
if (tokenCursor >= ordered.length)
|
|
138
|
-
break;
|
|
139
|
-
}
|
|
140
|
-
// Any packet beyond the survivors' combined slot capacity cannot be placed on
|
|
141
|
-
// an active pool. It MUST NOT stay assigned to a dropped/exhausted pool — it is
|
|
142
|
-
// removed from pending_tokens and surfaced as stranded (INV-QD-13).
|
|
143
|
-
const stranded = ordered.slice(tokenCursor);
|
|
144
|
-
const terminal = stranded.length > 0
|
|
145
|
-
? buildEmptyPoolTerminal(stranded.map((t) => t.id))
|
|
146
|
-
: null;
|
|
147
|
-
return {
|
|
148
|
-
state: { ...state, pending_tokens: reassigned },
|
|
149
|
-
allocation,
|
|
150
|
-
terminal,
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
//# sourceMappingURL=rollingEngine.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"rollingEngine.js","sourceRoot":"","sources":["../../../src/shared/quota/rollingEngine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAKH,OAAO,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAiEhF,8EAA8E;AAC9E,eAAe;AACf,8EAA8E;AAE9E;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,YA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