@indigoai-us/hq-cli 5.345.238 → 5.345.242
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 +74 -0
- package/assets/scaffold/core/scripts/hq-delegate-grant.sh +170 -8
- package/assets/scaffold/core/scripts/hq-delegate-publish.sh +21 -1
- package/assets/scaffold/core/scripts/hq-delegate-repo.sh +7 -1
- package/assets/scaffold/core/scripts/hq-delegate-secrets.sh +95 -20
- package/assets/scaffold/core/scripts/hq-delegate-transfer.sh +57 -9
- package/assets/scaffold/core/scripts/lib/delegate-engine.sh +77 -0
- package/dist/command-catalog.generated.d.ts +212 -10
- package/dist/command-catalog.generated.js +260 -10
- package/dist/command-registration-plan.d.ts +6 -0
- package/dist/command-registration-plan.js +1 -0
- package/dist/commands/cloud-off-gate.d.ts +9 -8
- package/dist/commands/cloud-off-gate.js +41 -40
- package/dist/commands/cloud.d.ts +17 -2
- package/dist/commands/cloud.js +126 -24
- package/dist/commands/core-delegate-w1b.js +333 -27
- package/dist/commands/core-delegate.d.ts +2 -1
- package/dist/commands/core-delegate.js +209 -48
- package/dist/commands/core-handoff.js +1 -1
- package/dist/commands/core-job-model-auth.d.ts +95 -0
- package/dist/commands/core-job-model-auth.js +247 -0
- package/dist/commands/core-job-run-native.js +280 -12
- package/dist/commands/core.js +1 -0
- package/dist/commands/deploy-comments.js +8 -2
- package/dist/commands/deploy-events.d.ts +40 -0
- package/dist/commands/deploy-events.js +300 -0
- package/dist/commands/doctor.d.ts +4 -4
- package/dist/commands/doctor.js +2 -2
- package/dist/commands/feedback.js +2 -3
- package/dist/commands/files-browse.js +2 -0
- package/dist/commands/files.js +4 -0
- package/dist/commands/integrations-core.d.ts +11 -0
- package/dist/commands/integrations-core.js +15 -1
- package/dist/commands/keyed-sync-pull.d.ts +12 -0
- package/dist/commands/keyed-sync-pull.js +151 -0
- package/dist/commands/lanes-link.js +2 -2
- package/dist/commands/lanes-loop.d.ts +2 -2
- package/dist/commands/lanes-loop.js +5 -5
- package/dist/commands/lanes-questions.js +1 -1
- package/dist/commands/lanes-stories.js +1 -1
- package/dist/commands/lanes.js +80 -14
- package/dist/commands/library-add.d.ts +5 -2
- package/dist/commands/library-add.js +22 -9
- package/dist/commands/mcp-registration.d.ts +4 -18
- package/dist/commands/mcp-registration.js +9 -29
- package/dist/commands/mesh.d.ts +4 -0
- package/dist/commands/mesh.js +25 -5
- package/dist/commands/pack-install.d.ts +2 -3
- package/dist/commands/pack-install.js +6 -8
- package/dist/commands/rescue.d.ts +3 -2
- package/dist/commands/rescue.js +48 -34
- package/dist/commands/search.d.ts +6 -0
- package/dist/commands/search.js +24 -4
- package/dist/commands/secrets.d.ts +3 -4
- package/dist/commands/secrets.js +3 -20
- package/dist/commands/sources.js +6 -2
- package/dist/commands/sync-core.d.ts +8 -0
- package/dist/commands/sync-core.js +43 -0
- package/dist/hq-cloud-sync-runner/bin/sync-runner.js +1830 -1468
- package/dist/hq-cloud-sync-runner/package.json +1 -1
- package/dist/lib/bot/api.d.ts +2 -1
- package/dist/lib/bot/api.js +2 -15
- package/dist/lib/capacity/accounts.d.ts +1 -1
- package/dist/lib/capacity/accounts.js +1 -1
- package/dist/lib/capacity/collectors/claude-oauth.d.ts +0 -2
- package/dist/lib/capacity/collectors/claude-oauth.js +0 -5
- package/dist/lib/capacity/freshness.d.ts +1 -1
- package/dist/lib/capacity/freshness.js +1 -1
- package/dist/lib/capacity/route.js +1 -1
- package/dist/lib/core-utils/delegate-helper-paths.d.ts +26 -0
- package/dist/lib/core-utils/delegate-helper-paths.js +33 -0
- package/dist/lib/daemon/catalog.d.ts +3 -0
- package/dist/lib/daemon/hook-requests.d.ts +1 -1
- package/dist/lib/daemon/hook-requests.js +4 -2
- package/dist/lib/daemon/jq-provision.d.ts +63 -0
- package/dist/lib/daemon/jq-provision.js +155 -0
- package/dist/lib/daemon/lanes-reconcile-guard.d.ts +4 -3
- package/dist/lib/daemon/lanes-reconcile-guard.js +4 -4
- package/dist/lib/daemon/mesh-owner.d.ts +4 -0
- package/dist/lib/daemon/mesh-owner.js +20 -0
- package/dist/lib/daemon/ops/policy.d.ts +3 -0
- package/dist/lib/daemon/ops/policy.js +32 -4
- package/dist/lib/daemon/run.js +17 -22
- package/dist/lib/daemon/server.d.ts +6 -0
- package/dist/lib/daemon/server.js +5 -0
- package/dist/lib/daemon/verified-jq.d.ts +96 -0
- package/dist/lib/daemon/verified-jq.js +337 -0
- package/dist/lib/doctor/checks/jq.js +16 -0
- package/dist/lib/doctor/deep/executor.d.ts +7 -0
- package/dist/lib/doctor/deep/executor.js +1 -1
- package/dist/lib/doctor/deep/parity.js +1 -27
- package/dist/lib/doctor/deep/sandbox.d.ts +2 -2
- package/dist/lib/doctor/deep/sandbox.js +3 -19
- package/dist/lib/doctor/fix/refresh-sync-handoff.js +52 -21
- package/dist/lib/doctor/fixtures/discover.d.ts +2 -0
- package/dist/lib/doctor/fixtures/discover.js +1 -1
- package/dist/lib/doctor/json-output.d.ts +1 -1
- package/dist/lib/doctor/registry.d.ts +6 -7
- package/dist/lib/doctor/registry.js +6 -7
- package/dist/lib/doctor/report.d.ts +9 -10
- package/dist/lib/doctor/report.js +4 -4
- package/dist/lib/environment/work-requirements.d.ts +1 -1
- package/dist/lib/environment/work-requirements.js +1 -1
- package/dist/lib/flag-registry-worker-source.generated.d.ts +1 -1
- package/dist/lib/flag-registry-worker-source.generated.js +1 -1
- package/dist/lib/hook-engine/coverage.js +11 -3
- package/dist/lib/hook-engine/git-stop-config.json +510 -510
- package/dist/lib/hook-engine/native-precompact-compatibility.json +443 -443
- package/dist/lib/hook-engine/native-stop-compatibility.json +359 -359
- package/dist/lib/hot-channels/adapters/meetings.d.ts +1 -16
- package/dist/lib/hot-channels/adapters/meetings.js +3 -28
- package/dist/lib/hot-channels/adapters/slack.d.ts +3 -1
- package/dist/lib/hot-channels/adapters/slack.js +4 -1
- package/dist/lib/hot-channels/contract.d.ts +14 -0
- package/dist/lib/hot-channels/fleet-complete.d.ts +18 -2
- package/dist/lib/hot-channels/fleet-complete.js +29 -4
- package/dist/lib/hot-channels/meeting-source-ref.d.ts +17 -0
- package/dist/lib/hot-channels/meeting-source-ref.js +32 -0
- package/dist/lib/hot-channels/prompts/signals-pass.md +6 -1
- package/dist/lib/hot-channels/run.d.ts +10 -0
- package/dist/lib/hot-channels/run.js +34 -0
- package/dist/lib/hot-channels/signals-pass.d.ts +27 -0
- package/dist/lib/hot-channels/signals-pass.js +57 -2
- package/dist/lib/hot-channels/signals-runtime.js +3 -2
- package/dist/lib/jq/install.d.ts +27 -0
- package/dist/lib/jq/install.js +156 -0
- package/dist/lib/lanes/accounts.js +2 -2
- package/dist/lib/lanes/claude-balance.d.ts +6 -0
- package/dist/lib/lanes/claude-balance.js +124 -0
- package/dist/lib/lanes/grants.js +15 -2
- package/dist/lib/lanes/hq-root.d.ts +1 -1
- package/dist/lib/lanes/hq-root.js +1 -1
- package/dist/lib/lanes/links.d.ts +1 -1
- package/dist/lib/lanes/liveness.d.ts +3 -0
- package/dist/lib/lanes/liveness.js +61 -7
- package/dist/lib/lanes/models.d.ts +1 -1
- package/dist/lib/lanes/models.js +1 -1
- package/dist/lib/lanes/outpost-dispatch.d.ts +1 -1
- package/dist/lib/lanes/outpost-dispatch.js +13 -13
- package/dist/lib/lanes/outpost-pruner-install.js +1 -1
- package/dist/lib/lanes/questions.d.ts +1 -1
- package/dist/lib/lanes/questions.js +2 -2
- package/dist/lib/lanes/spawn.js +4 -6
- package/dist/lib/lanes/store.d.ts +13 -2
- package/dist/lib/lanes/store.js +13 -5
- package/dist/lib/lanes/types.d.ts +7 -7
- package/dist/lib/lanes/types.js +1 -1
- package/dist/lib/lanes/watcher-main.js +1 -1
- package/dist/lib/lanes/watcher.d.ts +1 -1
- package/dist/lib/lanes/watcher.js +1 -1
- package/dist/lib/mesh/live/daemon/doctor.js +7 -1
- package/dist/lib/mesh/live/daemon/install.d.ts +4 -0
- package/dist/lib/mesh/live/daemon/install.js +10 -0
- package/dist/lib/mesh/live/daemon/run.js +17 -0
- package/dist/lib/mesh/live/emit-retry.d.ts +20 -2
- package/dist/lib/mesh/live/emit-retry.js +57 -4
- package/dist/lib/mesh/live/emit.js +25 -4
- package/dist/lib/mesh/live/flush.d.ts +2 -0
- package/dist/lib/mesh/live/flush.js +21 -8
- package/dist/lib/mesh/live/spool.d.ts +9 -1
- package/dist/lib/mesh/live/spool.js +41 -29
- package/dist/lib/onboarding/cli/onboard.js +5 -0
- package/dist/lib/signals/sanitize.d.ts +19 -0
- package/dist/lib/signals/sanitize.js +103 -7
- package/dist/lib/signals/steps/upload.d.ts +40 -1
- package/dist/lib/signals/steps/upload.js +122 -6
- package/dist/lib/sync-core/access-refresh.d.ts +29 -0
- package/dist/lib/sync-core/access-refresh.js +97 -0
- package/dist/lib/sync-core/company-adoption.d.ts +33 -0
- package/dist/lib/sync-core/company-adoption.js +223 -0
- package/dist/lib/sync-core/engine-home.d.ts +1 -0
- package/dist/lib/sync-core/engine-owned.d.ts +13 -0
- package/dist/lib/sync-core/engine-owned.js +38 -0
- package/dist/lib/sync-core/hand-back.d.ts +17 -0
- package/dist/lib/sync-core/hand-back.js +23 -0
- package/dist/lib/sync-core/post-apply-reindex.d.ts +33 -0
- package/dist/lib/sync-core/post-apply-reindex.js +149 -0
- package/dist/lib/sync-core/reconcile.d.ts +10 -0
- package/dist/lib/sync-core/reconcile.js +117 -12
- package/dist/lib/sync-core/rollout-state.d.ts +11 -1
- package/dist/lib/sync-core/rollout-state.js +40 -4
- package/dist/lib/vault-sync-switches.d.ts +14 -0
- package/dist/lib/vault-sync-switches.js +22 -0
- package/dist/lib/windows/jq.d.ts +4 -0
- package/dist/lib/windows/jq.js +10 -39
- package/dist/lib/workers-registry/index.d.ts +1 -1
- package/dist/lib/workers-registry/index.js +8 -12
- package/dist/utils/callback-port-busy.d.ts +2 -2
- package/dist/utils/callback-port-busy.js +2 -2
- package/dist/utils/cli-network-lifecycle.js +1 -0
- package/dist/utils/client-health-contract.d.ts +2 -0
- package/dist/utils/client-health-contract.js +1 -1
- package/dist/utils/client-health.js +1 -9
- package/dist/utils/cognito-config.js +5 -0
- package/dist/utils/cognito-session.d.ts +4 -6
- package/dist/utils/cognito-session.js +4 -24
- package/dist/utils/github-tag-fallback.d.ts +16 -0
- package/dist/utils/github-tag-fallback.js +126 -0
- package/dist/utils/incomplete-install-error.js +1 -11
- package/dist/utils/install-tree-torn.d.ts +11 -0
- package/dist/utils/install-tree-torn.js +1 -1
- package/dist/utils/resident-package-preload.js +2 -1
- package/dist/utils/version-report.d.ts +2 -1
- package/dist/utils/version-report.js +40 -27
- package/docs/anywhere-runtime.md +8 -0
- package/package.json +9 -9
|
@@ -46,7 +46,7 @@ export interface RaiseLaneQuestionInput {
|
|
|
46
46
|
priority?: QuestionPriority;
|
|
47
47
|
}
|
|
48
48
|
/**
|
|
49
|
-
* Persist one question the way `hq
|
|
49
|
+
* Persist one question the way `hq runners ask` does: createQuestion, write the
|
|
50
50
|
* tenant body, then CAS routing_history with reason `asked`.
|
|
51
51
|
*/
|
|
52
52
|
export declare function raiseLaneQuestion(input: RaiseLaneQuestionInput): QuestionRecord;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { assertQuestionNotImported } from "./imported-question.js";
|
|
2
2
|
/**
|
|
3
|
-
* Raise a lane question (spec §6.1). One function for the CLI `hq
|
|
3
|
+
* Raise a lane question (spec §6.1). One function for the CLI `hq runners ask`
|
|
4
4
|
* path and for envelope `decision: "ask"` ingestion. Two writers here would
|
|
5
5
|
* drift on hop, origin, raised_via, body store, and routing_history.
|
|
6
6
|
*/
|
|
@@ -158,7 +158,7 @@ export function writeQuestionBody(hqRoot, question, body) {
|
|
|
158
158
|
};
|
|
159
159
|
}
|
|
160
160
|
/**
|
|
161
|
-
* Persist one question the way `hq
|
|
161
|
+
* Persist one question the way `hq runners ask` does: createQuestion, write the
|
|
162
162
|
* tenant body, then CAS routing_history with reason `asked`.
|
|
163
163
|
*/
|
|
164
164
|
export function raiseLaneQuestion(input) {
|
package/dist/lib/lanes/spawn.js
CHANGED
|
@@ -32,7 +32,7 @@ import { AccountResolutionError, LanesError } from "./errors.js";
|
|
|
32
32
|
import { ignoredWorkerProfileFields, loadWorkerProfile, loadWorkerProfileWithRegistry, materializeWorkerProfile, workerProfilePrompt, } from "./profile.js";
|
|
33
33
|
import { registryWorkerRecord } from "./registry-persona.js";
|
|
34
34
|
import { resolveMachineIdentity, } from "./machine-identity.js";
|
|
35
|
-
import { appendCappedHistory,
|
|
35
|
+
import { appendCappedHistory, readAllLanes, readLane, retryUpdateLane } from "./store.js";
|
|
36
36
|
import { managerStatusGateHeartbeat } from "./manager-status-gate.js";
|
|
37
37
|
import { LANE_QUOTA_ACCOUNT_FAILOVER_FLAG } from "./flag-keys.js";
|
|
38
38
|
import { readLanesRegistryFlagFailOff } from "./registry-flag.js";
|
|
@@ -374,8 +374,7 @@ function selectSpawnAccount(input) {
|
|
|
374
374
|
...(admissionHost.aliases !== undefined ? { aliases: admissionHost.aliases } : {}),
|
|
375
375
|
}
|
|
376
376
|
: undefined;
|
|
377
|
-
const lanes =
|
|
378
|
-
.map((laneId) => readLane(hqRoot, laneId))
|
|
377
|
+
const lanes = readAllLanes(hqRoot)
|
|
379
378
|
.filter((record) => (record.host.kind === lane.host.kind && record.host.id === lane.host.id) ||
|
|
380
379
|
(localMatch !== undefined && laneRunsOnHost(record, { ...localMatch, outpostId: null })));
|
|
381
380
|
const capacity = buildHostCapacitySnapshot({
|
|
@@ -821,9 +820,8 @@ export async function retryLaneOnAlternateAccount(hqRoot, lane, reason, writer =
|
|
|
821
820
|
};
|
|
822
821
|
};
|
|
823
822
|
const candidate = moveToRetryQueue(current);
|
|
824
|
-
const admissionLanes =
|
|
825
|
-
.filter((
|
|
826
|
-
.map((id) => readLane(hqRoot, id));
|
|
823
|
+
const admissionLanes = readAllLanes(hqRoot)
|
|
824
|
+
.filter((row) => row.lane_id !== current.lane_id);
|
|
827
825
|
admissionLanes.push(candidate);
|
|
828
826
|
const profileMaxFor = (row) => row.worker_profile === undefined
|
|
829
827
|
? undefined
|
|
@@ -61,8 +61,19 @@ export declare function mergeLaneRecords(live: LaneRecord, sidecars: readonly La
|
|
|
61
61
|
export declare function mergeQuestionRecords(live: QuestionRecord, sidecars: readonly QuestionRecord[]): QuestionRecord;
|
|
62
62
|
export declare function tryReadLane(hqRoot: string, laneId: string, deps?: StoreDeps): LaneRecord | null;
|
|
63
63
|
export declare function readLane(hqRoot: string, laneId: string, deps?: StoreDeps): LaneRecord;
|
|
64
|
-
/**
|
|
65
|
-
export
|
|
64
|
+
/** A lane record readAllLanes skipped, with fields read best-effort from its raw JSON. */
|
|
65
|
+
export interface SkippedLaneRecord {
|
|
66
|
+
lane_id: string;
|
|
67
|
+
/** Raw `senior.id`, when the record's JSON has one. */
|
|
68
|
+
senior_id: string | undefined;
|
|
69
|
+
/** Raw `state`, unvalidated; undefined when the record has none. */
|
|
70
|
+
state: unknown;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Reads all lanes, indexing sidecars once and sorting by creation time then id.
|
|
74
|
+
* A record that fails to parse is skipped with a warning and reported to `onSkip`.
|
|
75
|
+
*/
|
|
76
|
+
export declare function readAllLanes(hqRoot: string, deps?: StoreDeps, onSkip?: (skipped: SkippedLaneRecord) => void): LaneRecord[];
|
|
66
77
|
export declare function tryReadQuestion(hqRoot: string, questionId: string, deps?: StoreDeps): QuestionRecord | null;
|
|
67
78
|
export declare function readQuestion(hqRoot: string, questionId: string, deps?: StoreDeps): QuestionRecord;
|
|
68
79
|
/** Semver precedence includes prerelease identifiers (for example, rc.2 > rc.1). */
|
package/dist/lib/lanes/store.js
CHANGED
|
@@ -1602,8 +1602,11 @@ export function readLane(hqRoot, laneId, deps = defaultStoreDeps()) {
|
|
|
1602
1602
|
throw new LaneNotFoundError("lane", laneId);
|
|
1603
1603
|
return record;
|
|
1604
1604
|
}
|
|
1605
|
-
/**
|
|
1606
|
-
|
|
1605
|
+
/**
|
|
1606
|
+
* Reads all lanes, indexing sidecars once and sorting by creation time then id.
|
|
1607
|
+
* A record that fails to parse is skipped with a warning and reported to `onSkip`.
|
|
1608
|
+
*/
|
|
1609
|
+
export function readAllLanes(hqRoot, deps = defaultStoreDeps(), onSkip) {
|
|
1607
1610
|
const laneIds = listLaneIds(hqRoot, deps);
|
|
1608
1611
|
if (laneIds.length === 0)
|
|
1609
1612
|
return [];
|
|
@@ -1646,9 +1649,14 @@ export function readAllLanes(hqRoot, deps = defaultStoreDeps()) {
|
|
|
1646
1649
|
throw err;
|
|
1647
1650
|
const filePath = laneRecordPath(hqRoot, laneId);
|
|
1648
1651
|
const raw = readJsonFile(filePath, indexedDeps);
|
|
1649
|
-
const
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
+
const rawRecord = isPlainObject(raw) ? raw : undefined;
|
|
1653
|
+
const rawSenior = isPlainObject(rawRecord?.senior) ? rawRecord.senior : undefined;
|
|
1654
|
+
onSkip?.({
|
|
1655
|
+
lane_id: laneId,
|
|
1656
|
+
senior_id: typeof rawSenior?.id === "string" ? rawSenior.id : undefined,
|
|
1657
|
+
state: rawRecord?.state,
|
|
1658
|
+
});
|
|
1659
|
+
const host = rawRecord?.host;
|
|
1652
1660
|
const hostRecord = host !== null && typeof host === "object" && !Array.isArray(host)
|
|
1653
1661
|
? host
|
|
1654
1662
|
: undefined;
|
|
@@ -331,7 +331,7 @@ export type LaneProvider = (typeof LANE_PROVIDERS)[number];
|
|
|
331
331
|
* Who runs a lane's work. A process lane (the default, recorded by absence)
|
|
332
332
|
* is a provider process HQ spawned and watches. A subagent lane is a record
|
|
333
333
|
* only: an in-session Claude subagent does the work and reports through
|
|
334
|
-
* `hq
|
|
334
|
+
* `hq runners progress`, so admission, watchers, reapers and keep-alive skip it.
|
|
335
335
|
*/
|
|
336
336
|
export declare const LANE_RUNNERS: readonly ["process", "subagent"];
|
|
337
337
|
export type LaneRunner = (typeof LANE_RUNNERS)[number];
|
|
@@ -481,7 +481,7 @@ interface LaneStopHistoryEntry {
|
|
|
481
481
|
at: string;
|
|
482
482
|
reason: string;
|
|
483
483
|
}
|
|
484
|
-
/** One `hq
|
|
484
|
+
/** One `hq runners set` change; it takes effect when the lane next resumes. */
|
|
485
485
|
export interface LaneSettingsHistoryEntry {
|
|
486
486
|
at: string;
|
|
487
487
|
actor: string;
|
|
@@ -728,7 +728,7 @@ export interface LaneRecord {
|
|
|
728
728
|
/** Short-lived slot reservation between create persistence and worker spawn. */
|
|
729
729
|
admission_reserved_at?: string;
|
|
730
730
|
/**
|
|
731
|
-
* Set by `hq
|
|
731
|
+
* Set by `hq runners pickup` when it stores an outpost lane and cleared by
|
|
732
732
|
* the account bind once the model probe has finished. While set, the
|
|
733
733
|
* reconcile pass does not admit the lane: a spawn during the probe would
|
|
734
734
|
* leave a running worker behind a record the probe result then rewrites.
|
|
@@ -918,10 +918,10 @@ export interface LaneRecord {
|
|
|
918
918
|
terminal_reason?: string;
|
|
919
919
|
/** Reasons supplied to explicit stop commands, retained independently of optional project ledgers. */
|
|
920
920
|
stop_history?: LaneStopHistoryEntry[];
|
|
921
|
-
/** Model and effort changes made with `hq
|
|
921
|
+
/** Model and effort changes made with `hq runners set`. */
|
|
922
922
|
settings_history?: LaneSettingsHistoryEntry[];
|
|
923
923
|
/**
|
|
924
|
-
* Model or effort from `hq
|
|
924
|
+
* Model or effort from `hq runners set` on a running lane. The running turn
|
|
925
925
|
* keeps its launched values (quota classification reads `model`); the next
|
|
926
926
|
* spawn applies these and clears them.
|
|
927
927
|
*/
|
|
@@ -1087,7 +1087,7 @@ export interface LaneResumeRecord {
|
|
|
1087
1087
|
message_id?: string;
|
|
1088
1088
|
monitor_event?: true;
|
|
1089
1089
|
/**
|
|
1090
|
-
* `hq
|
|
1090
|
+
* `hq runners resume` only: the state the lane was in when the operator
|
|
1091
1091
|
* resumed it (`interrupted`, `done`, `blocked`, `failed` or `awaiting_input`)
|
|
1092
1092
|
* and the text they sent.
|
|
1093
1093
|
*/
|
|
@@ -1293,7 +1293,7 @@ export interface LivenessWindows {
|
|
|
1293
1293
|
/** No event at all for this window (and no `session_end`) → lost. Default 12 hours. */
|
|
1294
1294
|
silent_lost_ms: number;
|
|
1295
1295
|
}
|
|
1296
|
-
/** Age limits used by `hq
|
|
1296
|
+
/** Age limits used by `hq runners checks`; each value is a positive millisecond count. */
|
|
1297
1297
|
export interface TrackerChecksConfig {
|
|
1298
1298
|
owner_question_surface_ms: number;
|
|
1299
1299
|
open_question_age_ms: number;
|
package/dist/lib/lanes/types.js
CHANGED
|
@@ -117,7 +117,7 @@ export const LANE_PROVIDERS = ["claude", "codex", "grok"];
|
|
|
117
117
|
* Who runs a lane's work. A process lane (the default, recorded by absence)
|
|
118
118
|
* is a provider process HQ spawned and watches. A subagent lane is a record
|
|
119
119
|
* only: an in-session Claude subagent does the work and reports through
|
|
120
|
-
* `hq
|
|
120
|
+
* `hq runners progress`, so admission, watchers, reapers and keep-alive skip it.
|
|
121
121
|
*/
|
|
122
122
|
export const LANE_RUNNERS = ["process", "subagent"];
|
|
123
123
|
export function parseLaneRunner(value) {
|
|
@@ -93,7 +93,7 @@ function main() {
|
|
|
93
93
|
const laneId = process.argv[2]?.trim();
|
|
94
94
|
const hqRoot = process.env.HQ_ROOT?.trim();
|
|
95
95
|
if (!laneId || !hqRoot) {
|
|
96
|
-
process.stderr.write("hq
|
|
96
|
+
process.stderr.write("hq runners watcher: requires lane id argv and HQ_ROOT in the environment\n");
|
|
97
97
|
process.exit(1);
|
|
98
98
|
}
|
|
99
99
|
void runWatcherLoop(hqRoot, laneId, watcherMainDeps(hqRoot, laneId, process.env)).catch((err) => {
|
|
@@ -115,7 +115,7 @@ export interface ApplyTerminalOpts {
|
|
|
115
115
|
export declare function stalledReason(silenceMs: number): string;
|
|
116
116
|
/**
|
|
117
117
|
* The consumer of the silence signal. A silence emit on a running lane sets
|
|
118
|
-
* `stalled` on the record so `hq
|
|
118
|
+
* `stalled` on the record so `hq runners list` and `show` surface it; the next
|
|
119
119
|
* progress emit clears it. Nothing here changes `state`.
|
|
120
120
|
*/
|
|
121
121
|
export declare function markLaneStalled(hqRoot: string, laneId: string, at: string, reason: string): LaneRecord;
|
|
@@ -341,7 +341,7 @@ export function stalledReason(silenceMs) {
|
|
|
341
341
|
}
|
|
342
342
|
/**
|
|
343
343
|
* The consumer of the silence signal. A silence emit on a running lane sets
|
|
344
|
-
* `stalled` on the record so `hq
|
|
344
|
+
* `stalled` on the record so `hq runners list` and `show` surface it; the next
|
|
345
345
|
* progress emit clears it. Nothing here changes `state`.
|
|
346
346
|
*/
|
|
347
347
|
export function markLaneStalled(hqRoot, laneId, at, reason) {
|
|
@@ -244,7 +244,13 @@ export function collectDaemonDoctor(deps = {}) {
|
|
|
244
244
|
const whoamiSubject = formatCognitoSubject(whoamiTokens);
|
|
245
245
|
const daemonSubject = formatCognitoSubject(daemonTokens);
|
|
246
246
|
const emitState = readEmitState(meshRoot);
|
|
247
|
-
|
|
247
|
+
let emitRetry = 0;
|
|
248
|
+
try {
|
|
249
|
+
emitRetry = emitRetryDepth(meshRoot);
|
|
250
|
+
}
|
|
251
|
+
catch (err) {
|
|
252
|
+
unhealthyReasons.push(`direct-emit retry file unreadable: ${err?.code ?? "read error"}`);
|
|
253
|
+
}
|
|
248
254
|
if (emitRetry > 0) {
|
|
249
255
|
unhealthyReasons.push(`direct-emit retry depth=${emitRetry}`);
|
|
250
256
|
}
|
|
@@ -397,6 +397,10 @@ export declare function daemonServiceStatus(opts: {
|
|
|
397
397
|
/** Windows: liveness probe for the daemon pid lock (tests inject). */
|
|
398
398
|
isProcessAlive?: (pid: number) => boolean;
|
|
399
399
|
readFileSync?: typeof fs.readFileSync;
|
|
400
|
+
hqDaemonMesh?: {
|
|
401
|
+
daemonPid: number;
|
|
402
|
+
pid?: number;
|
|
403
|
+
} | null;
|
|
400
404
|
}): InstallResult;
|
|
401
405
|
/** Read baked template files from assets/ (optional; renderers are primary). */
|
|
402
406
|
export declare function readAssetTemplate(name: "launchd.plist.template" | "systemd.user.service.template" | "systemd.system.service.template"): string | null;
|
|
@@ -1376,6 +1376,16 @@ export function daemonServiceStatus(opts) {
|
|
|
1376
1376
|
const platform = opts.platform ?? detectPlatform();
|
|
1377
1377
|
const paths = opts.paths ?? buildInstallPaths({});
|
|
1378
1378
|
const existsSync = opts.existsSync ?? fs.existsSync;
|
|
1379
|
+
if (opts.hqDaemonMesh) {
|
|
1380
|
+
const { daemonPid, pid } = opts.hqDaemonMesh;
|
|
1381
|
+
return {
|
|
1382
|
+
platform,
|
|
1383
|
+
action: "status",
|
|
1384
|
+
paths,
|
|
1385
|
+
running: true,
|
|
1386
|
+
message: `hq daemon (pid ${daemonPid}): mesh service running${pid ? `, pid ${pid}` : ""}. Details: hq daemon status`,
|
|
1387
|
+
};
|
|
1388
|
+
}
|
|
1379
1389
|
if (platform === "win32") {
|
|
1380
1390
|
const schtasks = opts.schtasks ?? defaultSchtasks;
|
|
1381
1391
|
// schtasks only tells us whether the task exists. Its Status column is
|
|
@@ -34,6 +34,7 @@ import { daemonDir } from "./paths.js";
|
|
|
34
34
|
import { PresenceClient, defaultMqttConnect, } from "./presence.js";
|
|
35
35
|
import { defaultDaemonState, patchDaemonState, readDaemonState, writeDaemonState, } from "./state.js";
|
|
36
36
|
import { workMeshHeldPath } from "../paths.js";
|
|
37
|
+
import { countJsonlLines } from "../spool.js";
|
|
37
38
|
import { defaultTranscriptFs, noteHookSessionsFromSpoolFile, TRANSCRIPT_WATCH_INTERVAL_MS, TranscriptWatcher, } from "./transcript-watch.js";
|
|
38
39
|
import { resolveMeshEmitMode, runsEmitPath, } from "./mode.js";
|
|
39
40
|
import { hasCliVersionDrift, readInstalledCliVersion } from "./version-drift.js";
|
|
@@ -64,6 +65,11 @@ export const DEVICE_DEFAULT_MEMBERSHIP_TIMEOUT_MS = 2_000;
|
|
|
64
65
|
export const DEVICE_DEFAULT_MEMBERSHIP_UNAVAILABLE_COOLDOWN_MS = 30_000;
|
|
65
66
|
/** Direct mode: longest wait between drain cycles after repeated failures. */
|
|
66
67
|
export const DIRECT_DRAIN_MAX_DELAY_MS = 5 * 60 * 1_000;
|
|
68
|
+
const DIRECT_NO_CLAIM_REASON_TEXT = {
|
|
69
|
+
operator_switch_off: "HQ Anywhere is switched off by the operator",
|
|
70
|
+
anywhere_off_no_company_session_event: "HQ Anywhere reads as off for this person or this machine and no queued event is from a company-bound session dated since it was first seen off",
|
|
71
|
+
no_claimable_line: "the queue files held no line this cycle could claim",
|
|
72
|
+
};
|
|
67
73
|
/**
|
|
68
74
|
* Wait before the next direct-mode drain cycle. FLUSH_INTERVAL_MS while cycles
|
|
69
75
|
* succeed; doubled for each cycle in a row that failed or delivered nothing
|
|
@@ -910,6 +916,7 @@ export async function runMeshDaemon(deps = {}) {
|
|
|
910
916
|
let directDrainHandle = null;
|
|
911
917
|
let directDrainInFlight = null;
|
|
912
918
|
let directDrainFailures = 0;
|
|
919
|
+
let directNoClaimLogged = null;
|
|
913
920
|
const runDirectDrain = async () => {
|
|
914
921
|
try {
|
|
915
922
|
const atMs = now().getTime();
|
|
@@ -929,6 +936,16 @@ export async function runMeshDaemon(deps = {}) {
|
|
|
929
936
|
patchDaemonState(dir, { lastFlushAt: now().toISOString(), lastFlushResult: { ...summary, ok: true } }, now);
|
|
930
937
|
if (summary.claimed > 0) {
|
|
931
938
|
log(dir, `drain(direct): claimed=${summary.claimed} posted=${summary.posted} held=${summary.held} dropped=${summary.dropped} deadLettered=${summary.deadLettered} restored=${summary.restored}`);
|
|
939
|
+
directNoClaimLogged = null;
|
|
940
|
+
}
|
|
941
|
+
else {
|
|
942
|
+
const reason = summary.noClaimReason ?? "no_claimable_line";
|
|
943
|
+
if (directNoClaimLogged !== reason) {
|
|
944
|
+
directNoClaimLogged = reason;
|
|
945
|
+
const spool = countJsonlLines(workMeshSpoolPath(meshRoot));
|
|
946
|
+
const held = countJsonlLines(workMeshHeldPath(meshRoot));
|
|
947
|
+
log(dir, `drain(direct): claimed=0 pending=${spool + held} (spool=${spool} held=${held}) reason=${reason}: ${DIRECT_NO_CLAIM_REASON_TEXT[reason]}`);
|
|
948
|
+
}
|
|
932
949
|
}
|
|
933
950
|
// Lines went back on the spool and nothing was delivered: the server is
|
|
934
951
|
// unreachable or refusing for now. Wait longer before the next cycle.
|
|
@@ -9,7 +9,12 @@
|
|
|
9
9
|
/** Default cap on retained retry events (oldest dropped past this). */
|
|
10
10
|
export declare const EMIT_RETRY_MAX = 5000;
|
|
11
11
|
export declare function emitRetryPath(workMeshRoot: string): string;
|
|
12
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* Read pending retry events (parseable objects only). Missing file → [].
|
|
14
|
+
* Any other read error throws: a caller that took it as "nothing pending" and
|
|
15
|
+
* rewrote the file would delete the events it holds. Use appendEmitRetry to
|
|
16
|
+
* keep new events when the read failed.
|
|
17
|
+
*/
|
|
13
18
|
export declare function readEmitRetry(workMeshRoot: string): Record<string, unknown>[];
|
|
14
19
|
/**
|
|
15
20
|
* Atomically replace the retry file with `events` (keeping the most recent
|
|
@@ -20,6 +25,19 @@ export declare function writeEmitRetry(workMeshRoot: string, events: Record<stri
|
|
|
20
25
|
written: number;
|
|
21
26
|
dropped: number;
|
|
22
27
|
};
|
|
23
|
-
/**
|
|
28
|
+
/**
|
|
29
|
+
* Append `events` to the retry file without reading or replacing it. Used when
|
|
30
|
+
* the file could not be read, so its existing events are left as they are.
|
|
31
|
+
* Duplicates are removed by eventId on the next drain, and the cap applies on
|
|
32
|
+
* the next full write.
|
|
33
|
+
*
|
|
34
|
+
* readEmitRetry accepts a final record with no trailing newline, and this path
|
|
35
|
+
* cannot read the file to check its last byte. So when the file already has
|
|
36
|
+
* bytes, the batch starts with a newline: otherwise it would join that final
|
|
37
|
+
* record into one invalid line and the reader would drop both. The reader
|
|
38
|
+
* skips the blank line this leaves when the file did end in a newline.
|
|
39
|
+
*/
|
|
40
|
+
export declare function appendEmitRetry(workMeshRoot: string, events: Record<string, unknown>[]): number;
|
|
41
|
+
/** Count of pending retry events (doctor retryDepth). Throws if the file cannot be read. */
|
|
24
42
|
export declare function emitRetryDepth(workMeshRoot: string): number;
|
|
25
43
|
//# sourceMappingURL=emit-retry.d.ts.map
|
|
@@ -16,15 +16,22 @@ export function emitRetryPath(workMeshRoot) {
|
|
|
16
16
|
function ensureFileDir(filePath) {
|
|
17
17
|
fs.mkdirSync(path.dirname(filePath), { recursive: true, mode: 0o700 });
|
|
18
18
|
}
|
|
19
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* Read pending retry events (parseable objects only). Missing file → [].
|
|
21
|
+
* Any other read error throws: a caller that took it as "nothing pending" and
|
|
22
|
+
* rewrote the file would delete the events it holds. Use appendEmitRetry to
|
|
23
|
+
* keep new events when the read failed.
|
|
24
|
+
*/
|
|
20
25
|
export function readEmitRetry(workMeshRoot) {
|
|
21
26
|
const p = emitRetryPath(workMeshRoot);
|
|
22
27
|
let raw;
|
|
23
28
|
try {
|
|
24
29
|
raw = fs.readFileSync(p, "utf8");
|
|
25
30
|
}
|
|
26
|
-
catch {
|
|
27
|
-
|
|
31
|
+
catch (err) {
|
|
32
|
+
if (err?.code === "ENOENT")
|
|
33
|
+
return [];
|
|
34
|
+
throw err;
|
|
28
35
|
}
|
|
29
36
|
const out = [];
|
|
30
37
|
for (const line of raw.split("\n")) {
|
|
@@ -72,7 +79,53 @@ export function writeEmitRetry(workMeshRoot, events, max = EMIT_RETRY_MAX) {
|
|
|
72
79
|
fs.renameSync(tmp, p);
|
|
73
80
|
return { written: keep.length, dropped };
|
|
74
81
|
}
|
|
75
|
-
/**
|
|
82
|
+
/**
|
|
83
|
+
* Append `events` to the retry file without reading or replacing it. Used when
|
|
84
|
+
* the file could not be read, so its existing events are left as they are.
|
|
85
|
+
* Duplicates are removed by eventId on the next drain, and the cap applies on
|
|
86
|
+
* the next full write.
|
|
87
|
+
*
|
|
88
|
+
* readEmitRetry accepts a final record with no trailing newline, and this path
|
|
89
|
+
* cannot read the file to check its last byte. So when the file already has
|
|
90
|
+
* bytes, the batch starts with a newline: otherwise it would join that final
|
|
91
|
+
* record into one invalid line and the reader would drop both. The reader
|
|
92
|
+
* skips the blank line this leaves when the file did end in a newline.
|
|
93
|
+
*/
|
|
94
|
+
export function appendEmitRetry(workMeshRoot, events) {
|
|
95
|
+
if (events.length === 0)
|
|
96
|
+
return 0;
|
|
97
|
+
const p = emitRetryPath(workMeshRoot);
|
|
98
|
+
ensureFileDir(p);
|
|
99
|
+
const body = events.map((e) => JSON.stringify(e)).join("\n") + "\n";
|
|
100
|
+
const fd = fs.openSync(p, "a", 0o600);
|
|
101
|
+
try {
|
|
102
|
+
// fstat needs no read permission, so it works on a file we cannot read.
|
|
103
|
+
const separator = fs.fstatSync(fd).size > 0 ? "\n" : "";
|
|
104
|
+
writeAll(fd, Buffer.from(separator + body, "utf8"));
|
|
105
|
+
}
|
|
106
|
+
finally {
|
|
107
|
+
fs.closeSync(fd);
|
|
108
|
+
}
|
|
109
|
+
return events.length;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Write every byte of `buf`. writeSync may write fewer bytes than asked (for
|
|
113
|
+
* example when the disk or quota is nearly full); stopping there would leave a
|
|
114
|
+
* truncated record that the reader drops while the caller counts it as kept.
|
|
115
|
+
* Errors propagate, and a write that makes no progress throws instead of
|
|
116
|
+
* looping forever.
|
|
117
|
+
*/
|
|
118
|
+
function writeAll(fd, buf) {
|
|
119
|
+
let offset = 0;
|
|
120
|
+
while (offset < buf.length) {
|
|
121
|
+
const n = fs.writeSync(fd, buf, offset, buf.length - offset);
|
|
122
|
+
if (n <= 0) {
|
|
123
|
+
throw new Error(`emit retry append wrote ${offset} of ${buf.length} bytes`);
|
|
124
|
+
}
|
|
125
|
+
offset += n;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/** Count of pending retry events (doctor retryDepth). Throws if the file cannot be read. */
|
|
76
129
|
export function emitRetryDepth(workMeshRoot) {
|
|
77
130
|
return readEmitRetry(workMeshRoot).length;
|
|
78
131
|
}
|
|
@@ -14,7 +14,7 @@ import { hqAnywhereRuntimeLocallyDisabled } from "../../anywhere-runtime-flag-ke
|
|
|
14
14
|
import * as fs from "node:fs";
|
|
15
15
|
import * as path from "node:path";
|
|
16
16
|
import { MESH_EVENTS_BATCH_MAX, parseEmitResults, } from "./emit-client.js";
|
|
17
|
-
import { EMIT_RETRY_MAX, readEmitRetry, writeEmitRetry, } from "./emit-retry.js";
|
|
17
|
+
import { EMIT_RETRY_MAX, appendEmitRetry, readEmitRetry, writeEmitRetry, } from "./emit-retry.js";
|
|
18
18
|
import { defaultSleep, fullJitterDelayMs, } from "./backoff.js";
|
|
19
19
|
export function emitStatePath(workMeshRoot) {
|
|
20
20
|
return path.join(workMeshRoot, "emit-state.json");
|
|
@@ -68,7 +68,28 @@ export async function emitEvents(deps) {
|
|
|
68
68
|
const maxAttempts = deps.maxAttempts ?? 3;
|
|
69
69
|
const retryMax = deps.retryMax ?? EMIT_RETRY_MAX;
|
|
70
70
|
// Combine pending retry + new events, deduped by eventId (first wins).
|
|
71
|
-
|
|
71
|
+
// A retry file that exists but cannot be read is never rewritten: that would
|
|
72
|
+
// delete the events in it. New events that are not sent are appended instead.
|
|
73
|
+
let pending = [];
|
|
74
|
+
let retryUnreadable = false;
|
|
75
|
+
try {
|
|
76
|
+
pending = readEmitRetry(deps.workMeshRoot);
|
|
77
|
+
}
|
|
78
|
+
catch (err) {
|
|
79
|
+
retryUnreadable = true;
|
|
80
|
+
deps.log?.(`emit retry file unreadable; left in place: ${(err instanceof Error ? err.message : String(err)).slice(0, 120)}`);
|
|
81
|
+
}
|
|
82
|
+
const persistRetry = (events) => {
|
|
83
|
+
if (!retryUnreadable)
|
|
84
|
+
return writeEmitRetry(deps.workMeshRoot, events, retryMax);
|
|
85
|
+
try {
|
|
86
|
+
return { written: appendEmitRetry(deps.workMeshRoot, events), dropped: 0 };
|
|
87
|
+
}
|
|
88
|
+
catch (err) {
|
|
89
|
+
deps.log?.(`emit retry append failed; ${events.length} events not retained: ${(err instanceof Error ? err.message : String(err)).slice(0, 120)}`);
|
|
90
|
+
return { written: 0, dropped: events.length };
|
|
91
|
+
}
|
|
92
|
+
};
|
|
72
93
|
const combined = [];
|
|
73
94
|
const seen = new Set();
|
|
74
95
|
for (const e of [...pending, ...(deps.newEvents ?? [])]) {
|
|
@@ -109,7 +130,7 @@ export async function emitEvents(deps) {
|
|
|
109
130
|
bound = combined.filter(event => eventDatedSince(event, offSinceMs) && hasWorkMeshEventCompanyBinding(event, env));
|
|
110
131
|
}
|
|
111
132
|
if (bound.length === 0) {
|
|
112
|
-
const written =
|
|
133
|
+
const written = persistRetry(combined);
|
|
113
134
|
return { ...summary, attempted: 0, retained: written.written,
|
|
114
135
|
retryDepth: written.written, droppedOverflow: written.dropped };
|
|
115
136
|
}
|
|
@@ -193,7 +214,7 @@ export async function emitEvents(deps) {
|
|
|
193
214
|
}
|
|
194
215
|
}
|
|
195
216
|
}
|
|
196
|
-
const written =
|
|
217
|
+
const written = persistRetry(keep);
|
|
197
218
|
summary.retained = written.written;
|
|
198
219
|
summary.droppedOverflow = written.dropped;
|
|
199
220
|
summary.retryDepth = written.written;
|
|
@@ -87,6 +87,7 @@ export interface FlushDeps {
|
|
|
87
87
|
*/
|
|
88
88
|
onSpoolLinesClaimed?: (lines: string[]) => void;
|
|
89
89
|
}
|
|
90
|
+
export type FlushNoClaimReason = "operator_switch_off" | "anywhere_off_no_company_session_event";
|
|
90
91
|
export interface FlushSummary {
|
|
91
92
|
claimed: number;
|
|
92
93
|
posted: number;
|
|
@@ -99,6 +100,7 @@ export interface FlushSummary {
|
|
|
99
100
|
heldClaimed?: boolean;
|
|
100
101
|
/** Oldest held lines dead-lettered this flush due to HELD_MAX_LINES. */
|
|
101
102
|
heldOverflow?: number;
|
|
103
|
+
noClaimReason?: FlushNoClaimReason;
|
|
102
104
|
}
|
|
103
105
|
/**
|
|
104
106
|
* Flush spool + held. Safe to call concurrently with enqueue (claim-by-rename).
|
|
@@ -175,8 +175,8 @@ async function postBatchWithRetries(poster, body, deps) {
|
|
|
175
175
|
*/
|
|
176
176
|
export async function flushSessionEvents(inputDeps) {
|
|
177
177
|
const env = inputDeps.env ?? process.env;
|
|
178
|
-
const nothingDone = () => ({ claimed: 0, posted: 0, held: 0, dropped: 0, deadLettered: 0,
|
|
179
|
-
restored: 0, batches: 0, heldClaimed: false, heldOverflow: 0 });
|
|
178
|
+
const nothingDone = (noClaimReason) => ({ claimed: 0, posted: 0, held: 0, dropped: 0, deadLettered: 0,
|
|
179
|
+
restored: 0, batches: 0, heldClaimed: false, heldOverflow: 0, ...(noClaimReason ? { noClaimReason } : {}) });
|
|
180
180
|
// Idle machine: with nothing spooled, held or orphaned there is nothing to
|
|
181
181
|
// report, so do not ask whether reporting is allowed. The gate still runs
|
|
182
182
|
// before anything is claimed or sent whenever there is something.
|
|
@@ -190,7 +190,7 @@ export async function flushSessionEvents(inputDeps) {
|
|
|
190
190
|
let boundOnly = false;
|
|
191
191
|
if (hqAnywhereRuntimeLocallyDisabled(env) || (inputDeps.reportingAllowed && !(await inputDeps.reportingAllowed()))) {
|
|
192
192
|
if (!operatorAllowsHqAnywhere(env))
|
|
193
|
-
return nothingDone();
|
|
193
|
+
return nothingDone("operator_switch_off");
|
|
194
194
|
boundOnly = true;
|
|
195
195
|
}
|
|
196
196
|
// Events stored before this machine first saw HQ Anywhere off were held
|
|
@@ -239,7 +239,7 @@ export async function flushSessionEvents(inputDeps) {
|
|
|
239
239
|
forEachJsonlLine(claim, look);
|
|
240
240
|
}
|
|
241
241
|
if (!any)
|
|
242
|
-
return nothingDone();
|
|
242
|
+
return nothingDone("anywhere_off_no_company_session_event");
|
|
243
243
|
}
|
|
244
244
|
// One resolver per flush: git lookups are cached per cwd for this flush only.
|
|
245
245
|
const deps = {
|
|
@@ -260,6 +260,9 @@ export async function flushSessionEvents(inputDeps) {
|
|
|
260
260
|
const orphans = boundOnly
|
|
261
261
|
? recoverOrphanSpoolClaims(deps.workMeshRoot)
|
|
262
262
|
: recoverOrphanClaims(deps.workMeshRoot);
|
|
263
|
+
for (const claim of orphans.unreadable) {
|
|
264
|
+
deps.log?.(`work-mesh: kept unreadable claim ${path.basename(claim.claimPath)} for the next flush: ${claim.error.slice(0, 120)}`);
|
|
265
|
+
}
|
|
263
266
|
const spoolClaim = claimSpool(deps.workMeshRoot, ts);
|
|
264
267
|
// Throttle held re-attempts; spool (fresh) events still flush every cycle.
|
|
265
268
|
const lastHeldRetryAtMs = deps.lastHeldRetryAtMs ?? 0;
|
|
@@ -580,23 +583,33 @@ export async function flushSessionEvents(inputDeps) {
|
|
|
580
583
|
}
|
|
581
584
|
finally {
|
|
582
585
|
// Crash / throw mid-flush: put unprocessed events back on the spool.
|
|
586
|
+
let restoreFailed = 0;
|
|
587
|
+
let restoreError = "";
|
|
583
588
|
for (const event of pendingRestore) {
|
|
584
589
|
try {
|
|
585
590
|
appendSpoolLine(JSON.stringify(canonicalizeForRestore(event)), deps.workMeshRoot);
|
|
586
591
|
summary.restored += 1;
|
|
587
592
|
}
|
|
588
|
-
catch {
|
|
589
|
-
|
|
593
|
+
catch (err) {
|
|
594
|
+
// The claim files still hold this event; they are kept below so the
|
|
595
|
+
// orphan claim scan retries it next flush.
|
|
596
|
+
restoreFailed += 1;
|
|
597
|
+
if (!restoreError)
|
|
598
|
+
restoreError = err instanceof Error ? err.message : String(err);
|
|
590
599
|
}
|
|
591
600
|
}
|
|
592
601
|
pendingRestore.clear();
|
|
593
|
-
let gaveBack =
|
|
602
|
+
let gaveBack = restoreFailed === 0;
|
|
603
|
+
if (restoreFailed > 0) {
|
|
604
|
+
deps.log?.(`work-mesh: could not put ${restoreFailed} events back on the spool; kept claim files for the next flush: ${restoreError.slice(0, 120)}`);
|
|
605
|
+
}
|
|
594
606
|
try {
|
|
595
607
|
appendRawSpoolLines(giveBack, deps.workMeshRoot);
|
|
596
608
|
}
|
|
597
|
-
catch {
|
|
609
|
+
catch (err) {
|
|
598
610
|
// The claim files still hold these lines; the next flush recovers them.
|
|
599
611
|
gaveBack = false;
|
|
612
|
+
deps.log?.(`work-mesh: could not give ${giveBack.length} lines back to the spool; kept claim files for the next flush: ${(err instanceof Error ? err.message : String(err)).slice(0, 120)}`);
|
|
600
613
|
}
|
|
601
614
|
if (gaveBack) {
|
|
602
615
|
for (const p of claimPaths) {
|
|
@@ -68,13 +68,20 @@ export declare function hasPendingFlushWork(root: string): boolean;
|
|
|
68
68
|
* file alone does not start a flush on every cycle.
|
|
69
69
|
*/
|
|
70
70
|
export declare function hasPendingSpoolWork(root: string): boolean;
|
|
71
|
+
/** A claim file this flush could not read. It is left on disk for the next flush. */
|
|
72
|
+
export interface UnreadableClaim {
|
|
73
|
+
claimPath: string;
|
|
74
|
+
error: string;
|
|
75
|
+
}
|
|
71
76
|
/**
|
|
72
77
|
* Recover orphaned claim files: read their lines and return paths to unlink
|
|
73
|
-
* after the flush dispositions them.
|
|
78
|
+
* after the flush dispositions them. A claim that cannot be read is listed in
|
|
79
|
+
* `unreadable` and left out of `claimPaths`, so it stays for the next flush.
|
|
74
80
|
*/
|
|
75
81
|
export declare function recoverOrphanClaims(root: string): {
|
|
76
82
|
lines: string[];
|
|
77
83
|
claimPaths: string[];
|
|
84
|
+
unreadable: UnreadableClaim[];
|
|
78
85
|
};
|
|
79
86
|
/** Orphaned claim files of the spool only (never held claims). */
|
|
80
87
|
export declare function listOrphanSpoolClaims(root: string): string[];
|
|
@@ -85,6 +92,7 @@ export declare function listOrphanSpoolClaims(root: string): string[];
|
|
|
85
92
|
export declare function recoverOrphanSpoolClaims(root: string): {
|
|
86
93
|
lines: string[];
|
|
87
94
|
claimPaths: string[];
|
|
95
|
+
unreadable: UnreadableClaim[];
|
|
88
96
|
};
|
|
89
97
|
export declare function removeClaimFile(claimPath: string | null): void;
|
|
90
98
|
export declare function deadLetterNonEmpty(root?: string): boolean;
|