@north-light/cli 0.3.716 → 0.3.718
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/node-transport.js +1 -1
- package/dist/builtin-memory/internal/nodes-and-canvas.md +2 -2
- package/dist/clients/attach/viewer.js +251 -251
- package/dist/core/conversation-store/client-worker.js +1 -1
- package/dist/core/grants/mirror.d.ts +3 -1
- package/dist/core/grants/mirror.js +3 -3
- package/dist/core/llm/breaker.d.ts +9 -0
- package/dist/core/llm/breaker.js +1 -0
- package/dist/core/runtime/bearings.d.ts +4 -1
- package/dist/core/runtime/bearings.js +7 -7
- package/dist/core/runtime/broker/cli-relay.js +1 -1
- package/dist/core/runtime/broker/fault-retry.d.ts +4 -1
- package/dist/core/runtime/broker/fault-retry.js +1 -1
- package/dist/core/runtime/broker/model-adapter.d.ts +9 -0
- package/dist/core/runtime/broker/model-adapter.js +3 -3
- package/dist/core/runtime/broker.js +1 -1
- package/dist/core/runtime/connectivity.d.ts +1 -2
- package/dist/core/runtime/deliver-live.js +1 -1
- package/dist/core/runtime/fault-recovery.d.ts +0 -3
- package/dist/core/runtime/fault-recovery.js +1 -1
- package/dist/core/substrate/delivery/deliver.d.ts +5 -0
- package/dist/core/substrate/delivery/deliver.js +3 -3
- package/dist/daemon/api/handlers/broker-ops.js +1 -1
- package/dist/daemon/api/handlers/delivery.js +1 -1
- package/dist/daemon/api/handlers/health.js +3 -3
- package/dist/daemon/api/handlers/llm.js +3 -3
- package/dist/daemon/reconcilers/fault-retry-backstop.d.ts +2 -4
- package/dist/daemon/reconcilers/fault-retry-backstop.js +1 -1
- package/package.json +3 -3
- package/packages/crouter-api/dist/api/node-transport.js +5 -1
- package/packages/crouter-api/dist/clients/attach/viewer.js +10 -0
- package/packages/crouter-api/dist/core/grants/mirror.js +11 -6
- package/packages/crouter-api/dist/core/runtime/bearings.js +10 -4
- package/packages/crouter-api/dist/core/runtime/broker/model-adapter.js +12 -3
- package/packages/crouter-api/dist/core/runtime/deliver-live.js +3 -2
- package/packages/crouter-api/dist/core/runtime/fault-recovery.js +11 -22
- package/packages/crouter-api/dist/core/substrate/delivery/deliver.js +12 -2
- package/packages/crouter-api/dist/daemon/api/handlers/broker-ops.js +13 -12
- package/packages/crouter-api/package.json +1 -1
- package/packages/crouter-identity/package.json +1 -1
- package/packages/crouter-plugin/package.json +3 -3
- package/runtime.lock.json +14 -14
|
@@ -1 +1 @@
|
|
|
1
|
-
var y=Object.defineProperty;var
|
|
1
|
+
var y=Object.defineProperty;var d=(i,t)=>y(i,"name",{value:t,configurable:!0});import{filterAsync as w}from"../../core/async-array.js";import{openDb as h,withCanvasWrite as A}from"../../core/canvas/db.js";import{getNode as I}from"../../core/canvas/canvas.js";import{liveExecutionForNode as k}from"../../core/canvas/executions.js";import{claimFaultNudge as v,listPendingProviderRetries as b,readLiveTurn as g}from"../../core/canvas/recovery.js";import{nextFaultRetry as E}from"../../core/runtime/fault-recovery.js";import{emitEvent as l}from"../../core/events/emit.js";import{operationIdContext as f}from"../../core/events/operation-id.js";import{isSafeNodeId as p}from"../../core/canvas/paths.js";import{runThrottledLane as N}from"./throttled-lane.js";import{asNodePerson as R}from"./node-lifecycle/node-person.js";import{wakeResident as L}from"./node-lifecycle/remote-wake.js";const u=2*6e4,S=15e3;function m(i){const{fault:t}=i;if(t.retry.nextAt!==void 0){const a=Date.parse(t.retry.nextAt);return Number.isFinite(a)?a:null}const n=Date.parse(i.updatedAt),o=E(t,n);return Number.isFinite(n)&&o!==null?n+o.delayMs:null}d(m,"dueAtMs");const T=6e4,F="fault-retry-backstop";class z{static{d(this,"FaultRetryBackstopReconciler")}deps;constructor(t={}){this.deps=t}run(t,n){if(!n.lifecycle.acceptsDetachedWork())return Promise.resolve();const o=N(F,"",t,S,T,()=>this.scan(t,n)).then(()=>{}).catch(a=>{f.fresh(()=>{l({level:"warn",event:"fault_retry_backstop.scan_failed",error:a})})});return n.lifecycle.registerDetached(o),o}async scan(t,n){const o=await(this.deps.list??b)(),a=this.deps.busy??(async e=>(await g(e))?.busy===!0),c=await w(o,async e=>{if(!await n.fleet.has(e.nodeId)||await a(e.nodeId))return!1;const r=m(e);return r===null||t<r+u?!1:e.nudgedAt===null||t-Date.parse(e.nudgedAt)>=u});if(c.length!==0)for(const e of c){if(!await n.fleet.has(e.nodeId)||await a(e.nodeId)||!await A(async()=>await v(e.fault.faultId,t,u)))continue;const r=await k(e.nodeId),s=r!==null&&r.runner!=="process"&&r.state==="running"?await I(e.nodeId):null;(r===null||s===null?"woken":await R({node_id:s.node_id,sub:s.sub??null,profile_id:s.profile_id??null},()=>L(r)).catch(_=>(l({level:"warn",event:"fault_retry_backstop.wake_failed",...p(e.nodeId)?{node_id:e.nodeId}:{},error:_}),null)))!=="lost"&&(await(await h()).prepare("SELECT pg_notify(?, ?)").get("crtr_signal",`fault_retry:${e.nodeId}`),f.fresh(()=>{l({level:"info",event:"fault_retry_backstop.nudged",...p(e.nodeId)?{node_id:e.nodeId}:{},fields:{kind:e.fault.kind,since:e.fault.since,overdue_ms:t-(m(e)??t)}})}))}}}export{S as FAULT_RETRY_SCAN_INTERVAL_MS,u as FAULT_RETRY_STALE_GRACE_MS,z as FaultRetryBackstopReconciler,m as dueAtMs};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@north-light/cli",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.718",
|
|
4
4
|
"description": "crtr — agent runtime with memory, plugins, and marketplaces",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -158,8 +158,8 @@
|
|
|
158
158
|
},
|
|
159
159
|
"license": "UNLICENSED",
|
|
160
160
|
"dependencies": {
|
|
161
|
-
"@north-light/identity": "0.3.
|
|
162
|
-
"@north-light/plugin": "0.3.
|
|
161
|
+
"@north-light/identity": "0.3.718",
|
|
162
|
+
"@north-light/plugin": "0.3.718",
|
|
163
163
|
"@earendil-works/chord": "1.5.2",
|
|
164
164
|
"@earendil-works/pi-agent-core": "1.5.2",
|
|
165
165
|
"@earendil-works/pi-ai": "1.5.2",
|
|
@@ -50,7 +50,11 @@ export function socketFetch(socketPath) {
|
|
|
50
50
|
if (payload !== undefined)
|
|
51
51
|
headers['content-length'] = String(Buffer.byteLength(payload));
|
|
52
52
|
return new Promise((resolvePromise, reject) => {
|
|
53
|
-
|
|
53
|
+
// `agent: false` = a private connection per request. The global agent pools sockets, and crtrd closes an idle one at its
|
|
54
|
+
// `keepAliveTimeout` without reading what is already written to it, so a POST landing on a socket the daemon is closing
|
|
55
|
+
// resets (ECONNRESET) and, being a mutation, is never replayed: `daemon_request_interrupted`. A fresh unix-socket connect
|
|
56
|
+
// costs microseconds; no pooled socket means no window. Every client of api.sock must do the same.
|
|
57
|
+
const req = httpRequest({ socketPath, path: url.pathname + url.search, method, headers, agent: false }, (res) => {
|
|
54
58
|
const body = new ReadableStream({
|
|
55
59
|
start(controller) {
|
|
56
60
|
res.on('data', (chunk) => controller.enqueue(new Uint8Array(chunk)));
|
|
@@ -627,6 +627,16 @@ onConnected) {
|
|
|
627
627
|
// The release selected on this machine, never the daemon's: a signed-in viewer's status call is answered by the server.
|
|
628
628
|
const selected = selectedGeneration().generation?.id;
|
|
629
629
|
if (mine !== undefined && selected !== undefined && selected !== mine && selected !== restartedFor && !lifecycle.isTornDown()) {
|
|
630
|
+
// The new process reads the account's settings before it paints and exits when it cannot. A welcome right after the computer
|
|
631
|
+
// wakes can come before its network does, so make that request first and leave the restart to a later welcome if it fails.
|
|
632
|
+
try {
|
|
633
|
+
await cliClient({ timeoutMs: 5_000 }).getSettings();
|
|
634
|
+
}
|
|
635
|
+
catch {
|
|
636
|
+
return;
|
|
637
|
+
}
|
|
638
|
+
if (lifecycle.isTornDown())
|
|
639
|
+
return;
|
|
630
640
|
restartViewer({ CRTR_ATTACH_RESTARTED_FOR: selected });
|
|
631
641
|
}
|
|
632
642
|
};
|
|
@@ -398,19 +398,24 @@ export async function dropLocalGrantMirror(db) {
|
|
|
398
398
|
export async function backfillComputedRev() {
|
|
399
399
|
return await withCanvasWrite(async (db) => Number((await db.prepare('UPDATE grants SET computed_rev = rev WHERE computed_rev IS NULL AND scopes_json IS NOT NULL AND resolved_scopes_json IS NOT NULL').run()).changes));
|
|
400
400
|
}
|
|
401
|
-
/** The `teams` a grant sync answer carried; absent (an unjoined install, an older directory) reads as none.
|
|
401
|
+
/** The `teams` a grant sync answer carried; absent (an unjoined install, an older directory) reads as none. Team
|
|
402
|
+
* membership is advisory next to the grants the same answer carries, so an entry that is not a directory team
|
|
403
|
+
* (`team:<id>`, e.g. a canvas group row echoed back) is dropped rather than failing the sync. */
|
|
402
404
|
export function teamsOf(value) {
|
|
403
405
|
if (value === undefined)
|
|
404
406
|
return [];
|
|
405
407
|
if (!Array.isArray(value))
|
|
406
408
|
throw new TypeError('invalid grant sync response');
|
|
407
|
-
|
|
409
|
+
const teams = [];
|
|
410
|
+
for (const entry of value) {
|
|
408
411
|
const { team, members } = (entry ?? {});
|
|
409
|
-
if (typeof team !== 'string' || !/^team:\S+$/.test(team)
|
|
410
|
-
|
|
412
|
+
if (typeof team !== 'string' || !/^team:\S+$/.test(team))
|
|
413
|
+
continue;
|
|
414
|
+
if (!Array.isArray(members) || members.some((member) => typeof member !== 'string' || !/^user:[^\s*]+$/.test(member)))
|
|
411
415
|
throw new TypeError('invalid grant sync response');
|
|
412
|
-
|
|
413
|
-
}
|
|
416
|
+
teams.push({ team, members });
|
|
417
|
+
}
|
|
418
|
+
return teams;
|
|
414
419
|
}
|
|
415
420
|
/** Replace the mirror with `grants` and the `written_by = 'directory'` team `member` facts with `teams`, in one transaction. The
|
|
416
421
|
* ledger's `grant:<id>` limit rows follow from the `grants` trigger `crtr_grant_limit` (schema delta 002). */
|
|
@@ -160,7 +160,7 @@ function managedWorktreeNote(node) {
|
|
|
160
160
|
* AGENTS.md/CLAUDE.md injection stays suppressed (`noContextFiles` in
|
|
161
161
|
* broker.ts); `crtr sys sync project-guidance` imports that guidance into
|
|
162
162
|
* documents owned by the directory's repo (its `<repo>/index` is the workspace front door). */
|
|
163
|
-
async function bearingsShell(nodeId, knowledge, workspaceContext) {
|
|
163
|
+
async function bearingsShell(nodeId, knowledge, workspaceContext, projectCtx) {
|
|
164
164
|
const node = await getNode(nodeId);
|
|
165
165
|
const execution = await latestExecutionForNode(nodeId);
|
|
166
166
|
const bearings = ['<crtr-bearings>', await buildIdentityAssertion(nodeId, node)];
|
|
@@ -187,16 +187,22 @@ async function bearingsShell(nodeId, knowledge, workspaceContext) {
|
|
|
187
187
|
// nested card inside the outer envelope. Never routed through the visible
|
|
188
188
|
// chat/digest path. '' when nothing was ever set.
|
|
189
189
|
const situational = await situationalContextEnvelope(nodeId) ?? '';
|
|
190
|
-
const projectCtx = node?.cwd !== undefined && execution?.runner === 'process' ? buildProjectContextBlock(node.cwd) : ''; // reads this host
|
|
191
190
|
return [bearings.join('\n'), knowledge, workspaceContext, situational, projectCtx]
|
|
192
191
|
.filter((s) => s !== '')
|
|
193
192
|
.join('\n');
|
|
194
193
|
}
|
|
194
|
+
/** The `<project_context>` snapshot of the node's cwd: it spawns git and tmux and reads this host's disk, so a caller builds it BEFORE
|
|
195
|
+
* opening the delivery transaction and passes it in as `projectContext`; '' when the node's engine does not run on this host. */
|
|
196
|
+
export async function projectContextForNode(nodeId) {
|
|
197
|
+
const node = await getNode(nodeId);
|
|
198
|
+
const execution = await latestExecutionForNode(nodeId);
|
|
199
|
+
return node?.cwd !== undefined && execution?.runner === 'process' ? buildProjectContextBlock(node.cwd) : '';
|
|
200
|
+
}
|
|
195
201
|
/** The bearings on the row-backed delivery engine: the knowledge catalog and
|
|
196
202
|
* the workspace-open documents render against `ctx`'s ledger; `delivered`
|
|
197
203
|
* lists what they delivered, for the caller to record. */
|
|
198
|
-
export async function buildContextBearings(nodeId, ctx) {
|
|
204
|
+
export async function buildContextBearings(nodeId, ctx, projectContext) {
|
|
199
205
|
const knowledge = await renderKnowledge(ctx);
|
|
200
206
|
const workspace = await renderWorkspaceOpen(ctx);
|
|
201
|
-
return { content: await bearingsShell(nodeId, knowledge.content, workspace.content), delivered: [...knowledge.delivered, ...workspace.delivered] };
|
|
207
|
+
return { content: await bearingsShell(nodeId, knowledge.content, workspace.content, projectContext), delivered: [...knowledge.delivered, ...workspace.delivered] };
|
|
202
208
|
}
|
|
@@ -197,6 +197,14 @@ function llmUrl() {
|
|
|
197
197
|
function llmFetch() {
|
|
198
198
|
return brokerApiUrl() === undefined ? socketFetch(apiSocketPath()) : globalThis.fetch;
|
|
199
199
|
}
|
|
200
|
+
/** Before a retry, ask this broker's own gateway whether it can serve `model` now (`GET /healthz?model=`); no wait means no answer. */
|
|
201
|
+
export async function askGateway(model) {
|
|
202
|
+
const response = await llmFetch()(llmUrl().replace(/\/v1\/llm$/, `/healthz?model=${encodeURIComponent(model)}`), { signal: AbortSignal.timeout(5_000) }).catch(() => null);
|
|
203
|
+
if (response?.status === 200)
|
|
204
|
+
return { ok: true };
|
|
205
|
+
const seconds = response?.status === 503 ? (await response.json().catch(() => null))?.error?.retry_after_s : undefined;
|
|
206
|
+
return typeof seconds === 'number' ? { ok: false, waitMs: seconds * 1000, reason: `waiting for ${model}: model unavailable` } : { ok: false, reason: `waiting for ${model}: gateway not answering` };
|
|
207
|
+
}
|
|
200
208
|
/** The real response under a deferred-head framing (`daemon/api/deferred-head.ts`): the magic line, keep-alive
|
|
201
209
|
* blank lines, one JSON head line, then the body unchanged. Any other response is returned as it is. */
|
|
202
210
|
export async function unwrapDeferredHead(response) {
|
|
@@ -304,7 +312,7 @@ export function streamBrokerModel(model, context, options = {}, intent, causedBy
|
|
|
304
312
|
// stamping it as a refusal would record it as fatal and park the node.
|
|
305
313
|
if (typeof seconds !== 'number' || !Number.isFinite(seconds) || seconds <= 0) {
|
|
306
314
|
// Named by code, not prose: `upstream_model_unavailable` is a connection fault with automatic retry (RT-LLM-65).
|
|
307
|
-
throw error.code === UPSTREAM_MODEL_UNAVAILABLE ? new UpstreamModelUnavailableError(error.message) : new Error(error.message);
|
|
315
|
+
throw error.code === UPSTREAM_MODEL_UNAVAILABLE ? new UpstreamModelUnavailableError(error.message, { cause: error.details?.breaker }) : new Error(error.message);
|
|
308
316
|
}
|
|
309
317
|
// A wait that outlasts what is left of the retry window cannot end in a
|
|
310
318
|
// retry here, so sleeping first only delays the same failure. Fail now
|
|
@@ -337,7 +345,7 @@ export function streamBrokerModel(model, context, options = {}, intent, causedBy
|
|
|
337
345
|
applyServedModel(message, refusalRoute(error));
|
|
338
346
|
if (error.retryable !== true)
|
|
339
347
|
throw new LlmRefusalError(error.message, undefined, refusalRateLimit(error), error.code, undefined, refusalPayment(error));
|
|
340
|
-
throw error.code === UPSTREAM_MODEL_UNAVAILABLE ? new UpstreamModelUnavailableError(error.message) : new Error(error.message);
|
|
348
|
+
throw error.code === UPSTREAM_MODEL_UNAVAILABLE ? new UpstreamModelUnavailableError(error.message, { cause: error.details?.breaker }) : new Error(error.message);
|
|
341
349
|
}
|
|
342
350
|
if (chunk.served_model) {
|
|
343
351
|
receivedServedModel = true;
|
|
@@ -431,8 +439,9 @@ export function streamBrokerModel(model, context, options = {}, intent, causedBy
|
|
|
431
439
|
: []),
|
|
432
440
|
];
|
|
433
441
|
}
|
|
442
|
+
// A breaker mark (`open` or `test`) tells the fault retry not to count this attempt.
|
|
434
443
|
if (error instanceof UpstreamModelUnavailableError)
|
|
435
|
-
message.diagnostics = [providerFailureDiagnostic({ status: 503, code: UPSTREAM_MODEL_UNAVAILABLE })];
|
|
444
|
+
message.diagnostics = [providerFailureDiagnostic({ status: 503, code: UPSTREAM_MODEL_UNAVAILABLE, ...(error.cause === undefined ? {} : { body: 'breaker' }) })];
|
|
436
445
|
if (error instanceof ContentFilteredError && message.stopReason === 'error')
|
|
437
446
|
message.rawStopReason = 'content_filter';
|
|
438
447
|
stream.push({ type: 'error', reason: message.stopReason, error: message });
|
|
@@ -21,7 +21,7 @@ import { getNode } from '../canvas/index.js';
|
|
|
21
21
|
import { openDb, withCanvasWrite } from '../canvas/db.js';
|
|
22
22
|
import { readerForNode, warmNodeRepos } from '../graph/reader.js';
|
|
23
23
|
import { checkoutsForCwd } from '../graph/repo-sync/repos.js';
|
|
24
|
-
import { deliver } from '../substrate/delivery/deliver.js';
|
|
24
|
+
import { deliver, withProjectContext } from '../substrate/delivery/deliver.js';
|
|
25
25
|
import { oneShotControllerRequest } from './broker-request.js';
|
|
26
26
|
import { isBrokerLive } from './model-swap.js';
|
|
27
27
|
import { CONTEXT_INTRO_CUSTOM_TYPE } from './bearings.js';
|
|
@@ -75,7 +75,8 @@ export async function deliverBearingsLive(nodeId) {
|
|
|
75
75
|
// The boot delivery clears and rewrites the ledger and freezes preferences in
|
|
76
76
|
// one transaction before Pi receives the bearings.
|
|
77
77
|
await warmNodeRepos(await openDb(), nodeId);
|
|
78
|
-
const
|
|
78
|
+
const request = await withProjectContext(nodeId, { activity: 'boot' });
|
|
79
|
+
const { content } = await withCanvasWrite(async (db) => await deliver(db, await readerForNode(db, nodeId, async (cwd, person, access) => await checkoutsForCwd(db, cwd, person, access)), request));
|
|
79
80
|
await deliverCustomMessageLive(nodeId, {
|
|
80
81
|
customType: CONTEXT_INTRO_CUSTOM_TYPE,
|
|
81
82
|
content: formatCard('bearings', {}, content),
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
const POLICIES = {
|
|
2
|
-
connection: { kind: 'connection',
|
|
3
|
-
'rate-limit': { kind: 'rate-limit',
|
|
4
|
-
overloaded: { kind: 'overloaded',
|
|
5
|
-
auth: { kind: 'auth',
|
|
6
|
-
protocol: { kind: 'protocol',
|
|
7
|
-
'context-overflow': { kind: 'context-overflow',
|
|
8
|
-
other: { kind: 'other',
|
|
2
|
+
connection: { kind: 'connection', max: 8, baseDelayMs: 5_000, capDelayMs: 60_000, fatal: false },
|
|
3
|
+
'rate-limit': { kind: 'rate-limit', max: 6, baseDelayMs: 30_000, capDelayMs: 5 * 60_000, fatal: false },
|
|
4
|
+
overloaded: { kind: 'overloaded', max: 6, baseDelayMs: 10_000, capDelayMs: 2 * 60_000, fatal: false },
|
|
5
|
+
auth: { kind: 'auth', max: 0, baseDelayMs: 0, capDelayMs: 0, fatal: true },
|
|
6
|
+
protocol: { kind: 'protocol', max: 0, baseDelayMs: 0, capDelayMs: 0, fatal: true },
|
|
7
|
+
'context-overflow': { kind: 'context-overflow', max: 0, baseDelayMs: 0, capDelayMs: 0, fatal: true },
|
|
8
|
+
other: { kind: 'other', max: 0, baseDelayMs: 0, capDelayMs: 0, fatal: true },
|
|
9
9
|
// A wedge is a daemon-detected stall, never auto-retried — recovery is a
|
|
10
10
|
// deliberate agent/operator decision (kill the runaway subprocess), not a
|
|
11
11
|
// provider back-off.
|
|
12
|
-
wedged: { kind: 'wedged',
|
|
12
|
+
wedged: { kind: 'wedged', max: 0, baseDelayMs: 0, capDelayMs: 0, fatal: true },
|
|
13
13
|
// A launch-time model resolution failure (unregistered/unauthenticated spec) —
|
|
14
14
|
// never auto-retried, since retrying with the same unresolved model would just
|
|
15
15
|
// fail again identically. Fixing it requires a new --model or new credentials.
|
|
16
|
-
'model-not-found': { kind: 'model-not-found',
|
|
16
|
+
'model-not-found': { kind: 'model-not-found', max: 0, baseDelayMs: 0, capDelayMs: 0, fatal: true },
|
|
17
17
|
};
|
|
18
18
|
export function policyFor(kind) {
|
|
19
19
|
return POLICIES[kind];
|
|
@@ -23,14 +23,7 @@ function clampDelay(delayMs, capMs) {
|
|
|
23
23
|
return 0;
|
|
24
24
|
return Math.min(Math.max(1, Math.round(delayMs)), capMs);
|
|
25
25
|
}
|
|
26
|
-
|
|
27
|
-
const seed = `${fault.link}|${fault.kind}|${fault.message}|${fault.since}|${attempt}`;
|
|
28
|
-
let hash = 0;
|
|
29
|
-
for (let i = 0; i < seed.length; i++) {
|
|
30
|
-
hash = (hash * 33 + seed.charCodeAt(i)) >>> 0;
|
|
31
|
-
}
|
|
32
|
-
return hash % 1_000;
|
|
33
|
-
}
|
|
26
|
+
/** Full jitter for connection and overloaded faults: a random delay between zero and the doubled delay, so nodes that failed together do not retry together. */
|
|
34
27
|
function retryDelayMs(fault, attempt, opts) {
|
|
35
28
|
const policy = policyFor(fault.kind);
|
|
36
29
|
if (policy.fatal)
|
|
@@ -38,11 +31,7 @@ function retryDelayMs(fault, attempt, opts) {
|
|
|
38
31
|
if (fault.kind === 'rate-limit' && typeof opts?.retryAfterMs === 'number' && Number.isFinite(opts.retryAfterMs)) {
|
|
39
32
|
return clampDelay(opts.retryAfterMs, policy.capDelayMs);
|
|
40
33
|
}
|
|
41
|
-
|
|
42
|
-
const jitter = fault.kind === 'overloaded'
|
|
43
|
-
? Math.max(0, Math.round(opts?.jitterMs?.(fault, attempt) ?? defaultOverloadedJitterMs(fault, attempt)))
|
|
44
|
-
: 0;
|
|
45
|
-
return clampDelay(delay + jitter, policy.capDelayMs);
|
|
34
|
+
return clampDelay((fault.kind === 'rate-limit' ? 1 : Math.random()) * Math.min(policy.capDelayMs, policy.baseDelayMs * 2 ** Math.max(0, attempt - 1)), policy.capDelayMs);
|
|
46
35
|
}
|
|
47
36
|
export function nextFaultRetry(fault, now, opts) {
|
|
48
37
|
const policy = policyFor(fault.kind);
|
|
@@ -24,13 +24,18 @@ import { appForNode } from '../../canvas/node-agent-paths.js';
|
|
|
24
24
|
import { interpolateNodePaths } from '../../canvas/paths.js';
|
|
25
25
|
import { readableProjectForScopes } from '../../spaces/permissions.js';
|
|
26
26
|
import { ApiError } from '../../../api/errors.js';
|
|
27
|
-
import { buildContextBearings } from '../../runtime/bearings.js';
|
|
27
|
+
import { buildContextBearings, projectContextForNode } from '../../runtime/bearings.js';
|
|
28
28
|
import { deliveryDocOf, listingCorpora, loadCorpus, nodeSubject, primeBodies, profileIdOfObject, viewOwners } from './corpus.js';
|
|
29
29
|
import { listingPrefixes } from './listings.js';
|
|
30
30
|
import { planDelivery } from './plan.js';
|
|
31
31
|
import { renderEvent, renderExplicitRead } from './render-event.js';
|
|
32
32
|
import { renderConfigDelta, renderKnowledge, renderPreferences, renderWorkspaceOpen } from './render-boot.js';
|
|
33
33
|
import { mapAsync } from '../../async-array.js';
|
|
34
|
+
/** `req` with what a `boot` of node `nodeId` reads from this host's disk and processes (git, tmux, a directory listing), computed now so the
|
|
35
|
+
* delivery transaction that follows holds its pooled connection for db statements only. Call before `withCanvasWrite`. */
|
|
36
|
+
export async function withProjectContext(nodeId, req) {
|
|
37
|
+
return req.activity === 'boot' && req.inherited !== true ? { ...req, projectContext: await projectContextForNode(nodeId) } : req;
|
|
38
|
+
}
|
|
34
39
|
function nodeOf(reader) {
|
|
35
40
|
if (reader.class !== 'node')
|
|
36
41
|
throw new Error(`delivery needs a node reader, got ${reader.class}`);
|
|
@@ -173,7 +178,7 @@ async function render(ctx, req) {
|
|
|
173
178
|
ledger.preferenceSnapshot = null;
|
|
174
179
|
return { result: { content: '', inherited: true }, delivered: [] };
|
|
175
180
|
}
|
|
176
|
-
const bearings = isHypothetical(reader) ? await hypotheticalBearings(ctx) : await buildContextBearings(reader.node.id, ctx);
|
|
181
|
+
const bearings = isHypothetical(reader) ? await hypotheticalBearings(ctx) : await buildContextBearings(reader.node.id, ctx, requireProjectContext(req));
|
|
177
182
|
const prefs = await renderPreferences({ ...ctx, channel: 'system' });
|
|
178
183
|
freezePreferences(ledger, prefs.content);
|
|
179
184
|
return { result: { content: bearings.content }, delivered: [...bearings.delivered, ...prefs.delivered] };
|
|
@@ -235,6 +240,11 @@ async function render(ctx, req) {
|
|
|
235
240
|
throw new ApiError(400, 'usage', `unknown delivery activity ${String(req.activity)}`);
|
|
236
241
|
}
|
|
237
242
|
}
|
|
243
|
+
function requireProjectContext(req) {
|
|
244
|
+
if (req.projectContext === undefined)
|
|
245
|
+
throw new Error('a node boot delivery needs its project context built before the transaction: pass the request through withProjectContext');
|
|
246
|
+
return req.projectContext;
|
|
247
|
+
}
|
|
238
248
|
/** A hypothetical node has no bearings of its own: its boot content is the
|
|
239
249
|
* knowledge catalog and the workspace-open documents. */
|
|
240
250
|
async function hypotheticalBearings(ctx) {
|
|
@@ -33,7 +33,7 @@ import { recoveryState, requireCurrentExecution } from './broker-recovery.js';
|
|
|
33
33
|
import { runAttachments } from './node-records.js';
|
|
34
34
|
import { readerForNode, warmNodeRepos } from '../../../core/graph/reader.js';
|
|
35
35
|
import { checkoutsForCwd } from '../../../core/graph/repo-sync/repos.js';
|
|
36
|
-
import { deliver } from '../../../core/substrate/delivery/deliver.js';
|
|
36
|
+
import { deliver, withProjectContext } from '../../../core/substrate/delivery/deliver.js';
|
|
37
37
|
import { nodeSubject } from '../../../core/substrate/delivery/corpus.js';
|
|
38
38
|
import { ensureRunObserver } from '../../runs/observer.js';
|
|
39
39
|
import { parseNodeTelemetryRecord, writeNodeTelemetryRecord } from './telemetry-record.js';
|
|
@@ -296,11 +296,11 @@ function parseCycleStartBody(body) {
|
|
|
296
296
|
/** The names, bearings and first system-prompt block a cycle opens with, delivered in one write the way the
|
|
297
297
|
* delivery route would deliver each. A warm spare is owed no bearings and no system prompt: its claim delivers them.
|
|
298
298
|
* `namesOnly` gives a node the same treatment while its bind is undecided. */
|
|
299
|
-
async function startupDelivery(db, reader, subject, state, bearings, namesOnly) {
|
|
299
|
+
async function startupDelivery(db, reader, subject, state, bearings, namesOnly, projectContext) {
|
|
300
300
|
const warm = state.warm_spare || namesOnly;
|
|
301
301
|
const bootOwed = !warm && bearings !== 'present';
|
|
302
302
|
const names = await deliver(db, reader, { activity: 'names' }, subject);
|
|
303
|
-
const boot = bootOwed ? await deliver(db, reader, { activity: 'boot', ...(bearings === 'inherited' ? { inherited: true } : {}) }, subject) : undefined;
|
|
303
|
+
const boot = bootOwed ? await deliver(db, reader, { activity: 'boot', ...(bearings === 'inherited' ? { inherited: true } : {}), ...(projectContext === undefined ? {} : { projectContext }) }, subject) : undefined;
|
|
304
304
|
const system = warm ? undefined : await deliver(db, reader, { activity: 'system-prompt' }, subject);
|
|
305
305
|
return {
|
|
306
306
|
names: { refs: names.refs, names: names.names },
|
|
@@ -314,12 +314,14 @@ async function startupDelivery(db, reader, subject, state, bearings, namesOnly)
|
|
|
314
314
|
export async function renderStartData(nodeId, bearings, namesOnly, warmed = false) {
|
|
315
315
|
if (!warmed)
|
|
316
316
|
await warmNodeRepos(await openDb(), nodeId);
|
|
317
|
+
// A fresh boot's project-context snapshot (git, tmux, a directory listing) is built before the transaction, so it holds its connection for db statements only.
|
|
318
|
+
const projectContext = !namesOnly && bearings === 'fresh' ? (await withProjectContext(nodeId, { activity: 'boot' })).projectContext : undefined;
|
|
317
319
|
const { state, delivery } = await withCanvasWrite(async (db) => {
|
|
318
320
|
const reader = await readerForNode(db, nodeId, async (cwd, person, access) => await checkoutsForCwd(db, cwd, person, access));
|
|
319
321
|
shareCorpusReads(reader);
|
|
320
322
|
const subject = await nodeSubject(db, reader);
|
|
321
323
|
const state = await extensionState(nodeId, subject);
|
|
322
|
-
return { state, delivery: await startupDelivery(db, reader, subject, state, bearings, namesOnly) };
|
|
324
|
+
return { state, delivery: await startupDelivery(db, reader, subject, state, bearings, namesOnly, projectContext) };
|
|
323
325
|
});
|
|
324
326
|
// The bearings just rendered are the persona baseline; the broker does not acknowledge it separately.
|
|
325
327
|
if (delivery.boot !== undefined) {
|
|
@@ -589,15 +591,14 @@ async function handleTelemetry(ctx) {
|
|
|
589
591
|
const nodeId = ctx.params['id'];
|
|
590
592
|
const request = parseTelemetryBody(ctx.body);
|
|
591
593
|
await requireCurrentExecution(nodeId, request.expected_execution_id);
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
});
|
|
599
|
-
writeNodeTelemetryRecord(nodeId, request);
|
|
594
|
+
// One statement, atomic on its own; the node-local file is filesystem work and must not hold a pooled connection.
|
|
595
|
+
await updateNodeTelemetry(nodeId, {
|
|
596
|
+
tokensIn: request.tokens_in,
|
|
597
|
+
contextTokens: request.context_tokens,
|
|
598
|
+
lastActivity: request.last_activity,
|
|
599
|
+
updatedAt: request.updated_at,
|
|
600
600
|
});
|
|
601
|
+
writeNodeTelemetryRecord(nodeId, request);
|
|
601
602
|
return { status: 204 };
|
|
602
603
|
}
|
|
603
604
|
async function handleModelCommit(ctx) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@north-light/api",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.718",
|
|
4
4
|
"description": "Typed crtrd /v1 API contract — DTOs, route builders, the error contract, the CrtrClient, and the command-plugin manifest format. Zero runtime dependencies.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/api/index.js",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@north-light/plugin",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.718",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"postpack": "node ../../scripts/pack-minify.mjs postpack packages/crouter-plugin"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@north-light/api": "0.3.
|
|
31
|
-
"@north-light/identity": "0.3.
|
|
30
|
+
"@north-light/api": "0.3.718",
|
|
31
|
+
"@north-light/identity": "0.3.718"
|
|
32
32
|
},
|
|
33
33
|
"license": "UNLICENSED",
|
|
34
34
|
"publishConfig": {
|
package/runtime.lock.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@north-light/cli",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.718",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@north-light/cli",
|
|
9
|
-
"version": "0.3.
|
|
9
|
+
"version": "0.3.718",
|
|
10
10
|
"hasInstallScript": true,
|
|
11
11
|
"license": "UNLICENSED",
|
|
12
12
|
"workspaces": [
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"@milkdown/preset-gfm": "^7.22.3",
|
|
29
29
|
"@milkdown/prose": "^7.22.3",
|
|
30
30
|
"@milkdown/utils": "^7.22.3",
|
|
31
|
-
"@north-light/identity": "0.3.
|
|
32
|
-
"@north-light/plugin": "0.3.
|
|
31
|
+
"@north-light/identity": "0.3.718",
|
|
32
|
+
"@north-light/plugin": "0.3.718",
|
|
33
33
|
"cron-parser": "^5.6.0",
|
|
34
34
|
"esbuild": "0.28.2",
|
|
35
35
|
"jose": "^6.2.12",
|
|
@@ -11902,17 +11902,17 @@
|
|
|
11902
11902
|
},
|
|
11903
11903
|
"packages/crouter-api": {
|
|
11904
11904
|
"name": "@north-light/api",
|
|
11905
|
-
"version": "0.3.
|
|
11905
|
+
"version": "0.3.718",
|
|
11906
11906
|
"license": "UNLICENSED"
|
|
11907
11907
|
},
|
|
11908
11908
|
"packages/crouter-env-docker": {
|
|
11909
11909
|
"name": "@north-light/env-docker",
|
|
11910
|
-
"version": "0.3.
|
|
11910
|
+
"version": "0.3.718",
|
|
11911
11911
|
"license": "UNLICENSED"
|
|
11912
11912
|
},
|
|
11913
11913
|
"packages/crouter-identity": {
|
|
11914
11914
|
"name": "@north-light/identity",
|
|
11915
|
-
"version": "0.3.
|
|
11915
|
+
"version": "0.3.718",
|
|
11916
11916
|
"license": "UNLICENSED",
|
|
11917
11917
|
"dependencies": {
|
|
11918
11918
|
"jose": "^6.2.1"
|
|
@@ -11920,21 +11920,21 @@
|
|
|
11920
11920
|
},
|
|
11921
11921
|
"packages/crouter-plugin": {
|
|
11922
11922
|
"name": "@north-light/plugin",
|
|
11923
|
-
"version": "0.3.
|
|
11923
|
+
"version": "0.3.718",
|
|
11924
11924
|
"license": "UNLICENSED",
|
|
11925
11925
|
"dependencies": {
|
|
11926
|
-
"@north-light/api": "0.3.
|
|
11927
|
-
"@north-light/identity": "0.3.
|
|
11926
|
+
"@north-light/api": "0.3.718",
|
|
11927
|
+
"@north-light/identity": "0.3.718"
|
|
11928
11928
|
}
|
|
11929
11929
|
},
|
|
11930
11930
|
"packages/crouter-sdk": {
|
|
11931
11931
|
"name": "@north-light/sdk",
|
|
11932
|
-
"version": "0.3.
|
|
11932
|
+
"version": "0.3.718",
|
|
11933
11933
|
"license": "UNLICENSED",
|
|
11934
11934
|
"dependencies": {
|
|
11935
|
-
"@north-light/api": "0.3.
|
|
11936
|
-
"@north-light/identity": "0.3.
|
|
11937
|
-
"@north-light/plugin": "0.3.
|
|
11935
|
+
"@north-light/api": "0.3.718",
|
|
11936
|
+
"@north-light/identity": "0.3.718",
|
|
11937
|
+
"@north-light/plugin": "0.3.718",
|
|
11938
11938
|
"jose": "^6.2.1"
|
|
11939
11939
|
},
|
|
11940
11940
|
"bin": {
|