@indigoai-us/hq-cli 5.345.130 → 5.345.131
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -0
- package/dist/commands/capacity.d.ts +1 -2
- package/dist/commands/capacity.js +7 -9
- package/dist/commands/lanes-loop.d.ts +14 -0
- package/dist/commands/lanes-loop.js +43 -2
- package/dist/commands/lanes.js +8 -4
- package/dist/lib/capacity/freshness.d.ts +17 -0
- package/dist/lib/capacity/freshness.js +16 -0
- package/dist/lib/capacity/route.d.ts +7 -0
- package/dist/lib/capacity/route.js +46 -1
- package/dist/lib/lanes/loop.d.ts +5 -0
- package/dist/lib/lanes/loop.js +8 -0
- package/dist/lib/lanes/reconcile.js +18 -1
- package/dist/lib/lanes/worker-continuity.d.ts +13 -1
- package/dist/lib/lanes/worker-continuity.js +14 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [5.345.131] — 2026-10-14
|
|
6
|
+
- `hq lanes --account auto` and `hq capacity route` no longer refuse every signed-in account when the capacity collector is off or its readings are stale; those accounts are picked with unknown usage, below accounts with fresh headroom.
|
|
7
|
+
- `hq lanes create` now resumes an earlier worker session only when the project, model, and effort match, and otherwise starts a fresh thread.
|
|
8
|
+
- A loop lane waiting for its next phase now shows as running in `hq lanes status` and `hq lanes list`, and becomes done only after it is stopped.
|
|
9
|
+
|
|
5
10
|
## [5.345.130] — 2026-10-14
|
|
6
11
|
- Add native TypeScript `hq core workflow run` orchestration with the bundled runner as its flag-off fallback.
|
|
7
12
|
|
|
@@ -15,8 +15,7 @@ import { type ClaudeRefreshLastEntry } from "../lib/capacity/collectors/claude-o
|
|
|
15
15
|
export declare const CAPACITY_SCHEMA_VERSION: "hq-capacity-now-view.v1";
|
|
16
16
|
export declare const DOCTOR_SCHEMA_VERSION = "hq-capacity-doctor.v1";
|
|
17
17
|
export declare const PARSER_FAILURE_WINDOW_MS: number;
|
|
18
|
-
|
|
19
|
-
export declare const CAPACITY_STALE_MS: number;
|
|
18
|
+
export { CAPACITY_STALE_MS } from "../lib/capacity/freshness.js";
|
|
20
19
|
/** Short versions inside test/fixtures/capacity/cli-versions.json. */
|
|
21
20
|
export declare const PINNED_CLI_VERSIONS: Record<string, string>;
|
|
22
21
|
export interface CapacityJson extends NowView {
|
|
@@ -7,6 +7,7 @@ import { LedgerCorrupt, LedgerMissing, READING_SOURCES, capacityOptionsFromEnv,
|
|
|
7
7
|
import { listCapacityAccounts, registryAccountIds } from "../lib/capacity/accounts.js";
|
|
8
8
|
import { claudeIdentityKeys, readClaudeRefreshLast } from "../lib/capacity/collectors/claude-oauth.js";
|
|
9
9
|
import { projectCapacityView } from "../lib/capacity/project.js";
|
|
10
|
+
import { capacityViewAge } from "../lib/capacity/freshness.js";
|
|
10
11
|
import { capacityWidgetTimeZone, renderCapacityWidget } from "../lib/capacity/widget.js";
|
|
11
12
|
import { resolveLanesHqRoot } from "../lib/lanes/hq-root.js";
|
|
12
13
|
import { loadLanesConfig } from "../lib/lanes/config.js";
|
|
@@ -18,8 +19,7 @@ import { CapacityUsageError, REFUSAL_HELP, ingestRefusal, } from "../lib/capacit
|
|
|
18
19
|
export const CAPACITY_SCHEMA_VERSION = nowViewJsonSchema.$id;
|
|
19
20
|
export const DOCTOR_SCHEMA_VERSION = "hq-capacity-doctor.v1";
|
|
20
21
|
export const PARSER_FAILURE_WINDOW_MS = 24 * 60 * 60 * 1000;
|
|
21
|
-
|
|
22
|
-
export const CAPACITY_STALE_MS = 5 * 60 * 1000;
|
|
22
|
+
export { CAPACITY_STALE_MS } from "../lib/capacity/freshness.js";
|
|
23
23
|
/** Short versions inside test/fixtures/capacity/cli-versions.json. */
|
|
24
24
|
export const PINNED_CLI_VERSIONS = {
|
|
25
25
|
claude: "2.1.152",
|
|
@@ -54,20 +54,18 @@ export function withSchemaVersion(view) {
|
|
|
54
54
|
}
|
|
55
55
|
/** Stale when generatedAt is missing or older than five minutes. */
|
|
56
56
|
export function capacityFreshness(generatedAt, nowMs) {
|
|
57
|
-
const
|
|
58
|
-
if (
|
|
57
|
+
const age = capacityViewAge(generatedAt, nowMs);
|
|
58
|
+
if (!age.known) {
|
|
59
59
|
return {
|
|
60
60
|
stale: true,
|
|
61
61
|
ageMs: 0,
|
|
62
62
|
message: "collector not running, numbers may be stale; last update unknown",
|
|
63
63
|
};
|
|
64
64
|
}
|
|
65
|
-
const ageMs = Math.max(0, nowMs - at);
|
|
66
|
-
const stale = ageMs > CAPACITY_STALE_MS;
|
|
67
65
|
return {
|
|
68
|
-
stale,
|
|
69
|
-
ageMs,
|
|
70
|
-
message: stale
|
|
66
|
+
stale: age.stale,
|
|
67
|
+
ageMs: age.ageMs,
|
|
68
|
+
message: age.stale
|
|
71
69
|
? `collector not running, numbers may be stale; last update ${formatAge(generatedAt, nowMs)}`
|
|
72
70
|
: null,
|
|
73
71
|
};
|
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
import type { Ctx, LaneResumeOptions } from "./lanes-shared.js";
|
|
2
2
|
import type { LaneRecord } from "../lib/lanes/types.js";
|
|
3
|
+
/**
|
|
4
|
+
* A loop lane that finished a phase and is waiting for its next envelope is
|
|
5
|
+
* alive, not finished. The watcher still writes `done` when the phase's worker
|
|
6
|
+
* exits (the controller reads that as the phase-complete signal); this moves
|
|
7
|
+
* the lane back to `running`, the same state an admitted loop lane holds
|
|
8
|
+
* before its first phase. Only a stop makes a loop lane `done`.
|
|
9
|
+
*/
|
|
10
|
+
export declare function settleLoopLaneIdle(hqRoot: string, laneId: string): LaneRecord;
|
|
11
|
+
/**
|
|
12
|
+
* The next phase resumes the provider session, which `hq lanes resume` only
|
|
13
|
+
* accepts from a resumable state. An idle loop lane sits in `running` with no
|
|
14
|
+
* worker, so it is handed to resume as the `done` lane the phase left.
|
|
15
|
+
*/
|
|
16
|
+
export declare function prepareIdleLoopLaneForResume(hqRoot: string, laneId: string): LaneRecord;
|
|
3
17
|
export interface LoopControllerDeps {
|
|
4
18
|
resumeLane(laneId: string, options: LaneResumeOptions): Promise<unknown>;
|
|
5
19
|
interruptLane(laneId: string, reason: string, options: {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { spawn } from "node:child_process";
|
|
2
2
|
import * as fs from "node:fs";
|
|
3
3
|
import * as path from "node:path";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { readLane, retryUpdateLane, updateLane } from "../lib/lanes/store.js";
|
|
5
|
+
import { LanesError, isLaneVersionConflict } from "../lib/lanes/errors.js";
|
|
6
6
|
import { readLatestEnvelopeRecord } from "../lib/lanes/watcher.js";
|
|
7
7
|
import { spawnLaneWorker } from "../lib/lanes/spawn.js";
|
|
8
8
|
import { raiseLaneQuestion } from "../lib/lanes/questions.js";
|
|
@@ -15,6 +15,43 @@ const LOOP_RUNS_REL = path.join("workspace", "lanes-runs");
|
|
|
15
15
|
function loopRunDir(hqRoot, laneId) {
|
|
16
16
|
return path.join(hqRoot, LOOP_RUNS_REL, laneId);
|
|
17
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* A loop lane that finished a phase and is waiting for its next envelope is
|
|
20
|
+
* alive, not finished. The watcher still writes `done` when the phase's worker
|
|
21
|
+
* exits (the controller reads that as the phase-complete signal); this moves
|
|
22
|
+
* the lane back to `running`, the same state an admitted loop lane holds
|
|
23
|
+
* before its first phase. Only a stop makes a loop lane `done`.
|
|
24
|
+
*/
|
|
25
|
+
export function settleLoopLaneIdle(hqRoot, laneId) {
|
|
26
|
+
return casLoopLaneState(hqRoot, laneId, "done", "running");
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The next phase resumes the provider session, which `hq lanes resume` only
|
|
30
|
+
* accepts from a resumable state. An idle loop lane sits in `running` with no
|
|
31
|
+
* worker, so it is handed to resume as the `done` lane the phase left.
|
|
32
|
+
*/
|
|
33
|
+
export function prepareIdleLoopLaneForResume(hqRoot, laneId) {
|
|
34
|
+
return casLoopLaneState(hqRoot, laneId, "running", "done");
|
|
35
|
+
}
|
|
36
|
+
function casLoopLaneState(hqRoot, laneId, from, to) {
|
|
37
|
+
for (let attempt = 0;; attempt += 1) {
|
|
38
|
+
const current = readLane(hqRoot, laneId);
|
|
39
|
+
if (current.loop_mode !== true || current.state !== from)
|
|
40
|
+
return current;
|
|
41
|
+
try {
|
|
42
|
+
return updateLane(hqRoot, laneId, current.version, "command", (record) => ({
|
|
43
|
+
...record,
|
|
44
|
+
state: to,
|
|
45
|
+
terminal_reason: undefined,
|
|
46
|
+
terminal_details: undefined,
|
|
47
|
+
}));
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
if (!isLaneVersionConflict(error) || attempt >= 4)
|
|
51
|
+
throw error;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
18
55
|
export function startLaneLoopController(ctx, laneId, initialAdmission = false) {
|
|
19
56
|
const entry = process.argv[1];
|
|
20
57
|
if (!entry)
|
|
@@ -151,6 +188,8 @@ export async function runLaneLoopController(ctx, laneId, deps) {
|
|
|
151
188
|
}));
|
|
152
189
|
}
|
|
153
190
|
else {
|
|
191
|
+
if (current.state === "running")
|
|
192
|
+
current = prepareIdleLoopLaneForResume(hqRoot, laneId);
|
|
154
193
|
await deps.resumeLane(laneId, {
|
|
155
194
|
text: `Read ${briefPath} and follow it as the complete instruction for this phase.`,
|
|
156
195
|
project: current.project_id,
|
|
@@ -187,6 +226,8 @@ export async function runLaneLoopController(ctx, laneId, deps) {
|
|
|
187
226
|
if (data.schema === "hq-phase-envelope/v1" && !handoff) {
|
|
188
227
|
throw new Error("section 8 phase requires an hq-phase-handoff/v1 object in the lane envelope artifacts");
|
|
189
228
|
}
|
|
229
|
+
if (latest.state === "done")
|
|
230
|
+
settleLoopLaneIdle(hqRoot, laneId);
|
|
190
231
|
return { output: JSON.stringify(handoff ?? envelopeRecord.envelope), ...(latest.provider_session_id ? { sessionId: latest.provider_session_id } : {}) };
|
|
191
232
|
}
|
|
192
233
|
await new Promise((resolve) => setTimeout(resolve, 250));
|
package/dist/commands/lanes.js
CHANGED
|
@@ -46,8 +46,8 @@ import { registerDaemonLanesReconcileHandler } from "../lib/lanes/daemon-reconci
|
|
|
46
46
|
import { appendProjectFocusOverride, readProjectStoryFocusData, removeProjectFocusOverride } from "../lib/lanes/story-ledger.js";
|
|
47
47
|
import { appendLaneFocusOverride, assertFocusGuardAllows, makeFocusOverride } from "../lib/lanes/focus-guard.js";
|
|
48
48
|
import { LANE_FOCUS_GUARD_FLAG, LANE_FOCUS_DASHBOARD_FLAG, LANE_HIRE_GRANT_FINISHED_LANES_FLAG, LANE_LIST_SKIP_REMOTE_REFRESH_FLAG, LANE_MESSAGE_ROUTE_OWNER_HOST_FLAG, LANE_ORPHANED_BARE_ID_DROPBOX_REPAIR_FLAG, LANE_PROFILE_PIN_EXHAUSTED_FALLBACK_FLAG, LANE_STATUS_ROW_FIELDS_FLAG, LANE_REAP_STOP_FLAG, LANE_REUSE_REFRESHES_PROFILE_FLAG, LANE_WORKER_CONTINUITY_FLAG, LANE_CONDUCT_LOOP_FLAG, LANE_ENVELOPE_REPAIR_GUIDANCE_FLAG, } from "../lib/lanes/flag-keys.js";
|
|
49
|
-
import { findWorkerContinuityLane, sameLaneHost, workerContinuityPrompt } from "../lib/lanes/worker-continuity.js";
|
|
50
|
-
import { commitIdleLoopStop, enqueueLoopEnvelope, interruptLoopQueue, interruptLoopQueueForStory, loopControllerIsAlive, loopStatus, validateLoopEnvelope } from "../lib/lanes/loop.js";
|
|
49
|
+
import { applyContinuitySettings, findWorkerContinuityLane, sameLaneHost, workerContinuityPrompt } from "../lib/lanes/worker-continuity.js";
|
|
50
|
+
import { commitIdleLoopStop, enqueueLoopEnvelope, interruptLoopQueue, interruptLoopQueueForStory, loopControllerIsAlive, loopLaneIsIdle, loopStatus, validateLoopEnvelope } from "../lib/lanes/loop.js";
|
|
51
51
|
import { runLaneLoopController, startLaneLoopController } from "./lanes-loop.js";
|
|
52
52
|
import { configuredCodexRolloutHomes, retainCodexRollouts } from "../lib/lanes/disk-guard.js";
|
|
53
53
|
import { isControllerAliasOutpostId } from "../lib/lanes/admission-host.js";
|
|
@@ -89,8 +89,9 @@ import { writeQuestionBody } from "../lib/lanes/questions.js";
|
|
|
89
89
|
import { compactionAfterUsage, } from "../lib/lanes/compaction.js";
|
|
90
90
|
import { parseCliEffort, resolveLaneEffort, } from "../lib/lanes/effort.js";
|
|
91
91
|
import { LanesError } from "../lib/lanes/errors.js";
|
|
92
|
-
import { LedgerCorrupt, capacityOptionsFromEnv, readNow, rebuildNow, } from "../lib/capacity/ledger.js";
|
|
92
|
+
import { LedgerCorrupt, capacityOptionsFromEnv, readCollectorMark, readNow, rebuildNow, } from "../lib/capacity/ledger.js";
|
|
93
93
|
import { pickAccount } from "../lib/capacity/route.js";
|
|
94
|
+
import { capacityViewAge } from "../lib/capacity/freshness.js";
|
|
94
95
|
import { readLatestEnvelopeRecord } from "../lib/lanes/watcher.js";
|
|
95
96
|
import { loadQuotaState, quotaBlockFor } from "../lib/lanes/quota.js";
|
|
96
97
|
import { SESSION_MOVE_REASON } from "../lib/lanes/move-account.js";
|
|
@@ -3436,6 +3437,8 @@ async function runCreate(ctx, opts) {
|
|
|
3436
3437
|
...(explicitProvider ? { providers: [explicitProvider] } : {}),
|
|
3437
3438
|
model: opts.model ?? null,
|
|
3438
3439
|
now: ctx.now(),
|
|
3440
|
+
collectorEnabled: readCollectorMark(ledgerOptions)?.enabled ?? null,
|
|
3441
|
+
capacityStale: capacityViewAge(view.generatedAt, ctx.now().getTime()).stale,
|
|
3439
3442
|
lanesError: routeLanesError,
|
|
3440
3443
|
});
|
|
3441
3444
|
if (!result.ok || !result.pick) {
|
|
@@ -4102,6 +4105,7 @@ async function runCreate(ctx, opts) {
|
|
|
4102
4105
|
providerEffort: config.providers[provider].effort,
|
|
4103
4106
|
model,
|
|
4104
4107
|
});
|
|
4108
|
+
workerContinuity = applyContinuitySettings(workerContinuity, { project, model, effort: effort.effort });
|
|
4105
4109
|
if (outpostId) {
|
|
4106
4110
|
admission = { action: "queue" };
|
|
4107
4111
|
validation = "pending";
|
|
@@ -8914,7 +8918,7 @@ async function runInterrupt(ctx, laneId, reason, options = {}) {
|
|
|
8914
8918
|
const queueInterrupt = lane.loop_mode === true && options.preserveLoopQueue !== true
|
|
8915
8919
|
? interruptLoopQueue(runDir(hqRoot, lane.lane_id))
|
|
8916
8920
|
: undefined;
|
|
8917
|
-
if (lane.loop_mode === true && lane.state !== "running") {
|
|
8921
|
+
if (lane.loop_mode === true && (lane.state !== "running" || loopLaneIsIdle(runDir(hqRoot, lane.lane_id), lane.lane_id))) {
|
|
8918
8922
|
if (!options.quiet)
|
|
8919
8923
|
printJson({ ok: true, action: "interrupt", lane_id: lane.lane_id, terminal: false, resumable: true, ...queueInterrupt });
|
|
8920
8924
|
return;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Capacity view freshness. Kept in lib (not commands/capacity.ts) so resident
|
|
3
|
+
* paths such as `hq lanes` can check staleness without pulling in the capacity
|
|
4
|
+
* command module and its lazy collector imports.
|
|
5
|
+
*/
|
|
6
|
+
/** now.json older than this is stale: the collector is not keeping the view current. */
|
|
7
|
+
export declare const CAPACITY_STALE_MS: number;
|
|
8
|
+
export interface CapacityViewAge {
|
|
9
|
+
stale: boolean;
|
|
10
|
+
/** Milliseconds since generatedAt; 0 when generatedAt is missing or unparseable. */
|
|
11
|
+
ageMs: number;
|
|
12
|
+
/** False when generatedAt is missing or unparseable. */
|
|
13
|
+
known: boolean;
|
|
14
|
+
}
|
|
15
|
+
/** Stale when generatedAt is missing or older than CAPACITY_STALE_MS. */
|
|
16
|
+
export declare function capacityViewAge(generatedAt: string, nowMs: number): CapacityViewAge;
|
|
17
|
+
//# sourceMappingURL=freshness.d.ts.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Capacity view freshness. Kept in lib (not commands/capacity.ts) so resident
|
|
3
|
+
* paths such as `hq lanes` can check staleness without pulling in the capacity
|
|
4
|
+
* command module and its lazy collector imports.
|
|
5
|
+
*/
|
|
6
|
+
/** now.json older than this is stale: the collector is not keeping the view current. */
|
|
7
|
+
export const CAPACITY_STALE_MS = 5 * 60 * 1000;
|
|
8
|
+
/** Stale when generatedAt is missing or older than CAPACITY_STALE_MS. */
|
|
9
|
+
export function capacityViewAge(generatedAt, nowMs) {
|
|
10
|
+
const at = Date.parse(generatedAt);
|
|
11
|
+
if (Number.isNaN(at))
|
|
12
|
+
return { stale: true, ageMs: 0, known: false };
|
|
13
|
+
const ageMs = Math.max(0, nowMs - at);
|
|
14
|
+
return { stale: ageMs > CAPACITY_STALE_MS, ageMs, known: true };
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=freshness.js.map
|
|
@@ -23,6 +23,11 @@ export declare const LIMIT_STALE_MS: number;
|
|
|
23
23
|
export declare const FRESH_MS: number;
|
|
24
24
|
/** Score penalty for an account whose binding limit reading is not fresh. */
|
|
25
25
|
export declare const OLD_READING_PENALTY = 10;
|
|
26
|
+
/**
|
|
27
|
+
* Score for an account ranked with unknown usage (collector off or capacity
|
|
28
|
+
* view stale). Sits below any account with fresh known headroom.
|
|
29
|
+
*/
|
|
30
|
+
export declare const UNKNOWN_USAGE_SCORE = -100;
|
|
26
31
|
/** Default --floor applied by the CLI (percent headroom to clear). */
|
|
27
32
|
export declare const DEFAULT_FLOOR = 15;
|
|
28
33
|
/** Default --prefer order applied by the CLI. */
|
|
@@ -78,6 +83,8 @@ export interface RouteRanked {
|
|
|
78
83
|
weekly_resets_at: string | null;
|
|
79
84
|
why: string;
|
|
80
85
|
lane_flags: string;
|
|
86
|
+
/** True when no usable reading exists and the account is ranked as unknown. */
|
|
87
|
+
usage_unknown: boolean;
|
|
81
88
|
}
|
|
82
89
|
/** Live lane on an account the router would avoid; command names a replacement. */
|
|
83
90
|
export interface RouteMove {
|
|
@@ -42,6 +42,11 @@ export const LIMIT_STALE_MS = 24 * 36e5;
|
|
|
42
42
|
export const FRESH_MS = 60 * 6e4;
|
|
43
43
|
/** Score penalty for an account whose binding limit reading is not fresh. */
|
|
44
44
|
export const OLD_READING_PENALTY = 10;
|
|
45
|
+
/**
|
|
46
|
+
* Score for an account ranked with unknown usage (collector off or capacity
|
|
47
|
+
* view stale). Sits below any account with fresh known headroom.
|
|
48
|
+
*/
|
|
49
|
+
export const UNKNOWN_USAGE_SCORE = -100;
|
|
45
50
|
/** Default --floor applied by the CLI (percent headroom to clear). */
|
|
46
51
|
export const DEFAULT_FLOOR = 15;
|
|
47
52
|
/** Default --prefer order applied by the CLI. */
|
|
@@ -197,6 +202,37 @@ export function pickAccount(input) {
|
|
|
197
202
|
const lanes = input.lanes ?? [];
|
|
198
203
|
const ranked = [];
|
|
199
204
|
const skipped = [];
|
|
205
|
+
// With the collector off (or its mark missing) or the view stale, readings
|
|
206
|
+
// never refresh. Missing or old readings then say nothing about the account,
|
|
207
|
+
// so a signed-in, enabled account is ranked as unknown instead of skipped.
|
|
208
|
+
const readingsUnreliable = input.collectorEnabled === false
|
|
209
|
+
|| input.collectorEnabled === null
|
|
210
|
+
|| input.capacityStale === true;
|
|
211
|
+
const rankUnknown = (base, accountId, tokenExpired) => {
|
|
212
|
+
const live = liveLaneCount(lanes, base.provider, accountId);
|
|
213
|
+
const whyParts = ["usage unknown, capacity readings are stale or the collector is off"];
|
|
214
|
+
if (live)
|
|
215
|
+
whyParts.push(`${live} live lane${live === 1 ? "" : "s"} already on it`);
|
|
216
|
+
if (tokenExpired)
|
|
217
|
+
whyParts.push("sign-in renews when the lane starts");
|
|
218
|
+
ranked.push({
|
|
219
|
+
provider: base.provider,
|
|
220
|
+
account: accountId,
|
|
221
|
+
label: base.label,
|
|
222
|
+
organization: base.organization,
|
|
223
|
+
headroom: 0,
|
|
224
|
+
score: UNKNOWN_USAGE_SCORE - live * LANE_PENALTY,
|
|
225
|
+
live_lanes: live,
|
|
226
|
+
reset_soon: false,
|
|
227
|
+
token_expired: tokenExpired,
|
|
228
|
+
reading_age_h: 0,
|
|
229
|
+
binding: { limit: "unknown", used_percent: 0, resets_at: null },
|
|
230
|
+
weekly_resets_at: null,
|
|
231
|
+
why: whyParts.join("; "),
|
|
232
|
+
lane_flags: `--provider ${base.provider} --account ${accountId}`,
|
|
233
|
+
usage_unknown: true,
|
|
234
|
+
});
|
|
235
|
+
};
|
|
200
236
|
for (const provider of input.view.providers) {
|
|
201
237
|
const providerId = provider.provider;
|
|
202
238
|
if (!isLaneProvider(providerId))
|
|
@@ -247,6 +283,10 @@ export function pickAccount(input) {
|
|
|
247
283
|
? Math.max(0, nowMs - observedMs)
|
|
248
284
|
: Infinity;
|
|
249
285
|
if (accountAge > STALE_SKIP_MS) {
|
|
286
|
+
if (readingsUnreliable) {
|
|
287
|
+
rankUnknown(base, laneMatch.id, tokenExpired);
|
|
288
|
+
continue;
|
|
289
|
+
}
|
|
250
290
|
skipped.push({
|
|
251
291
|
...base,
|
|
252
292
|
reason: "no reading in the last 24 hours",
|
|
@@ -313,6 +353,10 @@ export function pickAccount(input) {
|
|
|
313
353
|
}
|
|
314
354
|
const known = viewRows.filter((row) => typeof row.used === "number");
|
|
315
355
|
if (known.length === 0) {
|
|
356
|
+
if (readingsUnreliable) {
|
|
357
|
+
rankUnknown(base, laneMatch.id, tokenExpired);
|
|
358
|
+
continue;
|
|
359
|
+
}
|
|
316
360
|
skipped.push({
|
|
317
361
|
...base,
|
|
318
362
|
reason: "no usage numbers for this account in the last day",
|
|
@@ -376,6 +420,7 @@ export function pickAccount(input) {
|
|
|
376
420
|
weekly_resets_at: weekly?.resetsAt ?? null,
|
|
377
421
|
why: whyParts.join("; "),
|
|
378
422
|
lane_flags: `--provider ${providerId} --account ${laneMatch.id}`,
|
|
423
|
+
usage_unknown: false,
|
|
379
424
|
});
|
|
380
425
|
}
|
|
381
426
|
}
|
|
@@ -401,7 +446,7 @@ export function pickAccount(input) {
|
|
|
401
446
|
bad.set(`${row.provider}:${row.account}`, row.reason);
|
|
402
447
|
}
|
|
403
448
|
for (const row of ranked) {
|
|
404
|
-
if (row.headroom < floor) {
|
|
449
|
+
if (!row.usage_unknown && row.headroom < floor) {
|
|
405
450
|
bad.set(`${row.provider}:${row.account}`, `${row.binding.limit} has ${row.headroom}% left`);
|
|
406
451
|
}
|
|
407
452
|
}
|
package/dist/lib/lanes/loop.d.ts
CHANGED
|
@@ -188,6 +188,11 @@ export declare function loopStatus(runDir: string, laneId: string): LoopStatus;
|
|
|
188
188
|
export declare function commitIdleLoopStop(runDir: string, laneId: string, now?: () => Date): boolean;
|
|
189
189
|
export declare function setLoopControllerPid(runDir: string, laneId: string, pid: number | undefined): void;
|
|
190
190
|
export declare function clearLoopControllerPid(runDir: string, laneId: string, pid: number): void;
|
|
191
|
+
/**
|
|
192
|
+
* True when a loop lane's controller is alive with no phase active: the lane
|
|
193
|
+
* finished its last phase and is waiting for the next envelope.
|
|
194
|
+
*/
|
|
195
|
+
export declare function loopLaneIsIdle(runDir: string, laneId: string): boolean;
|
|
191
196
|
export declare function loopControllerIsAlive(runDir: string): boolean;
|
|
192
197
|
/** Run queued phases serially. Sessions are isolated by story and provider. */
|
|
193
198
|
export declare function runLoopLane(options: LoopRunnerOptions): Promise<LoopRunSummary>;
|
package/dist/lib/lanes/loop.js
CHANGED
|
@@ -648,6 +648,14 @@ export function clearLoopControllerPid(runDir, laneId, pid) {
|
|
|
648
648
|
if (currentPid === pid)
|
|
649
649
|
persistStatus(runDir, laneId, { pid: undefined });
|
|
650
650
|
}
|
|
651
|
+
/**
|
|
652
|
+
* True when a loop lane's controller is alive with no phase active: the lane
|
|
653
|
+
* finished its last phase and is waiting for the next envelope.
|
|
654
|
+
*/
|
|
655
|
+
export function loopLaneIsIdle(runDir, laneId) {
|
|
656
|
+
const status = loopStatus(runDir, laneId);
|
|
657
|
+
return status.state === "waiting" && status.active_envelope_id === null && loopControllerIsAlive(runDir);
|
|
658
|
+
}
|
|
651
659
|
export function loopControllerIsAlive(runDir) {
|
|
652
660
|
let pid;
|
|
653
661
|
try {
|
|
@@ -12,7 +12,7 @@ import { compareLaneQueueOrder, compareLaneQueueOrderWithLeads, leadLaneIds, has
|
|
|
12
12
|
import { accountStatus, isCredentialProven, resolveAccount } from "./accounts.js";
|
|
13
13
|
import { effectiveAccountHome } from "./account-home.js";
|
|
14
14
|
import { enforceRegistryApprovalGate } from "./approval-gate.js";
|
|
15
|
-
import { loopStatus } from "./loop.js";
|
|
15
|
+
import { loopLaneIsIdle, loopStatus } from "./loop.js";
|
|
16
16
|
import { loadLanesConfig, providerQuotaDefaultHoldMs } from "./config.js";
|
|
17
17
|
import { MAX_LANE_DEPTH } from "./constants.js";
|
|
18
18
|
import { laneDepthCap } from "./depth-cap.js";
|
|
@@ -1641,6 +1641,23 @@ async function heartbeatAndDeadHosts(hqRoot, lanes, summary, deps, now) {
|
|
|
1641
1641
|
// Watcher owns terminal classification of a process that has just exited.
|
|
1642
1642
|
continue;
|
|
1643
1643
|
}
|
|
1644
|
+
if (lane.loop_mode === true && loopLaneIsIdle(runDir, lane.lane_id)) {
|
|
1645
|
+
// An idle loop lane has no worker between phases. Its controller is
|
|
1646
|
+
// alive and waiting for the next envelope, so the lane is not finished.
|
|
1647
|
+
try {
|
|
1648
|
+
const result = casLaneIf(hqRoot, lane.lane_id, (current) => current.state === "running" && current.last_host_report_at !== nowIso, (current) => ({ ...current, last_host_report_at: nowIso }), deps.dryRun);
|
|
1649
|
+
if (result.changed)
|
|
1650
|
+
summary.heartbeats.push(lane.lane_id);
|
|
1651
|
+
}
|
|
1652
|
+
catch (err) {
|
|
1653
|
+
markDirty(summary, {
|
|
1654
|
+
kind: "lane",
|
|
1655
|
+
id: lane.lane_id,
|
|
1656
|
+
why: `heartbeat CAS failed: ${err instanceof Error ? err.message : String(err)}`,
|
|
1657
|
+
});
|
|
1658
|
+
}
|
|
1659
|
+
continue;
|
|
1660
|
+
}
|
|
1644
1661
|
const hadPids = workerPid !== null || watcherPid !== null;
|
|
1645
1662
|
if (!hadPids && nowMs - lastHostReportMs(lane) < DEAD_HOST_MS) {
|
|
1646
1663
|
try {
|
|
@@ -9,10 +9,22 @@ export interface WorkerContinuityLookup {
|
|
|
9
9
|
export interface WorkerContinuityResult {
|
|
10
10
|
previous?: LaneRecord;
|
|
11
11
|
resumable: boolean;
|
|
12
|
-
fallbackReason?: "provider_unsupported" | "session_id_missing" | "state_unsafe" | "host_mismatch";
|
|
12
|
+
fallbackReason?: "provider_unsupported" | "session_id_missing" | "state_unsafe" | "host_mismatch" | "settings_mismatch";
|
|
13
13
|
}
|
|
14
14
|
export declare function sameLaneHost(left: LaneRecord["host"], right: LaneRecord["host"]): boolean;
|
|
15
15
|
/** Select the prior worker lane within exactly one senior/company/provider scope. */
|
|
16
16
|
export declare function findWorkerContinuityLane(lanes: readonly LaneRecord[], lookup: WorkerContinuityLookup): WorkerContinuityResult;
|
|
17
|
+
export interface WorkerContinuitySettings {
|
|
18
|
+
project: LaneRecord["project_id"];
|
|
19
|
+
/** Resolved model for the new lane; undefined when the provider chooses. */
|
|
20
|
+
model?: string;
|
|
21
|
+
/** Resolved effort for the new lane; undefined when none is passed. */
|
|
22
|
+
effort?: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Refuse reuse when the earlier session ran under a different project, model,
|
|
26
|
+
* or effort. A prior lane that recorded no model does not match a pinned one.
|
|
27
|
+
*/
|
|
28
|
+
export declare function applyContinuitySettings(result: WorkerContinuityResult, settings: WorkerContinuitySettings): WorkerContinuityResult;
|
|
17
29
|
export declare function workerContinuityPrompt(previous: LaneRecord, resultSummary?: string, resultRef?: string): string;
|
|
18
30
|
//# sourceMappingURL=worker-continuity.d.ts.map
|
|
@@ -65,6 +65,20 @@ export function findWorkerContinuityLane(lanes, lookup) {
|
|
|
65
65
|
}
|
|
66
66
|
return { previous, resumable: true };
|
|
67
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Refuse reuse when the earlier session ran under a different project, model,
|
|
70
|
+
* or effort. A prior lane that recorded no model does not match a pinned one.
|
|
71
|
+
*/
|
|
72
|
+
export function applyContinuitySettings(result, settings) {
|
|
73
|
+
const previous = result.previous;
|
|
74
|
+
if (!result.resumable || !previous)
|
|
75
|
+
return result;
|
|
76
|
+
if (previous.project_id === settings.project && previous.model === settings.model &&
|
|
77
|
+
previous.effort === settings.effort) {
|
|
78
|
+
return result;
|
|
79
|
+
}
|
|
80
|
+
return { previous, resumable: false, fallbackReason: "settings_mismatch" };
|
|
81
|
+
}
|
|
68
82
|
export function workerContinuityPrompt(previous, resultSummary, resultRef) {
|
|
69
83
|
const summary = resultSummary?.trim();
|
|
70
84
|
const resultPath = resultRef?.trim()
|