@bli-cockpit/telemetry-core 0.1.49 → 0.1.50

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.
@@ -55,6 +55,56 @@ export declare const MEMORY_DAEMON_CONNECT_TIMEOUT_MS = 50;
55
55
  export declare const MEMORY_DAEMON_SPAWN_INTERVAL_MS = 3600000;
56
56
  /** The daemon exits after this long with no request. Two hours. */
57
57
  export declare const MEMORY_DAEMON_IDLE_EXIT_MS = 7200000;
58
+ /**
59
+ * How long the daemon's OUTBOUND connection to Tower is allowed to sit idle
60
+ * before this process's OWN dispatcher considers reusing it stale (BLI-10741).
61
+ *
62
+ * The daemon existing was never the whole promise — BLI-3884's docstring
63
+ * calls a warm connection out by name, and structurally it never landed:
64
+ * Node's BUILT-IN global `fetch` does not read the external `undici`
65
+ * package's `setGlobalDispatcher` at all. Verified live against this build
66
+ * (`node@26.8.1`, `undici@6.28.1` in `node_modules`): installing a custom
67
+ * `Agent` as the global dispatcher and then calling the ordinary global
68
+ * `fetch()` left three real `/api/memory/search` calls, spaced 6 s apart,
69
+ * exactly as slow as an unmodified run (569 / 523 / 546 ms — cold every
70
+ * time). So whatever pooling the daemon's `fetch()` calls were doing, this
71
+ * package had NO way to see it, tune it, or even confirm it was happening —
72
+ * `warm-fetch.ts` exists to give the daemon a connection it actually
73
+ * controls, over `undici`'s own `fetch` export with an explicit `dispatcher`,
74
+ * which a local test proves reuses one socket across an idle gap
75
+ * (`warm-fetch.test.ts`).
76
+ *
77
+ * The value is sized off two measurements, not guessed. 578 real gaps
78
+ * between one prompt-hook call and the next on Edward's own machine
79
+ * (`~/.local/state/bli-cockpit/memory-hook-samples`, 2026-09-24 to
80
+ * 2026-09-28) put only 9.2% of them under undici's own 4,000 ms default;
81
+ * 120,000 ms (two minutes) covers 76.6% of the same gaps — most of a working
82
+ * session's back-and-forth — while staying inside what ordinary HTTP/1.1
83
+ * reverse proxies keep an idle keep-alive connection open for; past that,
84
+ * the gain per extra second shrinks fast (300,000 ms only reaches 90.3%)
85
+ * against a growing chance the far end has already dropped the socket
86
+ * anyway. `docs/architecture/agent-memory.md` (BLI-10741) carries the
87
+ * end-to-end replay this sizing was checked against: 50 real recent prompt
88
+ * strings from this machine's own transcripts, run through the real search
89
+ * door with the hook's own 2,000 ms request deadline, once with a fresh
90
+ * dispatcher per call (the daemon's old, uncontrolled shape) and once
91
+ * through one shared warm dispatcher (this fix) — timeouts before and after,
92
+ * same measurement.
93
+ *
94
+ * A connection this process believed was warm and was not is never a hang: a
95
+ * write to a socket the far end already closed fails fast or the request
96
+ * simply opens a new one, and either way the hook's own per-request
97
+ * `AbortController` (`HOOK_BUDGETS`) still bounds the wait. Raising this
98
+ * number can only ever save time, never cost more of it than today.
99
+ */
100
+ export declare const MEMORY_DAEMON_KEEPALIVE_TIMEOUT_MS = 120000;
101
+ /**
102
+ * The absolute cap on one connection's life, warm or not — undici's own
103
+ * `keepAliveMaxTimeout`. Left far above the idle timeout above so the idle
104
+ * rule is always what actually retires a connection; it exists at all so a
105
+ * connection cannot be held open forever by a daemon that never goes idle.
106
+ */
107
+ export declare const MEMORY_DAEMON_KEEPALIVE_MAX_TIMEOUT_MS = 600000;
58
108
  /**
59
109
  * How long a unix socket PATH may be, in bytes, before the platform refuses to
60
110
  * bind it. `sun_path` is 104 on macOS/BSD and 108 on Linux; 100 is the safe
@@ -56,6 +56,56 @@ export const MEMORY_DAEMON_CONNECT_TIMEOUT_MS = 50;
56
56
  export const MEMORY_DAEMON_SPAWN_INTERVAL_MS = 3_600_000;
57
57
  /** The daemon exits after this long with no request. Two hours. */
58
58
  export const MEMORY_DAEMON_IDLE_EXIT_MS = 7_200_000;
59
+ /**
60
+ * How long the daemon's OUTBOUND connection to Tower is allowed to sit idle
61
+ * before this process's OWN dispatcher considers reusing it stale (BLI-10741).
62
+ *
63
+ * The daemon existing was never the whole promise — BLI-3884's docstring
64
+ * calls a warm connection out by name, and structurally it never landed:
65
+ * Node's BUILT-IN global `fetch` does not read the external `undici`
66
+ * package's `setGlobalDispatcher` at all. Verified live against this build
67
+ * (`node@26.8.1`, `undici@6.28.1` in `node_modules`): installing a custom
68
+ * `Agent` as the global dispatcher and then calling the ordinary global
69
+ * `fetch()` left three real `/api/memory/search` calls, spaced 6 s apart,
70
+ * exactly as slow as an unmodified run (569 / 523 / 546 ms — cold every
71
+ * time). So whatever pooling the daemon's `fetch()` calls were doing, this
72
+ * package had NO way to see it, tune it, or even confirm it was happening —
73
+ * `warm-fetch.ts` exists to give the daemon a connection it actually
74
+ * controls, over `undici`'s own `fetch` export with an explicit `dispatcher`,
75
+ * which a local test proves reuses one socket across an idle gap
76
+ * (`warm-fetch.test.ts`).
77
+ *
78
+ * The value is sized off two measurements, not guessed. 578 real gaps
79
+ * between one prompt-hook call and the next on Edward's own machine
80
+ * (`~/.local/state/bli-cockpit/memory-hook-samples`, 2026-09-24 to
81
+ * 2026-09-28) put only 9.2% of them under undici's own 4,000 ms default;
82
+ * 120,000 ms (two minutes) covers 76.6% of the same gaps — most of a working
83
+ * session's back-and-forth — while staying inside what ordinary HTTP/1.1
84
+ * reverse proxies keep an idle keep-alive connection open for; past that,
85
+ * the gain per extra second shrinks fast (300,000 ms only reaches 90.3%)
86
+ * against a growing chance the far end has already dropped the socket
87
+ * anyway. `docs/architecture/agent-memory.md` (BLI-10741) carries the
88
+ * end-to-end replay this sizing was checked against: 50 real recent prompt
89
+ * strings from this machine's own transcripts, run through the real search
90
+ * door with the hook's own 2,000 ms request deadline, once with a fresh
91
+ * dispatcher per call (the daemon's old, uncontrolled shape) and once
92
+ * through one shared warm dispatcher (this fix) — timeouts before and after,
93
+ * same measurement.
94
+ *
95
+ * A connection this process believed was warm and was not is never a hang: a
96
+ * write to a socket the far end already closed fails fast or the request
97
+ * simply opens a new one, and either way the hook's own per-request
98
+ * `AbortController` (`HOOK_BUDGETS`) still bounds the wait. Raising this
99
+ * number can only ever save time, never cost more of it than today.
100
+ */
101
+ export const MEMORY_DAEMON_KEEPALIVE_TIMEOUT_MS = 120_000;
102
+ /**
103
+ * The absolute cap on one connection's life, warm or not — undici's own
104
+ * `keepAliveMaxTimeout`. Left far above the idle timeout above so the idle
105
+ * rule is always what actually retires a connection; it exists at all so a
106
+ * connection cannot be held open forever by a daemon that never goes idle.
107
+ */
108
+ export const MEMORY_DAEMON_KEEPALIVE_MAX_TIMEOUT_MS = 600_000;
59
109
  /**
60
110
  * How long a unix socket PATH may be, in bytes, before the platform refuses to
61
111
  * bind it. `sun_path` is 104 on macOS/BSD and 108 on Linux; 100 is the safe
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bli-cockpit/telemetry-core",
3
- "version": "0.1.49",
3
+ "version": "0.1.50",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",