@culture.dev/agents 0.15.2 → 0.16.0
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/README.md +22 -0
- package/dist/contract-schemas/api.json +73 -15
- package/dist/contract-schemas/branches.json +163 -0
- package/dist/contract-schemas/capabilities.json +133 -6
- package/dist/contract-schemas/common.json +9 -3
- package/dist/contract-schemas/control-action.json +91 -14
- package/dist/contract-schemas/error.json +189 -48
- package/dist/contract-schemas/event.json +185 -2
- package/dist/contract-schemas/run.json +111 -4
- package/dist/contract-schemas/version.json +2 -2
- package/dist/src/contract/generated/branches.d.ts +34 -0
- package/dist/src/contract/generated/branches.js +3 -0
- package/dist/src/contract/generated/branches.js.map +1 -0
- package/dist/src/contract/generated/capabilities.d.ts +39 -7
- package/dist/src/contract/generated/common.d.ts +5 -3
- package/dist/src/contract/generated/control-action.d.ts +30 -11
- package/dist/src/contract/generated/error.d.ts +31 -7
- package/dist/src/contract/generated/event.d.ts +57 -8
- package/dist/src/contract/generated/index.d.ts +37 -12
- package/dist/src/contract/generated/run.d.ts +23 -5
- package/dist/src/contract/generated/version.d.ts +2 -2
- package/dist/src/contract/ids.d.ts +6 -3
- package/dist/src/contract/ids.js +5 -2
- package/dist/src/contract/ids.js.map +1 -1
- package/dist/src/contract/index.d.ts +1 -1
- package/dist/src/contract/index.js +1 -1
- package/dist/src/contract/index.js.map +1 -1
- package/dist/src/daemon/branch-routes.d.ts +13 -0
- package/dist/src/daemon/branch-routes.js +41 -0
- package/dist/src/daemon/branch-routes.js.map +1 -0
- package/dist/src/daemon/daemon.js +10 -2
- package/dist/src/daemon/daemon.js.map +1 -1
- package/dist/src/daemon/harness-catalog.d.ts +6 -0
- package/dist/src/daemon/harness-catalog.js +20 -0
- package/dist/src/daemon/harness-catalog.js.map +1 -1
- package/dist/src/daemon/limits.d.ts +31 -0
- package/dist/src/daemon/limits.js +61 -0
- package/dist/src/daemon/limits.js.map +1 -0
- package/dist/src/daemon/main.d.ts +10 -0
- package/dist/src/daemon/main.js +161 -41
- package/dist/src/daemon/main.js.map +1 -1
- package/dist/src/daemon/ports.d.ts +21 -11
- package/dist/src/daemon/routes.d.ts +3 -0
- package/dist/src/daemon/routes.js +26 -5
- package/dist/src/daemon/routes.js.map +1 -1
- package/dist/src/daemon/secrets.d.ts +24 -0
- package/dist/src/daemon/secrets.js +52 -0
- package/dist/src/daemon/secrets.js.map +1 -0
- package/dist/src/daemon/submitter.d.ts +9 -0
- package/dist/src/daemon/submitter.js +23 -0
- package/dist/src/daemon/submitter.js.map +1 -0
- package/dist/src/harness/claude-code/index.js +1 -1
- package/dist/src/harness/claude-code/index.js.map +1 -1
- package/dist/src/harness/common/capabilities.d.ts +26 -2
- package/dist/src/harness/common/capabilities.js +31 -6
- package/dist/src/harness/common/capabilities.js.map +1 -1
- package/dist/src/harness/common/guard.d.ts +2 -1
- package/dist/src/harness/common/guard.js +6 -0
- package/dist/src/harness/common/guard.js.map +1 -1
- package/dist/src/harness/common/run-driver.d.ts +6 -1
- package/dist/src/harness/common/run-driver.js +20 -3
- package/dist/src/harness/common/run-driver.js.map +1 -1
- package/dist/src/harness/common/sandbox-workspace.d.ts +5 -1
- package/dist/src/harness/common/sandbox-workspace.js +12 -3
- package/dist/src/harness/common/sandbox-workspace.js.map +1 -1
- package/dist/src/harness/common/types.d.ts +8 -0
- package/dist/src/harness/config.d.ts +5 -0
- package/dist/src/harness/config.js +7 -3
- package/dist/src/harness/config.js.map +1 -1
- package/dist/src/harness/index.js +2 -2
- package/dist/src/harness/index.js.map +1 -1
- package/dist/src/harness/opencode/index.js +1 -1
- package/dist/src/harness/opencode/index.js.map +1 -1
- package/dist/src/harness/stub/backend.d.ts +3 -0
- package/dist/src/harness/stub/backend.js +50 -1
- package/dist/src/harness/stub/backend.js.map +1 -1
- package/dist/src/harness/stub/index.d.ts +7 -1
- package/dist/src/harness/stub/index.js +10 -2
- package/dist/src/harness/stub/index.js.map +1 -1
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +1 -1
- package/dist/src/publish/config.d.ts +25 -0
- package/dist/src/publish/config.js +47 -0
- package/dist/src/publish/config.js.map +1 -0
- package/dist/src/publish/envelope.d.ts +61 -0
- package/dist/src/publish/envelope.js +109 -0
- package/dist/src/publish/envelope.js.map +1 -0
- package/dist/src/publish/index.d.ts +22 -0
- package/dist/src/publish/index.js +35 -0
- package/dist/src/publish/index.js.map +1 -0
- package/dist/src/publish/log-tail.d.ts +31 -0
- package/dist/src/publish/log-tail.js +172 -0
- package/dist/src/publish/log-tail.js.map +1 -0
- package/dist/src/publish/publisher.d.ts +34 -0
- package/dist/src/publish/publisher.js +207 -0
- package/dist/src/publish/publisher.js.map +1 -0
- package/dist/src/publish/transport.d.ts +14 -0
- package/dist/src/publish/transport.js +69 -0
- package/dist/src/publish/transport.js.map +1 -0
- package/dist/src/runs/admission.d.ts +27 -0
- package/dist/src/runs/admission.js +97 -0
- package/dist/src/runs/admission.js.map +1 -0
- package/dist/src/runs/answer.d.ts +24 -0
- package/dist/src/runs/answer.js +99 -0
- package/dist/src/runs/answer.js.map +1 -0
- package/dist/src/runs/base-commit.d.ts +6 -0
- package/dist/src/runs/base-commit.js +23 -0
- package/dist/src/runs/base-commit.js.map +1 -0
- package/dist/src/runs/branches.d.ts +23 -0
- package/dist/src/runs/branches.js +115 -0
- package/dist/src/runs/branches.js.map +1 -0
- package/dist/src/runs/control.d.ts +12 -4
- package/dist/src/runs/control.js +14 -6
- package/dist/src/runs/control.js.map +1 -1
- package/dist/src/runs/gateway.d.ts +25 -0
- package/dist/src/runs/gateway.js +122 -0
- package/dist/src/runs/gateway.js.map +1 -0
- package/dist/src/runs/keys.d.ts +21 -0
- package/dist/src/runs/keys.js +50 -0
- package/dist/src/runs/keys.js.map +1 -0
- package/dist/src/runs/limits.d.ts +15 -0
- package/dist/src/runs/limits.js +37 -0
- package/dist/src/runs/limits.js.map +1 -0
- package/dist/src/runs/ports.d.ts +3 -0
- package/dist/src/runs/ports.js.map +1 -1
- package/dist/src/runs/reattach.d.ts +37 -0
- package/dist/src/runs/reattach.js +70 -0
- package/dist/src/runs/reattach.js.map +1 -0
- package/dist/src/runs/scan.d.ts +11 -6
- package/dist/src/runs/scan.js +12 -15
- package/dist/src/runs/scan.js.map +1 -1
- package/dist/src/runs/service.d.ts +57 -7
- package/dist/src/runs/service.js +160 -95
- package/dist/src/runs/service.js.map +1 -1
- package/dist/src/runs/submit.d.ts +34 -0
- package/dist/src/runs/submit.js +92 -0
- package/dist/src/runs/submit.js.map +1 -0
- package/dist/src/sandbox/host-command.js +5 -1
- package/dist/src/sandbox/host-command.js.map +1 -1
- package/dist/src/sandbox/run-sandbox.d.ts +8 -2
- package/dist/src/sandbox/run-sandbox.js +10 -3
- package/dist/src/sandbox/run-sandbox.js.map +1 -1
- package/dist/src/store/derive.js +3 -0
- package/dist/src/store/derive.js.map +1 -1
- package/dist/src/store/entries.d.ts +29 -0
- package/dist/src/store/entries.js +41 -0
- package/dist/src/store/entries.js.map +1 -0
- package/dist/src/store/event-log.d.ts +3 -3
- package/dist/src/store/event-log.js +2 -2
- package/dist/src/store/event-log.js.map +1 -1
- package/dist/src/store/files.d.ts +4 -0
- package/dist/src/store/files.js +4 -0
- package/dist/src/store/files.js.map +1 -1
- package/dist/src/store/idempotency.d.ts +79 -0
- package/dist/src/store/idempotency.js +281 -0
- package/dist/src/store/idempotency.js.map +1 -0
- package/dist/src/store/index.d.ts +8 -0
- package/dist/src/store/index.js +5 -0
- package/dist/src/store/index.js.map +1 -1
- package/dist/src/store/questions.d.ts +40 -0
- package/dist/src/store/questions.js +90 -0
- package/dist/src/store/questions.js.map +1 -0
- package/dist/src/store/retention.d.ts +13 -0
- package/dist/src/store/retention.js +74 -0
- package/dist/src/store/retention.js.map +1 -0
- package/dist/src/store/run-store.d.ts +4 -0
- package/dist/src/store/run-store.js +20 -4
- package/dist/src/store/run-store.js.map +1 -1
- package/dist/src/store/startup.d.ts +9 -0
- package/dist/src/store/startup.js +92 -0
- package/dist/src/store/startup.js.map +1 -0
- package/dist/src/store/summary.d.ts +7 -0
- package/dist/src/store/summary.js +126 -0
- package/dist/src/store/summary.js.map +1 -0
- package/dist/src/store/version.d.ts +10 -0
- package/dist/src/store/version.js +46 -0
- package/dist/src/store/version.js.map +1 -0
- package/dist/src/trace/config.d.ts +31 -0
- package/dist/src/trace/config.js +69 -0
- package/dist/src/trace/config.js.map +1 -0
- package/dist/src/trace/follower.d.ts +20 -0
- package/dist/src/trace/follower.js +196 -0
- package/dist/src/trace/follower.js.map +1 -0
- package/dist/src/trace/index.d.ts +21 -0
- package/dist/src/trace/index.js +42 -0
- package/dist/src/trace/index.js.map +1 -0
- package/dist/src/trace/otlp.d.ts +11 -0
- package/dist/src/trace/otlp.js +52 -0
- package/dist/src/trace/otlp.js.map +1 -0
- package/dist/src/trace/spans.d.ts +28 -0
- package/dist/src/trace/spans.js +120 -0
- package/dist/src/trace/spans.js.map +1 -0
- package/dist/src/worker/answer.d.ts +29 -0
- package/dist/src/worker/answer.js +53 -0
- package/dist/src/worker/answer.js.map +1 -0
- package/dist/src/worker/asking.d.ts +22 -0
- package/dist/src/worker/asking.js +21 -0
- package/dist/src/worker/asking.js.map +1 -0
- package/dist/src/worker/control.d.ts +7 -1
- package/dist/src/worker/control.js +22 -10
- package/dist/src/worker/control.js.map +1 -1
- package/dist/src/worker/delivery.d.ts +2 -2
- package/dist/src/worker/delivery.js +1 -1
- package/dist/src/worker/delivery.js.map +1 -1
- package/dist/src/worker/driver.d.ts +46 -1
- package/dist/src/worker/fake-driver.d.ts +35 -1
- package/dist/src/worker/fake-driver.js +45 -0
- package/dist/src/worker/fake-driver.js.map +1 -1
- package/dist/src/worker/main.js +4 -1
- package/dist/src/worker/main.js.map +1 -1
- package/dist/src/worker/questions.d.ts +67 -0
- package/dist/src/worker/questions.js +152 -0
- package/dist/src/worker/questions.js.map +1 -0
- package/dist/src/worker/run-loop.d.ts +19 -1
- package/dist/src/worker/run-loop.js +91 -25
- package/dist/src/worker/run-loop.js.map +1 -1
- package/dist/src/worker/spawn.d.ts +9 -1
- package/dist/src/worker/spawn.js +12 -3
- package/dist/src/worker/spawn.js.map +1 -1
- package/package.json +3 -2
- package/policy/profiles/culture-agents-claude-subscription.yaml +1 -1
- package/policy/profiles/culture-agents-local-gateway.yaml +1 -1
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Idempotency on the run service's routes (contract/README.md: idempotency keys), over the on-disk
|
|
3
|
+
* key index (store/idempotency.ts). A key is looked up after the capability checks and before
|
|
4
|
+
* the limit check of a submit, and before the capability check of a steer or cancel:
|
|
5
|
+
*
|
|
6
|
+
* - no entry: the request proceeds and its key is written before anything else happens;
|
|
7
|
+
* - an entry whose effect is not established yet: settled from the store first (released, so the
|
|
8
|
+
* request proceeds; still pending, so `unavailable` with `retry_after_ms`);
|
|
9
|
+
* - the same digest: the first run (as it is now) or the first action, with `replayed: true`;
|
|
10
|
+
* - another digest: `conflict`, not retryable, with `idempotency_key` and the key's `run_id`.
|
|
11
|
+
*/
|
|
12
|
+
import type { AcceptedResponse, Run, SubmitResponse } from "../contract/index.js";
|
|
13
|
+
import { type KeyIndex } from "../store/idempotency.js";
|
|
14
|
+
/** The fault injection points of a submit, in on-disk order. */
|
|
15
|
+
export type SubmitStep = "after-key" | "after-run-dir" | "after-spawn";
|
|
16
|
+
/** Called at each step of a submit; a test kills the core there. Never set in production. */
|
|
17
|
+
export type SubmitFault = (step: SubmitStep) => void;
|
|
18
|
+
/** A repeated submit: the first run as it is now, or null when the key is free. */
|
|
19
|
+
export declare function replaySubmit(index: KeyIndex, key: string, digest: string, read: (runId: string) => Run | null): SubmitResponse | null;
|
|
20
|
+
/** A repeated steer or cancel: the first action record, or null when the key is free. */
|
|
21
|
+
export declare function replayAction(index: KeyIndex, scope: "steer" | "cancel", key: string, digest: string): AcceptedResponse | null;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { ControlError } from "../daemon/errors.js";
|
|
2
|
+
import { settleKey } from "../store/idempotency.js";
|
|
3
|
+
function conflict(entry) {
|
|
4
|
+
return new ControlError("conflict", `Idempotency key ${entry.key} was already used with a different ${entry.scope} request (run ${entry.run_id}).`, {
|
|
5
|
+
run_id: entry.run_id,
|
|
6
|
+
idempotency_key: entry.key,
|
|
7
|
+
retryable: false,
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
function pending(entry) {
|
|
11
|
+
return new ControlError("unavailable", `The ${entry.scope} with idempotency key ${entry.key} is still being established; retry shortly.`, {
|
|
12
|
+
run_id: entry.run_id,
|
|
13
|
+
retry_after_ms: 500,
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
/** The established entry for a key, or null when it is unused or was released. */
|
|
17
|
+
function lookup(index, scope, key, digest) {
|
|
18
|
+
const found = index.get(scope, key);
|
|
19
|
+
if (found === null)
|
|
20
|
+
return null;
|
|
21
|
+
const { settlement, entry } = settleKey(index, found);
|
|
22
|
+
if (settlement === "released")
|
|
23
|
+
return null;
|
|
24
|
+
if (entry.digest !== digest)
|
|
25
|
+
throw conflict(entry);
|
|
26
|
+
if (settlement === "pending")
|
|
27
|
+
throw pending(entry);
|
|
28
|
+
return entry;
|
|
29
|
+
}
|
|
30
|
+
/** A repeated submit: the first run as it is now, or null when the key is free. */
|
|
31
|
+
export function replaySubmit(index, key, digest, read) {
|
|
32
|
+
const entry = lookup(index, "submit", key, digest);
|
|
33
|
+
if (entry === null)
|
|
34
|
+
return null;
|
|
35
|
+
const run = read(entry.run_id);
|
|
36
|
+
if (run === null) {
|
|
37
|
+
// The run left the store (it was never established after all, or it was removed): the key is free.
|
|
38
|
+
index.release("submit", key);
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
return { run, replayed: true };
|
|
42
|
+
}
|
|
43
|
+
/** A repeated steer or cancel: the first action record, or null when the key is free. */
|
|
44
|
+
export function replayAction(index, scope, key, digest) {
|
|
45
|
+
const entry = lookup(index, scope, key, digest);
|
|
46
|
+
if (!entry?.action)
|
|
47
|
+
return null;
|
|
48
|
+
return { action: { ...entry.action, outcome: "accepted" }, replayed: true };
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=keys.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keys.js","sourceRoot":"","sources":["../../../src/runs/keys.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,SAAS,EAA+C,MAAM,yBAAyB,CAAC;AAQjG,SAAS,QAAQ,CAAC,KAAe;IAC/B,OAAO,IAAI,YAAY,CAAC,UAAU,EAAE,mBAAmB,KAAK,CAAC,GAAG,sCAAsC,KAAK,CAAC,KAAK,iBAAiB,KAAK,CAAC,MAAM,IAAI,EAAE;QAClJ,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,eAAe,EAAE,KAAK,CAAC,GAAG;QAC1B,SAAS,EAAE,KAAK;KACjB,CAAC,CAAC;AACL,CAAC;AAED,SAAS,OAAO,CAAC,KAAe;IAC9B,OAAO,IAAI,YAAY,CAAC,aAAa,EAAE,OAAO,KAAK,CAAC,KAAK,yBAAyB,KAAK,CAAC,GAAG,6CAA6C,EAAE;QACxI,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,cAAc,EAAE,GAAG;KACpB,CAAC,CAAC;AACL,CAAC;AAED,kFAAkF;AAClF,SAAS,MAAM,CAAC,KAAe,EAAE,KAAe,EAAE,GAAW,EAAE,MAAc;IAC3E,MAAM,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IACpC,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IAChC,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,GAAG,SAAS,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IACtD,IAAI,UAAU,KAAK,UAAU;QAAE,OAAO,IAAI,CAAC;IAC3C,IAAI,KAAK,CAAC,MAAM,KAAK,MAAM;QAAE,MAAM,QAAQ,CAAC,KAAK,CAAC,CAAC;IACnD,IAAI,UAAU,KAAK,SAAS;QAAE,MAAM,OAAO,CAAC,KAAK,CAAC,CAAC;IACnD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,mFAAmF;AACnF,MAAM,UAAU,YAAY,CAAC,KAAe,EAAE,GAAW,EAAE,MAAc,EAAE,IAAmC;IAC5G,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;IACnD,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IAChC,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAC/B,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;QACjB,mGAAmG;QACnG,KAAK,CAAC,OAAO,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;QAC7B,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;AACjC,CAAC;AAED,yFAAyF;AACzF,MAAM,UAAU,YAAY,CAAC,KAAe,EAAE,KAAyB,EAAE,GAAW,EAAE,MAAc;IAClG,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;IAChD,IAAI,CAAC,KAAK,EAAE,MAAM;QAAE,OAAO,IAAI,CAAC;IAChC,OAAO,EAAE,MAAM,EAAE,EAAE,GAAG,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;AAC9E,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The submit-time limit check (contract README, order of checks step 7). No limit applies unless
|
|
3
|
+
* the operator configured one (daemon/limits.ts); a submit past a configured limit is refused with
|
|
4
|
+
* `limit_reached` naming the limit, its value and the active count, and nothing is queued.
|
|
5
|
+
*
|
|
6
|
+
* Counted as active: every run in an active state (`isActive`), including a run whose worker
|
|
7
|
+
* survived a core restart, and every run that cannot be read but whose worker may be alive (an
|
|
8
|
+
* unreadable record counts against every repository). The repository limit is checked first.
|
|
9
|
+
*/
|
|
10
|
+
import { type Limits } from "../contract/index.js";
|
|
11
|
+
import { type ScanOptions } from "./scan.js";
|
|
12
|
+
/** No limit configured. */
|
|
13
|
+
export declare const NO_LIMITS: Limits;
|
|
14
|
+
/** Throw `limit_reached` when a configured limit has no room for one more run in `repo`. Reads nothing when no limit is configured. */
|
|
15
|
+
export declare function checkLimits(limits: Limits, scan: ScanOptions, repo: string): void;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The submit-time limit check (contract README, order of checks step 7). No limit applies unless
|
|
3
|
+
* the operator configured one (daemon/limits.ts); a submit past a configured limit is refused with
|
|
4
|
+
* `limit_reached` naming the limit, its value and the active count, and nothing is queued.
|
|
5
|
+
*
|
|
6
|
+
* Counted as active: every run in an active state (`isActive`), including a run whose worker
|
|
7
|
+
* survived a core restart, and every run that cannot be read but whose worker may be alive (an
|
|
8
|
+
* unreadable record counts against every repository). The repository limit is checked first.
|
|
9
|
+
*/
|
|
10
|
+
import { isActive } from "../contract/index.js";
|
|
11
|
+
import { ControlError } from "../daemon/errors.js";
|
|
12
|
+
import { scanRuns, unreadableLiveRuns } from "./scan.js";
|
|
13
|
+
/** No limit configured. */
|
|
14
|
+
export const NO_LIMITS = { runs_per_repository: null, runs_per_host: null };
|
|
15
|
+
/** Throw `limit_reached` when a configured limit has no room for one more run in `repo`. Reads nothing when no limit is configured. */
|
|
16
|
+
export function checkLimits(limits, scan, repo) {
|
|
17
|
+
const perRepo = limits.runs_per_repository;
|
|
18
|
+
const perHost = limits.runs_per_host;
|
|
19
|
+
if (perRepo === null && perHost === null)
|
|
20
|
+
return;
|
|
21
|
+
const active = scanRuns(scan).filter((run) => isActive(run.state));
|
|
22
|
+
const unreadable = unreadableLiveRuns(scan);
|
|
23
|
+
if (perRepo !== null) {
|
|
24
|
+
const count = active.filter((run) => run.repo === repo).length + unreadable.filter((run) => run.repo === null || run.repo === repo).length;
|
|
25
|
+
if (count >= perRepo)
|
|
26
|
+
refuse({ name: "runs_per_repository", value: perRepo, active: count, repo }, `Repository ${repo} has ${count} active runs and the configured limit runs_per_repository is ${perRepo}; nothing was queued, retry when a run ends.`);
|
|
27
|
+
}
|
|
28
|
+
if (perHost !== null) {
|
|
29
|
+
const count = active.length + unreadable.length;
|
|
30
|
+
if (count >= perHost)
|
|
31
|
+
refuse({ name: "runs_per_host", value: perHost, active: count }, `This host has ${count} active runs and the configured limit runs_per_host is ${perHost}; nothing was queued, retry when a run ends or submit elsewhere.`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function refuse(limit, message) {
|
|
35
|
+
throw new ControlError("limit_reached", message, { limit });
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=limits.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"limits.js","sourceRoot":"","sources":["../../../src/runs/limits.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,QAAQ,EAA2B,MAAM,sBAAsB,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAoB,MAAM,WAAW,CAAC;AAE3E,2BAA2B;AAC3B,MAAM,CAAC,MAAM,SAAS,GAAW,EAAE,mBAAmB,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC;AAEpF,uIAAuI;AACvI,MAAM,UAAU,WAAW,CAAC,MAAc,EAAE,IAAiB,EAAE,IAAY;IACzE,MAAM,OAAO,GAAG,MAAM,CAAC,mBAAmB,CAAC;IAC3C,MAAM,OAAO,GAAG,MAAM,CAAC,aAAa,CAAC;IACr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,EAAE,CAAC,CAAC;AAC9D,CAAC"}
|
package/dist/src/runs/ports.d.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* The real catalog lives elsewhere and is connected by `daemon/main.ts`; nothing here imports it.
|
|
5
5
|
*/
|
|
6
6
|
import type { Capabilities } from "../contract/index.js";
|
|
7
|
+
import type { GatewaySource } from "./gateway.js";
|
|
7
8
|
export interface HarnessEntry {
|
|
8
9
|
/** The harness id as submitted (`harness` in the request), for example `opencode`. */
|
|
9
10
|
id: string;
|
|
@@ -26,6 +27,8 @@ export interface HarnessCatalog {
|
|
|
26
27
|
* a catalog without workspaces of its own has nothing to reclaim.
|
|
27
28
|
*/
|
|
28
29
|
reclaim?(finishedRunIds: string[]): Promise<string[]>;
|
|
30
|
+
/** The model gateway some harnesses use; its admission is read for those harnesses only. */
|
|
31
|
+
gateway?: GatewaySource;
|
|
29
32
|
}
|
|
30
33
|
/** A catalog with no harness: every submit is refused with `not_found` for an unknown harness. */
|
|
31
34
|
export declare function emptyCatalog(): HarnessCatalog;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ports.js","sourceRoot":"","sources":["../../../src/runs/ports.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ports.js","sourceRoot":"","sources":["../../../src/runs/ports.ts"],"names":[],"mappings":"AAkCA,kGAAkG;AAClG,MAAM,UAAU,YAAY;IAC1B,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,SAAS,EAAE,CAAC;AAClD,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reattaching to the workers that survived a core restart (contract/README.md, step 7 and
|
|
3
|
+
* "after a core restart"). For each non-terminal run the core pings the worker's own control
|
|
4
|
+
* socket through `reconnectWorker`; an answering worker's `WorkerControl` goes into the service's
|
|
5
|
+
* map, so `live_control` is true again. A worker that is alive but does not answer is never
|
|
6
|
+
* reattached by guess and never signalled: its run keeps its logged state with `live_control: false`
|
|
7
|
+
* and the attempt is made again, on the next control request and on a bounded backoff, for as
|
|
8
|
+
* long as the worker is alive. A slow worker is not a gone worker.
|
|
9
|
+
*
|
|
10
|
+
* A control request that arrives while an attempt is still running waits for it (`settle`).
|
|
11
|
+
*/
|
|
12
|
+
import type { RunId } from "../contract/index.js";
|
|
13
|
+
import type { Reconnect, WorkerControl } from "../worker/spawn.js";
|
|
14
|
+
export type ReconnectFn = (stateDir: string, runId: RunId) => Promise<Reconnect>;
|
|
15
|
+
/** The first background retry after a live worker did not answer, and the most the backoff grows to. */
|
|
16
|
+
export declare const RETRY_FIRST_MS = 500;
|
|
17
|
+
export declare const RETRY_MAX_MS = 30000;
|
|
18
|
+
export interface ReattacherOptions {
|
|
19
|
+
stateDir: string;
|
|
20
|
+
controls: Map<RunId, WorkerControl>;
|
|
21
|
+
reconnect: ReconnectFn;
|
|
22
|
+
warn: (line: string) => void;
|
|
23
|
+
}
|
|
24
|
+
export declare class Reattacher {
|
|
25
|
+
private readonly options;
|
|
26
|
+
private readonly pending;
|
|
27
|
+
/** The next background retry of a live, silent worker, and the delay it was scheduled with. */
|
|
28
|
+
private readonly retries;
|
|
29
|
+
constructor(options: ReattacherOptions);
|
|
30
|
+
/** Start a reattach attempt for a run unless one is running or the run is controlled; resolves when it has finished. Never rejects. */
|
|
31
|
+
begin(runId: RunId): Promise<void>;
|
|
32
|
+
/** Whether the run's attempt (started if need be) finished within `ms`. */
|
|
33
|
+
settle(runId: RunId, ms: number): Promise<boolean>;
|
|
34
|
+
private attempt;
|
|
35
|
+
/** Schedule the next attempt for a live worker that did not answer, doubling the delay up to `RETRY_MAX_MS`. */
|
|
36
|
+
private retryLater;
|
|
37
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/** The first background retry after a live worker did not answer, and the most the backoff grows to. */
|
|
2
|
+
export const RETRY_FIRST_MS = 500;
|
|
3
|
+
export const RETRY_MAX_MS = 30_000;
|
|
4
|
+
const ignore = () => undefined;
|
|
5
|
+
export class Reattacher {
|
|
6
|
+
options;
|
|
7
|
+
pending = new Map();
|
|
8
|
+
/** The next background retry of a live, silent worker, and the delay it was scheduled with. */
|
|
9
|
+
retries = new Map();
|
|
10
|
+
constructor(options) {
|
|
11
|
+
this.options = options;
|
|
12
|
+
}
|
|
13
|
+
/** Start a reattach attempt for a run unless one is running or the run is controlled; resolves when it has finished. Never rejects. */
|
|
14
|
+
begin(runId) {
|
|
15
|
+
const existing = this.pending.get(runId);
|
|
16
|
+
if (existing)
|
|
17
|
+
return existing;
|
|
18
|
+
if (this.options.controls.has(runId))
|
|
19
|
+
return Promise.resolve();
|
|
20
|
+
const retry = this.retries.get(runId);
|
|
21
|
+
if (retry?.timer)
|
|
22
|
+
clearTimeout(retry.timer);
|
|
23
|
+
if (retry)
|
|
24
|
+
retry.timer = null;
|
|
25
|
+
const attempt = this.attempt(runId).finally(() => this.pending.delete(runId));
|
|
26
|
+
this.pending.set(runId, attempt);
|
|
27
|
+
return attempt;
|
|
28
|
+
}
|
|
29
|
+
/** Whether the run's attempt (started if need be) finished within `ms`. */
|
|
30
|
+
async settle(runId, ms) {
|
|
31
|
+
let timer;
|
|
32
|
+
const timeout = new Promise((resolve) => (timer = setTimeout(() => resolve(false), ms)));
|
|
33
|
+
try {
|
|
34
|
+
return await Promise.race([this.begin(runId).then(() => true), timeout]);
|
|
35
|
+
}
|
|
36
|
+
finally {
|
|
37
|
+
clearTimeout(timer);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
async attempt(runId) {
|
|
41
|
+
try {
|
|
42
|
+
const result = await this.options.reconnect(this.options.stateDir, runId);
|
|
43
|
+
if (result.live)
|
|
44
|
+
this.options.controls.set(runId, result.control);
|
|
45
|
+
if (!result.live && result.liveness.alive)
|
|
46
|
+
this.retryLater(runId);
|
|
47
|
+
else
|
|
48
|
+
this.retries.delete(runId);
|
|
49
|
+
// A worker that is not alive is settled `unknown` by the store read, as before.
|
|
50
|
+
}
|
|
51
|
+
catch (err) {
|
|
52
|
+
// Liveness could not be established: try again on the next control request.
|
|
53
|
+
this.options.warn(`culture-agents core: could not reattach to run ${runId}: ${err instanceof Error ? err.message : String(err)}`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/** Schedule the next attempt for a live worker that did not answer, doubling the delay up to `RETRY_MAX_MS`. */
|
|
57
|
+
retryLater(runId) {
|
|
58
|
+
const previous = this.retries.get(runId)?.delay;
|
|
59
|
+
const delay = previous === undefined ? RETRY_FIRST_MS : Math.min(previous * 2, RETRY_MAX_MS);
|
|
60
|
+
const timer = setTimeout(() => {
|
|
61
|
+
const retry = this.retries.get(runId);
|
|
62
|
+
if (retry)
|
|
63
|
+
retry.timer = null;
|
|
64
|
+
this.begin(runId).then(ignore, ignore);
|
|
65
|
+
}, delay);
|
|
66
|
+
timer.unref();
|
|
67
|
+
this.retries.set(runId, { delay, timer });
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=reattach.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reattach.js","sourceRoot":"","sources":["../../../src/runs/reattach.ts"],"names":[],"mappings":"AAgBA,wGAAwG;AACxG,MAAM,CAAC,MAAM,cAAc,GAAG,GAAG,CAAC;AAClC,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC;AASnC,MAAM,MAAM,GAAG,GAAS,EAAE,CAAC,SAAS,CAAC;AAErC,MAAM,OAAO,UAAU;IAKQ;IAJZ,OAAO,GAAG,IAAI,GAAG,EAAwB,CAAC;IAC3D,+FAA+F;IAC9E,OAAO,GAAG,IAAI,GAAG,EAA0D,CAAC;IAE7F,YAA6B,OAA0B;QAA1B,YAAO,GAAP,OAAO,CAAmB;IAAG,CAAC;IAE3D,uIAAuI;IACvI,KAAK,CAAC,KAAY;QAChB,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK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CAAC,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACzC,CAAC,EAAE,KAAK,CAAC,CAAC;QACV,KAAK,CAAC,KAAK,EAAE,CAAC;QACd,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;IAC5C,CAAC;CACF"}
|
package/dist/src/runs/scan.d.ts
CHANGED
|
@@ -5,6 +5,8 @@ export interface ScanOptions {
|
|
|
5
5
|
controllable: (runId: RunId) => boolean;
|
|
6
6
|
/** Where to report a run that cannot be read (corrupt log or record). */
|
|
7
7
|
warn: (line: string) => void;
|
|
8
|
+
/** How store files are read; tests inject a counting reader. Default `fs.readFileSync`. */
|
|
9
|
+
readFile?: (path: string) => Buffer;
|
|
8
10
|
}
|
|
9
11
|
/** A run directory exists but its record or log cannot be read. The run is not "absent": it is unreadable. */
|
|
10
12
|
export declare class UnreadableRunError extends Error {
|
|
@@ -19,16 +21,19 @@ export declare class UnreadableRunError extends Error {
|
|
|
19
21
|
* with `strict` (a caller asking for that one run must not be told it does not exist).
|
|
20
22
|
*/
|
|
21
23
|
export declare function readRun(options: ScanOptions, runId: string, strict?: boolean): Run | null;
|
|
24
|
+
/** A run whose stored state cannot be read and whose worker may be alive, with the repository its record names (null when that cannot be read either). */
|
|
25
|
+
export interface UnreadableLiveRun {
|
|
26
|
+
id: string;
|
|
27
|
+
repo: string | null;
|
|
28
|
+
}
|
|
22
29
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
30
|
+
* Every unreadable run that may still be working: its worker is alive (or its liveness cannot be
|
|
31
|
+
* read). A configured limit counts such a run as active, because treating it as absent could let
|
|
32
|
+
* more runs start than the operator allowed. With no limit configured nothing reads this.
|
|
26
33
|
*/
|
|
27
|
-
export declare function
|
|
34
|
+
export declare function unreadableLiveRuns(options: ScanOptions): UnreadableLiveRun[];
|
|
28
35
|
/** Every established run in the store, newest first by `created_at` (README: runs.list). */
|
|
29
36
|
export declare function scanRuns(options: ScanOptions): Run[];
|
|
30
|
-
/** The active run holding a canonical repository, if any. A run whose worker survived a restart counts. */
|
|
31
|
-
export declare function activeRunFor(options: ScanOptions, repo: string): Run | null;
|
|
32
37
|
/**
|
|
33
38
|
* The outcome of a terminal run, from its log. `summary` is the concatenation of the harness's
|
|
34
39
|
* `text` output deltas (null when there were none); `error` is the last fatal `run.error`, and a
|
package/dist/src/runs/scan.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* then the log's only writer (README: `unknown`).
|
|
6
6
|
*/
|
|
7
7
|
import { existsSync, readFileSync } from "node:fs";
|
|
8
|
-
import {
|
|
8
|
+
import { isRunId, } from "../contract/index.js";
|
|
9
9
|
import { readLog } from "../store/event-log.js";
|
|
10
10
|
import { runDir, runFile } from "../store/files.js";
|
|
11
11
|
import { checkLiveness } from "../store/liveness.js";
|
|
@@ -33,7 +33,8 @@ export function readRun(options, runId, strict = false) {
|
|
|
33
33
|
if (!existsSync(dir))
|
|
34
34
|
return null;
|
|
35
35
|
try {
|
|
36
|
-
|
|
36
|
+
// A live worker whose control socket does not answer keeps its logged state with `live_control: false`; it is never `unknown`.
|
|
37
|
+
return showRunAt(dir, { controllable: options.controllable(runId), settle: true, ...(options.readFile && { readFile: options.readFile }) })?.run ?? null;
|
|
37
38
|
}
|
|
38
39
|
catch (err) {
|
|
39
40
|
const detail = err instanceof Error ? err.message : String(err);
|
|
@@ -44,15 +45,16 @@ export function readRun(options, runId, strict = false) {
|
|
|
44
45
|
}
|
|
45
46
|
}
|
|
46
47
|
/**
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
48
|
+
* Every unreadable run that may still be working: its worker is alive (or its liveness cannot be
|
|
49
|
+
* read). A configured limit counts such a run as active, because treating it as absent could let
|
|
50
|
+
* more runs start than the operator allowed. With no limit configured nothing reads this.
|
|
50
51
|
*/
|
|
51
|
-
export function
|
|
52
|
+
export function unreadableLiveRuns(options) {
|
|
53
|
+
const out = [];
|
|
52
54
|
for (const id of listRunIds(options.stateDir)) {
|
|
53
55
|
const dir = runDir(options.stateDir, id);
|
|
54
56
|
try {
|
|
55
|
-
showRunAt(dir, { controllable: false, settle: false });
|
|
57
|
+
showRunAt(dir, { controllable: false, settle: false, ...(options.readFile && { readFile: options.readFile }) });
|
|
56
58
|
continue;
|
|
57
59
|
}
|
|
58
60
|
catch {
|
|
@@ -72,12 +74,11 @@ export function unreadableRunHolding(options, repo) {
|
|
|
72
74
|
recorded = JSON.parse(readFileSync(runFile(dir, "record"), "utf8")).repo;
|
|
73
75
|
}
|
|
74
76
|
catch {
|
|
75
|
-
|
|
77
|
+
recorded = null;
|
|
76
78
|
}
|
|
77
|
-
|
|
78
|
-
return id;
|
|
79
|
+
out.push({ id, repo: typeof recorded === "string" ? recorded : null });
|
|
79
80
|
}
|
|
80
|
-
return
|
|
81
|
+
return out;
|
|
81
82
|
}
|
|
82
83
|
/** Every established run in the store, newest first by `created_at` (README: runs.list). */
|
|
83
84
|
export function scanRuns(options) {
|
|
@@ -89,10 +90,6 @@ export function scanRuns(options) {
|
|
|
89
90
|
}
|
|
90
91
|
return runs.sort(newestFirst);
|
|
91
92
|
}
|
|
92
|
-
/** The active run holding a canonical repository, if any. A run whose worker survived a restart counts. */
|
|
93
|
-
export function activeRunFor(options, repo) {
|
|
94
|
-
return scanRuns(options).find((run) => run.repo === repo && isActive(run.state)) ?? null;
|
|
95
|
-
}
|
|
96
93
|
const SHA = /^[0-9a-f]{40}([0-9a-f]{24})?$/;
|
|
97
94
|
/** The commits the worker recorded for a run's branch, oldest first; empty when none were recorded or the file is unusable. */
|
|
98
95
|
function collectedCommits(dir, branch) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scan.js","sourceRoot":"","sources":["../../../src/runs/scan.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CA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AAW,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC;IACnE,IAAI,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QACzC,KAAK,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,CAAC,YAAY,IAAI,0CAA0C,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;IAC1H,CAAC;IACD,OAAO;QACL,MAAM,EAAE,GAAG,CAAC,EAAE;QACd,KAAK;QACL,OAAO,EAAE,IAAI;QACb,MAAM,EAAE,GAAG,CAAC,MAAM;QAClB,OAAO,EAAE,gBAAgB,CAAC,GAAG,EAAE,GAAG,CAAC,MAAM,CAAC;QAC1C,QAAQ,EAAE,GAAG,CAAC,QAAQ,IAAI,GAAG,CAAC,UAAU;QACxC,KAAK;KACO,CAAC,CAAC,kFAAkF;AACpG,CAAC"}
|
|
@@ -6,11 +6,17 @@
|
|
|
6
6
|
* empty, so a surviving worker's run reports `live_control: false` and its steer and cancel are
|
|
7
7
|
* refused naming `reconnect`; the worker is never signalled. Every reported state is derived from
|
|
8
8
|
* the store (scan.ts), and a run with neither a live worker nor a terminal event settles `unknown`.
|
|
9
|
+
*
|
|
10
|
+
* Idempotency keys (keys.ts, store/idempotency.ts): a submit writes its key, then the run
|
|
11
|
+
* directory, then spawns the worker, so a core killed at any step leaves evidence that the next
|
|
12
|
+
* core settles at startup (`reconcile`). Steer and cancel write their key before delivery.
|
|
9
13
|
*/
|
|
10
|
-
import { type AcceptedResponse, type Agent, type AgentList, type CancelRequest, type Capabilities, type ErrorBody, type EventPage, type Run, type RunEvent, type RunResult, type SteerRequest, type SubmitRequest } from "../contract/index.js";
|
|
14
|
+
import { type AcceptedResponse, type Agent, type AgentList, type AnswerRequest, type CancelRequest, type Capabilities, type ErrorBody, type EventPage, type Limits, type Run, type RunEvent, type RunResult, type SteerRequest, type SubmitRequest, type Submitter, type SubmitResponse } from "../contract/index.js";
|
|
11
15
|
import type { AllowlistState } from "../daemon/allowlist.js";
|
|
12
16
|
import type { DeferredKind, DeferredRequest, RunListQuery, RunService } from "../daemon/ports.js";
|
|
17
|
+
import { type SubmitFault } from "./keys.js";
|
|
13
18
|
import type { HarnessCatalog } from "./ports.js";
|
|
19
|
+
import { type ReconnectFn } from "./reattach.js";
|
|
14
20
|
export interface RunServiceOptions {
|
|
15
21
|
/** The run store's state directory. */
|
|
16
22
|
stateDir: string;
|
|
@@ -25,29 +31,59 @@ export interface RunServiceOptions {
|
|
|
25
31
|
heartbeatMs?: number;
|
|
26
32
|
cancelGraceMs?: number;
|
|
27
33
|
readyTimeoutMs?: number;
|
|
34
|
+
questionLimitMs?: number;
|
|
35
|
+
steerTimeoutMs?: number;
|
|
28
36
|
env?: NodeJS.ProcessEnv;
|
|
29
37
|
};
|
|
30
38
|
/** Poll interval of a live event stream. Default 20 ms. */
|
|
31
39
|
followPollMs?: number;
|
|
32
40
|
warn?: (line: string) => void;
|
|
41
|
+
/** How long a control request waits for its run's reattach attempt before `unavailable` with `retry_after_ms`. Default 5000. */
|
|
42
|
+
reattachWaitMs?: number;
|
|
43
|
+
/** Reaches a surviving worker. Default `reconnectWorker`; tests hold it open. */
|
|
44
|
+
reconnect?: ReconnectFn;
|
|
45
|
+
/** How store files are read (event logs, summaries). Default `fs.readFileSync`; tests inject a counting reader. */
|
|
46
|
+
readFile?: (path: string) => Buffer;
|
|
47
|
+
/** How long an established key of a terminal run is remembered after the run ended. Default 7 days. */
|
|
48
|
+
keyRetentionMs?: number;
|
|
49
|
+
/** Fault injection at each step of a submit (tests only). */
|
|
50
|
+
submitFault?: SubmitFault;
|
|
51
|
+
/** The operator's limits from the core's config file (daemon/limits.ts). Default: none. */
|
|
52
|
+
limits?: Limits;
|
|
53
|
+
/** The environment the heat signal's path is read from. Default: the process environment. */
|
|
54
|
+
env?: Readonly<Record<string, string | undefined>>;
|
|
55
|
+
/** How the heat state file is read (tests inject the payload). Default: `fs.readFileSync`. */
|
|
56
|
+
readHeatFile?: (path: string) => string;
|
|
33
57
|
}
|
|
58
|
+
/** Default `keyRetentionMs`: 7 days. */
|
|
59
|
+
export declare const KEY_RETENTION_MS: number;
|
|
34
60
|
export declare class StoreRunService implements RunService {
|
|
35
61
|
private readonly options;
|
|
36
62
|
private readonly controls;
|
|
37
63
|
private readonly scan;
|
|
64
|
+
private readonly reattacher;
|
|
38
65
|
private readonly now;
|
|
39
|
-
|
|
66
|
+
private readonly keys;
|
|
67
|
+
/** Serializes submits so the limit check and the spawn are one step. */
|
|
40
68
|
private submitChain;
|
|
41
69
|
constructor(options: RunServiceOptions);
|
|
42
70
|
/**
|
|
43
71
|
* Startup reconciliation: rebuild every run from disk. Orphaned runs (no live worker, no
|
|
44
|
-
* terminal event) get `unknown` appended; surviving workers are
|
|
45
|
-
*
|
|
72
|
+
* terminal event) get `unknown` appended; surviving workers are never signalled: the core
|
|
73
|
+
* reattaches to each over its control socket (started here, finished in the background; a control
|
|
74
|
+
* request waits for its run's attempt). Existing events are never rewritten. Returns the runs.
|
|
46
75
|
*/
|
|
47
76
|
reconcile(): Run[];
|
|
77
|
+
/** Housekeeping, on the daemon's interval: forget expired keys. Returns the keys removed. */
|
|
78
|
+
pruneExpiredKeys(): string[];
|
|
79
|
+
/**
|
|
80
|
+
* Forget established keys whose run directory is gone, or whose run ended longer ago than the
|
|
81
|
+
* retention. A run the scan could not read is not gone: its key is kept.
|
|
82
|
+
*/
|
|
83
|
+
private pruneKeys;
|
|
48
84
|
/** Ask the harnesses to delete what finished runs of this store left behind (README: cancel, sandbox). */
|
|
49
85
|
reclaim(): Promise<string[]>;
|
|
50
|
-
submit(request: SubmitRequest): Promise<
|
|
86
|
+
submit(request: SubmitRequest, submitter?: Submitter): Promise<SubmitResponse>;
|
|
51
87
|
private submitNow;
|
|
52
88
|
listRuns(query: RunListQuery): Promise<Run[]>;
|
|
53
89
|
/** One run, or null when there is none. A run that exists but cannot be read is `internal` on every route, never "no such run". */
|
|
@@ -56,14 +92,28 @@ export declare class StoreRunService implements RunService {
|
|
|
56
92
|
readEvents(runId: string, after: number, limit: number): Promise<EventPage | null>;
|
|
57
93
|
streamEvents(runId: string, after: number, signal: AbortSignal): AsyncIterable<RunEvent>;
|
|
58
94
|
getResult(runId: string): Promise<RunResult>;
|
|
59
|
-
steer(runId: string, request: SteerRequest): Promise<AcceptedResponse
|
|
60
|
-
cancel(runId: string, request: CancelRequest): Promise<AcceptedResponse
|
|
95
|
+
steer(runId: string, request: SteerRequest): Promise<AcceptedResponse>;
|
|
96
|
+
cancel(runId: string, request: CancelRequest): Promise<AcceptedResponse>;
|
|
97
|
+
/**
|
|
98
|
+
* A steer or cancel under its idempotency key: a repeat returns the first action and delivers
|
|
99
|
+
* nothing; a new key is written (reserved, with the action id) just before delivery, established
|
|
100
|
+
* once the worker accepted, and released when the worker refused it. With no answer (a timeout)
|
|
101
|
+
* the key is settled from the log, and stays reserved while the outcome is not known yet.
|
|
102
|
+
*/
|
|
103
|
+
private keyed;
|
|
61
104
|
private act;
|
|
105
|
+
/** Steps 5 to 9 of an answer to one of the run's questions (answer.ts). */
|
|
106
|
+
answer(runId: string, request: AnswerRequest): Promise<AcceptedResponse>;
|
|
107
|
+
/** The run as a control target, once its reattach attempt (after a core restart) has finished. */
|
|
108
|
+
private target;
|
|
62
109
|
/** Step 4, decided by the server: write the refusal to the log of a live run this core controls. Never rejects. */
|
|
63
110
|
recordRefusal(runId: string, kind: DeferredKind, request: DeferredRequest, error: ErrorBody): Promise<void>;
|
|
64
111
|
listAgents(): Promise<AgentList>;
|
|
65
112
|
getAgent(agentId: string): Promise<Agent | null>;
|
|
66
113
|
listHarnesses(): Promise<Capabilities[]>;
|
|
114
|
+
private hostEnv;
|
|
115
|
+
/** Every capability document with this host's limits, active runs and admission. */
|
|
116
|
+
private documents;
|
|
67
117
|
getHarness(harness: string): Promise<Capabilities | null>;
|
|
68
118
|
}
|
|
69
119
|
/** A run service; no I/O until used. Call `reconcile()` once the daemon holds its lock. */
|