@sentropic/artifacts 0.2.24 → 0.2.26
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 +28 -0
- package/dist/live-host/index.d.ts +1 -0
- package/dist/live-host/index.js +1 -0
- package/dist/live-host/recheck.d.ts +6 -0
- package/dist/live-host/recheck.js +2 -2
- package/dist/live-host/reconcile.d.ts +145 -0
- package/dist/live-host/reconcile.js +304 -0
- package/dist/mcp-core.d.ts +1 -1
- package/dist/mcp-core.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.25
|
|
4
|
+
|
|
5
|
+
- `@sentropic/artifacts/live-host` ships a generic pending-build reconcile: `reconcilePendingBuilds`
|
|
6
|
+
sweeps the host jobs stuck in `build_pending`/`building` past a threshold with bounded concurrency
|
|
7
|
+
(the threshold is enforced by the sweep on top of the host filter), and `reconcilePendingBuild`
|
|
8
|
+
reconciles one job on demand for the `live_status`, `git_publish` and `artifacts_get` read paths.
|
|
9
|
+
Both read the builder `GET /v1/builds/:artifactId/:jobId` status
|
|
10
|
+
(`build_pending`/`published`/`build_failed`, `code`/`reason`, `releaseId`) through a host status
|
|
11
|
+
client and apply only allowed transitions: the job moves to `build_failed` (with the builder
|
|
12
|
+
`code`/`reason`, blank codes dropped to the `build_failed` default) or to `published` (with the
|
|
13
|
+
`releaseId` from the stored handoff receipt when the receipts port is wired, else from the builder
|
|
14
|
+
status; without either no release is invented), and the git binding moves from `build_pending` to
|
|
15
|
+
`build_failed` under the version CAS (`server/git-bindings.ts:51`, action `publish`), stamping the
|
|
16
|
+
failure code on the binding `stateDetail`. The binding leads so a crash between the two writes still
|
|
17
|
+
converges; terminal rows are never regressed, rows are never deleted, and disagreements fail closed
|
|
18
|
+
(`receipt-conflict`, `binding-conflict`, `binding-still-pending`, `no-release`): a wired ledger
|
|
19
|
+
without a receipt never publishes on the builder word alone, a `build_failed` status is re-read
|
|
20
|
+
before any write (the builder re-admits the same `jobId` and flips `failed` to `published`
|
|
21
|
+
asynchronously), a version race won by the success path leaves the job alone, and a still-pending
|
|
22
|
+
binding leaves the job pending for the next run. The failure idempotency key binds the binding
|
|
23
|
+
version and pending SHA, so a re-pended `jobId` writes anew instead of replaying the older failure.
|
|
24
|
+
`ReconcileJobStore.markFailed` takes `code`/`reason` as optional hints for hosts without those
|
|
25
|
+
columns. Per-item outages report a bounded `error` stage (`store-error` never claims `unchanged`
|
|
26
|
+
for a committed write). Host ports only (`ReconcileJobStore`, `ReconcileStatusClient`,
|
|
27
|
+
the package `GitBindingStore`, optional `HostLedger.find`); no immo code in the package.
|
|
28
|
+
- `ARTIFACTS_PROVIDER_VERSION` follows the package (0.2.25): the APP-P1 manifest digest changes
|
|
29
|
+
through its version field only (four-tool selection and tool definitions unchanged).
|
|
30
|
+
|
|
3
31
|
## 0.2.24
|
|
4
32
|
|
|
5
33
|
- `artifacts_live_status` and `artifacts_live_control` start no longer walk the repository tree: they
|
|
@@ -10,3 +10,4 @@ export { encodeHandoffRequest, HOST_BUILD_PATHS, JOB_REQUEST_LIFETIME_MS, parseH
|
|
|
10
10
|
export { ASSERTION_HEADER, CONTROL_HEADER, FENCE_HEADER, MAX_ASSERTION_SECONDS, MAX_CONTROL_SECONDS, MAX_SKEW_SECONDS, MAX_SOURCE_REVISION_LENGTH, MIN_KEY_BYTES, signLiveAssertion, signLiveControl, signLiveFence, verifyLiveAssertion, verifyLiveControl, verifyLiveFence, type LiveAssertionClaims, type LiveControlClaims, type LiveFenceClaims, type VerifyOptions, } from './live-format.js';
|
|
11
11
|
export { LIVE_DRAFT_LIMITS, LIVE_DRAFT_PATHS, liveStoreDrafts, planLiveDraft, stageLiveDraft, type LiveDraftPageBody, type LiveDraftPageFile, type LiveDraftPlan, type LiveDraftSealBody, type LiveDraftSend, type LiveDraftSnapshot, type LiveDraftSource, } from './draft-stager.js';
|
|
12
12
|
export { createLiveWorkerClient, LIVE_WORKER_PATHS, liveStoreFences, type LiveBridgeAck, type LiveWorkerClientOptions, type LiveWorkerFences, } from './worker-client.js';
|
|
13
|
+
export { parseReconcileBuilderStatus, reconcilePendingBuild, reconcilePendingBuilds, RECONCILE_DEFAULTS, RECONCILE_ERROR_CODES, RECONCILE_ERROR_STAGES, RECONCILE_OUTCOMES, ReconcileError, type ReconcileBuilderStatus, type ReconcileErrorCode, type ReconcileErrorStage, type ReconcileItemResult, type ReconcileJobStore, type ReconcileOptions, type ReconcileOutcome, type ReconcilePendingJob, type ReconcileReport, type ReconcileStatusClient, } from './reconcile.js';
|
package/dist/live-host/index.js
CHANGED
|
@@ -10,3 +10,4 @@ export { encodeHandoffRequest, HOST_BUILD_PATHS, JOB_REQUEST_LIFETIME_MS, parseH
|
|
|
10
10
|
export { ASSERTION_HEADER, CONTROL_HEADER, FENCE_HEADER, MAX_ASSERTION_SECONDS, MAX_CONTROL_SECONDS, MAX_SKEW_SECONDS, MAX_SOURCE_REVISION_LENGTH, MIN_KEY_BYTES, signLiveAssertion, signLiveControl, signLiveFence, verifyLiveAssertion, verifyLiveControl, verifyLiveFence, } from './live-format.js';
|
|
11
11
|
export { LIVE_DRAFT_LIMITS, LIVE_DRAFT_PATHS, liveStoreDrafts, planLiveDraft, stageLiveDraft, } from './draft-stager.js';
|
|
12
12
|
export { createLiveWorkerClient, LIVE_WORKER_PATHS, liveStoreFences, } from './worker-client.js';
|
|
13
|
+
export { parseReconcileBuilderStatus, reconcilePendingBuild, reconcilePendingBuilds, RECONCILE_DEFAULTS, RECONCILE_ERROR_CODES, RECONCILE_ERROR_STAGES, RECONCILE_OUTCOMES, ReconcileError, } from './reconcile.js';
|
|
@@ -22,6 +22,9 @@ export interface HostRecheckView {
|
|
|
22
22
|
autoPublish: boolean;
|
|
23
23
|
pendingJobId: string | null;
|
|
24
24
|
pendingCommitSha: string | null;
|
|
25
|
+
/** Binding owner's principalId (personalPrincipalId, attachedBy fallback): the builder seeds its
|
|
26
|
+
* binding view from this field when the binding was never reconciled. */
|
|
27
|
+
ownerId: string;
|
|
25
28
|
};
|
|
26
29
|
/** The persisted G0 v3 §2.6 job; `fence` is the attempt last admitted by `resolvePendingJob`. */
|
|
27
30
|
job: {
|
|
@@ -48,6 +51,9 @@ export interface HostJob {
|
|
|
48
51
|
generation: number;
|
|
49
52
|
headSha: string;
|
|
50
53
|
expectedReleaseId: string | null;
|
|
54
|
+
/** Binding owner's principalId, copied from the pending job's binding: the builder's only owner source
|
|
55
|
+
* before the first live reconcile. */
|
|
56
|
+
ownerId: string;
|
|
51
57
|
}
|
|
52
58
|
/** Every §8.3 final recheck, in order; null admits. acceptHandoff applies it; the host only supplies the view. */
|
|
53
59
|
export declare function publicationRecheck(view: HostRecheckView, claims: HandoffClaims): RecheckRefusal | null;
|
|
@@ -40,6 +40,6 @@ export function resolvePendingJob(view, jobId, fence) {
|
|
|
40
40
|
|| (job.fence && (fence.attempt < job.fence.attempt || (fence.attempt === job.fence.attempt && fence.runId !== job.fence.runId)))) {
|
|
41
41
|
return null;
|
|
42
42
|
}
|
|
43
|
-
return { job: { jobId, generation: job.bindingGeneration, headSha: job.commitSha, expectedReleaseId: job.expectedCurrentReleaseId
|
|
44
|
-
|
|
43
|
+
return { job: { jobId, generation: job.bindingGeneration, headSha: job.commitSha, expectedReleaseId: job.expectedCurrentReleaseId,
|
|
44
|
+
ownerId: view.binding.ownerId }, fence: { runId: fence.runId, attempt: fence.attempt } };
|
|
45
45
|
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import type { GitBindingStore } from '../server/git-contracts.js';
|
|
2
|
+
import type { HostLedger } from './accept.js';
|
|
3
|
+
/** Builder status answer of `GET /v1/builds/:artifactId/:jobId` (contract #969): the host-facing
|
|
4
|
+
* `GitBuildJobState` vocabulary, never the builder ledger states. A `published` status carries the
|
|
5
|
+
* receipt `releaseId`; a `build_failed` status carries a closed builder `code` and its `reason`. */
|
|
6
|
+
export interface ReconcileBuilderStatus {
|
|
7
|
+
readonly jobId: string;
|
|
8
|
+
readonly state: 'build_pending' | 'published' | 'build_failed';
|
|
9
|
+
readonly code?: string | undefined;
|
|
10
|
+
readonly reason?: string | undefined;
|
|
11
|
+
readonly releaseId?: string | undefined;
|
|
12
|
+
}
|
|
13
|
+
/** Pending host job the sweep may touch. `updatedAtMs` drives the older-than threshold, enforced by
|
|
14
|
+
* the sweep itself on top of the host filter, so a host that ignores the filter cannot fail fresh jobs. */
|
|
15
|
+
export interface ReconcilePendingJob {
|
|
16
|
+
readonly scopeId: string;
|
|
17
|
+
readonly artifactId: string;
|
|
18
|
+
readonly jobId: string;
|
|
19
|
+
readonly updatedAtMs: number;
|
|
20
|
+
}
|
|
21
|
+
/** Host port: the pending-job store. Updates move a pending job to a terminal state only
|
|
22
|
+
* (compare-and-swap on the pending state); rows are never deleted. */
|
|
23
|
+
export interface ReconcileJobStore {
|
|
24
|
+
/** Jobs still pending, oldest first, bounded by `limit`. The host filters on `updatedAtMs`; the sweep
|
|
25
|
+
* re-checks the threshold itself, so a host that ignores the filter only wastes a status call. */
|
|
26
|
+
listPending(input: {
|
|
27
|
+
nowMs: number;
|
|
28
|
+
olderThanMs: number;
|
|
29
|
+
limit: number;
|
|
30
|
+
}): Promise<readonly ReconcilePendingJob[]>;
|
|
31
|
+
/** Current row, whatever its state; undefined when the host never recorded the job. */
|
|
32
|
+
read(input: {
|
|
33
|
+
scopeId: string;
|
|
34
|
+
artifactId: string;
|
|
35
|
+
jobId: string;
|
|
36
|
+
}): Promise<{
|
|
37
|
+
state: string;
|
|
38
|
+
} | undefined>;
|
|
39
|
+
/** Pending to `build_failed` only; answers whether the row moved. Never regresses a terminal row.
|
|
40
|
+
* `code`/`reason` are hints: a host without those columns ignores them — the failure code is also
|
|
41
|
+
* stamped on the binding `stateDetail` (package store), so it is never lost. */
|
|
42
|
+
markFailed(input: {
|
|
43
|
+
scopeId: string;
|
|
44
|
+
artifactId: string;
|
|
45
|
+
jobId: string;
|
|
46
|
+
code?: string | undefined;
|
|
47
|
+
reason?: string | undefined;
|
|
48
|
+
}): Promise<'updated' | 'already-terminal' | 'not-found'>;
|
|
49
|
+
/** Pending to `published` with the receipt `releaseId`; answers whether the row moved. Never invents a release. */
|
|
50
|
+
markPublished(input: {
|
|
51
|
+
scopeId: string;
|
|
52
|
+
artifactId: string;
|
|
53
|
+
jobId: string;
|
|
54
|
+
releaseId: string;
|
|
55
|
+
}): Promise<'updated' | 'already-terminal' | 'not-found'>;
|
|
56
|
+
}
|
|
57
|
+
/** Host port: the builder status client (immo `createHostBuildApiClient.status`). A transport
|
|
58
|
+
* failure throws (the item is skipped as `status-unavailable`); an unknown job answers undefined.
|
|
59
|
+
* `unknown-job` writes nothing and never converges by design (reconcile never deletes): the host must
|
|
60
|
+
* bound such rows itself (alert or escalate after N sweeps) — e.g. a job recorded but never POSTed. */
|
|
61
|
+
export interface ReconcileStatusClient {
|
|
62
|
+
status(input: {
|
|
63
|
+
scopeId: string;
|
|
64
|
+
artifactId: string;
|
|
65
|
+
jobId: string;
|
|
66
|
+
}): Promise<ReconcileBuilderStatus | undefined>;
|
|
67
|
+
}
|
|
68
|
+
/** Closed per-item outcome of one reconciled job. `store-error` is a per-item host-store outage:
|
|
69
|
+
* the item is skipped and the sweep continues; only invalid options and the initial pending
|
|
70
|
+
* listing throw. */
|
|
71
|
+
export declare const RECONCILE_OUTCOMES: readonly ["job-build-failed", "job-published", "still-pending", "already-terminal", "unknown-job", "status-unavailable", "status-invalid", "no-release", "receipt-conflict", "job-not-found", "binding-still-pending", "binding-conflict", "store-error"];
|
|
72
|
+
export type ReconcileOutcome = typeof RECONCILE_OUTCOMES[number];
|
|
73
|
+
/** Bounded pipeline stage where a `store-error` struck. The stage names the throwing call without
|
|
74
|
+
* exposing store internals, so a perpetual outage is alertable instead of silent. */
|
|
75
|
+
export declare const RECONCILE_ERROR_STAGES: readonly ["list-pending", "read-job", "read-status", "read-receipt", "confirm-status", "write-binding", "write-job", "read-binding"];
|
|
76
|
+
export type ReconcileErrorStage = typeof RECONCILE_ERROR_STAGES[number];
|
|
77
|
+
export interface ReconcileItemResult {
|
|
78
|
+
readonly scopeId: string;
|
|
79
|
+
readonly artifactId: string;
|
|
80
|
+
readonly jobId: string;
|
|
81
|
+
readonly outcome: ReconcileOutcome;
|
|
82
|
+
/** Whether the job row moved to its terminal state. On `store-error` this reports the writes that
|
|
83
|
+
* already committed before the failure, so a committed row is never reported `unchanged`. */
|
|
84
|
+
readonly job: 'updated' | 'unchanged';
|
|
85
|
+
/** Whether the binding moved from `build_pending` to `build_failed`. Unchanged by reconcile on
|
|
86
|
+
* the published path: the host publish transaction owns that transition, and a still-pending
|
|
87
|
+
* binding leaves the job pending too, reported as `binding-still-pending` for the next run. */
|
|
88
|
+
readonly binding: 'updated' | 'unchanged';
|
|
89
|
+
/** Present only on `store-error`: the stage that threw. */
|
|
90
|
+
readonly error?: ReconcileErrorStage | undefined;
|
|
91
|
+
}
|
|
92
|
+
export interface ReconcileReport {
|
|
93
|
+
readonly checked: number;
|
|
94
|
+
readonly updated: number;
|
|
95
|
+
readonly items: readonly ReconcileItemResult[];
|
|
96
|
+
}
|
|
97
|
+
export interface ReconcileOptions {
|
|
98
|
+
/** Pending-job store of the host. */
|
|
99
|
+
readonly jobs: ReconcileJobStore;
|
|
100
|
+
/** Builder status client of the host. */
|
|
101
|
+
readonly status: ReconcileStatusClient;
|
|
102
|
+
/** Package git binding store; only `build_pending` to `build_failed` is ever written. */
|
|
103
|
+
readonly bindings: Pick<GitBindingStore, 'get' | 'write'>;
|
|
104
|
+
/** Optional receipt read: a builder `published` applies the stored receipt `releaseId` first. */
|
|
105
|
+
readonly receipts?: Pick<HostLedger, 'find'> | undefined;
|
|
106
|
+
/** Actor stamped on the binding `publish` event (default `system:reconcile-pending-builds`). */
|
|
107
|
+
readonly systemActorId?: string | undefined;
|
|
108
|
+
readonly now?: () => number;
|
|
109
|
+
/** A pending job older than this is reconciled by the sweep (default 10 min). */
|
|
110
|
+
readonly olderThanMs?: number | undefined;
|
|
111
|
+
/** Upper bound of jobs per sweep (default 100, at most 500). */
|
|
112
|
+
readonly limit?: number | undefined;
|
|
113
|
+
/** Parallel status reads (default 4, at most 8). Store writes stay sequential per job. */
|
|
114
|
+
readonly concurrency?: number | undefined;
|
|
115
|
+
}
|
|
116
|
+
/** Closed reconcile input errors; per-item builder outcomes stay data, never throws. */
|
|
117
|
+
export declare const RECONCILE_ERROR_CODES: readonly ["reconcile_invalid_options"];
|
|
118
|
+
export type ReconcileErrorCode = typeof RECONCILE_ERROR_CODES[number];
|
|
119
|
+
export declare class ReconcileError extends Error {
|
|
120
|
+
readonly code: ReconcileErrorCode;
|
|
121
|
+
constructor(code: ReconcileErrorCode, detail?: string);
|
|
122
|
+
}
|
|
123
|
+
export declare const RECONCILE_DEFAULTS: Readonly<{
|
|
124
|
+
olderThanMs: 600000;
|
|
125
|
+
limit: 100;
|
|
126
|
+
concurrency: 4;
|
|
127
|
+
}>;
|
|
128
|
+
/** Bounded builder status shape (length-bounded strings over the exact contract state set); anything
|
|
129
|
+
* else is `status-invalid` and writes nothing. Extra keys are ignored: the builder is an
|
|
130
|
+
* authenticated peer, so unknown fields stay data, never a refusal. A `published` status may carry
|
|
131
|
+
* `code`/`reason` (ignored); a blank `code`/`reason` is dropped at the call site, and a `build_failed`
|
|
132
|
+
* status without `code` gets the `build_failed` default there. */
|
|
133
|
+
export declare function parseReconcileBuilderStatus(raw: unknown, jobId: string): ReconcileBuilderStatus | undefined;
|
|
134
|
+
/** On-demand reconcile of one pending job for the host read paths (`live_status`, `git_publish`,
|
|
135
|
+
* `artifacts_get`). No age check; terminal rows and unknown builders write nothing. */
|
|
136
|
+
export declare function reconcilePendingBuild(options: ReconcileOptions, key: {
|
|
137
|
+
scopeId: string;
|
|
138
|
+
artifactId: string;
|
|
139
|
+
jobId: string;
|
|
140
|
+
}): Promise<ReconcileItemResult>;
|
|
141
|
+
/** Sweep of the host pending jobs older than the threshold. One per-item failure never aborts the
|
|
142
|
+
* sweep: store and builder outages surface per item as `store-error`/`status-unavailable`. Only
|
|
143
|
+
* invalid options and the initial pending listing throw. Rows are only moved to terminal states,
|
|
144
|
+
* never deleted. */
|
|
145
|
+
export declare function reconcilePendingBuilds(options: ReconcileOptions): Promise<ReconcileReport>;
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
import { orderedDigest } from '../profile/json.js';
|
|
2
|
+
import { ArtifactOperationError } from '../server/failures.js';
|
|
3
|
+
import { jobKey } from './handoff.js';
|
|
4
|
+
/** Closed per-item outcome of one reconciled job. `store-error` is a per-item host-store outage:
|
|
5
|
+
* the item is skipped and the sweep continues; only invalid options and the initial pending
|
|
6
|
+
* listing throw. */
|
|
7
|
+
export const RECONCILE_OUTCOMES = ['job-build-failed', 'job-published', 'still-pending', 'already-terminal',
|
|
8
|
+
'unknown-job', 'status-unavailable', 'status-invalid', 'no-release', 'receipt-conflict', 'job-not-found',
|
|
9
|
+
'binding-still-pending', 'binding-conflict', 'store-error'];
|
|
10
|
+
/** Bounded pipeline stage where a `store-error` struck. The stage names the throwing call without
|
|
11
|
+
* exposing store internals, so a perpetual outage is alertable instead of silent. */
|
|
12
|
+
export const RECONCILE_ERROR_STAGES = ['list-pending', 'read-job', 'read-status', 'read-receipt', 'confirm-status',
|
|
13
|
+
'write-binding', 'write-job', 'read-binding'];
|
|
14
|
+
/** Closed reconcile input errors; per-item builder outcomes stay data, never throws. */
|
|
15
|
+
export const RECONCILE_ERROR_CODES = ['reconcile_invalid_options'];
|
|
16
|
+
export class ReconcileError extends Error {
|
|
17
|
+
code;
|
|
18
|
+
constructor(code, detail) {
|
|
19
|
+
super(detail ? `${code}: ${detail}` : code);
|
|
20
|
+
this.code = code;
|
|
21
|
+
this.name = 'ReconcileError';
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export const RECONCILE_DEFAULTS = Object.freeze({ olderThanMs: 600_000, limit: 100, concurrency: 4 });
|
|
25
|
+
const MAX_LIMIT = 500;
|
|
26
|
+
const MAX_CONCURRENCY = 8;
|
|
27
|
+
/** A builder failure without a machine code is still a builder failure, never an outage: the transport
|
|
28
|
+
* answered. `builder_unavailable` is reserved for thrown transports (`status-unavailable`). */
|
|
29
|
+
const DEFAULT_CODE = 'build_failed';
|
|
30
|
+
const CODE_MAX = 128;
|
|
31
|
+
const REASON_MAX = 1024;
|
|
32
|
+
const RELEASE_MAX = 256;
|
|
33
|
+
const ID = /^[A-Za-z0-9_-]{1,128}$/;
|
|
34
|
+
const text = (value, max) => typeof value === 'string' && value.length >= 1 && value.length <= max;
|
|
35
|
+
/** Builder padding carries no signal: a blank code/reason is absent, so the default applies. */
|
|
36
|
+
const clean = (value) => {
|
|
37
|
+
const trimmed = value?.trim();
|
|
38
|
+
return trimmed ? trimmed : undefined;
|
|
39
|
+
};
|
|
40
|
+
/** Bounded builder status shape (length-bounded strings over the exact contract state set); anything
|
|
41
|
+
* else is `status-invalid` and writes nothing. Extra keys are ignored: the builder is an
|
|
42
|
+
* authenticated peer, so unknown fields stay data, never a refusal. A `published` status may carry
|
|
43
|
+
* `code`/`reason` (ignored); a blank `code`/`reason` is dropped at the call site, and a `build_failed`
|
|
44
|
+
* status without `code` gets the `build_failed` default there. */
|
|
45
|
+
export function parseReconcileBuilderStatus(raw, jobId) {
|
|
46
|
+
if (!raw || typeof raw !== 'object')
|
|
47
|
+
return undefined;
|
|
48
|
+
const body = raw;
|
|
49
|
+
if (body.jobId !== jobId || (body.state !== 'build_pending' && body.state !== 'published' && body.state !== 'build_failed')) {
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
if (body.code !== undefined && !text(body.code, CODE_MAX))
|
|
53
|
+
return undefined;
|
|
54
|
+
if (body.reason !== undefined && !text(body.reason, REASON_MAX))
|
|
55
|
+
return undefined;
|
|
56
|
+
if (body.releaseId !== undefined && !text(body.releaseId, RELEASE_MAX))
|
|
57
|
+
return undefined;
|
|
58
|
+
return { jobId, state: body.state,
|
|
59
|
+
...(body.code !== undefined ? { code: body.code } : {}),
|
|
60
|
+
...(body.reason !== undefined ? { reason: body.reason } : {}),
|
|
61
|
+
...(body.releaseId !== undefined ? { releaseId: body.releaseId } : {}) };
|
|
62
|
+
}
|
|
63
|
+
function optionsOf(options) {
|
|
64
|
+
if (!options || typeof options !== 'object')
|
|
65
|
+
throw new ReconcileError('reconcile_invalid_options', 'options are required');
|
|
66
|
+
const ports = options;
|
|
67
|
+
if (!ports.jobs || !ports.status || !ports.bindings) {
|
|
68
|
+
throw new ReconcileError('reconcile_invalid_options', 'jobs, status and bindings are required');
|
|
69
|
+
}
|
|
70
|
+
const olderThanMs = ports.olderThanMs ?? RECONCILE_DEFAULTS.olderThanMs;
|
|
71
|
+
const limit = ports.limit ?? RECONCILE_DEFAULTS.limit;
|
|
72
|
+
const concurrency = ports.concurrency ?? RECONCILE_DEFAULTS.concurrency;
|
|
73
|
+
if (!Number.isFinite(olderThanMs) || olderThanMs < 0)
|
|
74
|
+
throw new ReconcileError('reconcile_invalid_options', 'olderThanMs');
|
|
75
|
+
if (!Number.isSafeInteger(limit) || limit < 1 || limit > MAX_LIMIT)
|
|
76
|
+
throw new ReconcileError('reconcile_invalid_options', 'limit');
|
|
77
|
+
if (!Number.isSafeInteger(concurrency) || concurrency < 1 || concurrency > MAX_CONCURRENCY) {
|
|
78
|
+
throw new ReconcileError('reconcile_invalid_options', 'concurrency');
|
|
79
|
+
}
|
|
80
|
+
const systemActorId = ports.systemActorId ?? 'system:reconcile-pending-builds';
|
|
81
|
+
if (typeof systemActorId !== 'string' || !systemActorId.trim()) {
|
|
82
|
+
throw new ReconcileError('reconcile_invalid_options', 'systemActorId');
|
|
83
|
+
}
|
|
84
|
+
return { olderThanMs, limit, concurrency, systemActorId };
|
|
85
|
+
}
|
|
86
|
+
/** Binding `build_pending` to `build_failed` under the version CAS (`server/git-bindings.ts:51`,
|
|
87
|
+
* action `publish`). The failure code is stamped on the binding `stateDetail`, so hosts without
|
|
88
|
+
* job `code`/`reason` columns lose nothing. The idempotency key and the command hash bind the
|
|
89
|
+
* binding version and pending SHA: a re-pended job (the same `jobId` admitted again) writes anew
|
|
90
|
+
* instead of replaying the older failure, and the `write()` result is verified so a stale replay
|
|
91
|
+
* can never report `updated`. The `live` key is never written (`validateGitBindingWrite` admits only
|
|
92
|
+
* an absent `live`). A concurrent move answers `binding-conflict`, except when the winner is the
|
|
93
|
+
* success path (`attached`): then the publish owns the job close and the job is left alone. */
|
|
94
|
+
async function failBinding(options, key, stamp) {
|
|
95
|
+
const before = await options.bindings.get(key.scopeId, key.artifactId);
|
|
96
|
+
if (!before || before.state !== 'build_pending' || before.pendingJobId !== key.jobId)
|
|
97
|
+
return 'unchanged';
|
|
98
|
+
const { live: _dropped, ...rest } = before;
|
|
99
|
+
void _dropped;
|
|
100
|
+
const idempotencyKey = `reconcile-build-failed:${key.scopeId}:${key.artifactId}:${key.jobId}:v${before.version}:${before.pendingCommitSha ?? ''}`;
|
|
101
|
+
try {
|
|
102
|
+
const written = await options.bindings.write({
|
|
103
|
+
binding: { ...rest, state: 'build_failed', stateDetail: stamp.code, version: before.version + 1, updatedAt: stamp.nowIso },
|
|
104
|
+
expectedVersion: before.version, actorId: options.systemActorId, idempotencyKey,
|
|
105
|
+
commandHash: orderedDigest({ operation: 'reconcile_build_failed', ...key,
|
|
106
|
+
expectedVersion: before.version, pendingCommitSha: before.pendingCommitSha }),
|
|
107
|
+
event: { action: 'publish', beforeSha: before.releaseCommitSha ?? undefined, afterSha: before.pendingCommitSha ?? undefined,
|
|
108
|
+
invocationId: `reconcile:${key.jobId}` },
|
|
109
|
+
});
|
|
110
|
+
// A replay answers inside `write`: it is only truthful for this exact version and SHA.
|
|
111
|
+
const binding = written.binding;
|
|
112
|
+
if (binding.state !== 'build_failed' || binding.version !== before.version + 1 || binding.pendingJobId !== key.jobId) {
|
|
113
|
+
return 'binding-conflict';
|
|
114
|
+
}
|
|
115
|
+
return 'updated';
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
// A concurrent move fails the version CAS. Re-read before touching the job: when the winner is
|
|
119
|
+
// the success path, failing the job would close a published artifact as failed.
|
|
120
|
+
if (error instanceof ArtifactOperationError &&
|
|
121
|
+
(error.kind === 'pointer_conflict' || error.kind === 'git_binding_conflict' || error.kind === 'command_conflict')) {
|
|
122
|
+
const current = await options.bindings.get(key.scopeId, key.artifactId);
|
|
123
|
+
if (current && current.state === 'attached')
|
|
124
|
+
return 'binding-moved-on';
|
|
125
|
+
return 'binding-conflict';
|
|
126
|
+
}
|
|
127
|
+
throw error;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
async function reconcileOne(options, key) {
|
|
131
|
+
const nowMs = options.now();
|
|
132
|
+
if (!Number.isFinite(nowMs))
|
|
133
|
+
throw new ReconcileError('reconcile_invalid_options', 'now');
|
|
134
|
+
// Moved flags tracked across the catch: a failure after a committed write reports what committed.
|
|
135
|
+
let job = 'unchanged';
|
|
136
|
+
let binding = 'unchanged';
|
|
137
|
+
let error = 'read-job';
|
|
138
|
+
try {
|
|
139
|
+
const stored = await options.jobs.read(key);
|
|
140
|
+
if (!stored)
|
|
141
|
+
return { ...key, outcome: 'job-not-found', job, binding };
|
|
142
|
+
if (stored.state !== 'build_pending' && stored.state !== 'building')
|
|
143
|
+
return { ...key, outcome: 'already-terminal', job, binding };
|
|
144
|
+
error = 'read-status';
|
|
145
|
+
let answer;
|
|
146
|
+
try {
|
|
147
|
+
answer = await options.status.status(key);
|
|
148
|
+
}
|
|
149
|
+
catch {
|
|
150
|
+
return { ...key, outcome: 'status-unavailable', job, binding };
|
|
151
|
+
}
|
|
152
|
+
if (answer === undefined)
|
|
153
|
+
return { ...key, outcome: 'unknown-job', job, binding };
|
|
154
|
+
let parsed = parseReconcileBuilderStatus(answer, key.jobId);
|
|
155
|
+
if (!parsed)
|
|
156
|
+
return { ...key, outcome: 'status-invalid', job, binding };
|
|
157
|
+
if (parsed.state === 'build_pending')
|
|
158
|
+
return { ...key, outcome: 'still-pending', job, binding };
|
|
159
|
+
// The stored handoff receipt is host proof of publication. When the receipts port is wired it is
|
|
160
|
+
// read once for both terminal branches: a receipt overrides a stale builder `build_failed` (the
|
|
161
|
+
// builder flips `failed` to `published` asynchronously in `record(receipt)`), and a missing
|
|
162
|
+
// receipt fails a builder `published` closed (the builder word alone never publishes a job).
|
|
163
|
+
let receipt;
|
|
164
|
+
if (options.receipts) {
|
|
165
|
+
error = 'read-receipt';
|
|
166
|
+
receipt = await options.receipts.find(jobKey(key));
|
|
167
|
+
if (receipt && !text(receipt.releaseId, RELEASE_MAX))
|
|
168
|
+
return { ...key, outcome: 'receipt-conflict', job, binding };
|
|
169
|
+
// A committed receipt overrides a stale builder `build_failed`: publication happened host-side.
|
|
170
|
+
if (receipt && parsed.state === 'build_failed') {
|
|
171
|
+
parsed = { jobId: key.jobId, state: 'published', releaseId: receipt.releaseId };
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
if (parsed.state === 'build_failed' && !receipt) {
|
|
175
|
+
// The builder ledger is not terminal on `failed`: `admit` re-runs the same `jobId` after a
|
|
176
|
+
// failure, and a run in flight may still publish. Re-read the status just before the writes;
|
|
177
|
+
// the fresher answer wins. `published` is terminal builder-side, so it needs no confirm.
|
|
178
|
+
error = 'confirm-status';
|
|
179
|
+
let confirm;
|
|
180
|
+
try {
|
|
181
|
+
confirm = await options.status.status(key);
|
|
182
|
+
}
|
|
183
|
+
catch {
|
|
184
|
+
return { ...key, outcome: 'status-unavailable', job, binding };
|
|
185
|
+
}
|
|
186
|
+
if (confirm === undefined)
|
|
187
|
+
return { ...key, outcome: 'unknown-job', job, binding };
|
|
188
|
+
const fresh = parseReconcileBuilderStatus(confirm, key.jobId);
|
|
189
|
+
if (!fresh)
|
|
190
|
+
return { ...key, outcome: 'status-invalid', job, binding };
|
|
191
|
+
if (fresh.state !== 'build_failed')
|
|
192
|
+
parsed = fresh;
|
|
193
|
+
if (parsed.state === 'build_pending')
|
|
194
|
+
return { ...key, outcome: 'still-pending', job, binding };
|
|
195
|
+
}
|
|
196
|
+
if (parsed.state === 'build_failed') {
|
|
197
|
+
// The binding leads: a crash between the two writes still converges, because a rerun finds the
|
|
198
|
+
// job pending and the binding already failed, then finishes the job move.
|
|
199
|
+
error = 'write-binding';
|
|
200
|
+
const code = clean(parsed.code) ?? DEFAULT_CODE;
|
|
201
|
+
const reason = clean(parsed.reason);
|
|
202
|
+
const failed = await failBinding({ bindings: options.bindings, systemActorId: options.systemActorId }, key, { code, nowIso: new Date(nowMs).toISOString() });
|
|
203
|
+
if (failed === 'binding-moved-on') {
|
|
204
|
+
return { ...key, outcome: 'binding-conflict', job, binding };
|
|
205
|
+
}
|
|
206
|
+
if (failed === 'binding-conflict') {
|
|
207
|
+
error = 'write-job';
|
|
208
|
+
const moved = await options.jobs.markFailed({ ...key, code, ...(reason !== undefined ? { reason } : {}) });
|
|
209
|
+
if (moved === 'updated')
|
|
210
|
+
job = 'updated';
|
|
211
|
+
return { ...key, outcome: 'binding-conflict', job, binding };
|
|
212
|
+
}
|
|
213
|
+
binding = failed;
|
|
214
|
+
error = 'write-job';
|
|
215
|
+
const moved = await options.jobs.markFailed({ ...key, code, ...(reason !== undefined ? { reason } : {}) });
|
|
216
|
+
if (moved === 'not-found')
|
|
217
|
+
return { ...key, outcome: 'job-not-found', job, binding };
|
|
218
|
+
if (moved === 'already-terminal')
|
|
219
|
+
return { ...key, outcome: 'already-terminal', job, binding };
|
|
220
|
+
job = 'updated';
|
|
221
|
+
return { ...key, outcome: 'job-build-failed', job, binding };
|
|
222
|
+
}
|
|
223
|
+
// Builder `published`: the releaseId comes from the stored handoff receipt when the receipts port
|
|
224
|
+
// is wired (a wired ledger without a receipt is `no-release`: the host never published), else
|
|
225
|
+
// from the builder status; without either the job stays pending and no release is invented.
|
|
226
|
+
let releaseId = parsed.releaseId;
|
|
227
|
+
if (options.receipts) {
|
|
228
|
+
if (!receipt)
|
|
229
|
+
return { ...key, outcome: 'no-release', job, binding };
|
|
230
|
+
if (releaseId !== undefined && receipt.releaseId !== releaseId)
|
|
231
|
+
return { ...key, outcome: 'receipt-conflict', job, binding };
|
|
232
|
+
releaseId = receipt.releaseId;
|
|
233
|
+
}
|
|
234
|
+
if (releaseId === undefined)
|
|
235
|
+
return { ...key, outcome: 'no-release', job, binding };
|
|
236
|
+
// The binding is read, never written, on this path — and before the job move: a still-pending
|
|
237
|
+
// binding for this job leaves the job pending too, so the next run reconverges instead of
|
|
238
|
+
// terminalizing the job over a lost binding write. A receipt that disagrees with the binding on
|
|
239
|
+
// the commit SHA fails closed, as `publicationRecheck` would refuse it.
|
|
240
|
+
error = 'read-binding';
|
|
241
|
+
const current = await options.bindings.get(key.scopeId, key.artifactId);
|
|
242
|
+
if (current && current.state === 'build_pending' && current.pendingJobId === key.jobId) {
|
|
243
|
+
if (receipt && receipt.commitSha !== current.pendingCommitSha)
|
|
244
|
+
return { ...key, outcome: 'receipt-conflict', job, binding };
|
|
245
|
+
return { ...key, outcome: 'binding-still-pending', job, binding };
|
|
246
|
+
}
|
|
247
|
+
error = 'write-job';
|
|
248
|
+
const moved = await options.jobs.markPublished({ ...key, releaseId });
|
|
249
|
+
if (moved === 'not-found')
|
|
250
|
+
return { ...key, outcome: 'job-not-found', job, binding };
|
|
251
|
+
if (moved === 'already-terminal')
|
|
252
|
+
return { ...key, outcome: 'already-terminal', job, binding };
|
|
253
|
+
job = 'updated';
|
|
254
|
+
return { ...key, outcome: 'job-published', job, binding };
|
|
255
|
+
}
|
|
256
|
+
catch {
|
|
257
|
+
return { ...key, outcome: 'store-error', job, binding, error };
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
/** On-demand reconcile of one pending job for the host read paths (`live_status`, `git_publish`,
|
|
261
|
+
* `artifacts_get`). No age check; terminal rows and unknown builders write nothing. */
|
|
262
|
+
export async function reconcilePendingBuild(options, key) {
|
|
263
|
+
const { systemActorId } = optionsOf(options);
|
|
264
|
+
if (!key || !ID.test(key.scopeId) || !ID.test(key.artifactId) || !ID.test(key.jobId)) {
|
|
265
|
+
throw new ReconcileError('reconcile_invalid_options', 'scopeId, artifactId and jobId are required');
|
|
266
|
+
}
|
|
267
|
+
return reconcileOne({ ...options, now: options.now ?? Date.now, systemActorId }, key);
|
|
268
|
+
}
|
|
269
|
+
/** Sweep of the host pending jobs older than the threshold. One per-item failure never aborts the
|
|
270
|
+
* sweep: store and builder outages surface per item as `store-error`/`status-unavailable`. Only
|
|
271
|
+
* invalid options and the initial pending listing throw. Rows are only moved to terminal states,
|
|
272
|
+
* never deleted. */
|
|
273
|
+
export async function reconcilePendingBuilds(options) {
|
|
274
|
+
const { olderThanMs, limit, concurrency, systemActorId } = optionsOf(options);
|
|
275
|
+
const now = options.now ?? Date.now;
|
|
276
|
+
const nowMs = now();
|
|
277
|
+
const pending = (await options.jobs.listPending({ nowMs, olderThanMs, limit })).slice(0, limit);
|
|
278
|
+
const items = new Array(pending.length);
|
|
279
|
+
let cursor = 0;
|
|
280
|
+
const workers = Array.from({ length: Math.min(concurrency, Math.max(pending.length, 1)) }, async () => {
|
|
281
|
+
for (;;) {
|
|
282
|
+
const index = cursor++;
|
|
283
|
+
if (index >= pending.length)
|
|
284
|
+
return;
|
|
285
|
+
const row = pending[index];
|
|
286
|
+
const key = { scopeId: String(row?.scopeId), artifactId: String(row?.artifactId), jobId: String(row?.jobId) };
|
|
287
|
+
// The sweep validates what the host listed: malformed ids are a host-store defect, surfaced
|
|
288
|
+
// per item instead of aborting the sweep.
|
|
289
|
+
if (!row || !ID.test(row.scopeId) || !ID.test(row.artifactId) || !ID.test(row.jobId)) {
|
|
290
|
+
items[index] = { ...key, outcome: 'store-error', job: 'unchanged', binding: 'unchanged', error: 'list-pending' };
|
|
291
|
+
continue;
|
|
292
|
+
}
|
|
293
|
+
// The threshold is enforced here too, not only by the host filter: a listed job that is not
|
|
294
|
+
// stale yet (or carries no usable age) is left pending without a single builder call.
|
|
295
|
+
if (!Number.isFinite(row.updatedAtMs) || nowMs - row.updatedAtMs < olderThanMs) {
|
|
296
|
+
items[index] = { ...key, outcome: 'still-pending', job: 'unchanged', binding: 'unchanged' };
|
|
297
|
+
continue;
|
|
298
|
+
}
|
|
299
|
+
items[index] = await reconcileOne({ ...options, now, systemActorId }, key);
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
await Promise.all(workers);
|
|
303
|
+
return { checked: items.length, updated: items.filter(item => item.job === 'updated' || item.binding === 'updated').length, items };
|
|
304
|
+
}
|
package/dist/mcp-core.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export { createRadarKeyDerivation } from './server/command-identity.js';
|
|
|
10
10
|
export type { ArtifactKeyDerivationBinding } from './server/command-identity.js';
|
|
11
11
|
export declare const ARTIFACTS_PROVIDER_ID = "sentropic.artifacts";
|
|
12
12
|
export declare const ARTIFACTS_APP_ID = "sentropic-artifacts";
|
|
13
|
-
export declare const ARTIFACTS_PROVIDER_VERSION = "0.2.
|
|
13
|
+
export declare const ARTIFACTS_PROVIDER_VERSION = "0.2.26";
|
|
14
14
|
export declare const ARTIFACTS_TOOL_NAMES: readonly ["artifacts_get_template", "artifacts_get_api_guide", "artifacts_ensure", "artifacts_publish", "artifacts_create_upload", "artifacts_commit_upload", "artifacts_list", "artifacts_get", "artifacts_get_source", "artifacts_fork", "artifacts_set_access", "artifacts_promote", "artifacts_renew", "artifacts_delete", "artifacts_restore", "artifacts_list_versions", "artifacts_revert", "artifacts_lookup_people", "artifacts_list_access", "artifacts_publish_bundle", "artifacts_revoke_reader_consent", "artifacts_create_upload_page", "artifacts_list_assets", "artifacts_publish_bundle_v2", "artifacts_list_app_sources", "artifacts_fetch_app_source", "artifacts_git_attach", "artifacts_git_commit", "artifacts_git_publish", "artifacts_git_live", "artifacts_live_write", "artifacts_live_read", "artifacts_live_reset", "artifacts_live_status", "artifacts_live_control", "artifacts_live_invite", "artifacts_live_accept_invitation", "artifacts_live_revoke_invitation", "artifacts_live_invitations"];
|
|
15
15
|
export type ArtifactsToolName = (typeof ARTIFACTS_TOOL_NAMES)[number];
|
|
16
16
|
export interface ArtifactsToolDefinition {
|
package/dist/mcp-core.js
CHANGED
|
@@ -7,7 +7,7 @@ export * from './profile/index.js';
|
|
|
7
7
|
export { createRadarKeyDerivation } from './server/command-identity.js';
|
|
8
8
|
export const ARTIFACTS_PROVIDER_ID = 'sentropic.artifacts';
|
|
9
9
|
export const ARTIFACTS_APP_ID = 'sentropic-artifacts';
|
|
10
|
-
export const ARTIFACTS_PROVIDER_VERSION = '0.2.
|
|
10
|
+
export const ARTIFACTS_PROVIDER_VERSION = '0.2.26';
|
|
11
11
|
export const ARTIFACTS_TOOL_NAMES = ARTIFACT_CAPABILITY_NAMES;
|
|
12
12
|
// ---------------------------------------------------------------------------
|
|
13
13
|
// Byte-stable tool definitions (MCP tool-definition stability rule).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sentropic/artifacts",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.26",
|
|
4
4
|
"description": "Generic configurable artifacts MCP and artifact service: StorageScope/Artifact/Binding/Release model, canonical manifests, object authorization, idempotent intents (spec-v8 §9).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|