@fro.bot/systematic 3.22.4 → 3.22.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +3 -3
- package/dist/{index-0sc6c1vd.js → index-aaygsm67.js} +19 -19
- package/dist/index.js +686 -156
- package/dist/lib/opencode-workflow-guard.d.ts +33 -1
- package/dist/lib/workflow-guard.d.ts +1 -1
- package/dist/pi.js +19 -19
- package/package.json +3 -3
- package/skills/ce-review/scripts/validate-review.mjs +22 -22
- package/skills/using-systematic/SKILL.md +1 -1
package/dist/index.js
CHANGED
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
extractCommandFrontmatter,
|
|
20
20
|
findSkillsInDir,
|
|
21
21
|
discoverSkills
|
|
22
|
-
} from "./index-
|
|
22
|
+
} from "./index-aaygsm67.js";
|
|
23
23
|
|
|
24
24
|
// src/index.ts
|
|
25
25
|
import { createHash as createHash4 } from "crypto";
|
|
@@ -9286,6 +9286,7 @@ function createWorkflowGuard(options) {
|
|
|
9286
9286
|
const runtimeRequired = normalizeOperations(options.runtimeRequiredOperations);
|
|
9287
9287
|
const runtimeScopes = normalizeResourceScopes2(options.runtimeResourceScopes);
|
|
9288
9288
|
let mode = options.mode ?? "protected";
|
|
9289
|
+
let declarationGeneration = 0;
|
|
9289
9290
|
let epoch;
|
|
9290
9291
|
let globalIssue;
|
|
9291
9292
|
const transitionsByCall = new Map;
|
|
@@ -9920,6 +9921,7 @@ function createWorkflowGuard(options) {
|
|
|
9920
9921
|
}
|
|
9921
9922
|
}
|
|
9922
9923
|
epoch.unit.status = "completed";
|
|
9924
|
+
declarationGeneration += 1;
|
|
9923
9925
|
return {
|
|
9924
9926
|
status: "completed",
|
|
9925
9927
|
target: lifecycle.target,
|
|
@@ -10118,6 +10120,7 @@ function createWorkflowGuard(options) {
|
|
|
10118
10120
|
if (!declarationChanged(unit, requiredOperations, resourceScopes)) {
|
|
10119
10121
|
return { status: "rejected", reasonCode: "unit-active" };
|
|
10120
10122
|
}
|
|
10123
|
+
declarationGeneration += 1;
|
|
10121
10124
|
unit.requiredOperations = requiredOperations;
|
|
10122
10125
|
unit.declaredResourceOperations = Object.freeze([...resourceScopes.keys()]);
|
|
10123
10126
|
unit.resourceScopes = resourceScopes;
|
|
@@ -10219,6 +10222,7 @@ function createWorkflowGuard(options) {
|
|
|
10219
10222
|
};
|
|
10220
10223
|
}
|
|
10221
10224
|
async function processOperation(input, parsed, unit, trustedClassification) {
|
|
10225
|
+
const generation = declarationGeneration;
|
|
10222
10226
|
if (!unit.requiredOperations.includes(parsed.operation)) {
|
|
10223
10227
|
markTerminalOperation(parsed, input);
|
|
10224
10228
|
return { status: "rejected", reasonCode: "operation-not-required" };
|
|
@@ -10237,28 +10241,45 @@ function createWorkflowGuard(options) {
|
|
|
10237
10241
|
if (prepared.status !== "prepared") {
|
|
10238
10242
|
return prepared.reasonCode === "call-context-conflict" ? { status: "rejected", reasonCode: "call-context-conflict" } : { status: "rejected", reasonCode: "rejected-operation" };
|
|
10239
10243
|
}
|
|
10240
|
-
const
|
|
10241
|
-
return
|
|
10244
|
+
const outcome = trustedClassification ? { kind: "classified", classification: trustedClassification } : await classifyPreparedOperation(parsed, input, unit, generation);
|
|
10245
|
+
return settleClassifiedOperation(parsed, input, unit, generation, outcome);
|
|
10246
|
+
}
|
|
10247
|
+
function settleClassifiedOperation(parsed, input, unit, generation, outcome) {
|
|
10248
|
+
if (outcome.kind === "stale" || generation !== declarationGeneration) {
|
|
10249
|
+
return supersedeOperation(parsed, input);
|
|
10250
|
+
}
|
|
10251
|
+
if (outcome.kind === "unclassified") {
|
|
10252
|
+
return { status: "rejected", reasonCode: "guard-unavailable" };
|
|
10253
|
+
}
|
|
10254
|
+
return finalizeOperation(parsed, input, unit, outcome.classification);
|
|
10255
|
+
}
|
|
10256
|
+
function supersedeOperation(parsed, input) {
|
|
10257
|
+
abandonPreparedOperation(parsed);
|
|
10258
|
+
markTerminalOperation(parsed, input);
|
|
10259
|
+
return { status: "rejected", reasonCode: "declaration-superseded" };
|
|
10242
10260
|
}
|
|
10243
10261
|
function rejectParsedOperation(parsed, input, unit, reasonCode) {
|
|
10244
10262
|
markTerminalOperation(parsed, input);
|
|
10245
10263
|
return recordUnitEvidenceIssue(unit, parsed.operation, reasonCode);
|
|
10246
10264
|
}
|
|
10247
|
-
async function classifyPreparedOperation(parsed, input, unit) {
|
|
10265
|
+
async function classifyPreparedOperation(parsed, input, unit, generation) {
|
|
10248
10266
|
const classifyOperation = options.classifier?.classifyOperation;
|
|
10249
10267
|
if (!classifyOperation) {
|
|
10250
10268
|
abandonPreparedOperation(parsed);
|
|
10251
10269
|
markTerminalOperation(parsed, input);
|
|
10252
10270
|
recordUnitEvidenceIssue(unit, parsed.operation, "guard-unavailable");
|
|
10253
|
-
return;
|
|
10271
|
+
return { kind: "unclassified" };
|
|
10254
10272
|
}
|
|
10255
10273
|
try {
|
|
10256
|
-
|
|
10274
|
+
const classification = await classifyOperation(input);
|
|
10275
|
+
return classification ? { kind: "classified", classification } : { kind: "unclassified" };
|
|
10257
10276
|
} catch {
|
|
10277
|
+
if (generation !== declarationGeneration)
|
|
10278
|
+
return { kind: "stale" };
|
|
10258
10279
|
abandonPreparedOperation(parsed);
|
|
10259
10280
|
markTerminalOperation(parsed, input);
|
|
10260
10281
|
recordUnitEvidenceIssue(unit, parsed.operation, "guard-unavailable");
|
|
10261
|
-
return;
|
|
10282
|
+
return { kind: "unclassified" };
|
|
10262
10283
|
}
|
|
10263
10284
|
}
|
|
10264
10285
|
function abandonPreparedOperation(parsed) {
|
|
@@ -10855,6 +10876,7 @@ function createWorkflowGuard(options) {
|
|
|
10855
10876
|
if (parsed.mode === mode)
|
|
10856
10877
|
return { status: "unchanged", mode };
|
|
10857
10878
|
mode = parsed.mode;
|
|
10879
|
+
declarationGeneration += 1;
|
|
10858
10880
|
for (const lifecycle of transitionsByCall.values()) {
|
|
10859
10881
|
if (lifecycle.state === "prepared")
|
|
10860
10882
|
lifecycle.state = "abandoned";
|
|
@@ -10936,6 +10958,7 @@ var REASON_CODES = new Set([
|
|
|
10936
10958
|
"rejected-operation",
|
|
10937
10959
|
"resource-mismatch",
|
|
10938
10960
|
"running-operation",
|
|
10961
|
+
"snapshot-blocked",
|
|
10939
10962
|
"stale-receipt",
|
|
10940
10963
|
"transition-finalized",
|
|
10941
10964
|
"transition-terminal",
|
|
@@ -10972,9 +10995,26 @@ function isWorkflowGuardBlockedError(value) {
|
|
|
10972
10995
|
function defaultTargetObserver(targetDirectory) {
|
|
10973
10996
|
return createOpencodeOperationObserver({ targetDirectory });
|
|
10974
10997
|
}
|
|
10998
|
+
var TIMED_OUT_READ = { status: "timeout" };
|
|
10975
10999
|
function unconfirmedReadback(probe) {
|
|
10976
11000
|
return { probe, reasonCode: "command-timeout" };
|
|
10977
11001
|
}
|
|
11002
|
+
var SNAPSHOT_BLOCKING_REASONS = [
|
|
11003
|
+
"file-limit",
|
|
11004
|
+
"file-output-limit",
|
|
11005
|
+
"command-output-limit",
|
|
11006
|
+
"worktree-unstable"
|
|
11007
|
+
];
|
|
11008
|
+
function isSnapshotBlockingReason(reasonCode) {
|
|
11009
|
+
return typeof reasonCode === "string" && SNAPSHOT_BLOCKING_REASONS.includes(reasonCode);
|
|
11010
|
+
}
|
|
11011
|
+
var INERT_SNAPSHOT_BLOCK = {
|
|
11012
|
+
set: () => false,
|
|
11013
|
+
current: () => {
|
|
11014
|
+
return;
|
|
11015
|
+
},
|
|
11016
|
+
clear: async () => ({ status: "not-blocked" })
|
|
11017
|
+
};
|
|
10978
11018
|
function initializationCause(kind) {
|
|
10979
11019
|
return { site: "initialize-session", kind, timedOut: false };
|
|
10980
11020
|
}
|
|
@@ -11000,6 +11040,17 @@ function beforeCause(kind, reasonCode) {
|
|
|
11000
11040
|
function afterCause(kind, reasonCode) {
|
|
11001
11041
|
return hookCause("tool-after", kind, reasonCode);
|
|
11002
11042
|
}
|
|
11043
|
+
function snapshotFailureCause(build) {
|
|
11044
|
+
return (reasonCode) => reasonCode === undefined ? build("local-snapshot-error") : build("local-snapshot-unavailable", reasonCode);
|
|
11045
|
+
}
|
|
11046
|
+
function seedCause(kind, reasonCode) {
|
|
11047
|
+
return {
|
|
11048
|
+
site: "seed-remote-scopes",
|
|
11049
|
+
kind,
|
|
11050
|
+
...reasonCode !== undefined ? { reasonCode } : {},
|
|
11051
|
+
timedOut: reasonCode === "command-timeout"
|
|
11052
|
+
};
|
|
11053
|
+
}
|
|
11003
11054
|
function afterFailure(kind, reasonCode) {
|
|
11004
11055
|
return { status: "unavailable", cause: afterCause(kind, reasonCode) };
|
|
11005
11056
|
}
|
|
@@ -11018,7 +11069,7 @@ async function readSnapshot(observer, expectedTargetIdentity) {
|
|
|
11018
11069
|
return { status: "fatal" };
|
|
11019
11070
|
}
|
|
11020
11071
|
if (isProbeTimeout(result))
|
|
11021
|
-
return
|
|
11072
|
+
return TIMED_OUT_READ;
|
|
11022
11073
|
if (result.status === "unavailable") {
|
|
11023
11074
|
return { status: "fatal", reasonCode: result.reasonCode };
|
|
11024
11075
|
}
|
|
@@ -11027,6 +11078,9 @@ async function readSnapshot(observer, expectedTargetIdentity) {
|
|
|
11027
11078
|
}
|
|
11028
11079
|
return { status: "ok", value: result.snapshot };
|
|
11029
11080
|
}
|
|
11081
|
+
function probeFailureReason(failure) {
|
|
11082
|
+
return failure.status === "timeout" ? "command-timeout" : failure.reasonCode;
|
|
11083
|
+
}
|
|
11030
11084
|
function isProbeTimeout(result) {
|
|
11031
11085
|
if (result === undefined)
|
|
11032
11086
|
return false;
|
|
@@ -11149,6 +11203,9 @@ function isLocalOperationTool(tool) {
|
|
|
11149
11203
|
function unavailableOperationTarget() {
|
|
11150
11204
|
return { status: "unavailable", reasonCode: "target-unavailable" };
|
|
11151
11205
|
}
|
|
11206
|
+
function timedOutOperationTarget() {
|
|
11207
|
+
return { status: "unavailable", reasonCode: "command-timeout" };
|
|
11208
|
+
}
|
|
11152
11209
|
function canonicalExistingPath(filePath, realPath) {
|
|
11153
11210
|
try {
|
|
11154
11211
|
return realPath(filePath);
|
|
@@ -11176,8 +11233,9 @@ function targetIsGitAdminStorage(targetPath, validation) {
|
|
|
11176
11233
|
return pathWithinOrEqual(path6.join(validation.targetRoot, ".git"), targetPath) || pathWithinOrEqual(validation.gitDir, targetPath) || pathWithinOrEqual(validation.commonDir, targetPath);
|
|
11177
11234
|
}
|
|
11178
11235
|
function targetResultFromValidation(candidatePath, validation) {
|
|
11179
|
-
if (validation.status === "error")
|
|
11180
|
-
return unavailableOperationTarget();
|
|
11236
|
+
if (validation.status === "error") {
|
|
11237
|
+
return isProbeTimeout(validation) ? timedOutOperationTarget() : unavailableOperationTarget();
|
|
11238
|
+
}
|
|
11181
11239
|
if (!pathWithinOrEqual(validation.targetRoot, candidatePath)) {
|
|
11182
11240
|
return unavailableOperationTarget();
|
|
11183
11241
|
}
|
|
@@ -11213,21 +11271,31 @@ function deriveFileTarget(rawPath, baseDirectory, parentTargetRoot, options, rea
|
|
|
11213
11271
|
}
|
|
11214
11272
|
function sharedTargetRoot(targets, extraRoots = []) {
|
|
11215
11273
|
const roots = [...extraRoots];
|
|
11274
|
+
let definiteFailure = false;
|
|
11275
|
+
let timedOut = false;
|
|
11216
11276
|
for (const target of targets) {
|
|
11217
|
-
if (target.status === "
|
|
11218
|
-
|
|
11219
|
-
|
|
11277
|
+
if (target.status === "available")
|
|
11278
|
+
roots.push(target.targetRoot);
|
|
11279
|
+
else if (target.reasonCode === "command-timeout")
|
|
11280
|
+
timedOut = true;
|
|
11281
|
+
else
|
|
11282
|
+
definiteFailure = true;
|
|
11220
11283
|
}
|
|
11221
11284
|
const targetRoot = roots[0];
|
|
11222
|
-
|
|
11285
|
+
const spans = targetRoot !== undefined && roots.some((r) => r !== targetRoot);
|
|
11286
|
+
if (definiteFailure || spans)
|
|
11287
|
+
return unavailableOperationTarget();
|
|
11288
|
+
if (timedOut)
|
|
11289
|
+
return timedOutOperationTarget();
|
|
11290
|
+
return targetRoot ? { status: "available", targetRoot } : unavailableOperationTarget();
|
|
11223
11291
|
}
|
|
11224
11292
|
function deriveDirectoryTarget(rawPath, baseDirectory, parentTargetRoot, options, realPath) {
|
|
11225
11293
|
const resolvedPath = canonicalExistingPath(path6.resolve(baseDirectory, rawPath), realPath);
|
|
11226
11294
|
if (!resolvedPath)
|
|
11227
|
-
return
|
|
11295
|
+
return unavailableOperationTarget();
|
|
11228
11296
|
const parentResult = path6.isAbsolute(rawPath) ? undefined : trustedParentTarget(parentTargetRoot, resolvedPath);
|
|
11229
11297
|
if (parentResult?.status === "unavailable") {
|
|
11230
|
-
return
|
|
11298
|
+
return unavailableOperationTarget();
|
|
11231
11299
|
}
|
|
11232
11300
|
if (parentResult) {
|
|
11233
11301
|
return {
|
|
@@ -11236,10 +11304,13 @@ function deriveDirectoryTarget(rawPath, baseDirectory, parentTargetRoot, options
|
|
|
11236
11304
|
};
|
|
11237
11305
|
}
|
|
11238
11306
|
const validated = validationForCandidate(resolvedPath, options);
|
|
11239
|
-
|
|
11240
|
-
|
|
11241
|
-
|
|
11242
|
-
|
|
11307
|
+
if (validated.status === "available") {
|
|
11308
|
+
return {
|
|
11309
|
+
status: "available",
|
|
11310
|
+
target: { targetRoot: validated.targetRoot, resolvedPath }
|
|
11311
|
+
};
|
|
11312
|
+
}
|
|
11313
|
+
return validated.reasonCode === "command-timeout" ? { status: "timeout", resolvedPath } : validated;
|
|
11243
11314
|
}
|
|
11244
11315
|
var PATCH_FILE_PREFIXES = [
|
|
11245
11316
|
"*** Add File:",
|
|
@@ -11302,8 +11373,7 @@ function deriveFileOperationTarget(args2, sessionLocation, parentTargetRoot, opt
|
|
|
11302
11373
|
if (!paths)
|
|
11303
11374
|
return unavailableOperationTarget();
|
|
11304
11375
|
const targets = paths.map((rawPath) => deriveFileTarget(rawPath, sessionLocation, parentTargetRoot, options, realPath));
|
|
11305
|
-
|
|
11306
|
-
return targetRoot ? { status: "available", targetRoot } : unavailableOperationTarget();
|
|
11376
|
+
return sharedTargetRoot(targets);
|
|
11307
11377
|
}
|
|
11308
11378
|
function deriveApplyPatchTarget(args2, sessionLocation, parentTargetRoot, options, realPath) {
|
|
11309
11379
|
if (args2.workdir !== undefined && (typeof args2.workdir !== "string" || args2.workdir.length === 0)) {
|
|
@@ -11320,11 +11390,13 @@ function deriveApplyPatchTarget(args2, sessionLocation, parentTargetRoot, option
|
|
|
11320
11390
|
}
|
|
11321
11391
|
} : deriveDirectoryTarget(args2.workdir, sessionLocation, parentTargetRoot, options, realPath);
|
|
11322
11392
|
if (workdir.status === "unavailable")
|
|
11323
|
-
return
|
|
11324
|
-
const
|
|
11393
|
+
return workdir;
|
|
11394
|
+
const resolvedWorkdir = workdir.status === "available" ? workdir.target.resolvedPath : workdir.resolvedPath;
|
|
11395
|
+
const targets = patchPaths.map((rawPath) => deriveFileTarget(rawPath, resolvedWorkdir, parentTargetRoot, options, realPath, args2.workdir === undefined));
|
|
11396
|
+
if (workdir.status === "timeout")
|
|
11397
|
+
targets.push(timedOutOperationTarget());
|
|
11325
11398
|
const seedWorkdirRoot = args2.workdir !== undefined || targets.length === 0;
|
|
11326
|
-
|
|
11327
|
-
return targetRoot ? { status: "available", targetRoot } : unavailableOperationTarget();
|
|
11399
|
+
return sharedTargetRoot(targets, seedWorkdirRoot && workdir.status === "available" ? [workdir.target.targetRoot] : []);
|
|
11328
11400
|
}
|
|
11329
11401
|
function deriveBashTarget(args2, sessionLocation, parentTargetRoot, options, realPath) {
|
|
11330
11402
|
if (args2.workdir === undefined) {
|
|
@@ -11529,7 +11601,7 @@ function isSuccessfulAfter(output) {
|
|
|
11529
11601
|
function isSuccessfulSkillAfter(output) {
|
|
11530
11602
|
return parseHostOutput(output, { maxOutputLength: Number.POSITIVE_INFINITY }) !== undefined;
|
|
11531
11603
|
}
|
|
11532
|
-
function statusForTool(status, unavailableCause, seedDeferrals = [], unconfirmedReadbacks = []) {
|
|
11604
|
+
function statusForTool(status, unavailableCause, seedDeferrals = [], unconfirmedReadbacks = [], snapshotBlock) {
|
|
11533
11605
|
return JSON.stringify({
|
|
11534
11606
|
state: status.state,
|
|
11535
11607
|
reasonCode: status.reasonCode,
|
|
@@ -11538,6 +11610,7 @@ function statusForTool(status, unavailableCause, seedDeferrals = [], unconfirmed
|
|
|
11538
11610
|
missingOperations: status.missingOperations,
|
|
11539
11611
|
...unavailableCause && status.state === "unavailable" ? { firstUnavailableCause: unavailableCause } : {},
|
|
11540
11612
|
...seedDeferrals.length > 0 ? { seedDeferrals } : {},
|
|
11613
|
+
...snapshotBlock ? { snapshotBlock } : {},
|
|
11541
11614
|
...unconfirmedReadbacks.length > 0 ? { unconfirmedReadbacks } : {}
|
|
11542
11615
|
});
|
|
11543
11616
|
}
|
|
@@ -11718,6 +11791,8 @@ function createSessionRuntime(options, operationObservers, recoveredOperationCon
|
|
|
11718
11791
|
const pendingOperations = new Map;
|
|
11719
11792
|
const sealedOperations = new Map;
|
|
11720
11793
|
const skippedOperations = new Set;
|
|
11794
|
+
let localCallSequence = 0;
|
|
11795
|
+
const inFlightLocalCalls = new Map;
|
|
11721
11796
|
const abandonedOperations = new Map;
|
|
11722
11797
|
const rolledUpChildren = new Set;
|
|
11723
11798
|
const questionAttestation = createQuestionAttestation();
|
|
@@ -11727,13 +11802,20 @@ function createSessionRuntime(options, operationObservers, recoveredOperationCon
|
|
|
11727
11802
|
let firstUnavailableCause;
|
|
11728
11803
|
let pendingUnavailableCause;
|
|
11729
11804
|
let seedDeferralRecord;
|
|
11805
|
+
let snapshotBlockRecord;
|
|
11806
|
+
let snapshotBlockVersion = 0;
|
|
11730
11807
|
let unitStartGeneration = 0;
|
|
11731
11808
|
function startFreshUnit(input, policy) {
|
|
11809
|
+
const previousUnitId = requireGuard().status().unit?.unitId;
|
|
11732
11810
|
const result = requireGuard().startUnit(input, policy);
|
|
11733
11811
|
if (result.status === "started") {
|
|
11734
11812
|
unitStartGeneration += 1;
|
|
11813
|
+
snapshotBlockVersion += 1;
|
|
11735
11814
|
firstUnavailableCause = undefined;
|
|
11736
|
-
|
|
11815
|
+
if (result.unit.unitId !== previousUnitId) {
|
|
11816
|
+
seedDeferralRecord = undefined;
|
|
11817
|
+
snapshotBlockRecord = undefined;
|
|
11818
|
+
}
|
|
11737
11819
|
}
|
|
11738
11820
|
return result;
|
|
11739
11821
|
}
|
|
@@ -11758,19 +11840,21 @@ function createSessionRuntime(options, operationObservers, recoveredOperationCon
|
|
|
11758
11840
|
}
|
|
11759
11841
|
function parentObserverRegistration() {
|
|
11760
11842
|
if (!options.observer)
|
|
11761
|
-
return;
|
|
11843
|
+
return { status: "fatal" };
|
|
11762
11844
|
const targetRoot = canonicalExistingPath(options.targetDirectory ?? process.cwd(), fs8.realpathSync);
|
|
11763
11845
|
if (!targetRoot)
|
|
11764
|
-
return;
|
|
11846
|
+
return { status: "fatal" };
|
|
11765
11847
|
let validation;
|
|
11766
11848
|
try {
|
|
11767
11849
|
validation = options.observer.validateRegisteredWorktree(targetRoot);
|
|
11768
11850
|
} catch {
|
|
11769
|
-
return;
|
|
11851
|
+
return { status: "fatal" };
|
|
11770
11852
|
}
|
|
11853
|
+
if (isProbeTimeout(validation))
|
|
11854
|
+
return TIMED_OUT_READ;
|
|
11771
11855
|
const registeredIdentity = registeredWorktreeIdentity(validation);
|
|
11772
11856
|
if (validation.status !== "ok" || registeredIdentity === undefined || validation.targetRoot !== targetRoot) {
|
|
11773
|
-
return;
|
|
11857
|
+
return { status: "fatal" };
|
|
11774
11858
|
}
|
|
11775
11859
|
const registration = {
|
|
11776
11860
|
targetRoot,
|
|
@@ -11778,14 +11862,15 @@ function createSessionRuntime(options, operationObservers, recoveredOperationCon
|
|
|
11778
11862
|
observer: options.observer
|
|
11779
11863
|
};
|
|
11780
11864
|
rememberOperationObserver(registration);
|
|
11781
|
-
return registration;
|
|
11865
|
+
return { status: "ok", value: registration };
|
|
11782
11866
|
}
|
|
11783
11867
|
function operationObserverRegistration(targetIdentity) {
|
|
11784
11868
|
const existing = operationObservers.get(targetIdentity);
|
|
11785
11869
|
if (existing)
|
|
11786
|
-
return existing;
|
|
11787
|
-
if (options.observer?.targetDigest !== targetIdentity)
|
|
11788
|
-
return;
|
|
11870
|
+
return { status: "ok", value: existing };
|
|
11871
|
+
if (options.observer?.targetDigest !== targetIdentity) {
|
|
11872
|
+
return { status: "fatal" };
|
|
11873
|
+
}
|
|
11789
11874
|
return parentObserverRegistration();
|
|
11790
11875
|
}
|
|
11791
11876
|
function resolveEffectiveObserver() {
|
|
@@ -11804,9 +11889,9 @@ function createSessionRuntime(options, operationObservers, recoveredOperationCon
|
|
|
11804
11889
|
};
|
|
11805
11890
|
}
|
|
11806
11891
|
const registration = operationObserverRegistration(pinnedTargetIdentity);
|
|
11807
|
-
if (
|
|
11808
|
-
return
|
|
11809
|
-
return resolvePinnedObserver(parentObserver, registration, pinnedTargetIdentity);
|
|
11892
|
+
if (registration.status !== "ok")
|
|
11893
|
+
return registration;
|
|
11894
|
+
return resolvePinnedObserver(parentObserver, registration.value, pinnedTargetIdentity);
|
|
11810
11895
|
}
|
|
11811
11896
|
function resolvePinnedObserver(parentObserver, registration, pinnedTargetIdentity) {
|
|
11812
11897
|
let validation;
|
|
@@ -11816,7 +11901,7 @@ function createSessionRuntime(options, operationObservers, recoveredOperationCon
|
|
|
11816
11901
|
return { status: "fatal" };
|
|
11817
11902
|
}
|
|
11818
11903
|
if (isProbeTimeout(validation))
|
|
11819
|
-
return
|
|
11904
|
+
return TIMED_OUT_READ;
|
|
11820
11905
|
if (validation.status !== "ok") {
|
|
11821
11906
|
return { status: "fatal", reasonCode: validation.reasonCode };
|
|
11822
11907
|
}
|
|
@@ -12286,6 +12371,34 @@ function createSessionRuntime(options, operationObservers, recoveredOperationCon
|
|
|
12286
12371
|
initializationPromise = next;
|
|
12287
12372
|
await next;
|
|
12288
12373
|
}
|
|
12374
|
+
function blockOrFailChildSnapshot(reasonCode, targetIdentity, rollupGeneration) {
|
|
12375
|
+
if (!isSnapshotBlockingReason(reasonCode)) {
|
|
12376
|
+
markUnavailable(snapshotFailureCause(afterCause)(reasonCode));
|
|
12377
|
+
return;
|
|
12378
|
+
}
|
|
12379
|
+
setSnapshotBlock(reasonCode, targetIdentity, {
|
|
12380
|
+
generation: rollupGeneration
|
|
12381
|
+
});
|
|
12382
|
+
}
|
|
12383
|
+
async function readChildSnapshot(observer, targetIdentity, rollupGeneration) {
|
|
12384
|
+
const capture = captureSnapshotBlock();
|
|
12385
|
+
const read = await readSnapshot(observer);
|
|
12386
|
+
if (read.status === "timeout")
|
|
12387
|
+
return { kind: "halt" };
|
|
12388
|
+
if (read.status !== "ok") {
|
|
12389
|
+
blockOrFailChildSnapshot(probeFailureReason(read), targetIdentity, rollupGeneration);
|
|
12390
|
+
return { kind: "halt" };
|
|
12391
|
+
}
|
|
12392
|
+
if (read.value.targetDigest !== targetIdentity) {
|
|
12393
|
+
markUnavailable(afterCause("operation-target-mismatch"));
|
|
12394
|
+
return { kind: "halt" };
|
|
12395
|
+
}
|
|
12396
|
+
return {
|
|
12397
|
+
kind: "snapshot",
|
|
12398
|
+
snapshot: read.value,
|
|
12399
|
+
...capture ? { blockCapture: capture } : {}
|
|
12400
|
+
};
|
|
12401
|
+
}
|
|
12289
12402
|
async function rollupForegroundTask(host, output) {
|
|
12290
12403
|
if (!options.hostReadback || !isRecord7(output))
|
|
12291
12404
|
return;
|
|
@@ -12298,6 +12411,7 @@ function createSessionRuntime(options, operationObservers, recoveredOperationCon
|
|
|
12298
12411
|
if (rolledUpChildren.has(rollupKey))
|
|
12299
12412
|
return;
|
|
12300
12413
|
const parentBefore = requireGuard().currentOperationContext();
|
|
12414
|
+
const rollupGeneration = unitStartGeneration;
|
|
12301
12415
|
const children = await options.hostReadback.listChildren(host.sessionID);
|
|
12302
12416
|
if (!children.some((child) => child.sessionId === childSessionID && child.parentID === host.sessionID)) {
|
|
12303
12417
|
markUnavailable(afterCause("call-lifecycle-mismatch"));
|
|
@@ -12345,6 +12459,7 @@ function createSessionRuntime(options, operationObservers, recoveredOperationCon
|
|
|
12345
12459
|
return;
|
|
12346
12460
|
const expectedWorkspace = childLedger.digestIdentity("workspace", parentBefore.workspaceIdentity);
|
|
12347
12461
|
let batchTargetIdentity = currentStatus.unit.pinnedOperationTargetIdentity;
|
|
12462
|
+
let blockClear;
|
|
12348
12463
|
const candidates = [];
|
|
12349
12464
|
for (const childReceipt of recovered.receipts) {
|
|
12350
12465
|
const operation = childReceipt.canonical.operation;
|
|
@@ -12364,11 +12479,14 @@ function createSessionRuntime(options, operationObservers, recoveredOperationCon
|
|
|
12364
12479
|
return;
|
|
12365
12480
|
}
|
|
12366
12481
|
batchTargetIdentity = targetIdentity;
|
|
12367
|
-
const
|
|
12368
|
-
if (
|
|
12482
|
+
const registered = operationObserverRegistration(targetIdentity);
|
|
12483
|
+
if (registered.status === "timeout")
|
|
12484
|
+
return;
|
|
12485
|
+
if (registered.status !== "ok" || !options.observer) {
|
|
12369
12486
|
markUnavailable(afterCause("operation-input-invalid"));
|
|
12370
12487
|
return;
|
|
12371
12488
|
}
|
|
12489
|
+
const registration = registered.value;
|
|
12372
12490
|
let validation;
|
|
12373
12491
|
try {
|
|
12374
12492
|
validation = options.observer.validateRegisteredWorktree(registration.targetRoot);
|
|
@@ -12376,38 +12494,35 @@ function createSessionRuntime(options, operationObservers, recoveredOperationCon
|
|
|
12376
12494
|
markUnavailable(afterCause("operation-input-invalid"));
|
|
12377
12495
|
return;
|
|
12378
12496
|
}
|
|
12497
|
+
if (isProbeTimeout(validation))
|
|
12498
|
+
return;
|
|
12379
12499
|
if (validation.status === "error" || validation.targetRoot !== registration.targetRoot || registeredWorktreeIdentity(validation) !== registration.registeredWorktreeIdentity || registration.observer.targetDigest !== targetIdentity) {
|
|
12380
12500
|
markUnavailable(afterCause("operation-input-invalid", validation.status === "error" ? validation.reasonCode : undefined));
|
|
12381
12501
|
return;
|
|
12382
12502
|
}
|
|
12383
|
-
|
|
12384
|
-
|
|
12385
|
-
targetResult = await registration.observer.snapshot();
|
|
12386
|
-
} catch {
|
|
12387
|
-
markUnavailable(afterCause("local-snapshot-error"));
|
|
12388
|
-
return;
|
|
12389
|
-
}
|
|
12390
|
-
if (targetResult.status === "unavailable") {
|
|
12391
|
-
markUnavailable(afterCause("local-snapshot-unavailable", targetResult.reasonCode));
|
|
12392
|
-
return;
|
|
12393
|
-
}
|
|
12394
|
-
if (targetResult.snapshot.targetDigest !== targetIdentity) {
|
|
12395
|
-
markUnavailable(afterCause("operation-target-mismatch"));
|
|
12503
|
+
const targetRead = await readChildSnapshot(registration.observer, targetIdentity, rollupGeneration);
|
|
12504
|
+
if (targetRead.kind === "halt")
|
|
12396
12505
|
return;
|
|
12506
|
+
if (targetRead.blockCapture) {
|
|
12507
|
+
blockClear = {
|
|
12508
|
+
capture: targetRead.blockCapture,
|
|
12509
|
+
targetIdentity,
|
|
12510
|
+
snapshot: targetRead.snapshot
|
|
12511
|
+
};
|
|
12397
12512
|
}
|
|
12398
12513
|
const recoveredContext = recoveredOperationContexts.get(childReceipt.canonical.receiptId);
|
|
12399
12514
|
if (recoveredContext && recoveredContext.targetIdentity !== targetIdentity || targetIdentity !== options.observer.targetDigest && !recoveredContext) {
|
|
12400
12515
|
markUnavailable(afterCause("operation-target-mismatch"));
|
|
12401
12516
|
return;
|
|
12402
12517
|
}
|
|
12403
|
-
const expectedRepository = childLedger.digestIdentity("repository",
|
|
12404
|
-
const expectedWorktree = childLedger.digestIdentity("worktree",
|
|
12518
|
+
const expectedRepository = childLedger.digestIdentity("repository", targetRead.snapshot.repositoryRevisionDigest);
|
|
12519
|
+
const expectedWorktree = childLedger.digestIdentity("worktree", targetRead.snapshot.worktreeRevisionDigest);
|
|
12405
12520
|
if (childReceipt.canonical.repositoryDigest !== expectedRepository || childReceipt.canonical.worktreeDigest !== expectedWorktree) {
|
|
12406
12521
|
continue;
|
|
12407
12522
|
}
|
|
12408
12523
|
candidates.push({
|
|
12409
12524
|
receipt: childReceipt,
|
|
12410
|
-
snapshot:
|
|
12525
|
+
snapshot: targetRead.snapshot,
|
|
12411
12526
|
before: recoveredContext?.before
|
|
12412
12527
|
});
|
|
12413
12528
|
}
|
|
@@ -12453,6 +12568,9 @@ function createSessionRuntime(options, operationObservers, recoveredOperationCon
|
|
|
12453
12568
|
}
|
|
12454
12569
|
if (minted)
|
|
12455
12570
|
rolledUpChildren.add(rollupKey);
|
|
12571
|
+
if (blockClear) {
|
|
12572
|
+
commitSnapshotBlockClear(blockClear.capture, readbackTarget(blockClear.targetIdentity), blockClear.snapshot, snapshotFailureCause(afterCause));
|
|
12573
|
+
}
|
|
12456
12574
|
}
|
|
12457
12575
|
let runtimePolicy = trustedSkillPolicy("unknown", options.runtimeRequiredOperations ?? []);
|
|
12458
12576
|
function markUnavailable(cause) {
|
|
@@ -12507,6 +12625,7 @@ function createSessionRuntime(options, operationObservers, recoveredOperationCon
|
|
|
12507
12625
|
abandonedOperations.set(callDigest, { skipped: true });
|
|
12508
12626
|
}
|
|
12509
12627
|
skippedOperations.clear();
|
|
12628
|
+
inFlightLocalCalls.clear();
|
|
12510
12629
|
}
|
|
12511
12630
|
function readStatus() {
|
|
12512
12631
|
return guard ? guard.status() : unavailableWorkflowStatus();
|
|
@@ -12577,24 +12696,45 @@ function createSessionRuntime(options, operationObservers, recoveredOperationCon
|
|
|
12577
12696
|
return [];
|
|
12578
12697
|
}
|
|
12579
12698
|
const effective = lookup.value;
|
|
12699
|
+
const blockCapture = captureSnapshotBlock();
|
|
12700
|
+
const blockVersion = snapshotBlockVersion;
|
|
12701
|
+
const generation = unitStartGeneration;
|
|
12580
12702
|
const read = await readSnapshot(effective.observer, effective.targetIdentity);
|
|
12581
12703
|
if (read.status === "timeout") {
|
|
12582
12704
|
return skippedWithRemoteTail(effective.pinned ? "pinned" : "local");
|
|
12583
12705
|
}
|
|
12584
12706
|
if (read.status === "fatal") {
|
|
12585
|
-
|
|
12707
|
+
return blockOrFailRefresh(read.reasonCode, effective, generation);
|
|
12708
|
+
}
|
|
12709
|
+
return applyRefreshSnapshot(effective, read.value, blockCapture, blockVersion);
|
|
12710
|
+
}
|
|
12711
|
+
function blockOrFailRefresh(reasonCode, effective, generation) {
|
|
12712
|
+
if (!isSnapshotBlockingReason(reasonCode)) {
|
|
12713
|
+
markUnavailable(observerReadbackFailedCause(reasonCode));
|
|
12586
12714
|
return [];
|
|
12587
12715
|
}
|
|
12588
|
-
|
|
12716
|
+
setSnapshotBlock(reasonCode, effective.targetIdentity, { generation });
|
|
12717
|
+
return [];
|
|
12589
12718
|
}
|
|
12590
|
-
async function
|
|
12591
|
-
const
|
|
12719
|
+
async function applyRefreshSnapshot(effective, snapshot, blockCapture, blockVersion) {
|
|
12720
|
+
const skipped = () => skippedWithRemoteTail(effective.pinned ? "pinned" : "local");
|
|
12721
|
+
if (snapshotBlockVersion !== blockVersion)
|
|
12722
|
+
return skipped();
|
|
12723
|
+
const cleared = blockCapture ? commitSnapshotBlockClear(blockCapture, effective, snapshot, observerReadbackFailedCause) : undefined;
|
|
12724
|
+
if (cleared?.status === "fatal")
|
|
12725
|
+
return [];
|
|
12726
|
+
if (cleared?.status === "stale")
|
|
12727
|
+
return skipped();
|
|
12728
|
+
return applyReadbackAndProbeRemote(effective, snapshot, cleared?.status === "cleared");
|
|
12729
|
+
}
|
|
12730
|
+
async function applyReadbackAndProbeRemote(effective, snapshot, localApplied = false) {
|
|
12731
|
+
const observed = localApplied ? undefined : requireGuard().observeReadback({
|
|
12592
12732
|
workspaceIdentity: options.workspaceIdentity,
|
|
12593
12733
|
repositoryIdentity: snapshot.repositoryRevisionDigest,
|
|
12594
12734
|
worktreeIdentity: snapshot.worktreeRevisionDigest,
|
|
12595
12735
|
...effective.pinned ? { operationTargetIdentity: effective.targetIdentity } : {}
|
|
12596
12736
|
});
|
|
12597
|
-
if (observed
|
|
12737
|
+
if (observed?.status === "rejected" && observed.reasonCode === "workspace-mismatch") {
|
|
12598
12738
|
markUnavailable(observerReadbackFailedCause());
|
|
12599
12739
|
return [];
|
|
12600
12740
|
}
|
|
@@ -12756,7 +12896,9 @@ function createSessionRuntime(options, operationObservers, recoveredOperationCon
|
|
|
12756
12896
|
output.title = title;
|
|
12757
12897
|
output.output = JSON.stringify({
|
|
12758
12898
|
status: result.status,
|
|
12759
|
-
reasonCode: result.reasonCode
|
|
12899
|
+
reasonCode: result.reasonCode,
|
|
12900
|
+
...result.blockReason ? { blockReason: result.blockReason } : {},
|
|
12901
|
+
...result.blockTarget ? { blockTarget: result.blockTarget } : {}
|
|
12760
12902
|
});
|
|
12761
12903
|
output.metadata = {
|
|
12762
12904
|
...withoutStaleConditionalMetadata(existingMetadata),
|
|
@@ -12904,9 +13046,96 @@ function createSessionRuntime(options, operationObservers, recoveredOperationCon
|
|
|
12904
13046
|
return { operation: classification.category };
|
|
12905
13047
|
}
|
|
12906
13048
|
}
|
|
13049
|
+
function isEffectiveTarget(observer) {
|
|
13050
|
+
return observer.targetDigest === currentEffectiveTargetIdentity();
|
|
13051
|
+
}
|
|
13052
|
+
async function takeBeforeSnapshot(observer, initiator) {
|
|
13053
|
+
const gated = await clearBlockForOtherTarget(observer, initiator);
|
|
13054
|
+
if (gated)
|
|
13055
|
+
return gated;
|
|
13056
|
+
const capture = captureSnapshotBlock();
|
|
13057
|
+
if (capture && !isEffectiveTarget(observer))
|
|
13058
|
+
return { kind: "skip" };
|
|
13059
|
+
const read = await readBeforeSnapshot(observer, initiator);
|
|
13060
|
+
if (read.kind !== "snapshot" || !capture)
|
|
13061
|
+
return read;
|
|
13062
|
+
return clearBlockFromBeforeSnapshot(capture, observer, read.snapshot);
|
|
13063
|
+
}
|
|
13064
|
+
async function readBeforeSnapshot(observer, initiator) {
|
|
13065
|
+
const read = await readSnapshot(observer);
|
|
13066
|
+
if (read.status === "timeout")
|
|
13067
|
+
return { kind: "skip" };
|
|
13068
|
+
if (read.status !== "ok") {
|
|
13069
|
+
return blockOrFailBeforeSnapshot(probeFailureReason(read), observer, initiator);
|
|
13070
|
+
}
|
|
13071
|
+
if (read.value.targetDigest !== observer.targetDigest) {
|
|
13072
|
+
markUnavailable(beforeCause("operation-target-mismatch"));
|
|
13073
|
+
return { kind: "stop" };
|
|
13074
|
+
}
|
|
13075
|
+
return { kind: "snapshot", snapshot: read.value };
|
|
13076
|
+
}
|
|
13077
|
+
function clearBlockFromBeforeSnapshot(capture, observer, snapshot) {
|
|
13078
|
+
const cleared = commitSnapshotBlockClear(capture, readbackTarget(observer.targetDigest), snapshot, snapshotFailureCause(beforeCause));
|
|
13079
|
+
if (cleared.status === "fatal")
|
|
13080
|
+
return { kind: "stop" };
|
|
13081
|
+
return cleared.status === "cleared" ? { kind: "snapshot", snapshot } : { kind: "skip" };
|
|
13082
|
+
}
|
|
13083
|
+
function blockOrFailBeforeSnapshot(reasonCode, observer, initiator) {
|
|
13084
|
+
if (!isSnapshotBlockingReason(reasonCode)) {
|
|
13085
|
+
markUnavailable(snapshotFailureCause(beforeCause)(reasonCode));
|
|
13086
|
+
return { kind: "stop" };
|
|
13087
|
+
}
|
|
13088
|
+
setSnapshotBlock(reasonCode, observer.targetDigest, { initiator });
|
|
13089
|
+
return { kind: "skip" };
|
|
13090
|
+
}
|
|
13091
|
+
async function clearBlockForOtherTarget(observer, initiator) {
|
|
13092
|
+
if (!captureSnapshotBlock() || isEffectiveTarget(observer))
|
|
13093
|
+
return;
|
|
13094
|
+
const lookup = resolveEffectiveObserver();
|
|
13095
|
+
if (lookup.status === "timeout")
|
|
13096
|
+
return { kind: "skip" };
|
|
13097
|
+
if (lookup.status !== "ok") {
|
|
13098
|
+
markUnavailable(beforeCause("operation-input-invalid", probeFailureReason(lookup)));
|
|
13099
|
+
return { kind: "stop" };
|
|
13100
|
+
}
|
|
13101
|
+
const result = await clearSnapshotBlock(lookup.value, snapshotFailureCause(beforeCause));
|
|
13102
|
+
if (result.status === "timeout")
|
|
13103
|
+
return { kind: "skip" };
|
|
13104
|
+
if (result.status === "fatal")
|
|
13105
|
+
return { kind: "stop" };
|
|
13106
|
+
if (result.status === "still-blocked") {
|
|
13107
|
+
setSnapshotBlock(result.reasonCode, lookup.value.targetIdentity, {
|
|
13108
|
+
initiator
|
|
13109
|
+
});
|
|
13110
|
+
return { kind: "skip" };
|
|
13111
|
+
}
|
|
13112
|
+
return result.status === "stale" ? { kind: "skip" } : undefined;
|
|
13113
|
+
}
|
|
13114
|
+
function beginLocalCall(callDigest) {
|
|
13115
|
+
localCallSequence += 1;
|
|
13116
|
+
const start2 = {
|
|
13117
|
+
sequenceAtStart: localCallSequence,
|
|
13118
|
+
otherInFlightAtStart: [...inFlightLocalCalls].some(([key, state]) => key !== callDigest && state !== "returned")
|
|
13119
|
+
};
|
|
13120
|
+
inFlightLocalCalls.set(callDigest, inFlightLocalCalls.has(callDigest) ? "ambiguous" : "running");
|
|
13121
|
+
return start2;
|
|
13122
|
+
}
|
|
13123
|
+
function endLocalCall(callDigest) {
|
|
13124
|
+
if (inFlightLocalCalls.get(callDigest) === "running") {
|
|
13125
|
+
inFlightLocalCalls.set(callDigest, "returned");
|
|
13126
|
+
}
|
|
13127
|
+
}
|
|
13128
|
+
function beginUnparsedLocalCall() {
|
|
13129
|
+
localCallSequence += 1;
|
|
13130
|
+
inFlightLocalCalls.set(`unparsed:${localCallSequence}`, "ambiguous");
|
|
13131
|
+
}
|
|
13132
|
+
function overlappedAnotherLocalCall(pending) {
|
|
13133
|
+
return pending.localCall.otherInFlightAtStart || localCallSequence !== pending.localCall.sequenceAtStart;
|
|
13134
|
+
}
|
|
12907
13135
|
async function prepareOperation(host, args2) {
|
|
12908
13136
|
if (!options.observer || !isLocalOperationTool(host.tool))
|
|
12909
13137
|
return;
|
|
13138
|
+
const localCall = beginLocalCall(digestCall(ledger, host.callID));
|
|
12910
13139
|
if (!operationObservationApplies()) {
|
|
12911
13140
|
skippedOperations.add(digestCall(ledger, host.callID));
|
|
12912
13141
|
return;
|
|
@@ -12928,6 +13157,10 @@ function createSessionRuntime(options, operationObservers, recoveredOperationCon
|
|
|
12928
13157
|
validateRegisteredWorktree: options.observer.validateRegisteredWorktree
|
|
12929
13158
|
});
|
|
12930
13159
|
if (target.status === "unavailable") {
|
|
13160
|
+
if (target.reasonCode === "command-timeout") {
|
|
13161
|
+
skippedOperations.add(callDigest);
|
|
13162
|
+
return;
|
|
13163
|
+
}
|
|
12931
13164
|
markUnavailable(beforeCause("operation-input-invalid", target.reasonCode));
|
|
12932
13165
|
return;
|
|
12933
13166
|
}
|
|
@@ -12938,6 +13171,10 @@ function createSessionRuntime(options, operationObservers, recoveredOperationCon
|
|
|
12938
13171
|
markUnavailable(beforeCause("operation-input-invalid"));
|
|
12939
13172
|
return;
|
|
12940
13173
|
}
|
|
13174
|
+
if (isProbeTimeout(registeredTarget)) {
|
|
13175
|
+
skippedOperations.add(callDigest);
|
|
13176
|
+
return;
|
|
13177
|
+
}
|
|
12941
13178
|
const registeredIdentity = registeredWorktreeIdentity(registeredTarget);
|
|
12942
13179
|
if (registeredTarget.status !== "ok" || registeredIdentity === undefined || registeredTarget.targetRoot !== target.targetRoot) {
|
|
12943
13180
|
markUnavailable(beforeCause("operation-input-invalid", registeredTarget.status === "error" ? registeredTarget.reasonCode : undefined));
|
|
@@ -12949,21 +13186,13 @@ function createSessionRuntime(options, operationObservers, recoveredOperationCon
|
|
|
12949
13186
|
return;
|
|
12950
13187
|
}
|
|
12951
13188
|
const operationObserver = target.targetRoot === canonicalParentTargetRoot ? options.observer : [...operationObservers.values()].find((registration) => registration.targetRoot === target.targetRoot)?.observer ?? (options.createTargetObserver ?? defaultTargetObserver)(target.targetRoot);
|
|
12952
|
-
|
|
12953
|
-
|
|
12954
|
-
|
|
12955
|
-
} catch {
|
|
12956
|
-
markUnavailable(beforeCause("local-snapshot-error"));
|
|
13189
|
+
const taken = await takeBeforeSnapshot(operationObserver, initiator);
|
|
13190
|
+
if (taken.kind === "skip") {
|
|
13191
|
+
skippedOperations.add(callDigest);
|
|
12957
13192
|
return;
|
|
12958
13193
|
}
|
|
12959
|
-
if (
|
|
12960
|
-
markUnavailable(beforeCause("local-snapshot-unavailable", result.reasonCode));
|
|
13194
|
+
if (taken.kind === "stop")
|
|
12961
13195
|
return;
|
|
12962
|
-
}
|
|
12963
|
-
if (result.snapshot.targetDigest !== operationObserver.targetDigest) {
|
|
12964
|
-
markUnavailable(beforeCause("operation-target-mismatch"));
|
|
12965
|
-
return;
|
|
12966
|
-
}
|
|
12967
13196
|
rememberOperationObserver({
|
|
12968
13197
|
targetRoot: target.targetRoot,
|
|
12969
13198
|
registeredWorktreeIdentity: registeredIdentity,
|
|
@@ -12981,7 +13210,8 @@ function createSessionRuntime(options, operationObservers, recoveredOperationCon
|
|
|
12981
13210
|
targetIdentity: operationObserver.targetDigest,
|
|
12982
13211
|
registeredWorktreeIdentity: registeredIdentity,
|
|
12983
13212
|
observer: operationObserver,
|
|
12984
|
-
before:
|
|
13213
|
+
before: taken.snapshot,
|
|
13214
|
+
localCall,
|
|
12985
13215
|
...initiator ? { initiator } : {},
|
|
12986
13216
|
...remote ? { remoteOperation: remote.operation, remoteBefore: remote.before } : {}
|
|
12987
13217
|
});
|
|
@@ -13097,31 +13327,52 @@ function createSessionRuntime(options, operationObservers, recoveredOperationCon
|
|
|
13097
13327
|
timedOut: false
|
|
13098
13328
|
};
|
|
13099
13329
|
}
|
|
13100
|
-
|
|
13101
|
-
|
|
13102
|
-
|
|
13103
|
-
|
|
13104
|
-
|
|
13105
|
-
|
|
13106
|
-
|
|
13107
|
-
|
|
13108
|
-
|
|
13330
|
+
const lookup = resolveEffectiveObserver();
|
|
13331
|
+
if (lookup.status !== "ok")
|
|
13332
|
+
return seedLookupCause(lookup);
|
|
13333
|
+
const generation = unitStartGeneration;
|
|
13334
|
+
const local = await readSeedSnapshot(lookup.value.observer);
|
|
13335
|
+
if (local.kind === "fatal")
|
|
13336
|
+
return local.cause;
|
|
13337
|
+
if (local.kind === "blocked") {
|
|
13338
|
+
blockSeededScopes(remoteOperations, local.reasonCode, lookup.value.targetIdentity, generation);
|
|
13339
|
+
return;
|
|
13109
13340
|
}
|
|
13110
|
-
|
|
13111
|
-
|
|
13112
|
-
|
|
13113
|
-
|
|
13114
|
-
|
|
13115
|
-
|
|
13116
|
-
|
|
13341
|
+
return seedEachRemoteScope(remoteOperations, remoteSnapshot, local.snapshot, generation);
|
|
13342
|
+
}
|
|
13343
|
+
function seedLookupCause(failure) {
|
|
13344
|
+
return snapshotFailureCause(seedCause)(probeFailureReason(failure));
|
|
13345
|
+
}
|
|
13346
|
+
async function readSeedSnapshot(observer) {
|
|
13347
|
+
const read = await readSnapshot(observer);
|
|
13348
|
+
if (read.status === "ok")
|
|
13349
|
+
return { kind: "snapshot", snapshot: read.value };
|
|
13350
|
+
const reasonCode = probeFailureReason(read);
|
|
13351
|
+
if (isSnapshotBlockingReason(reasonCode)) {
|
|
13352
|
+
return { kind: "blocked", reasonCode };
|
|
13353
|
+
}
|
|
13354
|
+
return {
|
|
13355
|
+
kind: "fatal",
|
|
13356
|
+
cause: snapshotFailureCause(seedCause)(reasonCode)
|
|
13357
|
+
};
|
|
13358
|
+
}
|
|
13359
|
+
function blockSeededScopes(operations, reasonCode, targetIdentity, generation) {
|
|
13360
|
+
if (generation !== unitStartGeneration)
|
|
13361
|
+
return;
|
|
13362
|
+
for (const operation of operations) {
|
|
13363
|
+
clearSeedDeferral(operation);
|
|
13364
|
+
recordSeedDeferral(operation, "snapshot-blocked");
|
|
13117
13365
|
}
|
|
13118
|
-
|
|
13366
|
+
setSnapshotBlock(reasonCode, targetIdentity, { generation });
|
|
13119
13367
|
}
|
|
13120
|
-
async function seedEachRemoteScope(operations, reader, local) {
|
|
13368
|
+
async function seedEachRemoteScope(operations, reader, local, generation) {
|
|
13121
13369
|
for (const operation of operations) {
|
|
13122
|
-
const outcome = await seedRemoteScope(reader, operation, local);
|
|
13370
|
+
const outcome = await seedRemoteScope(reader, operation, local, generation);
|
|
13371
|
+
if (outcome.kind === "superseded")
|
|
13372
|
+
return;
|
|
13123
13373
|
if (outcome.kind === "fatal")
|
|
13124
13374
|
return outcome.cause;
|
|
13375
|
+
clearSeedDeferral(operation);
|
|
13125
13376
|
if (outcome.kind === "deferred") {
|
|
13126
13377
|
recordSeedDeferral(operation, outcome.reasonCode);
|
|
13127
13378
|
}
|
|
@@ -13129,7 +13380,7 @@ function createSessionRuntime(options, operationObservers, recoveredOperationCon
|
|
|
13129
13380
|
return;
|
|
13130
13381
|
}
|
|
13131
13382
|
function recordSeedDeferral(operation, reasonCode) {
|
|
13132
|
-
if (
|
|
13383
|
+
if (hasDeclaredResourceScope(operation))
|
|
13133
13384
|
return;
|
|
13134
13385
|
const observer = options.observer;
|
|
13135
13386
|
if (!observer)
|
|
@@ -13141,6 +13392,10 @@ function createSessionRuntime(options, operationObservers, recoveredOperationCon
|
|
|
13141
13392
|
targetIdentity: observer.targetDigest
|
|
13142
13393
|
});
|
|
13143
13394
|
}
|
|
13395
|
+
function hasDeclaredResourceScope(operation) {
|
|
13396
|
+
const unit = requireGuard().status().unit;
|
|
13397
|
+
return unit?.requiredResourceOperations.includes(operation) ?? false;
|
|
13398
|
+
}
|
|
13144
13399
|
function seedDeferralEntries(reset = false) {
|
|
13145
13400
|
const unitId = requireGuard().status().unit?.unitId;
|
|
13146
13401
|
if (!unitId)
|
|
@@ -13169,7 +13424,9 @@ function createSessionRuntime(options, operationObservers, recoveredOperationCon
|
|
|
13169
13424
|
if (!deferred)
|
|
13170
13425
|
return;
|
|
13171
13426
|
if (requireGuard().hasResourceBaseline(operation)) {
|
|
13172
|
-
|
|
13427
|
+
if (before?.status === "available" && sameSeedObserver(deferred, observer)) {
|
|
13428
|
+
clearSeedDeferral(operation);
|
|
13429
|
+
}
|
|
13173
13430
|
return;
|
|
13174
13431
|
}
|
|
13175
13432
|
if (!before || !sameSeedObserver(deferred, observer))
|
|
@@ -13212,6 +13469,118 @@ function createSessionRuntime(options, operationObservers, recoveredOperationCon
|
|
|
13212
13469
|
...operation === "pr-creation" ? { propagate: false } : {}
|
|
13213
13470
|
};
|
|
13214
13471
|
}
|
|
13472
|
+
function currentEffectiveTargetIdentity() {
|
|
13473
|
+
return requireGuard().status().unit?.pinnedOperationTargetIdentity ?? options.workspaceIdentity;
|
|
13474
|
+
}
|
|
13475
|
+
function readbackTarget(targetIdentity) {
|
|
13476
|
+
return {
|
|
13477
|
+
targetIdentity,
|
|
13478
|
+
pinned: targetIdentity !== options.workspaceIdentity
|
|
13479
|
+
};
|
|
13480
|
+
}
|
|
13481
|
+
function writeSnapshotBlock(record2) {
|
|
13482
|
+
snapshotBlockRecord = record2;
|
|
13483
|
+
snapshotBlockVersion += 1;
|
|
13484
|
+
}
|
|
13485
|
+
function currentSnapshotBlock() {
|
|
13486
|
+
const record2 = snapshotBlockRecord;
|
|
13487
|
+
if (!record2)
|
|
13488
|
+
return;
|
|
13489
|
+
const status = requireGuard().status();
|
|
13490
|
+
if (record2.unitId !== status.unit?.unitId)
|
|
13491
|
+
return;
|
|
13492
|
+
if (record2.targetIdentity !== currentEffectiveTargetIdentity()) {
|
|
13493
|
+
writeSnapshotBlock(undefined);
|
|
13494
|
+
return;
|
|
13495
|
+
}
|
|
13496
|
+
return record2;
|
|
13497
|
+
}
|
|
13498
|
+
function blockSetIsCurrent(captured) {
|
|
13499
|
+
if ("generation" in captured) {
|
|
13500
|
+
return captured.generation === unitStartGeneration;
|
|
13501
|
+
}
|
|
13502
|
+
return captured.initiator !== undefined && isCurrentInitiator(captured.initiator);
|
|
13503
|
+
}
|
|
13504
|
+
function setSnapshotBlock(reasonCode, targetIdentity, captured) {
|
|
13505
|
+
const unitId = requireGuard().status().unit?.unitId;
|
|
13506
|
+
if (!unitId || !blockSetIsCurrent(captured) || targetIdentity !== currentEffectiveTargetIdentity()) {
|
|
13507
|
+
return false;
|
|
13508
|
+
}
|
|
13509
|
+
writeSnapshotBlock({
|
|
13510
|
+
unitId,
|
|
13511
|
+
unitGeneration: unitStartGeneration,
|
|
13512
|
+
targetIdentity,
|
|
13513
|
+
reasonCode
|
|
13514
|
+
});
|
|
13515
|
+
return true;
|
|
13516
|
+
}
|
|
13517
|
+
function captureSnapshotBlock() {
|
|
13518
|
+
const record2 = currentSnapshotBlock();
|
|
13519
|
+
return record2 ? { record: record2, generation: unitStartGeneration } : undefined;
|
|
13520
|
+
}
|
|
13521
|
+
function snapshotBlockStillCurrent(capture, snapshotTargetIdentity) {
|
|
13522
|
+
return snapshotBlockRecord === capture.record && unitStartGeneration === capture.generation && capture.record.targetIdentity === snapshotTargetIdentity && currentEffectiveTargetIdentity() === snapshotTargetIdentity;
|
|
13523
|
+
}
|
|
13524
|
+
async function clearSnapshotBlock(effective, failureCause) {
|
|
13525
|
+
const capture = captureSnapshotBlock();
|
|
13526
|
+
if (!capture)
|
|
13527
|
+
return { status: "not-blocked" };
|
|
13528
|
+
const read = await readSnapshot(effective.observer, effective.targetIdentity);
|
|
13529
|
+
if (read.status === "timeout")
|
|
13530
|
+
return TIMED_OUT_READ;
|
|
13531
|
+
if (read.status === "fatal") {
|
|
13532
|
+
return settleFailedBlockSnapshot(read.reasonCode, capture, effective.targetIdentity, failureCause);
|
|
13533
|
+
}
|
|
13534
|
+
return commitSnapshotBlockClear(capture, effective, read.value, failureCause);
|
|
13535
|
+
}
|
|
13536
|
+
function settleFailedBlockSnapshot(reasonCode, capture, targetIdentity, failureCause) {
|
|
13537
|
+
if (isSnapshotBlockingReason(reasonCode)) {
|
|
13538
|
+
return snapshotBlockStillCurrent(capture, targetIdentity) ? { status: "still-blocked", reasonCode } : { status: "stale" };
|
|
13539
|
+
}
|
|
13540
|
+
markUnavailable(failureCause(reasonCode));
|
|
13541
|
+
return { status: "fatal" };
|
|
13542
|
+
}
|
|
13543
|
+
function commitSnapshotBlockClear(capture, target, snapshot, failureCause) {
|
|
13544
|
+
if (!snapshotBlockStillCurrent(capture, target.targetIdentity)) {
|
|
13545
|
+
return { status: "stale" };
|
|
13546
|
+
}
|
|
13547
|
+
const observed = requireGuard().observeReadback({
|
|
13548
|
+
workspaceIdentity: options.workspaceIdentity,
|
|
13549
|
+
repositoryIdentity: snapshot.repositoryRevisionDigest,
|
|
13550
|
+
worktreeIdentity: snapshot.worktreeRevisionDigest,
|
|
13551
|
+
...target.pinned ? { operationTargetIdentity: target.targetIdentity } : {}
|
|
13552
|
+
});
|
|
13553
|
+
if (observed.status === "rejected" && observed.reasonCode === "workspace-mismatch") {
|
|
13554
|
+
markUnavailable(failureCause());
|
|
13555
|
+
return { status: "fatal" };
|
|
13556
|
+
}
|
|
13557
|
+
writeSnapshotBlock(undefined);
|
|
13558
|
+
return { status: "cleared" };
|
|
13559
|
+
}
|
|
13560
|
+
const snapshotBlockControls = {
|
|
13561
|
+
set: (reasonCode) => {
|
|
13562
|
+
ensureSynchronousRuntime();
|
|
13563
|
+
return setSnapshotBlock(reasonCode, currentEffectiveTargetIdentity(), {
|
|
13564
|
+
generation: unitStartGeneration
|
|
13565
|
+
});
|
|
13566
|
+
},
|
|
13567
|
+
current: () => {
|
|
13568
|
+
ensureSynchronousRuntime();
|
|
13569
|
+
const record2 = currentSnapshotBlock();
|
|
13570
|
+
return record2 ? { reasonCode: record2.reasonCode } : undefined;
|
|
13571
|
+
},
|
|
13572
|
+
clear: async () => {
|
|
13573
|
+
ensureSynchronousRuntime();
|
|
13574
|
+
const lookup = resolveEffectiveObserver();
|
|
13575
|
+
if (lookup.status === "timeout")
|
|
13576
|
+
return TIMED_OUT_READ;
|
|
13577
|
+
if (lookup.status === "fatal") {
|
|
13578
|
+
markUnavailable(observerReadbackFailedCause(lookup.reasonCode));
|
|
13579
|
+
return { status: "fatal" };
|
|
13580
|
+
}
|
|
13581
|
+
return clearSnapshotBlock(lookup.value, observerReadbackFailedCause);
|
|
13582
|
+
}
|
|
13583
|
+
};
|
|
13215
13584
|
function currentSeedDeferrals() {
|
|
13216
13585
|
return seedDeferralEntries().map(({ operation, reasonCode }) => ({
|
|
13217
13586
|
operation,
|
|
@@ -13221,8 +13590,7 @@ function createSessionRuntime(options, operationObservers, recoveredOperationCon
|
|
|
13221
13590
|
function fatalSeed(cause) {
|
|
13222
13591
|
return { kind: "fatal", cause };
|
|
13223
13592
|
}
|
|
13224
|
-
|
|
13225
|
-
const result = await readRemoteScope(reader, operation, "before");
|
|
13593
|
+
function classifyRemoteSeedRead(operation, result) {
|
|
13226
13594
|
if (!result) {
|
|
13227
13595
|
return fatalSeed({
|
|
13228
13596
|
site: "seed-remote-scope",
|
|
@@ -13232,24 +13600,30 @@ function createSessionRuntime(options, operationObservers, recoveredOperationCon
|
|
|
13232
13600
|
});
|
|
13233
13601
|
}
|
|
13234
13602
|
if (result.status === "missing-resource") {
|
|
13235
|
-
|
|
13236
|
-
return { kind: "deferred", reasonCode: "missing-resource" };
|
|
13237
|
-
}
|
|
13238
|
-
return { kind: "tolerated" };
|
|
13603
|
+
return operation === "push" ? { kind: "deferred", reasonCode: "missing-resource" } : { kind: "tolerated" };
|
|
13239
13604
|
}
|
|
13240
|
-
if (result.status
|
|
13241
|
-
|
|
13242
|
-
|
|
13243
|
-
|
|
13244
|
-
return
|
|
13245
|
-
site: "seed-remote-scope",
|
|
13246
|
-
kind: "remote-scope-unavailable",
|
|
13247
|
-
operation,
|
|
13248
|
-
reasonCode: result.reasonCode,
|
|
13249
|
-
timedOut: false
|
|
13250
|
-
});
|
|
13605
|
+
if (result.status === "available") {
|
|
13606
|
+
return { kind: "read", snapshot: result.snapshot };
|
|
13607
|
+
}
|
|
13608
|
+
if (result.reasonCode === "command-timeout") {
|
|
13609
|
+
return { kind: "deferred", reasonCode: "command-timeout" };
|
|
13251
13610
|
}
|
|
13252
|
-
|
|
13611
|
+
return fatalSeed({
|
|
13612
|
+
site: "seed-remote-scope",
|
|
13613
|
+
kind: "remote-scope-unavailable",
|
|
13614
|
+
operation,
|
|
13615
|
+
reasonCode: result.reasonCode,
|
|
13616
|
+
timedOut: false
|
|
13617
|
+
});
|
|
13618
|
+
}
|
|
13619
|
+
async function seedRemoteScope(reader, operation, local, generation) {
|
|
13620
|
+
const result = await readRemoteScope(reader, operation, "before");
|
|
13621
|
+
if (generation !== unitStartGeneration)
|
|
13622
|
+
return { kind: "superseded" };
|
|
13623
|
+
const read = classifyRemoteSeedRead(operation, result);
|
|
13624
|
+
if (read.kind !== "read")
|
|
13625
|
+
return read;
|
|
13626
|
+
const observed = requireGuard().observeReadback(remoteReadbackInput(operation, local, options.workspaceIdentity, read.snapshot, operation !== "pr-creation"));
|
|
13253
13627
|
if (observed.status === "rejected") {
|
|
13254
13628
|
return fatalSeed({
|
|
13255
13629
|
site: "seed-remote-scope",
|
|
@@ -13404,6 +13778,10 @@ function createSessionRuntime(options, operationObservers, recoveredOperationCon
|
|
|
13404
13778
|
return;
|
|
13405
13779
|
}
|
|
13406
13780
|
const reasonCode = "reasonCode" in result ? result.reasonCode : "guard-unavailable";
|
|
13781
|
+
if (reasonCode === "stale-receipt") {
|
|
13782
|
+
finishStaleFinalize(callDigest, pending, output);
|
|
13783
|
+
return;
|
|
13784
|
+
}
|
|
13407
13785
|
markUnavailable(afterCause("transition-finalize-rejected", reasonCode));
|
|
13408
13786
|
const terminal = {
|
|
13409
13787
|
target: pending.target,
|
|
@@ -13414,6 +13792,14 @@ function createSessionRuntime(options, operationObservers, recoveredOperationCon
|
|
|
13414
13792
|
terminalCompletes.set(callDigest, terminal);
|
|
13415
13793
|
writeTerminalCompletionResult(output, terminal, pending.target);
|
|
13416
13794
|
}
|
|
13795
|
+
function finishStaleFinalize(callDigest, pending, output) {
|
|
13796
|
+
rejectCompletion(callDigest, pending, output, {
|
|
13797
|
+
target: pending.target,
|
|
13798
|
+
status: "rejected",
|
|
13799
|
+
reasonCode: "stale-receipt",
|
|
13800
|
+
title: "Workflow receipt stale"
|
|
13801
|
+
}, { abandon: false });
|
|
13802
|
+
}
|
|
13417
13803
|
function writeTerminalReplay(output, terminal, target) {
|
|
13418
13804
|
if (terminal.metadataOnly) {
|
|
13419
13805
|
writeAbandonedCompletionMetadata(output, target, terminal.reasonCode);
|
|
@@ -13461,13 +13847,18 @@ function createSessionRuntime(options, operationObservers, recoveredOperationCon
|
|
|
13461
13847
|
if (remember)
|
|
13462
13848
|
abandonedCompletes.set(callDigest, pending.target);
|
|
13463
13849
|
}
|
|
13850
|
+
function blockedOrFailure(failure, targetIdentity) {
|
|
13851
|
+
return failure.status === "fatal" && isSnapshotBlockingReason(failure.reasonCode) ? { status: "blocked", reasonCode: failure.reasonCode, targetIdentity } : failure;
|
|
13852
|
+
}
|
|
13464
13853
|
async function completionReadbacks() {
|
|
13465
13854
|
const observer = options.observer;
|
|
13466
13855
|
if (!observer)
|
|
13467
13856
|
return { status: "none" };
|
|
13857
|
+
const blockCapture = captureSnapshotBlock();
|
|
13468
13858
|
const parent = await readSnapshot(observer, options.workspaceIdentity);
|
|
13469
|
-
if (parent.status !== "ok")
|
|
13470
|
-
return parent;
|
|
13859
|
+
if (parent.status !== "ok") {
|
|
13860
|
+
return blockedOrFailure(parent, options.workspaceIdentity);
|
|
13861
|
+
}
|
|
13471
13862
|
const lookup = resolveEffectiveObserver();
|
|
13472
13863
|
if (lookup.status !== "ok")
|
|
13473
13864
|
return lookup;
|
|
@@ -13475,18 +13866,27 @@ function createSessionRuntime(options, operationObservers, recoveredOperationCon
|
|
|
13475
13866
|
let initialEffective = parent.value;
|
|
13476
13867
|
if (effective.pinned) {
|
|
13477
13868
|
const pinned = await readSnapshot(effective.observer, effective.targetIdentity);
|
|
13478
|
-
if (pinned.status !== "ok")
|
|
13479
|
-
return pinned;
|
|
13869
|
+
if (pinned.status !== "ok") {
|
|
13870
|
+
return blockedOrFailure(pinned, effective.targetIdentity);
|
|
13871
|
+
}
|
|
13480
13872
|
initialEffective = pinned.value;
|
|
13481
13873
|
}
|
|
13482
13874
|
const remote = await completionRemoteReadbacks(effective.observer);
|
|
13483
13875
|
if (remote.status !== "ready")
|
|
13484
13876
|
return remote;
|
|
13485
13877
|
const finalParent = await readSnapshot(observer);
|
|
13486
|
-
if (finalParent.status !== "ok")
|
|
13487
|
-
return finalParent;
|
|
13488
|
-
|
|
13878
|
+
if (finalParent.status !== "ok") {
|
|
13879
|
+
return blockedOrFailure(finalParent, options.workspaceIdentity);
|
|
13880
|
+
}
|
|
13881
|
+
const drift = completionParentDrift(parent.value, finalParent.value);
|
|
13882
|
+
if (drift === "target")
|
|
13489
13883
|
return { status: "fatal" };
|
|
13884
|
+
if (drift === "revision") {
|
|
13885
|
+
return {
|
|
13886
|
+
status: "blocked",
|
|
13887
|
+
reasonCode: "worktree-unstable",
|
|
13888
|
+
targetIdentity: options.workspaceIdentity
|
|
13889
|
+
};
|
|
13490
13890
|
}
|
|
13491
13891
|
const final = effective.pinned ? await revalidatePinnedCompletion(effective, initialEffective) : { status: "ready", effective, snapshot: finalParent.value };
|
|
13492
13892
|
if (final.status !== "ready")
|
|
@@ -13501,11 +13901,20 @@ function createSessionRuntime(options, operationObservers, recoveredOperationCon
|
|
|
13501
13901
|
operationTargetIdentity: final.effective.targetIdentity
|
|
13502
13902
|
},
|
|
13503
13903
|
...remote.readbacks.map(({ operation, snapshot }) => remoteReadbackInput(operation, final.snapshot, options.workspaceIdentity, snapshot))
|
|
13504
|
-
]
|
|
13904
|
+
],
|
|
13905
|
+
...blockCapture ? {
|
|
13906
|
+
blockClear: {
|
|
13907
|
+
capture: blockCapture,
|
|
13908
|
+
target: final.effective,
|
|
13909
|
+
snapshot: final.snapshot
|
|
13910
|
+
}
|
|
13911
|
+
} : {}
|
|
13505
13912
|
};
|
|
13506
13913
|
}
|
|
13507
|
-
function
|
|
13508
|
-
|
|
13914
|
+
function completionParentDrift(initial, final) {
|
|
13915
|
+
if (final.targetDigest !== initial.targetDigest)
|
|
13916
|
+
return "target";
|
|
13917
|
+
return final.repositoryRevisionDigest !== initial.repositoryRevisionDigest || final.worktreeRevisionDigest !== initial.worktreeRevisionDigest ? "revision" : "none";
|
|
13509
13918
|
}
|
|
13510
13919
|
async function revalidatePinnedCompletion(effective, initial) {
|
|
13511
13920
|
const lookup = resolveEffectiveObserver();
|
|
@@ -13516,10 +13925,15 @@ function createSessionRuntime(options, operationObservers, recoveredOperationCon
|
|
|
13516
13925
|
return { status: "fatal" };
|
|
13517
13926
|
}
|
|
13518
13927
|
const pinned = await readSnapshot(revalidated.observer, revalidated.targetIdentity);
|
|
13519
|
-
if (pinned.status !== "ok")
|
|
13520
|
-
return pinned;
|
|
13928
|
+
if (pinned.status !== "ok") {
|
|
13929
|
+
return blockedOrFailure(pinned, revalidated.targetIdentity);
|
|
13930
|
+
}
|
|
13521
13931
|
if (pinned.value.repositoryRevisionDigest !== initial.repositoryRevisionDigest || pinned.value.worktreeRevisionDigest !== initial.worktreeRevisionDigest) {
|
|
13522
|
-
return {
|
|
13932
|
+
return {
|
|
13933
|
+
status: "blocked",
|
|
13934
|
+
reasonCode: "worktree-unstable",
|
|
13935
|
+
targetIdentity: revalidated.targetIdentity
|
|
13936
|
+
};
|
|
13523
13937
|
}
|
|
13524
13938
|
return {
|
|
13525
13939
|
status: "ready",
|
|
@@ -13538,7 +13952,7 @@ function createSessionRuntime(options, operationObservers, recoveredOperationCon
|
|
|
13538
13952
|
for (const operation of remoteOperations) {
|
|
13539
13953
|
const result = await readRemoteScope(remoteSnapshot, operation);
|
|
13540
13954
|
if (isProbeTimeout(result))
|
|
13541
|
-
return
|
|
13955
|
+
return TIMED_OUT_READ;
|
|
13542
13956
|
if (result?.status !== "available") {
|
|
13543
13957
|
return { status: "fatal", reasonCode: remoteFailureReason(result) };
|
|
13544
13958
|
}
|
|
@@ -13560,6 +13974,12 @@ function createSessionRuntime(options, operationObservers, recoveredOperationCon
|
|
|
13560
13974
|
markUnavailable(afterCause("call-lifecycle-mismatch"));
|
|
13561
13975
|
writeAbandonedCompletionResult(output, finalTarget, "guard-unavailable");
|
|
13562
13976
|
}
|
|
13977
|
+
function rejectCompletion(callDigest, pending, output, terminal, { abandon }) {
|
|
13978
|
+
if (abandon)
|
|
13979
|
+
abandonComplete(callDigest, pending, true);
|
|
13980
|
+
terminalCompletes.set(callDigest, terminal);
|
|
13981
|
+
writeTerminalCompletionResult(output, terminal, pending.target, terminal.title);
|
|
13982
|
+
}
|
|
13563
13983
|
function finishUnavailableReadback(callDigest, pending, output, reasonCode) {
|
|
13564
13984
|
abandonComplete(callDigest, pending, true);
|
|
13565
13985
|
terminalCompletes.set(callDigest, {
|
|
@@ -13578,16 +13998,38 @@ function createSessionRuntime(options, operationObservers, recoveredOperationCon
|
|
|
13578
13998
|
}
|
|
13579
13999
|
}
|
|
13580
14000
|
function finishRetryableReadback(callDigest, pending, output) {
|
|
13581
|
-
|
|
13582
|
-
const terminal = {
|
|
14001
|
+
rejectCompletion(callDigest, pending, output, {
|
|
13583
14002
|
target: pending.target,
|
|
13584
14003
|
status: "rejected",
|
|
13585
14004
|
reasonCode: "readback-timeout",
|
|
13586
14005
|
title: "Workflow readback timed out"
|
|
13587
|
-
};
|
|
13588
|
-
terminalCompletes.set(callDigest, terminal);
|
|
13589
|
-
writeTerminalCompletionResult(output, terminal, pending.target, terminal.title);
|
|
14006
|
+
}, { abandon: true });
|
|
13590
14007
|
}
|
|
14008
|
+
function finishBlockedComplete(callDigest, pending, output, reasonCode, blockTarget) {
|
|
14009
|
+
if (requireGuard().status().state === "unavailable") {
|
|
14010
|
+
finishUnavailableReadback(callDigest, pending, output, reasonCode);
|
|
14011
|
+
return;
|
|
14012
|
+
}
|
|
14013
|
+
rejectCompletion(callDigest, pending, output, {
|
|
14014
|
+
target: pending.target,
|
|
14015
|
+
status: "rejected",
|
|
14016
|
+
reasonCode: "snapshot-blocked",
|
|
14017
|
+
blockReason: reasonCode,
|
|
14018
|
+
...blockTarget ? { blockTarget } : {},
|
|
14019
|
+
title: "Workflow snapshot blocked"
|
|
14020
|
+
}, { abandon: true });
|
|
14021
|
+
}
|
|
14022
|
+
function commitCompletionBlockClear(readbacks) {
|
|
14023
|
+
if (readbacks.status !== "ready" || !readbacks.blockClear) {
|
|
14024
|
+
return { status: "none" };
|
|
14025
|
+
}
|
|
14026
|
+
const { capture, target, snapshot } = readbacks.blockClear;
|
|
14027
|
+
return commitSnapshotBlockClear(capture, target, snapshot, completionFailureCause);
|
|
14028
|
+
}
|
|
14029
|
+
function currentBlockReason() {
|
|
14030
|
+
return currentSnapshotBlock()?.reasonCode;
|
|
14031
|
+
}
|
|
14032
|
+
const completionFailureCause = (reasonCode) => observerReadbackFailedCause(reasonCode, "complete-readback");
|
|
13591
14033
|
async function finishComplete(host, output) {
|
|
13592
14034
|
const callDigest = digestCall(ledger, host.callID);
|
|
13593
14035
|
const pending = pendingCompletes.get(callDigest);
|
|
@@ -13602,7 +14044,23 @@ function createSessionRuntime(options, operationObservers, recoveredOperationCon
|
|
|
13602
14044
|
finishUnreplayableComplete(finalTarget, output);
|
|
13603
14045
|
return;
|
|
13604
14046
|
}
|
|
14047
|
+
const generation = unitStartGeneration;
|
|
13605
14048
|
const readbacks = await completionReadbacks();
|
|
14049
|
+
settleCompletionReadbacks(callDigest, pending, output, readbacks, generation);
|
|
14050
|
+
}
|
|
14051
|
+
function blockForCompletion(blocked, generation) {
|
|
14052
|
+
if (requireGuard().status().state !== "unavailable") {
|
|
14053
|
+
setSnapshotBlock(blocked.reasonCode, blocked.targetIdentity, {
|
|
14054
|
+
generation
|
|
14055
|
+
});
|
|
14056
|
+
}
|
|
14057
|
+
}
|
|
14058
|
+
function settleCompletionReadbacks(callDigest, pending, output, readbacks, generation) {
|
|
14059
|
+
if (readbacks.status === "blocked") {
|
|
14060
|
+
blockForCompletion(readbacks, generation);
|
|
14061
|
+
finishBlockedComplete(callDigest, pending, output, readbacks.reasonCode, readbacks.targetIdentity === currentEffectiveTargetIdentity() ? undefined : "parent-checkout");
|
|
14062
|
+
return;
|
|
14063
|
+
}
|
|
13606
14064
|
if (readbacks.status === "fatal") {
|
|
13607
14065
|
finishUnavailableReadback(callDigest, pending, output, readbacks.reasonCode);
|
|
13608
14066
|
return;
|
|
@@ -13611,6 +14069,15 @@ function createSessionRuntime(options, operationObservers, recoveredOperationCon
|
|
|
13611
14069
|
finishReadbackTimeout(callDigest, pending, output);
|
|
13612
14070
|
return;
|
|
13613
14071
|
}
|
|
14072
|
+
if (commitCompletionBlockClear(readbacks).status === "fatal") {
|
|
14073
|
+
finishUnavailableReadback(callDigest, pending, output);
|
|
14074
|
+
return;
|
|
14075
|
+
}
|
|
14076
|
+
const block = currentBlockReason();
|
|
14077
|
+
if (block) {
|
|
14078
|
+
finishBlockedComplete(callDigest, pending, output, block);
|
|
14079
|
+
return;
|
|
14080
|
+
}
|
|
13614
14081
|
finalizeComplete(callDigest, pending, output, readbacks.status === "ready" ? readbacks.readbacks : undefined);
|
|
13615
14082
|
}
|
|
13616
14083
|
function sealOperation(callDigest, operation, abandoned = false) {
|
|
@@ -13652,6 +14119,8 @@ function createSessionRuntime(options, operationObservers, recoveredOperationCon
|
|
|
13652
14119
|
} catch {
|
|
13653
14120
|
return afterFailure("operation-input-invalid");
|
|
13654
14121
|
}
|
|
14122
|
+
if (isProbeTimeout(validation))
|
|
14123
|
+
return TIMED_OUT_READ;
|
|
13655
14124
|
if (validation.status === "error" || validation.targetRoot !== pending.targetRoot || registeredWorktreeIdentity(validation) !== pending.registeredWorktreeIdentity) {
|
|
13656
14125
|
return afterFailure("operation-input-invalid", validation.status === "error" ? validation.reasonCode : undefined);
|
|
13657
14126
|
}
|
|
@@ -13663,16 +14132,34 @@ function createSessionRuntime(options, operationObservers, recoveredOperationCon
|
|
|
13663
14132
|
const targetFailure = afterTargetFailure(options.observer, pending);
|
|
13664
14133
|
if (targetFailure)
|
|
13665
14134
|
return targetFailure;
|
|
13666
|
-
|
|
13667
|
-
|
|
13668
|
-
|
|
13669
|
-
|
|
13670
|
-
return afterFailure("local-snapshot-error");
|
|
14135
|
+
const blockCapture = captureSnapshotBlock();
|
|
14136
|
+
const read = await readSnapshot(pending.observer);
|
|
14137
|
+
if (read.status === "ok") {
|
|
14138
|
+
return settleCleanAfterSnapshot(blockCapture, pending, read.value);
|
|
13671
14139
|
}
|
|
13672
|
-
if (
|
|
13673
|
-
return
|
|
14140
|
+
if (read.status === "timeout")
|
|
14141
|
+
return TIMED_OUT_READ;
|
|
14142
|
+
const reasonCode = probeFailureReason(read);
|
|
14143
|
+
if (isSnapshotBlockingReason(reasonCode)) {
|
|
14144
|
+
return { status: "blocked", reasonCode };
|
|
14145
|
+
}
|
|
14146
|
+
return reasonCode === undefined ? afterFailure("local-snapshot-error") : afterFailure("local-snapshot-unavailable", reasonCode);
|
|
14147
|
+
}
|
|
14148
|
+
function settleCleanAfterSnapshot(blockCapture, pending, snapshot) {
|
|
14149
|
+
if (snapshot.targetDigest !== pending.targetIdentity) {
|
|
14150
|
+
return afterFailure("operation-target-mismatch");
|
|
13674
14151
|
}
|
|
13675
|
-
|
|
14152
|
+
const failure = blockCapture ? clearBlockAfterOperation(blockCapture, pending, snapshot) : undefined;
|
|
14153
|
+
return failure ?? { status: "available", snapshot };
|
|
14154
|
+
}
|
|
14155
|
+
function clearBlockAfterOperation(capture, pending, snapshot) {
|
|
14156
|
+
const cleared = commitSnapshotBlockClear(capture, readbackTarget(pending.targetIdentity), snapshot, snapshotFailureCause(afterCause));
|
|
14157
|
+
return cleared.status === "fatal" ? afterFailure("local-snapshot-error") : undefined;
|
|
14158
|
+
}
|
|
14159
|
+
function setBlockFromAfterSnapshot(pending, reasonCode) {
|
|
14160
|
+
setSnapshotBlock(reasonCode, pending.targetIdentity, {
|
|
14161
|
+
initiator: pending.initiator
|
|
14162
|
+
});
|
|
13676
14163
|
}
|
|
13677
14164
|
async function captureRemoteAfter(operation, observer) {
|
|
13678
14165
|
const remoteSnapshot = observer.remoteSnapshot;
|
|
@@ -13684,7 +14171,13 @@ function createSessionRuntime(options, operationObservers, recoveredOperationCon
|
|
|
13684
14171
|
} catch {
|
|
13685
14172
|
return afterFailure("operation-observation-rejected");
|
|
13686
14173
|
}
|
|
13687
|
-
|
|
14174
|
+
if (isProbeTimeout(result))
|
|
14175
|
+
return TIMED_OUT_READ;
|
|
14176
|
+
const reasonCode = remoteFailureReason(result);
|
|
14177
|
+
if (reasonCode === "missing-resource" || reasonCode === "remote-not-advanced") {
|
|
14178
|
+
return { status: "unadvanced", reasonCode };
|
|
14179
|
+
}
|
|
14180
|
+
return result.status === "available" ? { status: "available", snapshot: result.snapshot } : afterFailure("operation-observation-rejected", reasonCode);
|
|
13688
14181
|
}
|
|
13689
14182
|
async function readRemoteScope(reader, operation, phase = "after") {
|
|
13690
14183
|
try {
|
|
@@ -13769,13 +14262,22 @@ function createSessionRuntime(options, operationObservers, recoveredOperationCon
|
|
|
13769
14262
|
function ownsOperation(pending) {
|
|
13770
14263
|
return !pending.initiator || isCurrentInitiator(pending.initiator);
|
|
13771
14264
|
}
|
|
13772
|
-
function
|
|
14265
|
+
function sealAndIgnore(callDigest, pending) {
|
|
13773
14266
|
sealOperation(callDigest, pending, true);
|
|
13774
14267
|
return { status: "ignored" };
|
|
13775
14268
|
}
|
|
14269
|
+
function settleUnadvancedRemote(callDigest, pending, finalOperation, unadvanced) {
|
|
14270
|
+
const bothPush = pending.remoteOperation === "push" && finalOperation === "push";
|
|
14271
|
+
const before = pending.remoteBefore;
|
|
14272
|
+
const sealed = bothPush && (unadvanced.reasonCode === "remote-not-advanced" || before?.status === "missing-resource" || isProbeTimeout(before));
|
|
14273
|
+
if (sealed)
|
|
14274
|
+
return sealAndIgnore(callDigest, pending);
|
|
14275
|
+
sealOperation(callDigest, pending, true);
|
|
14276
|
+
return afterFailure("operation-observation-rejected", unadvanced.reasonCode);
|
|
14277
|
+
}
|
|
13776
14278
|
async function completeOperationObservation(callDigest, host, pending, output) {
|
|
13777
14279
|
if (!ownsOperation(pending))
|
|
13778
|
-
return
|
|
14280
|
+
return sealAndIgnore(callDigest, pending);
|
|
13779
14281
|
const parsedOutput = parseHostOutput(output);
|
|
13780
14282
|
if (!parsedOutput) {
|
|
13781
14283
|
sealOperation(callDigest, pending, true);
|
|
@@ -13783,20 +14285,25 @@ function createSessionRuntime(options, operationObservers, recoveredOperationCon
|
|
|
13783
14285
|
}
|
|
13784
14286
|
const capture = await captureAfterOperation(pending);
|
|
13785
14287
|
if (!ownsOperation(pending))
|
|
13786
|
-
return
|
|
14288
|
+
return sealAndIgnore(callDigest, pending);
|
|
14289
|
+
if (capture.status === "blocked") {
|
|
14290
|
+
sealOperation(callDigest, pending, true);
|
|
14291
|
+
setBlockFromAfterSnapshot(pending, capture.reasonCode);
|
|
14292
|
+
return { status: "ignored" };
|
|
14293
|
+
}
|
|
14294
|
+
if (capture.status === "timeout")
|
|
14295
|
+
return sealAndIgnore(callDigest, pending);
|
|
13787
14296
|
if (capture.status === "unavailable") {
|
|
13788
14297
|
sealOperation(callDigest, pending, true);
|
|
13789
14298
|
return capture;
|
|
13790
14299
|
}
|
|
13791
14300
|
const afterSnapshot = capture.snapshot;
|
|
13792
14301
|
const observation = buildOperationObservation(host, pending, afterSnapshot, requireGuard().status(), parsedOutput);
|
|
13793
|
-
if (!observation)
|
|
13794
|
-
|
|
13795
|
-
return { status: "ignored" };
|
|
13796
|
-
}
|
|
14302
|
+
if (!observation)
|
|
14303
|
+
return sealAndIgnore(callDigest, pending);
|
|
13797
14304
|
const classification = await classifyLocalObservation(observation);
|
|
13798
14305
|
if (!ownsOperation(pending))
|
|
13799
|
-
return
|
|
14306
|
+
return sealAndIgnore(callDigest, pending);
|
|
13800
14307
|
if (classification.status !== "ready") {
|
|
13801
14308
|
sealOperation(callDigest, pending, true);
|
|
13802
14309
|
return classification;
|
|
@@ -13805,7 +14312,13 @@ function createSessionRuntime(options, operationObservers, recoveredOperationCon
|
|
|
13805
14312
|
if (remoteOperation(finalObservation.operation)) {
|
|
13806
14313
|
const remoteCapture = await captureRemoteAfter(finalObservation.operation, pending.observer);
|
|
13807
14314
|
if (!ownsOperation(pending)) {
|
|
13808
|
-
return
|
|
14315
|
+
return sealAndIgnore(callDigest, pending);
|
|
14316
|
+
}
|
|
14317
|
+
if (remoteCapture.status === "timeout") {
|
|
14318
|
+
return sealAndIgnore(callDigest, pending);
|
|
14319
|
+
}
|
|
14320
|
+
if (remoteCapture.status === "unadvanced") {
|
|
14321
|
+
return settleUnadvancedRemote(callDigest, pending, finalObservation.operation, remoteCapture);
|
|
13809
14322
|
}
|
|
13810
14323
|
if (remoteCapture.status === "unavailable") {
|
|
13811
14324
|
sealOperation(callDigest, pending, true);
|
|
@@ -13834,7 +14347,10 @@ function createSessionRuntime(options, operationObservers, recoveredOperationCon
|
|
|
13834
14347
|
}
|
|
13835
14348
|
}
|
|
13836
14349
|
if (!ownsOperation(pending))
|
|
13837
|
-
return
|
|
14350
|
+
return sealAndIgnore(callDigest, pending);
|
|
14351
|
+
if (finalObservation.operation === "verification" && overlappedAnotherLocalCall(pending)) {
|
|
14352
|
+
return sealAndIgnore(callDigest, pending);
|
|
14353
|
+
}
|
|
13838
14354
|
const observed = await observeClassifiedOperation(finalObservation);
|
|
13839
14355
|
if (!observed) {
|
|
13840
14356
|
sealOperation(callDigest, pending, true);
|
|
@@ -13890,6 +14406,7 @@ function createSessionRuntime(options, operationObservers, recoveredOperationCon
|
|
|
13890
14406
|
if (!options.observer || !isLocalOperationAfter(host))
|
|
13891
14407
|
return;
|
|
13892
14408
|
const callDigest = digestCall(ledger, host.callID);
|
|
14409
|
+
endLocalCall(callDigest);
|
|
13893
14410
|
const pending = takeOperationToFinish(callDigest, host);
|
|
13894
14411
|
if (!pending)
|
|
13895
14412
|
return;
|
|
@@ -13987,6 +14504,8 @@ ${marker}` : marker;
|
|
|
13987
14504
|
readStatus,
|
|
13988
14505
|
unavailableCause: () => firstUnavailableCause ?? pendingUnavailableCause,
|
|
13989
14506
|
seedDeferrals: currentSeedDeferrals,
|
|
14507
|
+
snapshotBlock: snapshotBlockControls,
|
|
14508
|
+
noteUnparsedLocalCall: beginUnparsedLocalCall,
|
|
13990
14509
|
refreshReadback,
|
|
13991
14510
|
observeReceipt: (input) => {
|
|
13992
14511
|
ensureSynchronousRuntime();
|
|
@@ -14106,7 +14625,7 @@ function createOpencodeWorkflowGuard(options) {
|
|
|
14106
14625
|
const unconfirmed = await runtime.refreshReadback();
|
|
14107
14626
|
return {
|
|
14108
14627
|
title: "Workflow guard status",
|
|
14109
|
-
output: statusToolSchema.safeParse(input).success ? statusForTool(runtime.readStatus(), runtime.unavailableCause(), runtime.seedDeferrals(), unconfirmed) : unavailableToolResult()
|
|
14628
|
+
output: statusToolSchema.safeParse(input).success ? statusForTool(runtime.readStatus(), runtime.unavailableCause(), runtime.seedDeferrals(), unconfirmed, runtime.snapshotBlock.current()) : unavailableToolResult()
|
|
14110
14629
|
};
|
|
14111
14630
|
}),
|
|
14112
14631
|
systematic_workflow_complete: makeWorkflowTool("Request completion of a guarded workflow unit or epoch.", completeToolShape, sessionRuntimeFor, (_runtime, input) => completeToolSchema.safeParse(input).success ? {
|
|
@@ -14124,10 +14643,18 @@ function createOpencodeWorkflowGuard(options) {
|
|
|
14124
14643
|
output: unavailableToolResult()
|
|
14125
14644
|
})
|
|
14126
14645
|
};
|
|
14646
|
+
function countUnparsedLocalCall(input) {
|
|
14647
|
+
if (!isRecord7(input) || !boundedString(input.sessionID, 256) || !boundedString(input.tool, 128) || !isLocalOperationTool(input.tool)) {
|
|
14648
|
+
return;
|
|
14649
|
+
}
|
|
14650
|
+
sessionRuntimeFor(input.sessionID).noteUnparsedLocalCall();
|
|
14651
|
+
}
|
|
14127
14652
|
async function before(input, output) {
|
|
14128
14653
|
const host = parseHostBefore(input);
|
|
14129
|
-
if (!host)
|
|
14654
|
+
if (!host) {
|
|
14655
|
+
countUnparsedLocalCall(input);
|
|
14130
14656
|
return;
|
|
14657
|
+
}
|
|
14131
14658
|
await sessionRuntimeFor(host.sessionID).hooks["tool.execute.before"](input, output);
|
|
14132
14659
|
}
|
|
14133
14660
|
async function after(input, output) {
|
|
@@ -14202,6 +14729,9 @@ function createOpencodeWorkflowGuard(options) {
|
|
|
14202
14729
|
return { status: "rejected", reasonCode: "guard-unavailable" };
|
|
14203
14730
|
}
|
|
14204
14731
|
return sessionRuntimeFor(sessionID).startUnit(input, policy);
|
|
14732
|
+
},
|
|
14733
|
+
snapshotBlock(sessionID) {
|
|
14734
|
+
return boundedString(sessionID, 256) ? sessionRuntimeFor(sessionID).snapshotBlock : INERT_SNAPSHOT_BLOCK;
|
|
14205
14735
|
}
|
|
14206
14736
|
};
|
|
14207
14737
|
}
|