@indigoai-us/hq-cli 5.345.247 → 5.345.248
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 +54 -0
- package/assets/lanes-hooks/hq-lanes-drain.sh +1 -1
- package/contracts/host-canary-release.json +14 -0
- package/dist/command-catalog.generated.d.ts +1113 -0
- package/dist/command-catalog.generated.js +1370 -0
- package/dist/command-registration-plan.d.ts +6 -0
- package/dist/command-registration-plan.js +1 -0
- package/dist/commands/lanes-hold.js +7 -7
- package/dist/commands/lanes-resume.js +2 -2
- package/dist/commands/lanes-review.js +1 -1
- package/dist/commands/lanes-session-start.d.ts +1 -1
- package/dist/commands/lanes-session-start.js +3 -3
- package/dist/commands/lanes-shared.d.ts +1 -1
- package/dist/commands/lanes.d.ts +2 -2
- package/dist/commands/lanes.js +50 -50
- package/dist/commands/mesh.d.ts +25 -0
- package/dist/commands/mesh.js +48 -8
- package/dist/commands/ontology-graph.d.ts +62 -0
- package/dist/commands/ontology-graph.js +439 -0
- package/dist/index.js +1 -1
- package/dist/lanes-monitor-check-argv.d.ts +1 -1
- package/dist/lanes-monitor-check-argv.js +1 -1
- package/dist/lanes-monitor-check-fast.d.ts +1 -1
- package/dist/lanes-monitor-check-fast.js +1 -1
- package/dist/lanes-session-start-argv.d.ts +1 -1
- package/dist/lanes-session-start-argv.js +1 -1
- package/dist/lib/capacity/sign-in.d.ts +1 -1
- package/dist/lib/capacity/sign-in.js +1 -1
- package/dist/lib/daemon/hook-requests-conduct-link.js +2 -2
- package/dist/lib/daemon/lanes-monitor-state.d.ts +2 -2
- package/dist/lib/daemon/lanes-monitor-state.js +2 -2
- package/dist/lib/daemon/merge-sections.d.ts +3 -3
- package/dist/lib/daemon/merge-sections.js +7 -7
- package/dist/lib/daemon/remote-control-pools.js +1 -1
- package/dist/lib/daemon/run.js +1 -1
- package/dist/lib/daemon/state-file.d.ts +1 -1
- package/dist/lib/daemon/state-file.js +1 -1
- package/dist/lib/flag-snapshot-file.d.ts +2 -0
- package/dist/lib/flag-snapshot-file.js +118 -48
- package/dist/lib/hook-engine/canary-gate.d.ts +57 -3
- package/dist/lib/hook-engine/canary-gate.js +138 -6
- package/dist/lib/hot-channels/graph-context.d.ts +105 -0
- package/dist/lib/hot-channels/graph-context.js +377 -0
- package/dist/lib/hot-channels/signals-pass.js +27 -1
- package/dist/lib/lanes/claude-credential.d.ts +1 -1
- package/dist/lib/lanes/claude-credential.js +1 -1
- package/dist/lib/lanes/delivery-core.d.ts +1 -1
- package/dist/lib/lanes/delivery-core.js +1 -1
- package/dist/lib/lanes/delivery.d.ts +10 -10
- package/dist/lib/lanes/delivery.js +8 -8
- package/dist/lib/lanes/dropbox.d.ts +1 -1
- package/dist/lib/lanes/dropbox.js +1 -1
- package/dist/lib/lanes/hooks-install.js +2 -2
- package/dist/lib/lanes/index.d.ts +1 -1
- package/dist/lib/lanes/index.js +1 -1
- package/dist/lib/lanes/monitor.js +1 -1
- package/dist/lib/lanes/quota-notice.js +1 -1
- package/dist/lib/lanes/quota.d.ts +1 -1
- package/dist/lib/lanes/quota.js +1 -1
- package/dist/lib/lanes/repo-merge-hold.d.ts +2 -2
- package/dist/lib/lanes/repo-merge-hold.js +2 -2
- package/dist/lib/lanes/spawn.d.ts +4 -4
- package/dist/lib/lanes/spawn.js +5 -5
- package/dist/lib/mesh/live/company-flag-refresh.d.ts +61 -0
- package/dist/lib/mesh/live/company-flag-refresh.js +159 -0
- package/dist/lib/mesh/live/company-reporting-gaps.d.ts +61 -0
- package/dist/lib/mesh/live/company-reporting-gaps.js +238 -0
- package/dist/lib/mesh/live/daemon/duplicate-unit.d.ts +156 -0
- package/dist/lib/mesh/live/daemon/duplicate-unit.js +616 -0
- package/dist/lib/mesh/live/daemon/run.d.ts +13 -0
- package/dist/lib/mesh/live/daemon/run.js +35 -2
- package/dist/lib/mesh/live/direct-drain.js +1 -1
- package/dist/lib/mesh/live/emit.d.ts +3 -0
- package/dist/lib/mesh/live/emit.js +32 -9
- package/dist/lib/mesh/live/flush.d.ts +3 -0
- package/dist/lib/mesh/live/flush.js +115 -32
- package/dist/lib/mesh/live/liveness-carry.d.ts +1 -1
- package/dist/lib/mesh/live/liveness-carry.js +1 -1
- package/dist/lib/mesh/live/reporting-privacy.d.ts +119 -3
- package/dist/lib/mesh/live/reporting-privacy.js +235 -11
- package/dist/lib/mesh/live/spool.d.ts +17 -2
- package/dist/lib/mesh/live/spool.js +22 -6
- package/dist/lib/ontology-graph/legacy/coverage.d.ts +67 -0
- package/dist/lib/ontology-graph/legacy/coverage.js +192 -0
- package/dist/lib/ontology-graph/legacy/index.d.ts +199 -0
- package/dist/lib/ontology-graph/legacy/index.js +1150 -0
- package/dist/lib/ontology-graph/legacy/parse.d.ts +49 -0
- package/dist/lib/ontology-graph/legacy/parse.js +126 -0
- package/dist/lib/ontology-graph/legacy/report.d.ts +14 -0
- package/dist/lib/ontology-graph/legacy/report.js +254 -0
- package/dist/lib/ontology-graph/legacy/verb-map.d.ts +35 -0
- package/dist/lib/ontology-graph/legacy/verb-map.js +84 -0
- package/dist/lib/ontology-graph/lint/checks.d.ts +140 -0
- package/dist/lib/ontology-graph/lint/checks.js +717 -0
- package/dist/lib/ontology-graph/lint/coverage.d.ts +106 -0
- package/dist/lib/ontology-graph/lint/coverage.js +241 -0
- package/dist/lib/ontology-graph/lint/daily-job.d.ts +259 -0
- package/dist/lib/ontology-graph/lint/daily-job.js +595 -0
- package/dist/lib/ontology-graph/lint/index.d.ts +65 -0
- package/dist/lib/ontology-graph/lint/index.js +176 -0
- package/dist/lib/ontology-graph/model/files.d.ts +20 -0
- package/dist/lib/ontology-graph/model/files.js +89 -0
- package/dist/lib/ontology-graph/model/index.d.ts +65 -0
- package/dist/lib/ontology-graph/model/index.js +100 -0
- package/dist/lib/ontology-graph/model/pass-tasks.d.ts +156 -0
- package/dist/lib/ontology-graph/model/pass-tasks.js +345 -0
- package/dist/lib/ontology-graph/model/pass.d.ts +109 -0
- package/dist/lib/ontology-graph/model/pass.js +958 -0
- package/dist/lib/ontology-graph/model/runner.d.ts +50 -0
- package/dist/lib/ontology-graph/model/runner.js +160 -0
- package/dist/lib/ontology-graph/model/step.d.ts +195 -0
- package/dist/lib/ontology-graph/model/step.js +523 -0
- package/dist/lib/ontology-graph/model/tasks.d.ts +183 -0
- package/dist/lib/ontology-graph/model/tasks.js +349 -0
- package/dist/lib/ontology-graph/not-implemented.d.ts +5 -0
- package/dist/lib/ontology-graph/not-implemented.js +8 -0
- package/dist/lib/ontology-graph/org/compare.d.ts +28 -0
- package/dist/lib/ontology-graph/org/compare.js +239 -0
- package/dist/lib/ontology-graph/org/derive.d.ts +65 -0
- package/dist/lib/ontology-graph/org/derive.js +352 -0
- package/dist/lib/ontology-graph/org/index.d.ts +73 -0
- package/dist/lib/ontology-graph/org/index.js +513 -0
- package/dist/lib/ontology-graph/org/load.d.ts +31 -0
- package/dist/lib/ontology-graph/org/load.js +476 -0
- package/dist/lib/ontology-graph/org/role.d.ts +38 -0
- package/dist/lib/ontology-graph/org/role.js +268 -0
- package/dist/lib/ontology-graph/org/structure.d.ts +63 -0
- package/dist/lib/ontology-graph/org/structure.js +437 -0
- package/dist/lib/ontology-graph/org/text.d.ts +95 -0
- package/dist/lib/ontology-graph/org/text.js +315 -0
- package/dist/lib/ontology-graph/org/types.d.ts +452 -0
- package/dist/lib/ontology-graph/org/types.js +80 -0
- package/dist/lib/ontology-graph/pages/index.d.ts +64 -0
- package/dist/lib/ontology-graph/pages/index.js +193 -0
- package/dist/lib/ontology-graph/pages/render.d.ts +142 -0
- package/dist/lib/ontology-graph/pages/render.js +682 -0
- package/dist/lib/ontology-graph/proposals/apply.d.ts +109 -0
- package/dist/lib/ontology-graph/proposals/apply.js +468 -0
- package/dist/lib/ontology-graph/proposals/group.d.ts +63 -0
- package/dist/lib/ontology-graph/proposals/group.js +232 -0
- package/dist/lib/ontology-graph/proposals/index.d.ts +173 -0
- package/dist/lib/ontology-graph/proposals/index.js +474 -0
- package/dist/lib/ontology-graph/proposals/model.d.ts +162 -0
- package/dist/lib/ontology-graph/proposals/model.js +196 -0
- package/dist/lib/ontology-graph/proposals/org-chart.d.ts +82 -0
- package/dist/lib/ontology-graph/proposals/org-chart.js +340 -0
- package/dist/lib/ontology-graph/read/brief.d.ts +26 -0
- package/dist/lib/ontology-graph/read/brief.js +251 -0
- package/dist/lib/ontology-graph/read/graph-index.d.ts +76 -0
- package/dist/lib/ontology-graph/read/graph-index.js +198 -0
- package/dist/lib/ontology-graph/read/index.d.ts +59 -0
- package/dist/lib/ontology-graph/read/index.js +792 -0
- package/dist/lib/ontology-graph/read/member.d.ts +7 -0
- package/dist/lib/ontology-graph/read/member.js +34 -0
- package/dist/lib/ontology-graph/read/names.d.ts +44 -0
- package/dist/lib/ontology-graph/read/names.js +292 -0
- package/dist/lib/ontology-graph/read/reader-setting.d.ts +19 -0
- package/dist/lib/ontology-graph/read/reader-setting.js +62 -0
- package/dist/lib/ontology-graph/read/test-graph.d.ts +37 -0
- package/dist/lib/ontology-graph/read/test-graph.js +150 -0
- package/dist/lib/ontology-graph/replay/buffered-store.d.ts +33 -0
- package/dist/lib/ontology-graph/replay/buffered-store.js +50 -0
- package/dist/lib/ontology-graph/replay/config.d.ts +41 -0
- package/dist/lib/ontology-graph/replay/config.js +105 -0
- package/dist/lib/ontology-graph/replay/engine.d.ts +100 -0
- package/dist/lib/ontology-graph/replay/engine.js +1174 -0
- package/dist/lib/ontology-graph/replay/extractors.d.ts +59 -0
- package/dist/lib/ontology-graph/replay/extractors.js +1555 -0
- package/dist/lib/ontology-graph/replay/index.d.ts +90 -0
- package/dist/lib/ontology-graph/replay/index.js +220 -0
- package/dist/lib/ontology-graph/replay/listing-manifest.d.ts +66 -0
- package/dist/lib/ontology-graph/replay/listing-manifest.js +242 -0
- package/dist/lib/ontology-graph/replay/member.d.ts +19 -0
- package/dist/lib/ontology-graph/replay/member.js +65 -0
- package/dist/lib/ontology-graph/replay/mentions.d.ts +58 -0
- package/dist/lib/ontology-graph/replay/mentions.js +239 -0
- package/dist/lib/ontology-graph/replay/readers.d.ts +98 -0
- package/dist/lib/ontology-graph/replay/readers.js +1251 -0
- package/dist/lib/ontology-graph/replay/rules.d.ts +127 -0
- package/dist/lib/ontology-graph/replay/rules.js +374 -0
- package/dist/lib/ontology-graph/replay/scope.d.ts +35 -0
- package/dist/lib/ontology-graph/replay/scope.js +115 -0
- package/dist/lib/ontology-graph/replay/transcripts.d.ts +39 -0
- package/dist/lib/ontology-graph/replay/transcripts.js +224 -0
- package/dist/lib/ontology-graph/replay/util.d.ts +55 -0
- package/dist/lib/ontology-graph/replay/util.js +256 -0
- package/dist/lib/ontology-graph/resolve/entity-index.d.ts +159 -0
- package/dist/lib/ontology-graph/resolve/entity-index.js +652 -0
- package/dist/lib/ontology-graph/resolve/index.d.ts +113 -0
- package/dist/lib/ontology-graph/resolve/index.js +214 -0
- package/dist/lib/ontology-graph/resolve/machine.d.ts +34 -0
- package/dist/lib/ontology-graph/resolve/machine.js +95 -0
- package/dist/lib/ontology-graph/resolve/normalize.d.ts +35 -0
- package/dist/lib/ontology-graph/resolve/normalize.js +124 -0
- package/dist/lib/ontology-graph/resolve/org-chart.d.ts +107 -0
- package/dist/lib/ontology-graph/resolve/org-chart.js +578 -0
- package/dist/lib/ontology-graph/resolve/org-layer.d.ts +78 -0
- package/dist/lib/ontology-graph/resolve/org-layer.js +159 -0
- package/dist/lib/ontology-graph/resolve/org-seed.d.ts +141 -0
- package/dist/lib/ontology-graph/resolve/org-seed.js +631 -0
- package/dist/lib/ontology-graph/resolve/org-sources.d.ts +165 -0
- package/dist/lib/ontology-graph/resolve/org-sources.js +634 -0
- package/dist/lib/ontology-graph/resolve/roster.d.ts +76 -0
- package/dist/lib/ontology-graph/resolve/roster.js +226 -0
- package/dist/lib/ontology-graph/resolve/seed.d.ts +267 -0
- package/dist/lib/ontology-graph/resolve/seed.js +1198 -0
- package/dist/lib/ontology-graph/resolve/upsert.d.ts +58 -0
- package/dist/lib/ontology-graph/resolve/upsert.js +139 -0
- package/dist/lib/ontology-graph/resolve/writer.d.ts +128 -0
- package/dist/lib/ontology-graph/resolve/writer.js +351 -0
- package/dist/lib/ontology-graph/schema/authority.d.ts +73 -0
- package/dist/lib/ontology-graph/schema/authority.js +157 -0
- package/dist/lib/ontology-graph/schema/default-schema.d.ts +10 -0
- package/dist/lib/ontology-graph/schema/default-schema.js +242 -0
- package/dist/lib/ontology-graph/schema/grammar.d.ts +57 -0
- package/dist/lib/ontology-graph/schema/grammar.js +409 -0
- package/dist/lib/ontology-graph/schema/index.d.ts +12 -0
- package/dist/lib/ontology-graph/schema/index.js +10 -0
- package/dist/lib/ontology-graph/schema/validate.d.ts +13 -0
- package/dist/lib/ontology-graph/schema/validate.js +132 -0
- package/dist/lib/ontology-graph/store/files.d.ts +34 -0
- package/dist/lib/ontology-graph/store/files.js +207 -0
- package/dist/lib/ontology-graph/store/fs.d.ts +30 -0
- package/dist/lib/ontology-graph/store/fs.js +101 -0
- package/dist/lib/ontology-graph/store/graph-store.d.ts +14 -0
- package/dist/lib/ontology-graph/store/graph-store.js +520 -0
- package/dist/lib/ontology-graph/store/index.d.ts +18 -0
- package/dist/lib/ontology-graph/store/index.js +15 -0
- package/dist/lib/ontology-graph/store/ingest.d.ts +37 -0
- package/dist/lib/ontology-graph/store/ingest.js +323 -0
- package/dist/lib/ontology-graph/store/paths.d.ts +114 -0
- package/dist/lib/ontology-graph/store/paths.js +232 -0
- package/dist/lib/ontology-graph/types.d.ts +1183 -0
- package/dist/lib/ontology-graph/types.js +131 -0
- package/dist/lib/secret-scan/gitleaks-rules.generated.js +1 -1
- package/dist/utils/frontmatter.d.ts +14 -0
- package/dist/utils/frontmatter.js +18 -0
- package/dist/utils/interactive-caller.js +1 -1
- package/package.json +8 -8
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createReportingStateGate } from "../reporting-privacy.js";
|
|
2
2
|
/**
|
|
3
3
|
* hq mesh daemon run — single-instance resident process.
|
|
4
4
|
*
|
|
@@ -43,6 +43,7 @@ import { resolveRunningCliEntry } from "./install.js";
|
|
|
43
43
|
import { readDaemonConfig } from "./config.js";
|
|
44
44
|
import { retireLegacyListen } from "./legacy-listen.js";
|
|
45
45
|
import { runDirectDrainCycle } from "../direct-drain.js";
|
|
46
|
+
import { COMPANY_FLAG_REFRESH_INTERVAL_MS, refreshCompanyFlagSnapshots, } from "../company-flag-refresh.js";
|
|
46
47
|
import { startWorkCacheSubscriber } from "./work-subscribe.js";
|
|
47
48
|
import { createOwnerChannelScope } from "./owner-inbox-push.js";
|
|
48
49
|
import { vaultApiFetch } from "../../../../utils/vault-api.js";
|
|
@@ -380,6 +381,31 @@ export async function runMeshDaemon(deps = {}) {
|
|
|
380
381
|
};
|
|
381
382
|
/** In-memory held re-attempt throttle (survives watch-triggered flushes). */
|
|
382
383
|
let lastHeldRetryAtMs = 0;
|
|
384
|
+
// Company flag snapshots for every company with recent verified session
|
|
385
|
+
// work, refreshed on an interval whatever this process's own company scope
|
|
386
|
+
// (rq_20261121230415_a549af8f50, informational 2). It runs beside the
|
|
387
|
+
// flush, never in front of it.
|
|
388
|
+
const companyFlagRefreshEnabled = Boolean(deps.companyFlagClient) || !deps.poster;
|
|
389
|
+
const companyFlagRefreshIntervalMs = deps.companyFlagRefreshIntervalMs ?? COMPANY_FLAG_REFRESH_INTERVAL_MS;
|
|
390
|
+
let lastCompanyFlagRefreshAtMs = null;
|
|
391
|
+
let companyFlagRefreshInFlight = null;
|
|
392
|
+
const maybeRefreshCompanyFlags = (atMs) => {
|
|
393
|
+
if (!companyFlagRefreshEnabled || companyFlagRefreshInFlight)
|
|
394
|
+
return;
|
|
395
|
+
if (lastCompanyFlagRefreshAtMs !== null && atMs - lastCompanyFlagRefreshAtMs < companyFlagRefreshIntervalMs)
|
|
396
|
+
return;
|
|
397
|
+
lastCompanyFlagRefreshAtMs = atMs;
|
|
398
|
+
companyFlagRefreshInFlight = refreshCompanyFlagSnapshots({
|
|
399
|
+
workContextRoot: ctxRoot,
|
|
400
|
+
env,
|
|
401
|
+
getToken,
|
|
402
|
+
now,
|
|
403
|
+
createClient: deps.companyFlagClient,
|
|
404
|
+
log: (message) => log(dir, message),
|
|
405
|
+
}).finally(() => {
|
|
406
|
+
companyFlagRefreshInFlight = null;
|
|
407
|
+
});
|
|
408
|
+
};
|
|
383
409
|
/** Epoch ms of the last held backfill (startup or periodic). */
|
|
384
410
|
let lastHeldBackfillAtMs = 0;
|
|
385
411
|
const heldBackfillIntervalMs = deps.heldBackfillIntervalMs ?? HELD_BACKFILL_INTERVAL_MS;
|
|
@@ -396,7 +422,11 @@ export async function runMeshDaemon(deps = {}) {
|
|
|
396
422
|
const shutdownController = new AbortController();
|
|
397
423
|
// One gate for the daemon's lifetime: the person setting is read from the
|
|
398
424
|
// server once and on change, not on every flush.
|
|
399
|
-
|
|
425
|
+
// One gate for the daemon's lifetime. It can say the person setting is
|
|
426
|
+
// unread, which is not a member's opt-out (see ReportingState).
|
|
427
|
+
const reportingState = deps.reportingState ??
|
|
428
|
+
(deps.reportingAllowed ? undefined : createReportingStateGate(machineIdentity, env, { home }));
|
|
429
|
+
const reportingAllowed = deps.reportingAllowed ?? (() => reportingState().then((state) => state === "on"));
|
|
400
430
|
// Held sessions whose local evidence only names a slug need the membership
|
|
401
431
|
// slug -> uid lookup, or they stay NEEDS_COMPANY forever.
|
|
402
432
|
const resolveCompanyUid = async (slug) => {
|
|
@@ -412,6 +442,7 @@ export async function runMeshDaemon(deps = {}) {
|
|
|
412
442
|
return {
|
|
413
443
|
env,
|
|
414
444
|
reportingAllowed,
|
|
445
|
+
reportingState,
|
|
415
446
|
workMeshRoot: meshRoot,
|
|
416
447
|
workContextRoot: ctxRoot,
|
|
417
448
|
poster: deps.poster ?? createSessionEventsPoster({ token: t, baseUrl: resolveVaultApiBase(env) }),
|
|
@@ -435,6 +466,7 @@ export async function runMeshDaemon(deps = {}) {
|
|
|
435
466
|
return flushSessionEvents({
|
|
436
467
|
env,
|
|
437
468
|
reportingAllowed,
|
|
469
|
+
reportingState,
|
|
438
470
|
workMeshRoot: meshRoot,
|
|
439
471
|
workContextRoot: ctxRoot,
|
|
440
472
|
poster,
|
|
@@ -809,6 +841,7 @@ export async function runMeshDaemon(deps = {}) {
|
|
|
809
841
|
}
|
|
810
842
|
// Record hook-emitted session ids from spool/held before claim/rename.
|
|
811
843
|
const at = now().getTime();
|
|
844
|
+
maybeRefreshCompanyFlags(at);
|
|
812
845
|
noteHookSessionsFromSpoolFile(workMeshSpoolPath(meshRoot), lastHookEventAt, at, defaultTranscriptFs, lastHookTurnEndAt);
|
|
813
846
|
noteHookSessionsFromSpoolFile(workMeshHeldPath(meshRoot), lastHookEventAt, at, defaultTranscriptFs, lastHookTurnEndAt);
|
|
814
847
|
const summary = await flushFn(shutdownController.signal);
|
|
@@ -90,7 +90,7 @@ export function ensureDirectDrainStart(root, now = () => new Date(), log) {
|
|
|
90
90
|
const setAside = [];
|
|
91
91
|
let backlogDir;
|
|
92
92
|
if (queued.length > 0) {
|
|
93
|
-
// Read-only pass so `hq
|
|
93
|
+
// Read-only pass so `hq runners` still knows each session's last event.
|
|
94
94
|
// Only kind, time and sequence number are copied; nothing is posted.
|
|
95
95
|
try {
|
|
96
96
|
updateLivenessCarry(dir, (ingest) => {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type ReportingState } from "./reporting-privacy.js";
|
|
1
2
|
import { type EmitPoster, type EmitEventStatus } from "./emit-client.js";
|
|
2
3
|
import { type RandomFn, type SleepFn } from "./backoff.js";
|
|
3
4
|
export interface EmitStateFile {
|
|
@@ -14,6 +15,8 @@ export declare function readEmitState(workMeshRoot: string): EmitStateFile | nul
|
|
|
14
15
|
export interface EmitEventsDeps {
|
|
15
16
|
env?: NodeJS.ProcessEnv;
|
|
16
17
|
reportingAllowed?: () => Promise<boolean>;
|
|
18
|
+
/** Preferred over `reportingAllowed`: can say the person setting is unread (see ReportingState). */
|
|
19
|
+
reportingState?: () => Promise<ReportingState>;
|
|
17
20
|
workMeshRoot: string;
|
|
18
21
|
poster: EmitPoster;
|
|
19
22
|
/** New events to emit this invocation (may be empty — just drain retry). */
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { hqAnywhereRuntimeLocallyDisabled } from "../../anywhere-runtime-flag-key.js";
|
|
1
|
+
import { anywhereBacklogCutoff, backlogCutoffKey, enforcementEpisode, eventDatedOutsideGaps, fleetSessionJudge, hasWorkMeshEventCompanyBinding, logAnywhereOffSinceAhead, mayEmitConversation, operatorAllowsHqAnywhere, readAnywhereOffSince, resolveReportingState, workMeshEventBinding, workMeshSwitchDisabled, } from "./reporting-privacy.js";
|
|
3
2
|
/**
|
|
4
3
|
* Direct-emit orchestration (owner decision 2026-09-08). One invocation:
|
|
5
4
|
* 1. drains the local retry file (prior failures),
|
|
@@ -12,6 +11,7 @@ import { hqAnywhereRuntimeLocallyDisabled } from "../../anywhere-runtime-flag-ke
|
|
|
12
11
|
* count — never re-posted). No long-lived process, spool, or held queue.
|
|
13
12
|
*/
|
|
14
13
|
import * as fs from "node:fs";
|
|
14
|
+
import { workContextRoot } from "../../work-context/paths.js";
|
|
15
15
|
import * as path from "node:path";
|
|
16
16
|
import { MESH_EVENTS_BATCH_MAX, parseEmitResults, } from "./emit-client.js";
|
|
17
17
|
import { EMIT_RETRY_MAX, appendEmitRetry, readEmitRetry, writeEmitRetry, } from "./emit-retry.js";
|
|
@@ -118,18 +118,41 @@ export async function emitEvents(deps) {
|
|
|
118
118
|
// in the retry file, as before. Empty unless HQ Anywhere is off.
|
|
119
119
|
let withheld = [];
|
|
120
120
|
let sendable = combined;
|
|
121
|
-
|
|
121
|
+
// Each session's fleet answer, read once for this emit: the binding, the
|
|
122
|
+
// cutoff key and the episode all use the same read (review of #3469, INFO-1).
|
|
123
|
+
const fleet = fleetSessionJudge(env, workContextRoot(undefined, env));
|
|
124
|
+
const resolvedAnywhere = resolveReportingState(env, deps);
|
|
125
|
+
const anywhere = typeof resolvedAnywhere === "string" ? resolvedAnywhere : await resolvedAnywhere;
|
|
126
|
+
if (anywhere !== "on") {
|
|
122
127
|
// The member's HQ Anywhere switch does not stop a session with a verified
|
|
123
128
|
// company binding. The operator's switch stops everything.
|
|
124
129
|
// Events stored before this machine first saw HQ Anywhere off were held
|
|
125
|
-
// back by the member's opt-out; while it stays off they wait.
|
|
130
|
+
// back by the member's opt-out; while it stays off they wait. So do
|
|
131
|
+
// events from before the company's enforcement episode started.
|
|
126
132
|
let bound = [];
|
|
127
133
|
const confirmed = operatorAllowsHqAnywhere(env)
|
|
128
|
-
? combined.
|
|
134
|
+
? combined.flatMap(event => {
|
|
135
|
+
const state = workMeshEventBinding(event, env, fleet);
|
|
136
|
+
return state ? [{ event, state }] : [];
|
|
137
|
+
}) : [];
|
|
129
138
|
if (confirmed.length > 0) {
|
|
130
|
-
const
|
|
131
|
-
|
|
132
|
-
|
|
139
|
+
const cutoffs = new Map();
|
|
140
|
+
for (const { event, state } of confirmed) {
|
|
141
|
+
// Keyed by company and fleet session: only a member session gets the
|
|
142
|
+
// enforcement-episode cutoff, judged per session (#3464).
|
|
143
|
+
const cutoffKey = backlogCutoffKey(state, fleet);
|
|
144
|
+
let judged = cutoffs.get(cutoffKey);
|
|
145
|
+
if (judged === undefined) {
|
|
146
|
+
const episode = enforcementEpisode(deps.workMeshRoot, state, env, fleet, now);
|
|
147
|
+
judged = { cutoff: anywhereBacklogCutoff(deps.workMeshRoot, anywhere, episode.since, now), gaps: episode.gaps };
|
|
148
|
+
cutoffs.set(cutoffKey, judged);
|
|
149
|
+
}
|
|
150
|
+
if (judged.cutoff !== null && eventDatedOutsideGaps(event, judged.cutoff, judged.gaps))
|
|
151
|
+
bound.push(event);
|
|
152
|
+
}
|
|
153
|
+
const offSinceMs = readAnywhereOffSince(deps.workMeshRoot);
|
|
154
|
+
if (offSinceMs !== null)
|
|
155
|
+
logAnywhereOffSinceAhead(deps.workMeshRoot, offSinceMs, now().getTime(), deps.log);
|
|
133
156
|
}
|
|
134
157
|
if (bound.length === 0) {
|
|
135
158
|
const written = persistRetry(combined);
|
|
@@ -142,7 +165,7 @@ export async function emitEvents(deps) {
|
|
|
142
165
|
}
|
|
143
166
|
const meshDisabled = workMeshSwitchDisabled(env);
|
|
144
167
|
const allowed = sendable.filter(event => {
|
|
145
|
-
const code = meshDisabled && !hasWorkMeshEventCompanyBinding(event, env)
|
|
168
|
+
const code = meshDisabled && !hasWorkMeshEventCompanyBinding(event, env, fleet)
|
|
146
169
|
? "WORK_MESH_DISABLED"
|
|
147
170
|
: !mayEmitConversation(event, env) ? "PERSONAL_OR_UNATTRIBUTED" : undefined;
|
|
148
171
|
if (code === undefined)
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
* Orphan `*.claimed` files from a prior crash are recovered first.
|
|
9
9
|
* 2xx responses are accounted per eventId (accepted / duplicates / rejected).
|
|
10
10
|
*/
|
|
11
|
+
import { type ReportingState } from "./reporting-privacy.js";
|
|
11
12
|
import { type SessionStateFile } from "../../work-context/state.js";
|
|
12
13
|
import { type RandomFn, type SleepFn } from "./backoff.js";
|
|
13
14
|
import { type WorkLocationResolver } from "./work-location.js";
|
|
@@ -73,6 +74,8 @@ export interface FlushDeps {
|
|
|
73
74
|
* that keeps the person setting between flushes (createReportingGate).
|
|
74
75
|
*/
|
|
75
76
|
reportingAllowed?: () => Promise<boolean>;
|
|
77
|
+
/** Preferred over `reportingAllowed`: can say the person setting is unread (see ReportingState). */
|
|
78
|
+
reportingState?: () => Promise<ReportingState>;
|
|
76
79
|
workMeshRoot: string;
|
|
77
80
|
workContextRoot: string;
|
|
78
81
|
poster: SessionEventsPoster;
|
|
@@ -9,8 +9,7 @@
|
|
|
9
9
|
* 2xx responses are accounted per eventId (accepted / duplicates / rejected).
|
|
10
10
|
*/
|
|
11
11
|
import * as fs from "node:fs";
|
|
12
|
-
import {
|
|
13
|
-
import { hqAnywhereRuntimeLocallyDisabled } from "../../anywhere-runtime-flag-key.js";
|
|
12
|
+
import { anywhereBacklogCutoff, backlogCutoffKey, companyReportingRequiredSince, enforcementEpisode, eventDatedOutsideGaps, eventMatchesWorkMeshCompany, fleetSessionJudge, hasWorkMeshCompanyBinding, logAnywhereOffSinceAhead, operatorAllowsHqAnywhere, readAnywhereOffSince, readCompanyReportingRequired, resolveReportingState, workMeshSwitchDisabled, } from "./reporting-privacy.js";
|
|
14
13
|
import * as path from "node:path";
|
|
15
14
|
import { readMetaCompanySlug, resolveCompany } from "../../work-context/company.js";
|
|
16
15
|
import { companyBindingChanged, isNonCloudCompanySlug, reboundSessionProjection, } from "../../work-context/company-rebind.js";
|
|
@@ -25,7 +24,7 @@ import { LOCAL_ONLY_FIELDS, stripLocalOnlyFields } from "./format-spool-line.js"
|
|
|
25
24
|
import { enrichSessionEndEvent } from "./report-summary.js";
|
|
26
25
|
import { createWorkLocationResolver, withWorkLocation, } from "./work-location.js";
|
|
27
26
|
import { SESSION_EVENTS_BATCH_MAX, WRITABLE_CONTEXT_STATUSES, isSessionOwnerMismatch, parseSessionEventsBatchAck, SESSION_OWNER_MISMATCH, } from "./session-events-client.js";
|
|
28
|
-
import { appendDeadLetterLine, appendDroppedReceipt, appendHeldLinesIfAbsent, appendSpoolLine, claimHeld, claimHeldPath, claimSpoolPath, countDistinctHeldEvents, countJsonlLines, createParkedAppender, createStagedAppender, forEachJsonlLine, forEachJsonlLineYielding, hasPendingFlushWork, JsonlAppender, listOrphanClaims, listOrphanSpoolClaims, removeClaimFile, removeStaleStagingFiles, reofferParkedLines, appendDroppedReceiptOnce, parkedTimesRange, verifiedParkedClaimTimes, segmentsRange, } from "./spool.js";
|
|
27
|
+
import { appendDeadLetterLine, appendDroppedReceipt, appendHeldLinesIfAbsent, appendSpoolLine, claimHeld, claimHeldPath, claimSpoolPath, countDistinctHeldEvents, countJsonlLines, createParkedAppender, createStagedAppender, forEachJsonlLine, forEachJsonlLineYielding, hasPendingFlushWork, JsonlAppender, listOrphanClaims, listOrphanSpoolClaims, removeClaimFile, removeStaleStagingFiles, reofferParkedLines, appendDroppedReceiptOnce, parkedTimesRange, parkedHasUnreadLines, verifiedParkedClaimTimes, segmentsRange, } from "./spool.js";
|
|
29
28
|
import { createHash } from "node:crypto";
|
|
30
29
|
import { workMeshHeldPath, workMeshRoot, workMeshSpoolPath } from "./paths.js";
|
|
31
30
|
/** Bound a replayed session backlog so one flush cannot burst hundreds of events. */
|
|
@@ -79,6 +78,13 @@ export const PARKED_CLOCK_SKEW_MS = 5 * 60 * 1000;
|
|
|
79
78
|
* line is past PARKED_LINE_MAX_AGE_MS. Later flushes do neither.
|
|
80
79
|
*/
|
|
81
80
|
const firstBoundOnlyFlushDone = new Set();
|
|
81
|
+
/**
|
|
82
|
+
* The last person-setting answer each mesh root's flush saw in this process.
|
|
83
|
+
* The first "off" after another answer (an unread setting, for example)
|
|
84
|
+
* re-reads the parked lines parked while it was unread, so they start their
|
|
85
|
+
* age then and not only after a restart (review of #3469, INFO-A).
|
|
86
|
+
*/
|
|
87
|
+
const lastAnywhereSeen = new Map();
|
|
82
88
|
/**
|
|
83
89
|
* The smallest spool the first bound-only flush parks with no bound session's
|
|
84
90
|
* event in it. Below one read chunk, scanning the spool costs little, and the
|
|
@@ -88,6 +94,7 @@ export const PARK_BACKLOG_MIN_BYTES = 1024 * 1024;
|
|
|
88
94
|
/** Test hook: forget which roots had their first bound-only flush. */
|
|
89
95
|
export function resetFirstBoundOnlyFlushes() {
|
|
90
96
|
firstBoundOnlyFlushDone.clear();
|
|
97
|
+
lastAnywhereSeen.clear();
|
|
91
98
|
}
|
|
92
99
|
/**
|
|
93
100
|
* Most distinct eventIds one flush remembers to collapse repeated lines of the
|
|
@@ -120,7 +127,7 @@ function oldestParkedLineExpired(root, nowMs) {
|
|
|
120
127
|
return false;
|
|
121
128
|
return nowMs - range.oldestMs > PARKED_LINE_MAX_AGE_MS;
|
|
122
129
|
}
|
|
123
|
-
/** The parked-at
|
|
130
|
+
/** The parked-at segment of each non-empty line of a parked claim, in order (null: not known). */
|
|
124
131
|
function parkedAtCursor(segments) {
|
|
125
132
|
let index = 0;
|
|
126
133
|
let used = 0;
|
|
@@ -132,7 +139,7 @@ function parkedAtCursor(segments) {
|
|
|
132
139
|
if (!segments || index >= segments.length)
|
|
133
140
|
return null;
|
|
134
141
|
used += 1;
|
|
135
|
-
return segments[index]
|
|
142
|
+
return segments[index];
|
|
136
143
|
};
|
|
137
144
|
}
|
|
138
145
|
const isParkedClaim = (claimPath) => path.basename(claimPath).endsWith(".parked.claimed");
|
|
@@ -153,8 +160,8 @@ function sessionIdOf(obj) {
|
|
|
153
160
|
: null;
|
|
154
161
|
}
|
|
155
162
|
/** The binding a parked session is recorded with; a change re-offers its lines. */
|
|
156
|
-
function parkedBinding(state, env, root) {
|
|
157
|
-
return hasWorkMeshCompanyBinding(state, env, root) ? `bound:${state.companySlug ?? ""}` : "unbound";
|
|
163
|
+
function parkedBinding(state, env, root, fleet) {
|
|
164
|
+
return hasWorkMeshCompanyBinding(state, env, root, fleet) ? `bound:${state.companySlug ?? ""}` : "unbound";
|
|
158
165
|
}
|
|
159
166
|
/**
|
|
160
167
|
* Orphan claims this flush can open. One it cannot open (other than one that
|
|
@@ -305,51 +312,94 @@ export async function flushSessionEvents(inputDeps) {
|
|
|
305
312
|
// events are flushed, and every other line stays exactly where it is. The
|
|
306
313
|
// operator's switch, from the server's flag snapshot, stops everything.
|
|
307
314
|
let boundOnly = false;
|
|
308
|
-
|
|
315
|
+
const resolvedAnywhere = resolveReportingState(env, inputDeps);
|
|
316
|
+
const anywhere = typeof resolvedAnywhere === "string" ? resolvedAnywhere : await resolvedAnywhere;
|
|
317
|
+
if (anywhere !== "on") {
|
|
309
318
|
if (!operatorAllowsHqAnywhere(env))
|
|
310
319
|
return nothingDone("operator_switch_off");
|
|
311
320
|
boundOnly = true;
|
|
312
321
|
}
|
|
313
322
|
// Events stored before this machine first saw HQ Anywhere off were held
|
|
314
|
-
// back by the member's opt-out
|
|
315
|
-
|
|
323
|
+
// back by the member's opt-out, and so were events from before the
|
|
324
|
+
// company's enforcement episode started. While it stays off they are not
|
|
325
|
+
// sent. One cutoff per company per flush, with the episode's stale
|
|
326
|
+
// stretches.
|
|
327
|
+
const cutoffs = new Map();
|
|
328
|
+
const episodesSeen = new Set();
|
|
329
|
+
let aheadLogged = false;
|
|
316
330
|
// A recorded time ahead of the clock (a wrong clock when it was written, or
|
|
317
331
|
// an edited file) stops every bound session's events. It is not moved back:
|
|
318
332
|
// that would release what was stored before it whenever a clock is set
|
|
319
333
|
// back. It is said in the log instead, once per process.
|
|
320
334
|
const bindings = new Map();
|
|
335
|
+
// Each session's fleet answer, read once for this flush: the binding, the
|
|
336
|
+
// cutoff key and the episode all use the same read (review of #3469, INFO-1).
|
|
337
|
+
const fleet = fleetSessionJudge(env, inputDeps.workContextRoot);
|
|
321
338
|
/**
|
|
322
339
|
* The event belongs to a session whose own state holds a verified company
|
|
323
340
|
* binding and, with HQ Anywhere off, is dated from the time it was first
|
|
324
341
|
* seen off.
|
|
325
342
|
*/
|
|
326
|
-
|
|
343
|
+
/**
|
|
344
|
+
* "send": a bound session's event that may go now. "stale": a bound
|
|
345
|
+
* session's event from before the cutoff; with HQ Anywhere off it is parked
|
|
346
|
+
* so it does not stay on the spool (rq_20261121230415_a549af8f50, finding
|
|
347
|
+
* 3). "unbound": anything else.
|
|
348
|
+
*/
|
|
349
|
+
const boundVerdict = (event) => {
|
|
327
350
|
const sessionId = typeof event.sessionId === "string" ? event.sessionId : "";
|
|
328
351
|
if (!sessionId)
|
|
329
|
-
return
|
|
352
|
+
return "unbound";
|
|
330
353
|
let state = bindings.get(sessionId);
|
|
331
354
|
if (state === undefined) {
|
|
332
355
|
state = readSessionState(sessionId, inputDeps.workContextRoot);
|
|
333
356
|
bindings.set(sessionId, state);
|
|
334
357
|
}
|
|
335
|
-
|
|
336
|
-
|
|
358
|
+
// With HQ Anywhere not on, each company seen is checked once per flush,
|
|
359
|
+
// bound or not: a flag that is not on ends that company's enforcement
|
|
360
|
+
// episode, so turning it on again starts a new one.
|
|
361
|
+
const uid = state?.companyUid;
|
|
362
|
+
if (boundOnly && typeof uid === "string" && uid.trim() && !episodesSeen.has(uid)) {
|
|
363
|
+
episodesSeen.add(uid);
|
|
364
|
+
companyReportingRequiredSince(inputDeps.workMeshRoot, uid, readCompanyReportingRequired(uid, env), inputDeps.now ?? (() => new Date()));
|
|
365
|
+
}
|
|
366
|
+
if (!hasWorkMeshCompanyBinding(state, env, inputDeps.workContextRoot, fleet) || !eventMatchesWorkMeshCompany(event, state.companySlug))
|
|
367
|
+
return "unbound";
|
|
337
368
|
if (boundOnly) {
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
369
|
+
const clock = inputDeps.now ?? (() => new Date());
|
|
370
|
+
// A fleet session and a member session of the same company get
|
|
371
|
+
// different cutoffs: only a member session's is the episode start.
|
|
372
|
+
const cutoffKey = backlogCutoffKey(state, fleet);
|
|
373
|
+
let judged = cutoffs.get(cutoffKey);
|
|
374
|
+
if (judged === undefined) {
|
|
375
|
+
// No first-seen-off record is created unless HQ Anywhere is
|
|
376
|
+
// confirmed off and the session is enforced.
|
|
377
|
+
const episode = enforcementEpisode(inputDeps.workMeshRoot, state, env, fleet, clock);
|
|
378
|
+
judged = { cutoff: anywhereBacklogCutoff(inputDeps.workMeshRoot, anywhere, episode.since, clock), gaps: episode.gaps };
|
|
379
|
+
cutoffs.set(cutoffKey, judged);
|
|
380
|
+
}
|
|
381
|
+
if (!aheadLogged) {
|
|
382
|
+
aheadLogged = true;
|
|
383
|
+
const offSinceMs = readAnywhereOffSince(inputDeps.workMeshRoot);
|
|
384
|
+
if (offSinceMs !== null)
|
|
385
|
+
logAnywhereOffSinceAhead(inputDeps.workMeshRoot, offSinceMs, clock().getTime(), inputDeps.log);
|
|
386
|
+
}
|
|
387
|
+
// The person setting is unread and no off was ever recorded: wait.
|
|
388
|
+
if (judged.cutoff === null)
|
|
389
|
+
return "wait";
|
|
390
|
+
if (!eventDatedOutsideGaps(event, judged.cutoff, judged.gaps))
|
|
391
|
+
return "stale";
|
|
343
392
|
}
|
|
344
|
-
return
|
|
393
|
+
return "send";
|
|
345
394
|
};
|
|
395
|
+
const eventOfBoundSession = (event) => boundVerdict(event) === "send";
|
|
346
396
|
const bindingOf = (sessionId) => {
|
|
347
397
|
let state = bindings.get(sessionId);
|
|
348
398
|
if (state === undefined) {
|
|
349
399
|
state = readSessionState(sessionId, inputDeps.workContextRoot);
|
|
350
400
|
bindings.set(sessionId, state);
|
|
351
401
|
}
|
|
352
|
-
return parkedBinding(state, env, inputDeps.workContextRoot);
|
|
402
|
+
return parkedBinding(state, env, inputDeps.workContextRoot, fleet);
|
|
353
403
|
};
|
|
354
404
|
// Parked lines (see workMeshParkedPath) come back as a spool claim: always
|
|
355
405
|
// with HQ Anywhere on, and with it off only when a parked session's company
|
|
@@ -361,8 +411,20 @@ export async function flushSessionEvents(inputDeps) {
|
|
|
361
411
|
const firstBoundOnly = parkingAllowed && !firstBoundOnlyFlushDone.has(inputDeps.workMeshRoot);
|
|
362
412
|
if (parkingAllowed)
|
|
363
413
|
firstBoundOnlyFlushDone.add(inputDeps.workMeshRoot);
|
|
414
|
+
// The first flush in this process that reads a confirmed off after any
|
|
415
|
+
// other answer (or none) also re-reads lines parked while the setting was
|
|
416
|
+
// unread. A daemon that first saw it unread and later off does not wait
|
|
417
|
+
// for a restart.
|
|
418
|
+
const firstOffAfterOther = parkingAllowed && anywhere === "off" &&
|
|
419
|
+
lastAnywhereSeen.get(inputDeps.workMeshRoot) !== "off";
|
|
420
|
+
if (parkingAllowed || anywhere !== "off")
|
|
421
|
+
lastAnywhereSeen.set(inputDeps.workMeshRoot, anywhere);
|
|
364
422
|
const flushStartMs = (inputDeps.now ?? (() => new Date()))().getTime();
|
|
365
|
-
|
|
423
|
+
// With HQ Anywhere confirmed off, lines parked while the setting was unread
|
|
424
|
+
// are read again too, so they lose the unread mark and start their age
|
|
425
|
+
// (rq_20261121230415_a549af8f50; review of #3469, informational 1 and A).
|
|
426
|
+
const expireParked = (firstBoundOnly && oldestParkedLineExpired(inputDeps.workMeshRoot, flushStartMs)) ||
|
|
427
|
+
(firstOffAfterOther && parkedHasUnreadLines(inputDeps.workMeshRoot));
|
|
366
428
|
const reoffered = reofferParkedLines(inputDeps.workMeshRoot, `${flushStartMs}`, boundOnly && !expireParked
|
|
367
429
|
? (index) => Object.entries(index.sessions).some(([sessionId, recorded]) => bindingOf(sessionId) !== recorded)
|
|
368
430
|
: null);
|
|
@@ -379,10 +441,16 @@ export async function flushSessionEvents(inputDeps) {
|
|
|
379
441
|
// spool for every later flush to scan.
|
|
380
442
|
if (boundOnly && listOrphanSpoolClaims(inputDeps.workMeshRoot).length === 0) {
|
|
381
443
|
let any = false;
|
|
444
|
+
// A bound session's line from before the cutoff also counts: it is
|
|
445
|
+
// claimed once and parked, instead of staying on the spool, where it kept
|
|
446
|
+
// `hq daemon doctor` unhealthy.
|
|
382
447
|
const looked = forEachJsonlLineYielding(workMeshSpoolPath(inputDeps.workMeshRoot), (line) => {
|
|
383
448
|
const parsed = parseLine(line);
|
|
384
|
-
if (parsed
|
|
385
|
-
|
|
449
|
+
if (parsed) {
|
|
450
|
+
const verdict = boundVerdict(parsed);
|
|
451
|
+
if (verdict === "send" || verdict === "stale")
|
|
452
|
+
any = true;
|
|
453
|
+
}
|
|
386
454
|
return !any;
|
|
387
455
|
});
|
|
388
456
|
if (typeof looked !== "boolean")
|
|
@@ -572,12 +640,19 @@ export async function flushSessionEvents(inputDeps) {
|
|
|
572
640
|
}
|
|
573
641
|
const nextParkedAt = parkedAtCursor(segments);
|
|
574
642
|
let parkedAt = null;
|
|
643
|
+
let parkedUnread = false;
|
|
575
644
|
let mayDrop = false;
|
|
576
645
|
const reading = forEachJsonlLineYielding(source.claimPath, (line) => {
|
|
577
646
|
if (!line.trim())
|
|
578
647
|
return;
|
|
579
|
-
|
|
580
|
-
|
|
648
|
+
const segment = nextParkedAt();
|
|
649
|
+
parkedAt = segment?.parkedAt ?? null;
|
|
650
|
+
parkedUnread = segment?.unread === true;
|
|
651
|
+
// Lines are dropped for age only while HQ Anywhere is confirmed off,
|
|
652
|
+
// and never lines parked while the person setting was unread: those
|
|
653
|
+
// are a member's events waiting for the setting, not an opt-out's
|
|
654
|
+
// backlog (rq_20261121230415_a549af8f50; review-daemon-r3 probe W).
|
|
655
|
+
mayDrop = parkedSource && !clockBehind && parkedAt !== null && !parkedUnread && anywhere === "off";
|
|
581
656
|
if (source.observe && deps.onSpoolLinesClaimed) {
|
|
582
657
|
observed.push(line);
|
|
583
658
|
if (observed.length >= OBSERVER_BATCH_LINES)
|
|
@@ -595,7 +670,8 @@ export async function flushSessionEvents(inputDeps) {
|
|
|
595
670
|
if (seenEventIds.size < dedupeMaxIds)
|
|
596
671
|
seenEventIds.add(eventId);
|
|
597
672
|
}
|
|
598
|
-
|
|
673
|
+
const verdict = boundOnly && parsed ? boundVerdict(parsed) : "unbound";
|
|
674
|
+
if (boundOnly && verdict !== "send") {
|
|
599
675
|
const parkedAtMs = parkedAt === null ? Number.NaN : Date.parse(parkedAt);
|
|
600
676
|
if (mayDrop && nowMs - parkedAtMs > PARKED_LINE_MAX_AGE_MS) {
|
|
601
677
|
// Read back from the parked file and parked longer ago than the
|
|
@@ -605,7 +681,14 @@ export async function flushSessionEvents(inputDeps) {
|
|
|
605
681
|
return;
|
|
606
682
|
}
|
|
607
683
|
if (parkedOut) {
|
|
608
|
-
|
|
684
|
+
// A line parked while the setting was unread keeps that mark only
|
|
685
|
+
// while it stays unread. Once off is confirmed, the mark goes and
|
|
686
|
+
// its age starts now, never from when it was first parked, so it
|
|
687
|
+
// is not dropped early and does not stay on disk for good.
|
|
688
|
+
const confirmedOff = anywhere === "off";
|
|
689
|
+
const unreadNow = !confirmedOff && (parkedUnread || verdict === "wait");
|
|
690
|
+
const parkedSince = parkedUnread && confirmedOff ? flushNowIso : (parkedAt ?? flushNowIso);
|
|
691
|
+
parkedOut.push(line, parsed ? sessionIdOf(parsed) : null, parkedSince, unreadNow);
|
|
609
692
|
summary.parked = (summary.parked ?? 0) + 1;
|
|
610
693
|
}
|
|
611
694
|
else {
|
|
@@ -677,7 +760,7 @@ export async function flushSessionEvents(inputDeps) {
|
|
|
677
760
|
// Mesh switch is set, or HQ Anywhere is off), the repair is for those
|
|
678
761
|
// sessions alone: it must not write a binding into another session's state.
|
|
679
762
|
const repairFor = boundOnly || meshDisabled
|
|
680
|
-
? [...bySession.keys()].filter(sessionId => hasWorkMeshCompanyBinding(readSessionState(sessionId, deps.workContextRoot), env, deps.workContextRoot))
|
|
763
|
+
? [...bySession.keys()].filter(sessionId => hasWorkMeshCompanyBinding(readSessionState(sessionId, deps.workContextRoot), env, deps.workContextRoot, fleet))
|
|
681
764
|
: [...bySession.keys()];
|
|
682
765
|
repairAckedRegisterStates(deps.workContextRoot, new Set(repairFor), now);
|
|
683
766
|
const markDisposed = (event) => {
|
|
@@ -692,13 +775,13 @@ export async function flushSessionEvents(inputDeps) {
|
|
|
692
775
|
// Bound-only: a session without a verified company binding is not
|
|
693
776
|
// touched. Its events are not sent, held or dropped and its state is
|
|
694
777
|
// not rebound; they go back to the spool (finally block).
|
|
695
|
-
if (boundOnly && !hasWorkMeshCompanyBinding(state, env, deps.workContextRoot))
|
|
778
|
+
if (boundOnly && !hasWorkMeshCompanyBinding(state, env, deps.workContextRoot, fleet))
|
|
696
779
|
continue;
|
|
697
780
|
state = applySessionMetaCompanyRebind(sessionId, sessionItems, state, deps, now);
|
|
698
781
|
let items = sessionItems;
|
|
699
782
|
if (boundOnly) {
|
|
700
783
|
const binding = state;
|
|
701
|
-
if (!hasWorkMeshCompanyBinding(binding, env, deps.workContextRoot))
|
|
784
|
+
if (!hasWorkMeshCompanyBinding(binding, env, deps.workContextRoot, fleet))
|
|
702
785
|
continue;
|
|
703
786
|
items = sessionItems.filter(item => eventMatchesWorkMeshCompany(item.event, binding.companySlug));
|
|
704
787
|
if (items.length === 0)
|
|
@@ -707,7 +790,7 @@ export async function flushSessionEvents(inputDeps) {
|
|
|
707
790
|
else if (meshDisabled) {
|
|
708
791
|
const binding = state;
|
|
709
792
|
items = sessionItems.filter(item => {
|
|
710
|
-
if (hasWorkMeshCompanyBinding(binding, env, deps.workContextRoot) && eventMatchesWorkMeshCompany(item.event, binding.companySlug))
|
|
793
|
+
if (hasWorkMeshCompanyBinding(binding, env, deps.workContextRoot, fleet) && eventMatchesWorkMeshCompany(item.event, binding.companySlug))
|
|
711
794
|
return true;
|
|
712
795
|
summary.dropped += 1;
|
|
713
796
|
markDisposed(item.event);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Session liveness that outlives the spool.
|
|
3
3
|
*
|
|
4
|
-
* `hq
|
|
4
|
+
* `hq runners` reads the last event of each session from spool.jsonl. Once the
|
|
5
5
|
* direct-mode drain delivers spool lines and removes them, that record would
|
|
6
6
|
* be gone, so the drain first copies the last event per session here: kind,
|
|
7
7
|
* time and sequence number only, never the event body. Lanes merges this file
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Session liveness that outlives the spool.
|
|
3
3
|
*
|
|
4
|
-
* `hq
|
|
4
|
+
* `hq runners` reads the last event of each session from spool.jsonl. Once the
|
|
5
5
|
* direct-mode drain delivers spool lines and removes them, that record would
|
|
6
6
|
* be gone, so the drain first copies the last event per session here: kind,
|
|
7
7
|
* time and sequence number only, never the event body. Lanes merges this file
|