@sentropic/artifacts 0.2.26 → 0.2.27
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 +24 -0
- package/dist/adapters/postgres-live.js +14 -3
- package/dist/live-host/worker-client.d.ts +7 -1
- package/dist/live-host/worker-client.js +8 -1
- package/dist/mcp-core.d.ts +1 -1
- package/dist/mcp-core.js +1 -1
- package/dist/server/live-commit.js +3 -3
- package/dist/server/live-contracts.d.ts +40 -1
- package/dist/server/live-contracts.js +3 -0
- package/dist/server/live-invitation-state.d.ts +1 -1
- package/dist/server/live-mutations.js +3 -1
- package/dist/server/live-service.js +6 -5
- package/dist/server/live-store.d.ts +10 -0
- package/dist/server/live-store.js +28 -0
- package/dist/server/live-worker.d.ts +18 -4
- package/dist/server/live-worker.js +235 -40
- package/migrations/0014_live_drafts_pending.sql +7 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.27
|
|
4
|
+
|
|
5
|
+
- Wire the builder terminal failure through the live package: a `reconcile` answer with
|
|
6
|
+
`ready: false` and `failure: { code, reason }` moves the runtime to DORMANT with
|
|
7
|
+
`code:reason` as `stateDetail`, reports `onWorkerEvent` (`failed` with the code and reason),
|
|
8
|
+
and is never re-driven; a later owner `start` or edit revives normally. The live-host
|
|
9
|
+
`LiveBridgeAck` parser preserves a well-formed `failure` and ignores malformed shapes.
|
|
10
|
+
A total `stop` (builder holds no or no longer this session) converges instead of replaying
|
|
11
|
+
a refusal.
|
|
12
|
+
- Fence concurrent live settles: one settle per identity at a time (no parallel
|
|
13
|
+
`reconcile`/`stop` for the same session), a stop requires its session plus a
|
|
14
|
+
`QUIESCING`/`SAVING`/`DECOMMISSIONING` phase and lease match before any worker call, and a
|
|
15
|
+
settle that did not move the runtime reports `skipped` instead of `settled`. A `void`
|
|
16
|
+
reconcile answer reports `pending` with an event instead of going silent.
|
|
17
|
+
- Bound the re-drive: `pending` limits clamp to `[0, 64]` identically on memory and Postgres,
|
|
18
|
+
ordering is deterministic (`lastAccessAt`, `artifact_id`, `binding_generation`), and
|
|
19
|
+
`redriveLiveWorkers` runs at most 4 items in flight (tunable via
|
|
20
|
+
`redriveConcurrency`) with a 35 s per-item budget (tunable via `redriveItemTimeoutMs`,
|
|
21
|
+
`timeout` failure on expiry) and skips an overlapping pass for the same scope.
|
|
22
|
+
- Add partial index migration `0014_live_drafts_pending.sql` so the scoped pending scan reads
|
|
23
|
+
pending rows only; DORMANT rows stay out of the index.
|
|
24
|
+
- `codeOf` also reads `error.code`/`error.name` instead of `unknown` for standard errors.
|
|
25
|
+
- Stays in `0.2.x` (cluster-mesh peer `>=0.2.0 <0.3.0`).
|
|
26
|
+
|
|
3
27
|
## 0.2.25
|
|
4
28
|
|
|
5
29
|
- `@sentropic/artifacts/live-host` ships a generic pending-build reconcile: `reconcilePendingBuilds`
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ArtifactOperationError } from '../server/failures.js';
|
|
2
|
-
import { liveIdentityKey } from '../server/live-store.js';
|
|
2
|
+
import { liveIdentityKey, normalizeRedriveLimit } from '../server/live-store.js';
|
|
3
3
|
const INVITATION_COLUMNS = `storage_scope_id,artifact_id,binding_generation,live_session_id,invitation_id,principal_id,
|
|
4
4
|
created_by,status,epoch,expires_at,accepted_at,revoked_at,created_at,row_version`;
|
|
5
5
|
const iso = (value) => value === null ? null : new Date(value).toISOString();
|
|
@@ -48,6 +48,16 @@ export function createPostgresLiveStore(pool) {
|
|
|
48
48
|
WHERE storage_scope_id=$1 AND artifact_id=$2 AND record #>> '{runtime,liveSessionId}'=$3`, [scope, artifactId, sessionId]);
|
|
49
49
|
return result.rows[0] ? { storageScopeId: scope, artifactId, bindingGeneration: Number(result.rows[0].binding_generation) } : undefined;
|
|
50
50
|
},
|
|
51
|
+
async pending(scope, limit) {
|
|
52
|
+
// Partial index 0014_live_drafts_pending.sql covers the scope filter and the access-time order;
|
|
53
|
+
// DORMANT rows stay out of the index so every host tick scans pending rows only.
|
|
54
|
+
const result = await pool.query(`SELECT artifact_id, binding_generation FROM artifacts.live_drafts
|
|
55
|
+
WHERE storage_scope_id=$1 AND (record #>> '{runtime,phase}' IN ('REVIVING','QUIESCING','SAVING','DECOMMISSIONING')
|
|
56
|
+
OR (record #>> '{runtime,phase}' = 'LIVE' AND record #>> '{runtime,appliedRevision}' IS DISTINCT FROM record ->> 'revision'))
|
|
57
|
+
ORDER BY record #>> '{runtime,lastAccessAt}', artifact_id, binding_generation LIMIT $2`, [scope, normalizeRedriveLimit(limit)]);
|
|
58
|
+
return result.rows.map(row => ({ storageScopeId: scope, artifactId: String(row.artifact_id),
|
|
59
|
+
bindingGeneration: Number(row.binding_generation) }));
|
|
60
|
+
},
|
|
51
61
|
async transaction(identity, action) {
|
|
52
62
|
const client = await pool.connect();
|
|
53
63
|
const values = [identity.storageScopeId, identity.artifactId, identity.bindingGeneration];
|
|
@@ -99,10 +109,11 @@ export function createPostgresLiveStore(pool) {
|
|
|
99
109
|
(storage_scope_id,actor_id,artifact_id,invocation_id,created_at) VALUES ($1,$2,$3,$4,$5)`, [identity.storageScopeId, actor, identity.artifactId, invocation, now]);
|
|
100
110
|
},
|
|
101
111
|
async advanceBinding(input) {
|
|
112
|
+
// The state is kept: a commit on a build_failed binding leaves it build_failed until the next publish.
|
|
102
113
|
const result = await client.query(`UPDATE artifacts.git_bindings SET head_commit_sha=$4,
|
|
103
|
-
|
|
114
|
+
version=version+1, updated_at=$5
|
|
104
115
|
WHERE storage_scope_id=$1 AND artifact_id=$2 AND generation=$3 AND head_commit_sha=$6
|
|
105
|
-
AND state
|
|
116
|
+
AND state IN ('attached','build_failed') RETURNING artifact_id`, [...values, input.commitSha, input.now, input.expectedHeadSha]);
|
|
106
117
|
if (!result.rows.length)
|
|
107
118
|
throw new ArtifactOperationError('git_live_conflict', { publicDetails: { reason: 'stale_fence' } });
|
|
108
119
|
await client.query(`INSERT INTO artifacts.git_binding_events
|
|
@@ -17,13 +17,19 @@ export interface LiveWorkerFences {
|
|
|
17
17
|
routeEpoch: number;
|
|
18
18
|
} | undefined>;
|
|
19
19
|
}
|
|
20
|
-
/** Builder answer of a reconcile; the package checks it against its own fences before marking the session LIVE.
|
|
20
|
+
/** Builder answer of a reconcile; the package checks it against its own fences before marking the session LIVE.
|
|
21
|
+
* A terminal `failure` abandons the revive: the package moves the runtime to DORMANT with `code:reason` as
|
|
22
|
+
* stateDetail and stops re-driving it. Unknown failure shapes are ignored, so older builders stay compatible. */
|
|
21
23
|
export interface LiveBridgeAck {
|
|
22
24
|
liveSessionId: string;
|
|
23
25
|
leaseEpoch: number;
|
|
24
26
|
routeEpoch: number;
|
|
25
27
|
revision: string;
|
|
26
28
|
ready: boolean;
|
|
29
|
+
failure?: {
|
|
30
|
+
code: string;
|
|
31
|
+
reason: string;
|
|
32
|
+
};
|
|
27
33
|
}
|
|
28
34
|
export interface LiveWorkerClientOptions {
|
|
29
35
|
/** Builder base URL (https, no query or fragment); absent keeps every call closed with builder_unavailable. */
|
|
@@ -54,7 +54,14 @@ function parseAck(raw) {
|
|
|
54
54
|
|| !count(r.routeEpoch) || typeof r.revision !== 'string' || !REVISION.test(r.revision) || typeof r.ready !== 'boolean') {
|
|
55
55
|
throw new ArtifactOperationError('provider_unavailable');
|
|
56
56
|
}
|
|
57
|
-
|
|
57
|
+
const ack = { liveSessionId: r.liveSessionId, leaseEpoch: r.leaseEpoch, routeEpoch: r.routeEpoch,
|
|
58
|
+
revision: r.revision, ready: r.ready };
|
|
59
|
+
const failure = r.failure;
|
|
60
|
+
if (failure && typeof failure === 'object' && typeof failure.code === 'string' && failure.code &&
|
|
61
|
+
typeof failure.reason === 'string' && failure.reason) {
|
|
62
|
+
ack.failure = { code: failure.code, reason: failure.reason };
|
|
63
|
+
}
|
|
64
|
+
return ack;
|
|
58
65
|
}
|
|
59
66
|
/**
|
|
60
67
|
* HTTP LiveWorkerPort of the Sentropic builder, composed as the package LiveService `worker`. A reconcile reads the
|
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.27";
|
|
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.27';
|
|
11
11
|
export const ARTIFACTS_TOOL_NAMES = ARTIFACT_CAPABILITY_NAMES;
|
|
12
12
|
// ---------------------------------------------------------------------------
|
|
13
13
|
// Byte-stable tool definitions (MCP tool-definition stability rule).
|
|
@@ -4,7 +4,7 @@ import { readLiveOverlay } from './live-drafts.js';
|
|
|
4
4
|
import { applyLiveMutation, liveTreeSha, validateLiveMutation } from './live-tree.js';
|
|
5
5
|
import { orderedDigest } from '../profile/json.js';
|
|
6
6
|
import { liveBusy } from './live-mutations.js';
|
|
7
|
-
import { liveResponse } from './live-contracts.js';
|
|
7
|
+
import { liveResponse, liveWritable } from './live-contracts.js';
|
|
8
8
|
import { LiveCommitUnknownError } from './live-commit-outcome.js';
|
|
9
9
|
import { isGitSha } from './git-port-policy.js';
|
|
10
10
|
import { settleLiveWorker } from './live-worker.js';
|
|
@@ -21,7 +21,7 @@ export async function executeLiveCommit(input) {
|
|
|
21
21
|
throw new ArtifactOperationError('git_live_no_changes');
|
|
22
22
|
const current = await deps.authorize(invocation, identity.artifactId);
|
|
23
23
|
if (!current.canReadCode || !current.canWrite || !current.humanLinked || current.ownerId !== invocation.actorId ||
|
|
24
|
-
current.binding.generation !== identity.bindingGeneration || current.binding.state
|
|
24
|
+
current.binding.generation !== identity.bindingGeneration || !liveWritable(current.binding.state))
|
|
25
25
|
throw new ArtifactOperationError('access_denied');
|
|
26
26
|
validateLiveMutation(current.repository, current.target, args, 255, 8 * 1024 * 1024);
|
|
27
27
|
const prior = await tx.receipt(command.actorId, command.key);
|
|
@@ -108,7 +108,7 @@ export async function executeLiveCommit(input) {
|
|
|
108
108
|
const current = await deps.authorize(invocation, identity.artifactId);
|
|
109
109
|
if (!current.canReadCode || !current.canWrite || !current.humanLinked || current.ownerId !== invocation.actorId)
|
|
110
110
|
throw new ArtifactOperationError('access_denied');
|
|
111
|
-
if (current.binding.generation !== identity.bindingGeneration || current.binding.state
|
|
111
|
+
if (current.binding.generation !== identity.bindingGeneration || !liveWritable(current.binding.state))
|
|
112
112
|
liveBusy('stale_fence');
|
|
113
113
|
await tx.advanceBinding?.({ expectedHeadSha: intent.expectedHeadSha, commitSha: committed.commitSha,
|
|
114
114
|
invocationId: intent.invocationId, actorId: invocation.actorId, now: new Date(now).toISOString() });
|
|
@@ -19,6 +19,13 @@ export interface LiveAuthority {
|
|
|
19
19
|
repository: GitPortRepository;
|
|
20
20
|
target: GitPortTarget;
|
|
21
21
|
}
|
|
22
|
+
/** A binding accepts live writers while attached, and after a terminal build failure: the failed job is over, and
|
|
23
|
+
* only edits and a new commit can repair the build (a pending job still refuses with pending_publication). */
|
|
24
|
+
export declare const liveWritable: (state: GitBinding['state']) => boolean;
|
|
25
|
+
export interface LiveWorkerFailure {
|
|
26
|
+
code: string;
|
|
27
|
+
reason: string;
|
|
28
|
+
}
|
|
22
29
|
export interface LiveWorkerPort {
|
|
23
30
|
/** Trusted controller reads the authoritative store; no draft key or store API enters the worker. */
|
|
24
31
|
reconcile(identity: LiveIdentity): Promise<void | {
|
|
@@ -27,8 +34,11 @@ export interface LiveWorkerPort {
|
|
|
27
34
|
routeEpoch: number;
|
|
28
35
|
revision: string;
|
|
29
36
|
ready: boolean;
|
|
37
|
+
failure?: LiveWorkerFailure;
|
|
30
38
|
}>;
|
|
31
|
-
/** Confirms quiescence, durable checkpoint and complete pod/volume decommissioning.
|
|
39
|
+
/** Confirms quiescence, durable checkpoint and complete pod/volume decommissioning. A total stop
|
|
40
|
+
* answers without touching the runtime when it holds no (or no longer this) session, so a re-driven
|
|
41
|
+
* stop converges instead of replaying a refusal. */
|
|
32
42
|
stop(input: LiveIdentity & {
|
|
33
43
|
liveSessionId: string;
|
|
34
44
|
leaseEpoch: number;
|
|
@@ -77,6 +87,32 @@ export interface LiveServiceDeps {
|
|
|
77
87
|
gitMessageMaxUnits?: number;
|
|
78
88
|
idempotencyKeyMaxUnits?: number;
|
|
79
89
|
invitations?: LiveInvitationPort;
|
|
90
|
+
/** Observer of every worker settle that did not complete: 'failed' carries the typed code of the refusal, 'pending'
|
|
91
|
+
* a worker that is not ready yet. A terminal builder failure also carries its reason and moves the runtime to
|
|
92
|
+
* DORMANT with `code:reason` as stateDetail, so the host stops re-driving it. The host logs it; a throw is ignored. */
|
|
93
|
+
onWorkerEvent?(event: LiveWorkerEvent): void;
|
|
94
|
+
/** Bounded re-drive tuning. Defaults keep the 60 s host timer safe: at most 4 worker calls in flight,
|
|
95
|
+
* each abandoned after 35 s. Hosts with a faster builder may raise the concurrency; a slower one lowers it. */
|
|
96
|
+
redriveConcurrency?: number;
|
|
97
|
+
/** Per-item settle budget in milliseconds for redriveLiveWorkers (default 35000). Never throws: an expired
|
|
98
|
+
* item reports 'failed' with code 'timeout' and stays pending for the next tick, unless it already moved. */
|
|
99
|
+
redriveItemTimeoutMs?: number;
|
|
100
|
+
}
|
|
101
|
+
/** 'settled': the worker confirmed and the runtime moved; 'pending': not ready yet; 'failed': the worker refused,
|
|
102
|
+
* was unreachable, timed out, or abandoned the revive (terminal: the runtime moved to DORMANT with the failure as
|
|
103
|
+
* stateDetail and the host stops re-driving it); 'skipped': nothing to do (no worker, or the session is no longer
|
|
104
|
+
* the current one, or a concurrent settle already moved it). */
|
|
105
|
+
export type LiveWorkerOutcome = 'settled' | 'pending' | 'failed' | 'skipped';
|
|
106
|
+
export interface LiveWorkerEvent {
|
|
107
|
+
identity: LiveIdentity;
|
|
108
|
+
action: 'project' | 'stop';
|
|
109
|
+
outcome: 'failed' | 'pending';
|
|
110
|
+
code?: string;
|
|
111
|
+
reason?: string;
|
|
112
|
+
}
|
|
113
|
+
export interface LiveRedriveItem extends LiveIdentity {
|
|
114
|
+
action: 'project' | 'stop';
|
|
115
|
+
outcome: LiveWorkerOutcome;
|
|
80
116
|
}
|
|
81
117
|
export interface LiveService {
|
|
82
118
|
execute(operation: string, args: Record<string, unknown>, invocation: LiveInvocation): Promise<Record<string, any>>;
|
|
@@ -85,6 +121,9 @@ export interface LiveService {
|
|
|
85
121
|
export interface LiveSessionService extends LiveService {
|
|
86
122
|
liveInvitationState(identity: LiveIdentity): Promise<LiveInvitationState>;
|
|
87
123
|
liveViewer(identity: LiveIdentity, principalId: string): Promise<LiveViewer>;
|
|
124
|
+
/** Settles again every runtime of the scope that still waits for the worker (see redriveLiveWorkers). Never throws
|
|
125
|
+
* for a worker refusal; empty without a worker or without 'LiveStore.pending'. */
|
|
126
|
+
redrive(storageScopeId: string, limit?: number): Promise<LiveRedriveItem[]>;
|
|
88
127
|
}
|
|
89
128
|
export declare function liveResponse(record: LiveDraftRecord, currentHeadSha: string, now?: number): Record<string, unknown>;
|
|
90
129
|
export type LiveSessionTransaction = LiveTransaction;
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/** A binding accepts live writers while attached, and after a terminal build failure: the failed job is over, and
|
|
2
|
+
* only edits and a new commit can repair the build (a pending job still refuses with pending_publication). */
|
|
3
|
+
export const liveWritable = (state) => state === 'attached' || state === 'build_failed';
|
|
1
4
|
export function liveResponse(record, currentHeadSha, now = Date.now()) {
|
|
2
5
|
return { artifactId: record.artifactId, bindingGeneration: record.bindingGeneration,
|
|
3
6
|
liveRevision: record.revision, revision: record.revision, baseHeadSha: record.baseHeadSha, currentHeadSha,
|
|
@@ -6,4 +6,4 @@ export declare const currentLiveSession: (record: LiveDraftRecord | undefined) =
|
|
|
6
6
|
/** Projects ceased (other session or generation) and expired invitations; writers persist the transitions. */
|
|
7
7
|
export declare function sweepInvitations(tx: LiveTransaction, identity: LiveIdentity, now: number, persist: boolean): Promise<LiveInvitationRecord[]>;
|
|
8
8
|
/** `liveInvitationState` and `liveViewer` read the committed state; they never write. */
|
|
9
|
-
export declare function liveInvitationViews(deps: LiveServiceDeps): Omit<LiveSessionService, 'execute'>;
|
|
9
|
+
export declare function liveInvitationViews(deps: LiveServiceDeps): Omit<LiveSessionService, 'execute' | 'redrive'>;
|
|
@@ -57,7 +57,9 @@ export async function mutateLive(input) {
|
|
|
57
57
|
action = 'project';
|
|
58
58
|
}
|
|
59
59
|
else {
|
|
60
|
-
|
|
60
|
+
// A start on a session that is still reviving joins it and dispatches the worker again (same session, same
|
|
61
|
+
// fences); only a session that is already LIVE refuses.
|
|
62
|
+
if (phase !== 'DORMANT' && phase !== 'REVIVING')
|
|
61
63
|
liveBusy('active_session');
|
|
62
64
|
action = 'project';
|
|
63
65
|
}
|
|
@@ -9,15 +9,16 @@ import { validateLiveMutation } from './live-tree.js';
|
|
|
9
9
|
import { readLivePage } from './live-read.js';
|
|
10
10
|
import { liveBusy, mutateLive } from './live-mutations.js';
|
|
11
11
|
import { executeLiveCommit } from './live-commit.js';
|
|
12
|
-
import { settleLiveWorker } from './live-worker.js';
|
|
13
|
-
import { liveResponse } from './live-contracts.js';
|
|
12
|
+
import { redriveLiveWorkers, settleLiveWorker } from './live-worker.js';
|
|
13
|
+
import { liveResponse, liveWritable } from './live-contracts.js';
|
|
14
14
|
import { executeLiveInvitation, LIVE_INVITATION_OPERATIONS } from './live-invitations.js';
|
|
15
15
|
import { liveInvitationViews } from './live-invitation-state.js';
|
|
16
16
|
export { LIVE_INVITATIONS_OPEN_MAX } from './live-invitations.js';
|
|
17
17
|
export { LIVE_INVITATION_TOOL_CLASSES } from '../git-tool-definitions.js';
|
|
18
18
|
export function createLiveService(deps) {
|
|
19
19
|
const now = deps.now ?? Date.now;
|
|
20
|
-
return { ...liveInvitationViews(deps),
|
|
20
|
+
return { ...liveInvitationViews(deps), redrive: (storageScopeId, limit) => redriveLiveWorkers(deps, storageScopeId, limit),
|
|
21
|
+
async execute(operation, raw, invocation) {
|
|
21
22
|
const args = structuredClone(raw);
|
|
22
23
|
if (LIVE_INVITATION_OPERATIONS.includes(operation)) {
|
|
23
24
|
if (!matchesSchema(args, GIT_TOOL_DEFINITIONS[`artifacts_${operation}`].inputSchema)) {
|
|
@@ -57,7 +58,7 @@ export function createLiveService(deps) {
|
|
|
57
58
|
throw new ArtifactOperationError('git_diverged');
|
|
58
59
|
if (binding.state === 'detached')
|
|
59
60
|
throw new ArtifactOperationError('git_not_attached');
|
|
60
|
-
if (binding.state
|
|
61
|
+
if (!liveWritable(binding.state))
|
|
61
62
|
liveBusy(binding.pendingJobId ? 'pending_publication' : 'invalid_phase');
|
|
62
63
|
if (binding.channel !== 'personal' || binding.personalPrincipalId !== invocation.actorId || binding.executor !== 'sandbox')
|
|
63
64
|
liveBusy('invalid_phase');
|
|
@@ -134,7 +135,7 @@ export function createLiveService(deps) {
|
|
|
134
135
|
!(operation === 'live_read' && current.invited && current.canReadCode) ||
|
|
135
136
|
(!stop && !current.canReadCode))
|
|
136
137
|
throw new ArtifactOperationError('access_denied');
|
|
137
|
-
if (writer && !stop && (!current.canWrite || !current.humanLinked || current.binding.state
|
|
138
|
+
if (writer && !stop && (!current.canWrite || !current.humanLinked || !liveWritable(current.binding.state)))
|
|
138
139
|
throw new ArtifactOperationError('access_denied');
|
|
139
140
|
if ((operation === 'live_write' || operation === 'live_control' && !stop) && !current.qualified)
|
|
140
141
|
throw new ArtifactOperationError('builder_unavailable');
|
|
@@ -5,6 +5,11 @@ export interface LiveIdentity {
|
|
|
5
5
|
}
|
|
6
6
|
/** A-LIVE Amendment 1: idle strictly after 900 s since the last qualifying access; there is no absolute lifetime. */
|
|
7
7
|
export declare const LIVE_IDLE_THRESHOLD_MS = 900000;
|
|
8
|
+
/** Upper bound of one redriveLiveWorkers pass: the 60 s host timer stays safe with the default pool. */
|
|
9
|
+
export declare const MAX_REDRIVE_LIMIT = 64;
|
|
10
|
+
/** Clamps a caller limit to [0, MAX_REDRIVE_LIMIT]: undefined stays the default, 0/negative/NaN select nothing,
|
|
11
|
+
* oversized values stop at the cap. Memory and Postgres share it so both adapters agree on every input. */
|
|
12
|
+
export declare const normalizeRedriveLimit: (limit?: unknown) => number;
|
|
8
13
|
export interface LiveOverlayEntry {
|
|
9
14
|
path: string;
|
|
10
15
|
text: string | null;
|
|
@@ -133,7 +138,12 @@ export interface LiveTransaction {
|
|
|
133
138
|
export interface LiveStore {
|
|
134
139
|
transaction<T>(identity: LiveIdentity, action: (tx: LiveTransaction) => Promise<T>): Promise<T>;
|
|
135
140
|
sessionIdentity(scope: string, artifactId: string, liveSessionId: string): Promise<LiveIdentity | undefined>;
|
|
141
|
+
/** Drafts of the scope whose runtime still waits for the worker (see liveWorkerPending), oldest access first.
|
|
142
|
+
* Absent when the adapter cannot list them: the host then has no durable re-drive. */
|
|
143
|
+
pending?(scope: string, limit?: number): Promise<LiveIdentity[]>;
|
|
136
144
|
}
|
|
145
|
+
/** A runtime waits for the worker while it revives, while a stop is not DORMANT yet, or while LIVE trails its draft. */
|
|
146
|
+
export declare function liveWorkerPending(record: Pick<LiveDraftRecord, 'revision' | 'runtime'> | undefined): 'project' | 'stop' | null;
|
|
137
147
|
export declare const liveIdentityKey: (identity: LiveIdentity) => string;
|
|
138
148
|
/** Atomic fake; the persisted representation contains encrypted objects and metadata only. */
|
|
139
149
|
export declare function createMemoryLiveStore(): LiveStore;
|
|
@@ -2,6 +2,27 @@ import { createKeyMutex } from './ports.js';
|
|
|
2
2
|
import { ArtifactOperationError } from './failures.js';
|
|
3
3
|
/** A-LIVE Amendment 1: idle strictly after 900 s since the last qualifying access; there is no absolute lifetime. */
|
|
4
4
|
export const LIVE_IDLE_THRESHOLD_MS = 900_000;
|
|
5
|
+
/** Upper bound of one redriveLiveWorkers pass: the 60 s host timer stays safe with the default pool. */
|
|
6
|
+
export const MAX_REDRIVE_LIMIT = 64;
|
|
7
|
+
/** Clamps a caller limit to [0, MAX_REDRIVE_LIMIT]: undefined stays the default, 0/negative/NaN select nothing,
|
|
8
|
+
* oversized values stop at the cap. Memory and Postgres share it so both adapters agree on every input. */
|
|
9
|
+
export const normalizeRedriveLimit = (limit) => {
|
|
10
|
+
if (limit === undefined)
|
|
11
|
+
return MAX_REDRIVE_LIMIT;
|
|
12
|
+
const n = Math.trunc(Number(limit));
|
|
13
|
+
if (!Number.isFinite(n) || n <= 0)
|
|
14
|
+
return 0;
|
|
15
|
+
return Math.min(n, MAX_REDRIVE_LIMIT);
|
|
16
|
+
};
|
|
17
|
+
/** A runtime waits for the worker while it revives, while a stop is not DORMANT yet, or while LIVE trails its draft. */
|
|
18
|
+
export function liveWorkerPending(record) {
|
|
19
|
+
const runtime = record?.runtime;
|
|
20
|
+
if (!record || !runtime)
|
|
21
|
+
return null;
|
|
22
|
+
if (runtime.phase === 'QUIESCING' || runtime.phase === 'SAVING' || runtime.phase === 'DECOMMISSIONING')
|
|
23
|
+
return 'stop';
|
|
24
|
+
return runtime.phase === 'REVIVING' || (runtime.phase === 'LIVE' && runtime.appliedRevision !== record.revision) ? 'project' : null;
|
|
25
|
+
}
|
|
5
26
|
export const liveIdentityKey = (identity) => JSON.stringify([
|
|
6
27
|
identity.storageScopeId, identity.artifactId, identity.bindingGeneration
|
|
7
28
|
]);
|
|
@@ -49,6 +70,13 @@ export function createMemoryLiveStore() {
|
|
|
49
70
|
row.runtime?.liveSessionId === sessionId);
|
|
50
71
|
return record ? { storageScopeId: scope, artifactId, bindingGeneration: record.bindingGeneration } : undefined;
|
|
51
72
|
},
|
|
73
|
+
async pending(scope, limit) {
|
|
74
|
+
return [...records.values()].filter(row => row.storageScopeId === scope && liveWorkerPending(row))
|
|
75
|
+
.sort((a, b) => a.runtime.lastAccessAt.localeCompare(b.runtime.lastAccessAt) ||
|
|
76
|
+
a.artifactId.localeCompare(b.artifactId) || a.bindingGeneration - b.bindingGeneration)
|
|
77
|
+
.slice(0, normalizeRedriveLimit(limit))
|
|
78
|
+
.map(row => ({ storageScopeId: scope, artifactId: row.artifactId, bindingGeneration: row.bindingGeneration }));
|
|
79
|
+
},
|
|
52
80
|
transaction: (identity, action) => mutex.runSerialized('live-store', async () => {
|
|
53
81
|
const id = liveIdentityKey(identity);
|
|
54
82
|
const pendingObjects = new Map();
|
|
@@ -1,10 +1,24 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type { LiveServiceDeps } from './live-contracts.js';
|
|
3
|
-
/**
|
|
1
|
+
import { type LiveIdentity } from './live-store.js';
|
|
2
|
+
import type { LiveRedriveItem, LiveServiceDeps, LiveWorkerOutcome } from './live-contracts.js';
|
|
3
|
+
/**
|
|
4
|
+
* Side effects follow durable intents. Failure leaves the accepted source recoverable and pending: the outcome is
|
|
5
|
+
* returned and reported to `deps.onWorkerEvent` (`failed` with the typed code, `pending` for a worker that is not
|
|
6
|
+
* ready yet), and `redriveLiveWorkers` settles the same intent again. Never throws.
|
|
7
|
+
*/
|
|
4
8
|
export declare function settleLiveWorker(input: {
|
|
5
9
|
deps: LiveServiceDeps;
|
|
6
10
|
identity: LiveIdentity;
|
|
7
11
|
action: 'project' | 'stop';
|
|
8
12
|
result: Record<string, any>;
|
|
9
13
|
now: number;
|
|
10
|
-
}): Promise<
|
|
14
|
+
}): Promise<LiveWorkerOutcome>;
|
|
15
|
+
/**
|
|
16
|
+
* Durable re-drive (host timer, at boot and at most every 60 s): settles again every runtime of the scope that still
|
|
17
|
+
* waits for the worker. A revive whose builder answered `ready: false`, a settle lost with its process and a stop the
|
|
18
|
+
* worker refused are all picked up here; the worker call is the same fenced, idempotent reconcile or stop.
|
|
19
|
+
* Bounded: at most `redriveConcurrency` (default 4) worker calls in flight, each abandoned after
|
|
20
|
+
* `redriveItemTimeoutMs` (default 35 s) with a `timeout` failure; an overlapping pass for the same scope yields
|
|
21
|
+
* no items. A terminal builder failure (`failure: { code, reason }`) moves the runtime to DORMANT with
|
|
22
|
+
* `code:reason` as stateDetail and is never re-driven. Never throws.
|
|
23
|
+
*/
|
|
24
|
+
export declare function redriveLiveWorkers(deps: LiveServiceDeps, storageScopeId: string, limit?: number): Promise<LiveRedriveItem[]>;
|
|
@@ -1,55 +1,250 @@
|
|
|
1
1
|
import { expireLiveDraft, persistLiveOverlay, readLiveOverlay } from './live-drafts.js';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
import { liveIdentityKey, liveWorkerPending, normalizeRedriveLimit } from './live-store.js';
|
|
3
|
+
const REDRIVE_CONCURRENCY_DEFAULT = 4;
|
|
4
|
+
const REDRIVE_CONCURRENCY_MAX = 8;
|
|
5
|
+
const REDRIVE_ITEM_TIMEOUT_MS_DEFAULT = 35_000;
|
|
6
|
+
const STOP_PHASES = ['QUIESCING', 'SAVING', 'DECOMMISSIONING'];
|
|
7
|
+
const LIVE_SETTLE_PHASES = ['REVIVING', 'LIVE'];
|
|
8
|
+
const codeOf = (error) => {
|
|
9
|
+
const record = error;
|
|
10
|
+
if (record) {
|
|
11
|
+
if (typeof record.kind === 'string' && record.kind)
|
|
12
|
+
return record.kind;
|
|
13
|
+
if (typeof record.code === 'string' && record.code)
|
|
14
|
+
return record.code;
|
|
15
|
+
if (typeof record.code === 'number')
|
|
16
|
+
return String(record.code);
|
|
17
|
+
if (typeof record.name === 'string' && record.name && record.name !== 'Error')
|
|
18
|
+
return record.name;
|
|
19
|
+
}
|
|
20
|
+
return 'unknown';
|
|
21
|
+
};
|
|
22
|
+
/** A host observer never changes the outcome of a settle. */
|
|
23
|
+
function report(deps, identity, action, outcome, code, reason) {
|
|
24
|
+
try {
|
|
25
|
+
deps.onWorkerEvent?.({ identity, action, outcome, ...(code ? { code } : {}), ...(reason ? { reason } : {}) });
|
|
26
|
+
}
|
|
27
|
+
catch { /* observer only */ }
|
|
28
|
+
}
|
|
29
|
+
const validFailure = (failure) => {
|
|
30
|
+
if (!failure || typeof failure !== 'object')
|
|
31
|
+
return null;
|
|
32
|
+
const { code, reason } = failure;
|
|
33
|
+
if (typeof code !== 'string' || !code)
|
|
34
|
+
return null;
|
|
35
|
+
return { code, reason: typeof reason === 'string' && reason ? reason : code };
|
|
36
|
+
};
|
|
37
|
+
/** One settle per identity at a time: a concurrent caller waits for the in-flight attempt instead of
|
|
38
|
+
* doubling the worker call, then runs its own fenced attempt. No parallel reconcile/stop per session. */
|
|
39
|
+
const settleLocks = new Map();
|
|
40
|
+
async function withSettleLock(key, run) {
|
|
41
|
+
while (settleLocks.has(key)) {
|
|
42
|
+
try {
|
|
43
|
+
await settleLocks.get(key);
|
|
44
|
+
}
|
|
45
|
+
catch { /* locks never reject */ }
|
|
46
|
+
}
|
|
47
|
+
let release;
|
|
48
|
+
const current = new Promise(resolve => { release = resolve; });
|
|
49
|
+
settleLocks.set(key, current);
|
|
50
|
+
try {
|
|
51
|
+
return await run();
|
|
52
|
+
}
|
|
53
|
+
finally {
|
|
54
|
+
if (settleLocks.get(key) === current)
|
|
55
|
+
settleLocks.delete(key);
|
|
56
|
+
release();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/** One redrive pass per scope at a time: an overlapping timer tick yields no items instead of doubling the pool. */
|
|
60
|
+
const redriveInflight = new Set();
|
|
61
|
+
async function settleOnce(input) {
|
|
62
|
+
const { deps, identity, action, result } = input;
|
|
5
63
|
if (!deps.worker)
|
|
6
|
-
return;
|
|
64
|
+
return 'skipped';
|
|
7
65
|
try {
|
|
8
66
|
if (action === 'stop') {
|
|
9
67
|
const runtime = await deps.store.transaction(identity, async (tx) => tx.record?.runtime);
|
|
68
|
+
const expectedLease = typeof result.leaseEpoch === 'number'
|
|
69
|
+
? result.leaseEpoch : undefined;
|
|
10
70
|
if (!runtime || runtime.liveSessionId !== result.liveSessionId)
|
|
11
|
-
return;
|
|
71
|
+
return 'skipped';
|
|
72
|
+
if (!STOP_PHASES.includes(runtime.phase))
|
|
73
|
+
return 'skipped';
|
|
74
|
+
if (expectedLease !== undefined && runtime.leaseEpoch !== expectedLease)
|
|
75
|
+
return 'skipped';
|
|
12
76
|
await deps.worker.stop({ ...identity, liveSessionId: runtime.liveSessionId, leaseEpoch: runtime.leaseEpoch });
|
|
13
|
-
await deps.store.transaction(identity, async (tx) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
77
|
+
const moved = await deps.store.transaction(identity, async (tx) => {
|
|
78
|
+
const current = tx.record?.runtime;
|
|
79
|
+
if (!current || current.liveSessionId !== runtime.liveSessionId || current.leaseEpoch !== runtime.leaseEpoch ||
|
|
80
|
+
!STOP_PHASES.includes(current.phase))
|
|
81
|
+
return false;
|
|
82
|
+
current.phase = 'DORMANT';
|
|
83
|
+
current.appliedRevision = null;
|
|
84
|
+
result.state = 'DORMANT';
|
|
85
|
+
result.runtimeState = 'DORMANT';
|
|
86
|
+
result.appliedRevision = null;
|
|
87
|
+
return true;
|
|
88
|
+
});
|
|
89
|
+
return moved ? 'settled' : 'skipped';
|
|
90
|
+
}
|
|
91
|
+
const stillProject = await deps.store.transaction(identity, async (tx) => liveWorkerPending(tx.record) === 'project');
|
|
92
|
+
if (!stillProject)
|
|
93
|
+
return 'skipped';
|
|
94
|
+
const ack = await deps.worker.reconcile(identity);
|
|
95
|
+
if (!ack) {
|
|
96
|
+
report(deps, identity, action, 'pending');
|
|
97
|
+
return 'pending';
|
|
98
|
+
}
|
|
99
|
+
if (!ack.ready) {
|
|
100
|
+
const failure = validFailure(ack.failure);
|
|
101
|
+
if (failure) {
|
|
102
|
+
const moved = await deps.store.transaction(identity, async (tx) => {
|
|
103
|
+
const record = tx.record;
|
|
104
|
+
const runtime = record?.runtime;
|
|
105
|
+
if (!record || !runtime || ack.liveSessionId !== runtime.liveSessionId || ack.leaseEpoch !== runtime.leaseEpoch ||
|
|
106
|
+
ack.routeEpoch !== runtime.routeEpoch || ack.revision !== record.revision ||
|
|
107
|
+
!(runtime.phase === 'REVIVING' || (runtime.phase === 'LIVE' && runtime.appliedRevision !== record.revision)))
|
|
108
|
+
return false;
|
|
109
|
+
runtime.phase = 'DORMANT';
|
|
110
|
+
runtime.appliedRevision = null;
|
|
111
|
+
runtime.stateDetail = `${failure.code}:${failure.reason}`;
|
|
18
112
|
result.state = 'DORMANT';
|
|
19
113
|
result.runtimeState = 'DORMANT';
|
|
20
114
|
result.appliedRevision = null;
|
|
21
|
-
|
|
22
|
-
|
|
115
|
+
result.stateDetail = runtime.stateDetail;
|
|
116
|
+
return true;
|
|
117
|
+
}).catch(() => false);
|
|
118
|
+
if (!moved)
|
|
119
|
+
return 'skipped';
|
|
120
|
+
report(deps, identity, action, 'failed', failure.code, failure.reason);
|
|
121
|
+
return 'failed';
|
|
122
|
+
}
|
|
123
|
+
report(deps, identity, action, 'pending');
|
|
124
|
+
return 'pending';
|
|
23
125
|
}
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
|
|
126
|
+
const moved = await deps.store.transaction(identity, async (tx) => {
|
|
127
|
+
const record = tx.record;
|
|
128
|
+
const runtime = record?.runtime;
|
|
129
|
+
if (!record || !runtime || ack.liveSessionId !== runtime.liveSessionId || ack.leaseEpoch !== runtime.leaseEpoch ||
|
|
130
|
+
ack.routeEpoch !== runtime.routeEpoch || ack.revision !== record.revision || !LIVE_SETTLE_PHASES.includes(runtime.phase))
|
|
131
|
+
return false;
|
|
132
|
+
const at = (deps.now ?? Date.now)();
|
|
133
|
+
if (expireLiveDraft(tx, at))
|
|
134
|
+
return false;
|
|
135
|
+
if (runtime.renewOnReady && record.changedPaths) {
|
|
136
|
+
const overlay = await readLiveOverlay(tx, deps.keys);
|
|
137
|
+
const renewed = await persistLiveOverlay(tx, deps.keys, { identity, expectedRevision: record.revision,
|
|
138
|
+
baseHeadSha: record.baseHeadSha, baseTreeSha: record.baseTreeSha, liveTreeSha: record.liveTreeSha, overlay }, at, true, true);
|
|
139
|
+
// Source revision remains fenced to the worker ACK; reauthentication is handled by the vault.
|
|
140
|
+
result.draftExpiresAt = renewed.expiresAt;
|
|
141
|
+
}
|
|
142
|
+
runtime.renewOnReady = false;
|
|
143
|
+
runtime.appliedRevision = ack.revision;
|
|
144
|
+
runtime.phase = 'LIVE';
|
|
145
|
+
result.appliedRevision = ack.revision;
|
|
146
|
+
result.workerPending = false;
|
|
147
|
+
result.runtimeState = 'LIVE';
|
|
148
|
+
result.state = 'LIVE';
|
|
149
|
+
return true;
|
|
150
|
+
});
|
|
151
|
+
return moved ? 'settled' : 'skipped';
|
|
152
|
+
}
|
|
153
|
+
catch (error) {
|
|
154
|
+
// The durable intent remains available to redriveLiveWorkers; the failure is reported, never silent.
|
|
155
|
+
report(deps, identity, action, 'failed', codeOf(error));
|
|
156
|
+
return 'failed';
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Side effects follow durable intents. Failure leaves the accepted source recoverable and pending: the outcome is
|
|
161
|
+
* returned and reported to `deps.onWorkerEvent` (`failed` with the typed code, `pending` for a worker that is not
|
|
162
|
+
* ready yet), and `redriveLiveWorkers` settles the same intent again. Never throws.
|
|
163
|
+
*/
|
|
164
|
+
export async function settleLiveWorker(input) {
|
|
165
|
+
if (!input.deps.worker)
|
|
166
|
+
return 'skipped';
|
|
167
|
+
return withSettleLock(liveIdentityKey(input.identity), () => settleOnce(input));
|
|
168
|
+
}
|
|
169
|
+
const normalizeConcurrency = (value) => {
|
|
170
|
+
const n = Math.trunc(Number(value));
|
|
171
|
+
if (!Number.isFinite(n))
|
|
172
|
+
return REDRIVE_CONCURRENCY_DEFAULT;
|
|
173
|
+
return Math.min(REDRIVE_CONCURRENCY_MAX, Math.max(1, n));
|
|
174
|
+
};
|
|
175
|
+
const normalizeItemTimeout = (value) => {
|
|
176
|
+
const n = Math.trunc(Number(value));
|
|
177
|
+
if (!Number.isFinite(n) || n <= 0)
|
|
178
|
+
return REDRIVE_ITEM_TIMEOUT_MS_DEFAULT;
|
|
179
|
+
return Math.min(120_000, n);
|
|
180
|
+
};
|
|
181
|
+
/**
|
|
182
|
+
* Durable re-drive (host timer, at boot and at most every 60 s): settles again every runtime of the scope that still
|
|
183
|
+
* waits for the worker. A revive whose builder answered `ready: false`, a settle lost with its process and a stop the
|
|
184
|
+
* worker refused are all picked up here; the worker call is the same fenced, idempotent reconcile or stop.
|
|
185
|
+
* Bounded: at most `redriveConcurrency` (default 4) worker calls in flight, each abandoned after
|
|
186
|
+
* `redriveItemTimeoutMs` (default 35 s) with a `timeout` failure; an overlapping pass for the same scope yields
|
|
187
|
+
* no items. A terminal builder failure (`failure: { code, reason }`) moves the runtime to DORMANT with
|
|
188
|
+
* `code:reason` as stateDetail and is never re-driven. Never throws.
|
|
189
|
+
*/
|
|
190
|
+
export async function redriveLiveWorkers(deps, storageScopeId, limit) {
|
|
191
|
+
if (!deps.worker || !deps.store.pending)
|
|
192
|
+
return [];
|
|
193
|
+
if (redriveInflight.has(storageScopeId))
|
|
194
|
+
return [];
|
|
195
|
+
redriveInflight.add(storageScopeId);
|
|
196
|
+
try {
|
|
197
|
+
const pending = await deps.store.pending(storageScopeId, normalizeRedriveLimit(limit));
|
|
198
|
+
if (!pending.length)
|
|
199
|
+
return [];
|
|
200
|
+
const concurrency = normalizeConcurrency(deps.redriveConcurrency);
|
|
201
|
+
const timeoutMs = normalizeItemTimeout(deps.redriveItemTimeoutMs);
|
|
202
|
+
const ordered = new Array(pending.length).fill(null);
|
|
203
|
+
let next = 0;
|
|
204
|
+
const runOne = async () => {
|
|
205
|
+
while (true) {
|
|
206
|
+
const index = next++;
|
|
207
|
+
if (index >= pending.length)
|
|
36
208
|
return;
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
209
|
+
const identity = pending[index];
|
|
210
|
+
let waiting = null;
|
|
211
|
+
try {
|
|
212
|
+
waiting = await deps.store.transaction(identity, async (tx) => {
|
|
213
|
+
const action = liveWorkerPending(tx.record);
|
|
214
|
+
return action && tx.record.runtime
|
|
215
|
+
? { action, liveSessionId: tx.record.runtime.liveSessionId, leaseEpoch: tx.record.runtime.leaseEpoch } : null;
|
|
216
|
+
});
|
|
43
217
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
218
|
+
catch {
|
|
219
|
+
waiting = null;
|
|
220
|
+
}
|
|
221
|
+
if (!waiting)
|
|
222
|
+
continue;
|
|
223
|
+
let timer;
|
|
224
|
+
try {
|
|
225
|
+
const settle = settleLiveWorker({ deps, identity, action: waiting.action,
|
|
226
|
+
result: { liveSessionId: waiting.liveSessionId, leaseEpoch: waiting.leaseEpoch }, now: (deps.now ?? Date.now)() });
|
|
227
|
+
const late = new Promise(resolve => {
|
|
228
|
+
timer = setTimeout(() => {
|
|
229
|
+
report(deps, identity, waiting.action, 'failed', 'timeout');
|
|
230
|
+
resolve('failed');
|
|
231
|
+
}, timeoutMs);
|
|
232
|
+
});
|
|
233
|
+
ordered[index] = { ...identity, action: waiting.action, outcome: await Promise.race([settle, late]) };
|
|
234
|
+
}
|
|
235
|
+
catch {
|
|
236
|
+
ordered[index] = { ...identity, action: waiting.action, outcome: 'failed' };
|
|
237
|
+
}
|
|
238
|
+
finally {
|
|
239
|
+
if (timer)
|
|
240
|
+
clearTimeout(timer);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
await Promise.all(Array.from({ length: Math.min(concurrency, pending.length) }, () => runOne()));
|
|
245
|
+
return ordered.filter((item) => item !== null);
|
|
246
|
+
}
|
|
247
|
+
finally {
|
|
248
|
+
redriveInflight.delete(storageScopeId);
|
|
53
249
|
}
|
|
54
|
-
catch { /* The durable intent remains available to the controller's fenced reconciliation. */ }
|
|
55
250
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
-- Live re-drive pending scan (package redriveLiveWorkers, host timer at boot and every <= 60 s).
|
|
2
|
+
-- The pending() query filters one storage scope on JSONB phase and orders by last access time; DORMANT
|
|
3
|
+
-- rows (the idle majority) stay out of this partial index so every tick scans pending rows only.
|
|
4
|
+
CREATE INDEX IF NOT EXISTS live_drafts_pending_idx ON artifacts.live_drafts
|
|
5
|
+
(storage_scope_id, (record #>> '{runtime,lastAccessAt}'), artifact_id, binding_generation)
|
|
6
|
+
WHERE (record #>> '{runtime,phase}' IN ('REVIVING','QUIESCING','SAVING','DECOMMISSIONING')
|
|
7
|
+
OR (record #>> '{runtime,phase}' = 'LIVE'));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sentropic/artifacts",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.27",
|
|
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",
|