@akagilnc/pi-workflow-roles 0.1.3932 → 0.1.3975
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/CLAUDE.md +1 -1
- package/dist/acp-host/production-host.js +2389 -6018
- package/dist/analyst-gate-cycles-read.js +15 -19
- package/dist/audit-escalation.js +16 -46
- package/dist/auditor-dossier-tool.js +7 -62
- package/dist/collector-identity.js +0 -157
- package/dist/collector-ledger.js +2 -42
- package/dist/compliance-transport.js +40 -14
- package/dist/diarist-contracts.js +2 -40
- package/dist/doctor-contracts.js +39 -108
- package/dist/doctor-evidence.js +1 -5
- package/dist/engine-detour-tool.js +1 -1
- package/dist/gatekeeper-role.js +49 -38
- package/dist/headless-host/production-host.js +4814 -8450
- package/dist/host-contracts.js +0 -5
- package/dist/merger-contracts.js +4 -6
- package/dist/navigator-attendance.js +30 -52
- package/dist/navigator-invocation-identity.js +0 -1
- package/dist/navigator-public-session.js +2 -1
- package/dist/notary-contracts.js +4 -10
- package/dist/package-contracts/auditor-output.js +5 -23
- package/dist/package-contracts/fixer-output.js +25 -49
- package/dist/package-contracts/gatekeeper-output.js +3 -13
- package/dist/package-contracts/navigator-output.js +4 -7
- package/dist/package-contracts/reviewer-output.js +1 -95
- package/dist/package-contracts/terminating-tools.js +33 -144
- package/dist/package-contracts/worker-output.js +1 -3
- package/dist/public-cli/auto-resume.js +30 -68
- package/dist/public-cli/case-dossier-delivery.js +5 -17
- package/dist/public-cli/diarist-run.js +9 -4
- package/dist/public-cli/inspector-run.js +2 -8
- package/dist/public-cli/instruction-seat-run.js +3 -7
- package/dist/public-cli/invocation.js +5 -2
- package/dist/public-cli/main.js +6068 -6964
- package/dist/public-cli/notary-run.js +1 -8
- package/dist/public-cli/post-admission.js +314 -113
- package/dist/public-cli/run-lifecycle.js +14 -38
- package/dist/public-cli/settlement.js +209 -390
- package/dist/public-cli/terminal.js +51 -45
- package/dist/public-role-summons.js +1 -12
- package/dist/reviewer-dispatch.js +12 -258
- package/dist/submission-correctable-error.js +0 -12
- package/dist/submission-errors.js +6 -1
- package/dist/submission-ledger.js +125 -168
- package/dist/ticket-provenance-contracts.js +2 -49
- package/dist/ticket-provenance.js +82 -31
- package/extensions/role-runtime.ts +1 -6
- package/package.json +1 -1
- package/resources/836-deleted-machine-instruction-inventory.md +18 -0
- package/src/acp-host/role-turn-host.ts +8 -3
- package/src/analyst-gate-cycles-read.ts +17 -29
- package/src/audit-escalation.ts +20 -50
- package/src/auditor-dossier-tool.ts +5 -103
- package/src/canonical-skill-binding.ts +3 -2
- package/src/collector-identity.ts +0 -179
- package/src/collector-ledger.ts +3 -46
- package/src/collector-role.ts +32 -61
- package/src/collector-tool-schemas.ts +20 -14
- package/src/compliance-transport.ts +55 -17
- package/src/countersign-role.ts +17 -8
- package/src/diarist-contracts.ts +3 -36
- package/src/diarist-role.ts +13 -7
- package/src/diarist.ts +4 -16
- package/src/doctor-contracts.ts +73 -94
- package/src/doctor-evidence.ts +1 -1
- package/src/doctor-role.ts +3 -3
- package/src/engine-detour-tool.ts +4 -1
- package/src/external-host-turn-loop.ts +9 -3
- package/src/gatekeeper-pass-envelope.ts +7 -12
- package/src/gatekeeper-role.ts +56 -50
- package/src/gleaner-left-role.ts +4 -2
- package/src/headless-host/role-turn-host.ts +4 -5
- package/src/host-contracts.ts +3 -8
- package/src/judge-role.ts +19 -13
- package/src/merger-contracts.ts +10 -6
- package/src/merger-role.ts +1 -5
- package/src/navigator-attendance.ts +37 -74
- package/src/navigator-invocation-identity.ts +0 -6
- package/src/navigator-public-session.ts +2 -1
- package/src/notary-contracts.ts +7 -10
- package/src/package-contracts/auditor-output.ts +4 -21
- package/src/package-contracts/fixer-output.ts +34 -52
- package/src/package-contracts/gatekeeper-output.ts +5 -22
- package/src/package-contracts/navigator-output.ts +7 -7
- package/src/package-contracts/reviewer-output.ts +2 -150
- package/src/package-contracts/terminating-tools.ts +32 -147
- package/src/package-contracts/worker-output.ts +0 -1
- package/src/pi/adapter.ts +3 -8
- package/src/public-cli/auto-resume.ts +41 -94
- package/src/public-cli/case-dossier-delivery.ts +5 -15
- package/src/public-cli/countersign-run.ts +14 -6
- package/src/public-cli/diarist-run.ts +11 -9
- package/src/public-cli/inspector-run.ts +2 -18
- package/src/public-cli/instruction-seat-run.ts +3 -17
- package/src/public-cli/invocation.ts +5 -2
- package/src/public-cli/merger-run.ts +1 -1
- package/src/public-cli/notary-run.ts +1 -18
- package/src/public-cli/post-admission.ts +385 -115
- package/src/public-cli/run-lifecycle.ts +13 -44
- package/src/public-cli/settlement.ts +314 -562
- package/src/public-cli/terminal.ts +66 -72
- package/src/public-role-summons.ts +5 -30
- package/src/reviewer-dispatch.ts +29 -331
- package/src/reviewer-role.ts +16 -83
- package/src/role-envelope.ts +16 -24
- package/src/role-runtime-dependencies.ts +1 -6
- package/src/role-runtime.ts +65 -201
- package/src/submission-correctable-error.ts +0 -14
- package/src/submission-errors.ts +6 -1
- package/src/submission-ledger.ts +187 -187
- package/src/ticket-provenance-contracts.ts +4 -60
- package/src/ticket-provenance.ts +98 -32
- package/src/worker-role.ts +35 -36
- package/dist/activation-ledger-session.js +0 -105
- package/dist/activation-ledger.js +0 -139
- package/dist/activation-trace.js +0 -33
- package/dist/atomic-write.js +0 -23
- package/dist/auditor-role.js +0 -12
- package/dist/canonical-skill-binding.js +0 -61
- package/dist/collector-handbook.js +0 -142
- package/dist/collector-receipt.js +0 -107
- package/dist/collector-role.js +0 -566
- package/dist/collector-tool-schemas.js +0 -107
- package/dist/countersign-role.js +0 -28
- package/dist/diarist-role.js +0 -44
- package/dist/diarist.js +0 -66
- package/dist/doctor-role.js +0 -75
- package/dist/fixer-bash-seatbelt.js +0 -13
- package/dist/gatekeeper-pass-envelope.js +0 -77
- package/dist/gleaner-left-role.js +0 -26
- package/dist/inspector-role.js +0 -29
- package/dist/judge-role.js +0 -104
- package/dist/merger-role.js +0 -55
- package/dist/navigator-role.js +0 -12
- package/dist/notary-role.js +0 -134
- package/dist/oauth-keepalive.js +0 -158
- package/dist/pi/adapter.js +0 -223
- package/dist/reviewer-agent.js +0 -122
- package/dist/reviewer-child-executor.js +0 -194
- package/dist/reviewer-construction.js +0 -103
- package/dist/reviewer-execution-ledger.js +0 -166
- package/dist/reviewer-failure-diagnostic.js +0 -17
- package/dist/reviewer-role.js +0 -159
- package/dist/reviewer-scope-prompt.js +0 -21
- package/dist/reviewer-settlement.js +0 -66
- package/dist/reviewer-workspace.js +0 -132
- package/dist/role-runtime.js +0 -1604
- package/dist/stderr-jsonl.js +0 -26
- package/dist/tool-execution-observation.js +0 -141
- package/dist/worker-role.js +0 -345
- package/dist/worker-submission-gates.js +0 -305
- package/src/collector-receipt.ts +0 -140
- package/src/diagnostic-tail.ts +0 -18
- package/src/reviewer-agent.ts +0 -135
- package/src/reviewer-child-executor.ts +0 -252
- package/src/reviewer-construction.ts +0 -195
- package/src/reviewer-execution-ledger.ts +0 -212
- package/src/reviewer-failure-diagnostic.ts +0 -18
- package/src/reviewer-scope-prompt.ts +0 -24
- package/src/reviewer-settlement.ts +0 -74
- package/src/reviewer-workspace.ts +0 -105
- package/src/shape-unreadable-failure.ts +0 -49
|
@@ -11,6 +11,7 @@ import { isAbsolute, join, resolve } from "node:path";
|
|
|
11
11
|
|
|
12
12
|
import {
|
|
13
13
|
buildResumeContinuationPrompt,
|
|
14
|
+
GATE_DOSSIER_POINTER_PREFIX,
|
|
14
15
|
RESUME_TRANSPORT_ENVELOPE,
|
|
15
16
|
type PublicResumeRequest,
|
|
16
17
|
type SameTicketSummonsMaterials,
|
|
@@ -37,6 +38,15 @@ import type {
|
|
|
37
38
|
} from "../host-contracts.ts";
|
|
38
39
|
import { projectCaseDossierPointerSection } from "./case-dossier-delivery.ts";
|
|
39
40
|
|
|
41
|
+
/** Original error bytes, never relabeled — a secondary fact riding beside a classified cause. */
|
|
42
|
+
function describeCaughtError(error: unknown): { name?: string; message: string; code?: string | number } {
|
|
43
|
+
if (error instanceof Error) {
|
|
44
|
+
const code = (error as NodeJS.ErrnoException).code;
|
|
45
|
+
return { name: error.name, message: error.message, ...(code === undefined ? {} : { code }) };
|
|
46
|
+
}
|
|
47
|
+
return { message: String(error) };
|
|
48
|
+
}
|
|
49
|
+
|
|
40
50
|
/** Append one system section to a continuation prompt, keeping its kind. */
|
|
41
51
|
function appendContinuationSection(
|
|
42
52
|
continuation: RoleTurnContinuation,
|
|
@@ -69,9 +79,9 @@ import {
|
|
|
69
79
|
type WriterLeaseDiagnosticKind,
|
|
70
80
|
} from "./run-lifecycle.ts";
|
|
71
81
|
import { homeFromRunDirectory } from "../activation-ledger-topology.ts";
|
|
72
|
-
import { readSealedSubmission } from "../submission-ledger.ts";
|
|
73
82
|
import { clearReviewerDispatchRejection } from "./reviewer-dispatch-rejection.ts";
|
|
74
83
|
import {
|
|
84
|
+
attemptProducedFreshSubmission,
|
|
75
85
|
classifyPostAdmissionFailure,
|
|
76
86
|
controlledFailureInputFromResolution,
|
|
77
87
|
exitCodeForTerminalOutcome,
|
|
@@ -85,7 +95,8 @@ import {
|
|
|
85
95
|
resolveAuditedRunnerFailureResolution,
|
|
86
96
|
resolveControlledFailureResumeObservation,
|
|
87
97
|
settleFailureTerminalResult,
|
|
88
|
-
|
|
98
|
+
settleHostEndedNoReceipt,
|
|
99
|
+
attachRecordedSubmissions,
|
|
89
100
|
} from "./settlement.ts";
|
|
90
101
|
import type { CliIo } from "./cli-io.ts";
|
|
91
102
|
import type { AdmittedRoleInvocation } from "./invocation.ts";
|
|
@@ -270,6 +281,13 @@ export type ControlledFailureInput = {
|
|
|
270
281
|
knownDetails?: Readonly<Record<string, unknown>>;
|
|
271
282
|
typedHttpObservationSettled?: true;
|
|
272
283
|
typedHttpObservation?: TypedProviderHttpObservation;
|
|
284
|
+
/**
|
|
285
|
+
* #836: set when the caller already attempted markRunTerminal/markRunResumable
|
|
286
|
+
* and it is what threw `thrown` — presentControlledFailure must not retry
|
|
287
|
+
* the same known-failing run-state write a second time; the caught error is
|
|
288
|
+
* already the reported cause.
|
|
289
|
+
*/
|
|
290
|
+
skipRunStateWrite?: boolean;
|
|
273
291
|
};
|
|
274
292
|
|
|
275
293
|
/** Result of seat prep after the single pre-lease admitted load. */
|
|
@@ -399,17 +417,20 @@ export async function presentControlledFailure<
|
|
|
399
417
|
resumable = sessionPrincipalAvailable && typedHttp429 !== undefined;
|
|
400
418
|
}
|
|
401
419
|
|
|
402
|
-
if (persistRunState) {
|
|
420
|
+
if (persistRunState && !failureInput.skipRunStateWrite) {
|
|
403
421
|
await persistReturnedRunState(admitted, authority);
|
|
404
422
|
}
|
|
405
423
|
|
|
406
|
-
const terminal = await
|
|
424
|
+
const terminal = await attachRecordedSubmissions(
|
|
407
425
|
admitted,
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
426
|
+
await settleFailureTerminalResult(
|
|
427
|
+
admitted,
|
|
428
|
+
failure,
|
|
429
|
+
authority,
|
|
430
|
+
resumable
|
|
431
|
+
? { resume: { command: renderResumeCommand(admitted.runId) } }
|
|
432
|
+
: {},
|
|
433
|
+
),
|
|
413
434
|
);
|
|
414
435
|
presentFailureTerminal(terminal, io);
|
|
415
436
|
return {
|
|
@@ -455,6 +476,57 @@ async function settleAfterTurnStarted<
|
|
|
455
476
|
}
|
|
456
477
|
}
|
|
457
478
|
|
|
479
|
+
/**
|
|
480
|
+
* Persist run-state for a result dispatchPostAdmissionTurn deferred
|
|
481
|
+
* (needsPersist — station-child / resumable auto-resume loop, #416/#840):
|
|
482
|
+
* that write must land outside the loop's own retried-dispatch try, but its
|
|
483
|
+
* failure still settles through the single existing controlled-failure
|
|
484
|
+
* authority (settleAfterTurnStarted / presentControlledFailure, ADR 0080
|
|
485
|
+
* single-settlement-disposition) — never a second hand-rolled
|
|
486
|
+
* classify/artifact/Terminal (#836 r12 class 3), and never lawful/non-lawful
|
|
487
|
+
* settling differently (#836 r13 class 2: a caller's io here may be a no-op,
|
|
488
|
+
* so a stderr-only trace is never seen and the failure is otherwise
|
|
489
|
+
* swallowed — 失败诚实宪法 真因必须落痕). Both cases settle through
|
|
490
|
+
* settleAfterTurnStarted, which attaches the run's already-recorded ledger
|
|
491
|
+
* submissions to the new failure terminal and returns skipAutoResume so the
|
|
492
|
+
* caller presents it once and stops — never re-entering auto-resume.
|
|
493
|
+
*/
|
|
494
|
+
async function settleDeferredPersist<
|
|
495
|
+
A extends AdmittedRoleInvocation,
|
|
496
|
+
T extends TerminalResult,
|
|
497
|
+
>(
|
|
498
|
+
admitted: A,
|
|
499
|
+
authority: DurablePrincipalAuthority,
|
|
500
|
+
adapters: PostAdmissionAdapters<A, T>,
|
|
501
|
+
io: CliIo,
|
|
502
|
+
result: {
|
|
503
|
+
exitCode: number;
|
|
504
|
+
admitted: A;
|
|
505
|
+
terminal?: T;
|
|
506
|
+
skipAutoResume?: true;
|
|
507
|
+
turnDispatched?: true;
|
|
508
|
+
needsPersist?: true;
|
|
509
|
+
},
|
|
510
|
+
): Promise<typeof result> {
|
|
511
|
+
if (result.needsPersist !== true || result.terminal === undefined) return result;
|
|
512
|
+
const { needsPersist: _needsPersist, ...settledResult } = result;
|
|
513
|
+
const lawful = isLawfulTypedTerminalOutcome(result.terminal.roleOutcome);
|
|
514
|
+
try {
|
|
515
|
+
await persistReturnedRunState(admitted, authority, lawful ? { lawful: true } : undefined);
|
|
516
|
+
return settledResult;
|
|
517
|
+
} catch (error) {
|
|
518
|
+
const failed = await settleAfterTurnStarted(
|
|
519
|
+
admitted,
|
|
520
|
+
{ timedOut: false, code: null, stderr: "", thrown: error, skipRunStateWrite: true },
|
|
521
|
+
adapters,
|
|
522
|
+
authority,
|
|
523
|
+
io,
|
|
524
|
+
true,
|
|
525
|
+
);
|
|
526
|
+
return { ...failed, turnDispatched: true as const, skipAutoResume: true as const };
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
|
|
458
530
|
export async function dispatchPostAdmissionTurn<
|
|
459
531
|
A extends AdmittedRoleInvocation,
|
|
460
532
|
T extends TerminalResult = TerminalResult,
|
|
@@ -630,6 +702,18 @@ export async function dispatchPostAdmissionTurn<
|
|
|
630
702
|
return { ...settled, turnDispatched: true as const, ...deferredPersist };
|
|
631
703
|
}
|
|
632
704
|
|
|
705
|
+
// `result.stderr` stays live in memory for the real classification below
|
|
706
|
+
// regardless of whether this durable mirror write succeeds. A write
|
|
707
|
+
// failure here (unwritable run directory, stderr.log occupied as a
|
|
708
|
+
// directory, ...) is a real infrastructure problem and must never be
|
|
709
|
+
// dropped silently (catch-and-continue with no trace is a defect) — but
|
|
710
|
+
// it also must never become THE controlling failure and wash out a
|
|
711
|
+
// primary child signal that already arrived on `result`, or an
|
|
712
|
+
// already-sealed accepted payload (#836: a secondary failure must not
|
|
713
|
+
// overwrite an already-known cause or an already-recorded leg). It rides
|
|
714
|
+
// beside whatever the real classification below determines, and only
|
|
715
|
+
// becomes the reported failure itself when nothing else is wrong.
|
|
716
|
+
//
|
|
633
717
|
// Everything below runs after the host turn genuinely started (#840 r9
|
|
634
718
|
// 判词 class 1 boundary — 覆盖 executeTurn 已启动后至返回带 turnDispatched
|
|
635
719
|
// 结果前的全部异常). Each fallible step routes any failure through the
|
|
@@ -645,6 +729,7 @@ export async function dispatchPostAdmissionTurn<
|
|
|
645
729
|
// turn genuinely started, so the next retry sends a resume payload — the
|
|
646
730
|
// true cause settles through the loop's own existing dispatch-exception
|
|
647
731
|
// machinery once the retry budget is exhausted.
|
|
732
|
+
let stderrLogWriteFailure: unknown;
|
|
648
733
|
try {
|
|
649
734
|
await writeFile(
|
|
650
735
|
join(admitted.runDirectory, "stderr.log"),
|
|
@@ -652,10 +737,13 @@ export async function dispatchPostAdmissionTurn<
|
|
|
652
737
|
"utf8",
|
|
653
738
|
);
|
|
654
739
|
} catch (error) {
|
|
740
|
+
stderrLogWriteFailure = error;
|
|
655
741
|
// Best-effort: the turn's own stderr capture is secondary to lawful /
|
|
656
742
|
// controlled-failure settlement below, but the failure itself must
|
|
657
743
|
// still leave a real trace (失败诚实宪法 真因必须落痕) — durably, since
|
|
658
|
-
// every auto-resume attempt's io is dummyIo (#840 r9 判词 class 1).
|
|
744
|
+
// every auto-resume attempt's io is dummyIo (#840 r9 判词 class 1). It
|
|
745
|
+
// still rides beside the classification below and, if nothing else is
|
|
746
|
+
// wrong, becomes the reported failure itself (#836).
|
|
659
747
|
await recordBestEffortPostDispatchDiagnostic(
|
|
660
748
|
admitted,
|
|
661
749
|
env,
|
|
@@ -664,26 +752,109 @@ export async function dispatchPostAdmissionTurn<
|
|
|
664
752
|
);
|
|
665
753
|
}
|
|
666
754
|
|
|
667
|
-
let settled: T | undefined;
|
|
668
|
-
// Same-ticket re-summons carry courtAttemptId — settle only that attempt so a
|
|
669
|
-
// prior sealed pass cannot wash this turn's missing/escalated/failed result.
|
|
670
755
|
const courtScope =
|
|
671
756
|
request.courtAttemptId === undefined || request.courtAttemptId.length === 0
|
|
672
757
|
? undefined
|
|
673
758
|
: { courtAttemptId: request.courtAttemptId };
|
|
674
|
-
|
|
675
|
-
//
|
|
676
|
-
//
|
|
677
|
-
//
|
|
678
|
-
//
|
|
679
|
-
//
|
|
680
|
-
//
|
|
759
|
+
|
|
760
|
+
// Single complete boundary (#840 r9 判词 class 1): resolving the
|
|
761
|
+
// host/runner failure facts, trySettle, its shouldPresent gate, and the
|
|
762
|
+
// accepted-settlement cleanup all settle through this one catch — a
|
|
763
|
+
// throw from any of them (including the session-file decode itself)
|
|
764
|
+
// still routes through settleAfterTurnStarted's TurnDispatchedFailure
|
|
765
|
+
// instead of losing turnDispatched to an uncaught throw. The facts are
|
|
766
|
+
// resolved before trySettle (#836) so an already-accepted settlement is
|
|
767
|
+
// never presented over a real current host/runner failure signal or a
|
|
768
|
+
// real stderr.log durable-write failure — both stay a real failure with
|
|
769
|
+
// the recorded payload riding beside it, not replacing it.
|
|
770
|
+
let settled: T | undefined;
|
|
681
771
|
let settledOutcome:
|
|
682
772
|
| { exitCode: number; admitted: A; terminal: T; turnDispatched: true }
|
|
683
773
|
| undefined;
|
|
774
|
+
let hostSignalFailed = false;
|
|
775
|
+
let resolution: Awaited<ReturnType<typeof resolveAuditedRunnerFailureResolution>> | undefined;
|
|
684
776
|
try {
|
|
777
|
+
const sessionFile =
|
|
778
|
+
admitted.principal !== undefined
|
|
779
|
+
? env.principalAuthority.decode(admitted.principal).sessionFile
|
|
780
|
+
: "";
|
|
781
|
+
const runnerKnownFailure =
|
|
782
|
+
adapters.resolveRunnerKnownFailure !== undefined && sessionFile !== ""
|
|
783
|
+
? await adapters.resolveRunnerKnownFailure({ result, sessionFile })
|
|
784
|
+
: result.knownFailure;
|
|
785
|
+
const credentialFailure = postRunMissingCredentialFailure(
|
|
786
|
+
result,
|
|
787
|
+
env.model,
|
|
788
|
+
env.credentials,
|
|
789
|
+
);
|
|
790
|
+
resolution = await resolveAuditedRunnerFailureResolution({
|
|
791
|
+
runner: runnerKnownFailure,
|
|
792
|
+
sessionFile,
|
|
793
|
+
credential: credentialFailure,
|
|
794
|
+
runDirectory: admitted.runDirectory,
|
|
795
|
+
});
|
|
796
|
+
// A direct, current signal from the host/runner itself (timeout / host
|
|
797
|
+
// knownFailure / runner knownFailure / missing credential) is a real
|
|
798
|
+
// problem regardless of what else already settled — a settled accepted
|
|
799
|
+
// outcome must not paper over it (it rides beside the recorded payload
|
|
800
|
+
// via `submissions`, never replacing the payload). The audited
|
|
801
|
+
// resolution's own typed session read (malformed JSONL, provider-stop,
|
|
802
|
+
// an illegal/unsealed accepted status, a stale/superseded typed-HTTP
|
|
803
|
+
// observation, ...) makes a run with no sealed acceptance a true
|
|
804
|
+
// failure too — it must not be discarded into a lawful no_receipt just
|
|
805
|
+
// because the raw runner signal alone looked clean. But it must not
|
|
806
|
+
// retroactively invalidate an acceptance that already sealed this turn
|
|
807
|
+
// — a resolved 429 observed earlier in the same session is exactly
|
|
808
|
+
// that.
|
|
809
|
+
const directHostFailureSignal =
|
|
810
|
+
result.timedOut
|
|
811
|
+
|| result.knownFailure !== undefined
|
|
812
|
+
|| runnerKnownFailure !== undefined
|
|
813
|
+
|| credentialFailure !== undefined;
|
|
814
|
+
hostSignalFailed =
|
|
815
|
+
directHostFailureSignal
|
|
816
|
+
|| (result.code !== null && result.code !== 0)
|
|
817
|
+
|| resolution.knownFailure !== undefined;
|
|
818
|
+
|
|
685
819
|
settled = await adapters.trySettle(admitted, env.principalAuthority, courtScope);
|
|
686
|
-
if (settled !== undefined
|
|
820
|
+
if (settled !== undefined) {
|
|
821
|
+
settled = await attachRecordedSubmissions(admitted, settled, courtScope) as T;
|
|
822
|
+
}
|
|
823
|
+
// #836 r12 class 2: an accepted/audit_escalation settlement can be
|
|
824
|
+
// entirely a prior attempt's stale payload (courtAttempt is a
|
|
825
|
+
// recording tag, not a visibility gate — attachRecordedSubmissions
|
|
826
|
+
// above still surfaces that historical payload honestly either way).
|
|
827
|
+
// Consume the ledger's own subject.attemptId (submission-ledger.ts)
|
|
828
|
+
// only to learn whether *this* attempt itself produced a fresh seal —
|
|
829
|
+
// never to filter what presents.
|
|
830
|
+
const settledIsFreshThisAttempt =
|
|
831
|
+
settled === undefined
|
|
832
|
+
|| (settled.roleOutcome.kind !== "accepted" && settled.roleOutcome.kind !== "audit_escalation")
|
|
833
|
+
? true
|
|
834
|
+
: await attemptProducedFreshSubmission(admitted, courtScope);
|
|
835
|
+
// A lawful settled outcome already reached this turn takes precedence
|
|
836
|
+
// over a later bare exit-code / session-inspection signal (trailing
|
|
837
|
+
// nonzero exit, late stderr noise, a stale already-superseded
|
|
838
|
+
// typed-HTTP observation, ...) — but never over a direct current
|
|
839
|
+
// host/runner failure signal, nor over a real stderr.log durable-write
|
|
840
|
+
// failure (confirmed infrastructure trouble, not weak/bare evidence),
|
|
841
|
+
// both of which stay a real failure with the recorded payload riding
|
|
842
|
+
// beside it, not replacing it (#836: never kill an already-recorded
|
|
843
|
+
// leg, but never wash a real failure away either). Note: the narrower
|
|
844
|
+
// directHostFailureSignal gates acceptance here; the broader
|
|
845
|
+
// hostSignalFailed (adds bare exit code / resolution.knownFailure)
|
|
846
|
+
// only gates the no-settlement fallback below — except when the
|
|
847
|
+
// settlement itself is entirely stale (no fresh seal this attempt),
|
|
848
|
+
// where a bare nonzero exit / resolution failure must not be outranked
|
|
849
|
+
// by someone else's earlier success (#836 r12 class 2).
|
|
850
|
+
const staleAcceptanceOutranksRealFailure = !settledIsFreshThisAttempt && hostSignalFailed;
|
|
851
|
+
if (
|
|
852
|
+
settled !== undefined
|
|
853
|
+
&& shouldPresent(settled)
|
|
854
|
+
&& !directHostFailureSignal
|
|
855
|
+
&& !staleAcceptanceOutranksRealFailure
|
|
856
|
+
&& stderrLogWriteFailure === undefined
|
|
857
|
+
) {
|
|
687
858
|
// This court sealed — drop open-court pointer (bare resume no longer continues it).
|
|
688
859
|
if (
|
|
689
860
|
settled.roleOutcome.kind === "accepted" &&
|
|
@@ -717,8 +888,8 @@ export async function dispatchPostAdmissionTurn<
|
|
|
717
888
|
};
|
|
718
889
|
}
|
|
719
890
|
} catch (error) {
|
|
720
|
-
// Settle (or its shouldPresent gate
|
|
721
|
-
// never swallow into undefined.
|
|
891
|
+
// Settle (or its shouldPresent gate, or the failure-fact resolution
|
|
892
|
+
// above) throw is a real failure fact — never swallow into undefined.
|
|
722
893
|
const settledFailure = await settleAfterTurnStarted(
|
|
723
894
|
admitted,
|
|
724
895
|
{
|
|
@@ -735,60 +906,136 @@ export async function dispatchPostAdmissionTurn<
|
|
|
735
906
|
return { ...settledFailure, turnDispatched: true as const, ...deferredPersist };
|
|
736
907
|
}
|
|
737
908
|
if (settledOutcome !== undefined) {
|
|
909
|
+
if (persistRunState) {
|
|
910
|
+
try {
|
|
911
|
+
await persistReturnedRunState(admitted, env.principalAuthority, { lawful: true });
|
|
912
|
+
} catch (error) {
|
|
913
|
+
// #836: `settledOutcome.terminal` already carries recorded
|
|
914
|
+
// submissions (attachRecordedSubmissions above). A real run-state
|
|
915
|
+
// persistence failure here must surface loudly through the same
|
|
916
|
+
// controlled-failure seam every other dispatch-time failure in
|
|
917
|
+
// this function uses (ADR 0080: one settlement disposition owner)
|
|
918
|
+
// — not escape uncaught to auto-resume's dispatch-retry path,
|
|
919
|
+
// whose exhausted-budget terminal carries no recorded submissions
|
|
920
|
+
// at all. skipRunStateWrite: the write that just threw is the same
|
|
921
|
+
// write presentControlledFailure would otherwise retry — don't
|
|
922
|
+
// call a known-failing operation twice.
|
|
923
|
+
const failed = await settleAfterTurnStarted(
|
|
924
|
+
admitted,
|
|
925
|
+
{
|
|
926
|
+
timedOut: false,
|
|
927
|
+
code: null,
|
|
928
|
+
stderr: "",
|
|
929
|
+
thrown: error,
|
|
930
|
+
skipRunStateWrite: true,
|
|
931
|
+
},
|
|
932
|
+
adapters,
|
|
933
|
+
env.principalAuthority,
|
|
934
|
+
io,
|
|
935
|
+
persistRunState,
|
|
936
|
+
);
|
|
937
|
+
return { ...failed, turnDispatched: true as const, ...deferredPersist };
|
|
938
|
+
}
|
|
939
|
+
}
|
|
738
940
|
// Lawful persist + present is the caller's stop seam (auto-resume loop /
|
|
739
941
|
// manual resume), not this retried host-turn function.
|
|
740
942
|
return { ...settledOutcome, ...deferredPersist };
|
|
741
943
|
}
|
|
742
944
|
|
|
743
|
-
//
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
const
|
|
751
|
-
admitted
|
|
752
|
-
|
|
753
|
-
:
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
945
|
+
// Host/runner true failure coexists with already-recorded payloads — never wash as accepted.
|
|
946
|
+
if (hostSignalFailed) {
|
|
947
|
+
const resolutionInput = controlledFailureInputFromResolution(resolution!);
|
|
948
|
+
const stderrLogWriteDetails =
|
|
949
|
+
stderrLogWriteFailure === undefined
|
|
950
|
+
? undefined
|
|
951
|
+
: { stderrLogWriteFailure: describeCaughtError(stderrLogWriteFailure) };
|
|
952
|
+
const failed = await settleAfterTurnStarted(
|
|
953
|
+
admitted,
|
|
954
|
+
{
|
|
955
|
+
timedOut: result.timedOut,
|
|
956
|
+
code: result.code,
|
|
957
|
+
stderr: result.stderr,
|
|
958
|
+
...resolutionInput,
|
|
959
|
+
// Secondary fact only — never the cause. Rides on whichever channel
|
|
960
|
+
// classification actually reads (knownFailure.details owns it when
|
|
961
|
+
// a knownFailure exists; the top-level knownDetails otherwise).
|
|
962
|
+
...(stderrLogWriteDetails === undefined
|
|
963
|
+
? {}
|
|
964
|
+
: resolutionInput.knownFailure !== undefined
|
|
965
|
+
? {
|
|
966
|
+
knownFailure: {
|
|
967
|
+
...resolutionInput.knownFailure,
|
|
968
|
+
details: { ...(resolutionInput.knownFailure.details ?? {}), ...stderrLogWriteDetails },
|
|
969
|
+
},
|
|
970
|
+
}
|
|
971
|
+
: { knownDetails: stderrLogWriteDetails }),
|
|
972
|
+
},
|
|
973
|
+
adapters,
|
|
974
|
+
env.principalAuthority,
|
|
975
|
+
io,
|
|
976
|
+
persistRunState,
|
|
762
977
|
);
|
|
763
|
-
|
|
764
|
-
runner: runnerKnownFailure,
|
|
765
|
-
sessionFile,
|
|
766
|
-
credential: credentialFailure,
|
|
767
|
-
runDirectory: admitted.runDirectory,
|
|
768
|
-
});
|
|
769
|
-
failureInput = {
|
|
770
|
-
timedOut: result.timedOut,
|
|
771
|
-
code: result.code,
|
|
772
|
-
stderr: result.stderr,
|
|
773
|
-
...controlledFailureInputFromResolution(resolution),
|
|
774
|
-
};
|
|
775
|
-
} catch (error) {
|
|
776
|
-
failureInput = {
|
|
777
|
-
timedOut: false,
|
|
778
|
-
code: result.code,
|
|
779
|
-
stderr: result.stderr,
|
|
780
|
-
thrown: error,
|
|
781
|
-
};
|
|
978
|
+
return { ...failed, turnDispatched: true as const, ...deferredPersist };
|
|
782
979
|
}
|
|
783
|
-
|
|
980
|
+
|
|
981
|
+
// Nothing else was wrong, but the durable stderr mirror itself failed to
|
|
982
|
+
// write — that is the real (infrastructure) problem in this case, not a
|
|
983
|
+
// lawful absence of a receipt. Honest and loud, not silently no_receipt.
|
|
984
|
+
if (stderrLogWriteFailure !== undefined) {
|
|
985
|
+
const failed = await settleAfterTurnStarted(
|
|
986
|
+
admitted,
|
|
987
|
+
{
|
|
988
|
+
timedOut: false,
|
|
989
|
+
code: result.code,
|
|
990
|
+
stderr: result.stderr,
|
|
991
|
+
thrown: stderrLogWriteFailure,
|
|
992
|
+
},
|
|
993
|
+
adapters,
|
|
994
|
+
env.principalAuthority,
|
|
995
|
+
io,
|
|
996
|
+
persistRunState,
|
|
997
|
+
);
|
|
998
|
+
return { ...failed, turnDispatched: true as const, ...deferredPersist };
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
const noReceipt = await attachRecordedSubmissions(
|
|
784
1002
|
admitted,
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
env.principalAuthority,
|
|
788
|
-
io,
|
|
789
|
-
persistRunState,
|
|
1003
|
+
await settleHostEndedNoReceipt(admitted, env.principalAuthority) as T,
|
|
1004
|
+
courtScope,
|
|
790
1005
|
);
|
|
791
|
-
|
|
1006
|
+
if (persistRunState) {
|
|
1007
|
+
try {
|
|
1008
|
+
await persistReturnedRunState(admitted, env.principalAuthority, { lawful: true });
|
|
1009
|
+
} catch (error) {
|
|
1010
|
+
// #836: same run-state persistence hazard as the settled/accepted
|
|
1011
|
+
// branch above — route through the shared controlled-failure seam so
|
|
1012
|
+
// the real failure surfaces loudly instead of escaping uncaught to
|
|
1013
|
+
// auto-resume's dispatch-retry path with no recorded submissions.
|
|
1014
|
+
// skipRunStateWrite: don't retry the write that just threw.
|
|
1015
|
+
const failed = await settleAfterTurnStarted(
|
|
1016
|
+
admitted,
|
|
1017
|
+
{
|
|
1018
|
+
timedOut: false,
|
|
1019
|
+
code: null,
|
|
1020
|
+
stderr: "",
|
|
1021
|
+
thrown: error,
|
|
1022
|
+
skipRunStateWrite: true,
|
|
1023
|
+
},
|
|
1024
|
+
adapters,
|
|
1025
|
+
env.principalAuthority,
|
|
1026
|
+
io,
|
|
1027
|
+
persistRunState,
|
|
1028
|
+
);
|
|
1029
|
+
return { ...failed, turnDispatched: true as const, ...deferredPersist };
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
return {
|
|
1033
|
+
exitCode: exitCodeForTerminalOutcome(noReceipt.roleOutcome),
|
|
1034
|
+
admitted,
|
|
1035
|
+
terminal: noReceipt,
|
|
1036
|
+
turnDispatched: true as const,
|
|
1037
|
+
...deferredPersist,
|
|
1038
|
+
};
|
|
792
1039
|
} finally {
|
|
793
1040
|
try {
|
|
794
1041
|
await lease.release();
|
|
@@ -832,19 +1079,32 @@ export function resumeTurnRequestProjectionOptions(
|
|
|
832
1079
|
readonly attachments: readonly { frozenPath: string }[];
|
|
833
1080
|
},
|
|
834
1081
|
): RoleTurnRequestProjectionOptions {
|
|
1082
|
+
const officerSourcePath = request.summons?.sourceRunPath;
|
|
1083
|
+
const withReread = (body: string): string => {
|
|
1084
|
+
if (
|
|
1085
|
+
officerSourcePath === undefined
|
|
1086
|
+
|| (admitted.role !== "notary"
|
|
1087
|
+
&& admitted.role !== "inspector"
|
|
1088
|
+
&& admitted.role !== "auditor")
|
|
1089
|
+
) {
|
|
1090
|
+
return body;
|
|
1091
|
+
}
|
|
1092
|
+
if (body.startsWith("请重读")) return body;
|
|
1093
|
+
return `请重读\n${body}`;
|
|
1094
|
+
};
|
|
835
1095
|
let prompt: string;
|
|
836
1096
|
if (request.message !== undefined) {
|
|
837
1097
|
if (summonsPrepared !== undefined) {
|
|
838
1098
|
// #755: same-ticket review / open-court — caller words + optional paths.
|
|
839
1099
|
// Attachments are not a gate: message-only summons must stay plain too.
|
|
840
|
-
prompt = buildInstructionTransportPrompt({
|
|
1100
|
+
prompt = withReread(buildInstructionTransportPrompt({
|
|
841
1101
|
instruction: request.message,
|
|
842
1102
|
instructionEmpty: false,
|
|
843
1103
|
attachments: summonsPrepared.attachments,
|
|
844
|
-
});
|
|
1104
|
+
}));
|
|
845
1105
|
} else if (request.summons !== undefined) {
|
|
846
1106
|
// #755: same-ticket summons without prepared materials — caller words only.
|
|
847
|
-
prompt = request.message;
|
|
1107
|
+
prompt = withReread(request.message);
|
|
848
1108
|
} else {
|
|
849
1109
|
// Bare manual resume — outsourcing engine axis keeps handbook (#600/#736).
|
|
850
1110
|
prompt = buildResumeContinuationPrompt({
|
|
@@ -855,11 +1115,27 @@ export function resumeTurnRequestProjectionOptions(
|
|
|
855
1115
|
}
|
|
856
1116
|
} else if (summonsPrepared !== undefined) {
|
|
857
1117
|
// #755: same-ticket review summons — instruction/attachments only.
|
|
858
|
-
prompt = buildInstructionTransportPrompt(summonsPrepared);
|
|
1118
|
+
prompt = withReread(buildInstructionTransportPrompt(summonsPrepared));
|
|
859
1119
|
} else if (request.summons !== undefined) {
|
|
860
1120
|
// #755: same-ticket summons with no instruction/attachments (e.g. notary
|
|
861
|
-
// source-run pointer)
|
|
862
|
-
|
|
1121
|
+
// source-run pointer). #836: officer resume opening adds「请重读」+ path pointer.
|
|
1122
|
+
const path = request.summons.sourceRunPath;
|
|
1123
|
+
if (
|
|
1124
|
+
path !== undefined &&
|
|
1125
|
+
(admitted.role === "notary" ||
|
|
1126
|
+
admitted.role === "inspector" ||
|
|
1127
|
+
admitted.role === "auditor")
|
|
1128
|
+
) {
|
|
1129
|
+
prompt = `请重读\n${GATE_DOSSIER_POINTER_PREFIX}${path}`;
|
|
1130
|
+
} else if (
|
|
1131
|
+
admitted.role === "notary" ||
|
|
1132
|
+
admitted.role === "inspector" ||
|
|
1133
|
+
admitted.role === "auditor"
|
|
1134
|
+
) {
|
|
1135
|
+
prompt = "请重读";
|
|
1136
|
+
} else {
|
|
1137
|
+
prompt = "";
|
|
1138
|
+
}
|
|
863
1139
|
} else {
|
|
864
1140
|
// Bare manual resume — outsourcing engine axis keeps handbook (#600/#736).
|
|
865
1141
|
prompt = buildResumeContinuationPrompt({
|
|
@@ -1028,41 +1304,23 @@ export async function runPostAdmissionSeatResume<
|
|
|
1028
1304
|
// court materials ride). Settlement identity stays on the outer admitted.
|
|
1029
1305
|
let admittedForBuild = loaded.admitted;
|
|
1030
1306
|
|
|
1031
|
-
// Bare resume:
|
|
1307
|
+
// Bare resume: open-court pointer is the continue signal (not ledger seal).
|
|
1032
1308
|
if (request.summons === undefined) {
|
|
1033
1309
|
const openCourt = await readCurrentCourt(admittedForBuild.runDirectory);
|
|
1034
1310
|
if (openCourt !== undefined) {
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
runId: request.runId,
|
|
1049
|
-
...(request.message === undefined
|
|
1050
|
-
? {}
|
|
1051
|
-
: { message: request.message }),
|
|
1052
|
-
...(openCourt.summons === undefined
|
|
1053
|
-
? {}
|
|
1054
|
-
: { summons: openCourt.summons }),
|
|
1055
|
-
};
|
|
1056
|
-
if (openCourt.summons !== undefined) {
|
|
1057
|
-
const reloaded = await input.load(request);
|
|
1058
|
-
admittedForBuild = reloaded.admitted;
|
|
1059
|
-
}
|
|
1060
|
-
} else {
|
|
1061
|
-
// Open court already sealed — clear only the court id just judged.
|
|
1062
|
-
await clearCurrentCourt(
|
|
1063
|
-
admittedForBuild.runDirectory,
|
|
1064
|
-
openCourt.courtAttemptId,
|
|
1065
|
-
);
|
|
1311
|
+
openCourtAttemptId = openCourt.courtAttemptId;
|
|
1312
|
+
request = {
|
|
1313
|
+
runId: request.runId,
|
|
1314
|
+
...(request.message === undefined
|
|
1315
|
+
? {}
|
|
1316
|
+
: { message: request.message }),
|
|
1317
|
+
...(openCourt.summons === undefined
|
|
1318
|
+
? {}
|
|
1319
|
+
: { summons: openCourt.summons }),
|
|
1320
|
+
};
|
|
1321
|
+
if (openCourt.summons !== undefined) {
|
|
1322
|
+
const reloaded = await input.load(request);
|
|
1323
|
+
admittedForBuild = reloaded.admitted;
|
|
1066
1324
|
}
|
|
1067
1325
|
}
|
|
1068
1326
|
}
|
|
@@ -1168,8 +1426,8 @@ export async function runPostAdmissionSeatResume<
|
|
|
1168
1426
|
firstTurn = turnRequest;
|
|
1169
1427
|
return turnRequest;
|
|
1170
1428
|
},
|
|
1171
|
-
dispatch: (turnRequest) =>
|
|
1172
|
-
dispatchPostAdmissionTurn({
|
|
1429
|
+
dispatch: async (turnRequest) => {
|
|
1430
|
+
const result = await dispatchPostAdmissionTurn({
|
|
1173
1431
|
admitted: loaded.admitted,
|
|
1174
1432
|
env: {
|
|
1175
1433
|
...input.env,
|
|
@@ -1185,7 +1443,15 @@ export async function runPostAdmissionSeatResume<
|
|
|
1185
1443
|
...(input.effectiveEngine === undefined
|
|
1186
1444
|
? {}
|
|
1187
1445
|
: { effectiveEngine: input.effectiveEngine }),
|
|
1188
|
-
})
|
|
1446
|
+
});
|
|
1447
|
+
return settleDeferredPersist(
|
|
1448
|
+
loaded.admitted,
|
|
1449
|
+
input.env.principalAuthority,
|
|
1450
|
+
stationAdapters,
|
|
1451
|
+
attemptIo,
|
|
1452
|
+
result,
|
|
1453
|
+
);
|
|
1454
|
+
},
|
|
1189
1455
|
}),
|
|
1190
1456
|
});
|
|
1191
1457
|
}
|
|
@@ -1284,10 +1550,8 @@ export async function runPostAdmissionResumable<
|
|
|
1284
1550
|
autoResumeLimit: env.autoResumeLimit,
|
|
1285
1551
|
buildInitialPayload: buildInitialRequest,
|
|
1286
1552
|
buildResumePayload: buildResumeRequest,
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
dispatch: (request, lease, _isFirst, attemptIo) =>
|
|
1290
|
-
dispatchPostAdmissionTurn({
|
|
1553
|
+
dispatch: async (request, lease, _isFirst, attemptIo) => {
|
|
1554
|
+
const result = await dispatchPostAdmissionTurn({
|
|
1291
1555
|
admitted,
|
|
1292
1556
|
env: {
|
|
1293
1557
|
...env,
|
|
@@ -1300,7 +1564,9 @@ export async function runPostAdmissionResumable<
|
|
|
1300
1564
|
persistRunState: false,
|
|
1301
1565
|
// #600: every attempt (initial + auto-resume) writes seat engine when present.
|
|
1302
1566
|
...(effectiveEngine === undefined ? {} : { effectiveEngine }),
|
|
1303
|
-
})
|
|
1567
|
+
});
|
|
1568
|
+
return settleDeferredPersist(admitted, env.principalAuthority, adapters, attemptIo, result);
|
|
1569
|
+
},
|
|
1304
1570
|
});
|
|
1305
1571
|
}
|
|
1306
1572
|
|
|
@@ -1402,7 +1668,11 @@ export async function runPostAdmissionManualResume<
|
|
|
1402
1668
|
result.terminal !== undefined &&
|
|
1403
1669
|
isLawfulTypedTerminalOutcome(result.terminal.roleOutcome)
|
|
1404
1670
|
) {
|
|
1405
|
-
|
|
1671
|
+
// dispatchPostAdmissionTurn already persisted this lawful outcome inline
|
|
1672
|
+
// (persistRunState defaults true here — no station-child/loop deferral)
|
|
1673
|
+
// through its own settleAfterTurnStarted-backed branches; a lawful result
|
|
1674
|
+
// only ever reaches this point once that persist has already succeeded
|
|
1675
|
+
// (#836 r12 class 3 dedup — one persist owner, not a second here).
|
|
1406
1676
|
io.stdout(formatTerminalResult(result.terminal));
|
|
1407
1677
|
}
|
|
1408
1678
|
if (result.terminal !== undefined) {
|