@sema-agent/server 7.110.0 → 7.111.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/MIGRATION.md +8 -0
- package/dist/approval-ask-audit-store.d.ts +38 -25
- package/dist/approval-ask-audit-store.js +26 -59
- package/dist/bench/s1/run-firm.d.ts +11 -0
- package/dist/bench/s1/run-firm.js +47 -32
- package/dist/boot/coordinators.js +1 -1
- package/dist/boot/session-faces.d.ts +4 -0
- package/dist/boot/session-faces.js +3 -1
- package/dist/boot/stage-07-capability-layer.d.ts +1 -0
- package/dist/boot/stage-07-capability-layer.js +4 -3
- package/dist/boot/stage-08-reapers.d.ts +1 -0
- package/dist/boot/stage-09-leader.d.ts +1 -0
- package/dist/boot/stage-09-leader.js +2 -1
- package/dist/boot/stage-10-http-server.d.ts +1 -0
- package/dist/boot/workflow-orchestration.js +1 -1
- package/dist/http/resume-legs.js +6 -3
- package/dist/http/routes/runs.js +14 -1
- package/dist/http/routes/tasks.js +8 -6
- package/dist/http/server.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/instruction-selection.d.ts +34 -0
- package/dist/instruction-selection.js +23 -0
- package/dist/observability/corrupt-read-seat.d.ts +18 -0
- package/dist/observability/corrupt-read-seat.js +18 -0
- package/dist/observability/fail-open.d.ts +15 -3
- package/dist/observability/fail-open.js +15 -3
- package/dist/orchestration/workflow-agent-session-index.d.ts +12 -23
- package/dist/orchestration/workflow-agent-session-index.js +11 -50
- package/dist/orchestration/workflow-notify-journal.d.ts +11 -8
- package/dist/orchestration/workflow-notify-journal.js +20 -36
- package/dist/plugins/file-outcome-sink.d.ts +4 -1
- package/dist/plugins/file-outcome-sink.js +9 -3
- package/dist/plugins/file-run-store.js +3 -3
- package/dist/plugins/retention-store-sql.d.ts +1 -1
- package/dist/plugins/retention-store-sql.js +2 -0
- package/dist/plugins/store-backend.js +1 -0
- package/dist/plugins/store-contracts.d.ts +19 -2
- package/dist/plugins/store-contracts.js +9 -0
- package/dist/plugins/user-input-ledger-file.d.ts +4 -2
- package/dist/plugins/user-input-ledger-file.js +11 -1
- package/dist/plugins/user-input-ledger-sql.d.ts +14 -4
- package/dist/plugins/user-input-ledger-sql.js +46 -18
- package/dist/project-memory.d.ts +10 -2
- package/dist/project-memory.js +5 -2
- package/dist/runs.js +5 -3
- package/dist/trace/ledger-sink.d.ts +4 -0
- package/dist/trace/ledger-sink.js +1 -1
- package/dist/trace/project.d.ts +11 -3
- package/dist/trace/project.js +6 -5
- package/dist/trace/self-minted-wire.d.ts +26 -0
- package/dist/trace/self-minted-wire.js +9 -0
- package/dist/trace/wire-projection-faces.d.ts +3 -3
- package/dist/trace/wire-projection-faces.js +4 -2
- package/dist/user-input-ledger.d.ts +101 -48
- package/dist/user-input-ledger.js +52 -35
- package/package.json +2 -2
|
@@ -28,6 +28,7 @@ import { failOpenTagForDroppedFrame, recordFailOpen } from "../../observability/
|
|
|
28
28
|
import { buildSyncSubmitBody } from "../sync-submit-body.js";
|
|
29
29
|
import { assertNever } from "../route-ctx.js";
|
|
30
30
|
import { withModelReachScope } from "../../model-reach-scope.js";
|
|
31
|
+
import { createInstructionSelectionLeg } from "../../instruction-selection.js";
|
|
31
32
|
const DISCONNECT_PARK_GRACE_MS = 10_000;
|
|
32
33
|
function sseData(res, payload) {
|
|
33
34
|
const anchor = payload.eventId;
|
|
@@ -114,6 +115,7 @@ export async function handleTasks(req, res, match, ctx) {
|
|
|
114
115
|
const principal = prepared.auth?.principal;
|
|
115
116
|
const wiringOperatorFace = explicitOperatorOk(gatedPrincipal(req, deps.config), deps.config.operatorPrincipals);
|
|
116
117
|
let wiringReceipt;
|
|
118
|
+
const instructionLeg = createInstructionSelectionLeg();
|
|
117
119
|
const withRunReceipt = (out) => wiringReceipt !== undefined ? { ...out, wiringManifest: wiringReceipt } : out;
|
|
118
120
|
if (liveStream) {
|
|
119
121
|
if (prepared.verify || prepared.cascade) {
|
|
@@ -261,7 +263,7 @@ export async function handleTasks(req, res, match, ctx) {
|
|
|
261
263
|
if (durableTaskId && deps.runStore) {
|
|
262
264
|
const rs = deps.runStore;
|
|
263
265
|
const tid = durableTaskId;
|
|
264
|
-
ledgerSink = createLedgerSink({ appendEvent: (seq, type, data) => rs.appendEvent(tid, seq, type, data), persistThinking: deps.config.traceThinking, onActivity: (kind, statusData) => recordTurnActivity(tid, kind, statusData) });
|
|
266
|
+
ledgerSink = createLedgerSink({ appendEvent: (seq, type, data) => rs.appendEvent(tid, seq, type, data), persistThinking: deps.config.traceThinking, onActivity: (kind, statusData) => recordTurnActivity(tid, kind, statusData), instructionsSegment: instructionLeg.segment });
|
|
265
267
|
usageKey = tid;
|
|
266
268
|
deps.modelUsage?.register(tid);
|
|
267
269
|
const owner = principal ?? null;
|
|
@@ -504,7 +506,7 @@ export async function handleTasks(req, res, match, ctx) {
|
|
|
504
506
|
sseData(res, { type: "compaction_outcome", ...compactionOutcomeEventData(ev) });
|
|
505
507
|
}
|
|
506
508
|
else if (ev.type === "wiring_manifest") {
|
|
507
|
-
const wiringFace = wiringManifestFaceEventData(ev, wiringOperatorFace);
|
|
509
|
+
const wiringFace = wiringManifestFaceEventData(ev, wiringOperatorFace, instructionLeg.segment());
|
|
508
510
|
wiringReceipt ??= wiringFace;
|
|
509
511
|
sseData(res, { type: "wiring_manifest", ...wiringFace });
|
|
510
512
|
}
|
|
@@ -647,7 +649,7 @@ export async function handleTasks(req, res, match, ctx) {
|
|
|
647
649
|
});
|
|
648
650
|
}
|
|
649
651
|
const withApproval = () => approvalCtx && deps.toolApproval ? deps.toolApproval.runWithContext(approvalCtx, withQuestion) : withQuestion();
|
|
650
|
-
await withModelReachScope(prepared.spec.sessionId, () => deps.sendUserFile
|
|
652
|
+
await instructionLeg.run(prepared.spec.sessionId, () => withModelReachScope(prepared.spec.sessionId, () => deps.sendUserFile
|
|
651
653
|
? deps.sendUserFile.runWithContext({
|
|
652
654
|
taskId: askTaskId,
|
|
653
655
|
emit: async (f) => {
|
|
@@ -658,7 +660,7 @@ export async function handleTasks(req, res, match, ctx) {
|
|
|
658
660
|
}
|
|
659
661
|
},
|
|
660
662
|
}, withApproval)
|
|
661
|
-
: withApproval());
|
|
663
|
+
: withApproval()));
|
|
662
664
|
if (durableTaskId && deps.runStore) {
|
|
663
665
|
const finalPlane = finalResult ? outwardPlane(finalResult.terminal) : undefined;
|
|
664
666
|
if (finalResult && finalPlane?.status === "suspended" && deps.checkpointStore)
|
|
@@ -836,7 +838,7 @@ export async function handleTasks(req, res, match, ctx) {
|
|
|
836
838
|
const observeSyncLegEvent = (ev) => {
|
|
837
839
|
if (ev.type !== "wiring_manifest" || wiringReceipt !== undefined)
|
|
838
840
|
return;
|
|
839
|
-
wiringReceipt = wiringManifestFaceEventData(ev, wiringOperatorFace);
|
|
841
|
+
wiringReceipt = wiringManifestFaceEventData(ev, wiringOperatorFace, instructionLeg.segment());
|
|
840
842
|
};
|
|
841
843
|
let result;
|
|
842
844
|
let cancelVerbLabel = false;
|
|
@@ -850,7 +852,7 @@ export async function handleTasks(req, res, match, ctx) {
|
|
|
850
852
|
observeSyncLegEvent(ev);
|
|
851
853
|
return stream.result();
|
|
852
854
|
};
|
|
853
|
-
result = await withPrincipal(principal, () => prepared.verify ? verifyLeg(prepared.verify) : prepared.cascade ? cascadeLeg() : plainLeg());
|
|
855
|
+
result = await instructionLeg.run(prepared.spec.sessionId, () => withPrincipal(principal, () => prepared.verify ? verifyLeg(prepared.verify) : prepared.cascade ? cascadeLeg() : plainLeg()));
|
|
854
856
|
}
|
|
855
857
|
finally {
|
|
856
858
|
counters.uncountedBillableInflight--;
|
package/dist/http/server.d.ts
CHANGED
|
@@ -218,7 +218,7 @@ export interface ServiceStoreDeps {
|
|
|
218
218
|
* 已配 AND 有 store backend(main.ts 建;写点在两条 send lane 的 withLedgerRecording)。 */
|
|
219
219
|
sendFileLedger?: import("../plugins/send-file-ledger.js").SendFileLedger;
|
|
220
220
|
/** S-928 用户输入受理账本(「200 applied」受理的影子;单写者 = `src/user-input-ledger.ts` 的活对象,boot 装配在 stage-07 并跑一次收敛)。
|
|
221
|
-
* 在场 ⇔ 有 store backend(生产恒与 `runStore` 同源于 backend)。消费点:steer 的 live
|
|
221
|
+
* 在场 ⇔ 有 store backend(生产恒与 `runStore` 同源于 backend)。消费点:steer 的 live 腿 / interrupt{text} / 同步子代的 steer(S-966)受理前写 `accepted`(写不进 ⇒ 503
|
|
222
222
|
* `steering.ledger_unavailable`)、三条 run 腿开通告口那一拍铸 `crashed` 通告并在收场时 settle、`GET /v1/sessions/:id` 的
|
|
223
223
|
* `userInputUndrained` 读面。缺席只出现在不接 backend 的 stub-harness 上(那时没有这一面,行为与修前逐字相同)。 */
|
|
224
224
|
userInputLedger?: import("../user-input-ledger.js").UserInputLedger;
|
package/dist/index.d.ts
CHANGED
|
@@ -29,5 +29,5 @@ export { createKeyResolver, resolveModelApiKey, type ModelKeyRef } from "./key-r
|
|
|
29
29
|
export { isModelKeyPoison, ModelKeyPoisonedError, type ModelKeyPoison, type ModelKeyPoisonReason } from "./key-resolver.js";
|
|
30
30
|
export { RETIRED_ENVS, type RetiredEnv, type RetiredEnvKind, type RetiredEnvWire } from "./config.js";
|
|
31
31
|
export { CATALOG_ENTRY_HEADER_LANES, CATALOG_ENTRY_HEADER_NAMES, type CatalogEntryHeaderName } from "./model-entry-headers.js";
|
|
32
|
-
export type { UserInputLedgerStore, UserInputAcceptance, NewUserInputAcceptance, OpenScanCursor, SettleHow, WriterGoneEvidence } from "./user-input-ledger.js";
|
|
32
|
+
export type { UserInputLedgerStore, UserInputAcceptance, NewUserInputAcceptance, OpenScanCursor, OpenScanPage, SettleHow, WriterGoneEvidence } from "./user-input-ledger.js";
|
|
33
33
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { InstructionChainMember } from "./project-memory.js";
|
|
2
|
+
/** wire 段 `wiring_manifest.instructions` 的形。`selected` 的成员拼写 = `INSTRUCTION_FILE_CHAIN` 的成员(相对 cwd)。 */
|
|
3
|
+
export interface InstructionsSegment {
|
|
4
|
+
readonly selected: readonly InstructionChainMember[];
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* 一次 loader 调用对**腿**说了什么:
|
|
8
|
+
* · `stated: false` —— 没有陈述(走链之前的门拦下了:无手 / cwd 不是本机绝对目录;或这是委派子代的 prepare);
|
|
9
|
+
* · `stated: true` —— 走了链,`file` = 选中的链成员,`null` = 一个都没有。
|
|
10
|
+
* 判别式显式写出来(不拿 `undefined` / `null` 两个空值各代表一件事 —— O6 那条教训:「不适用」不是「来源 = 无」)。
|
|
11
|
+
*/
|
|
12
|
+
export type LegInstructionStatement = {
|
|
13
|
+
readonly stated: false;
|
|
14
|
+
} | {
|
|
15
|
+
readonly stated: true;
|
|
16
|
+
readonly file: InstructionChainMember | null;
|
|
17
|
+
};
|
|
18
|
+
/** 一条腿的指令文件选择:开作用域 + 读段。每条投 `wiring_manifest` 的腿(流式 / 非流式 / bg / 续跑)各建一只。 */
|
|
19
|
+
export interface InstructionSelectionLeg {
|
|
20
|
+
/** 在这条腿的作用域里跑它的模型驱动(引擎的 prepare 在里面调 loader)。`sessionId` = 这条腿的会话 —— 作用域里只有**同会话**的 loader 调用
|
|
21
|
+
* 才算这条腿自己的 prepare([ref] opus 腿 F1:wake 续跑在腿自己的 prepare 之前同步跑部署 `userPromptSubmit` 的 agent 型 hook,hook agent 是另一只
|
|
22
|
+
* 会话、却与本进程共用同一只 loader ⇒ 只按「第一次调用」会被它抢先封槽)。嵌套时内层覆盖外层 —— 每条腿说自己的。 */
|
|
23
|
+
run<T>(sessionId: string | undefined, fn: () => T): T;
|
|
24
|
+
/** 这条腿的 `instructions` 段;`undefined` ⇒ 段缺席。在投帧那一刻读:core 在推帧之前已经 await 过 loader。 */
|
|
25
|
+
segment(): InstructionsSegment | undefined;
|
|
26
|
+
}
|
|
27
|
+
export declare function createInstructionSelectionLeg(): InstructionSelectionLeg;
|
|
28
|
+
/**
|
|
29
|
+
* loader 侧唯一写口:当前作用域里、**同会话的**第一次调用封槽(`sessionId` = loader ctx 带的会话;不等于腿的会话 —— hook agent / 子代 /
|
|
30
|
+
* 别的嵌套 run 的 prepare —— 一律不算,也不封槽,等这条腿自己的那一次);作用域外(run-local、leader、council 子任务 …)无效。
|
|
31
|
+
* 「身份 = 作用域 ∧ 同会话」两条都要:只靠作用域会被同进程共用 loader 的别的 Runner 抢先(F1);只靠会话会让同会话的并发腿 / 快速续跑串值。
|
|
32
|
+
*/
|
|
33
|
+
export declare function settleLegInstructionStatement(statement: LegInstructionStatement, sessionId: string | undefined): void;
|
|
34
|
+
//# sourceMappingURL=instruction-selection.d.ts.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
+
const legScope = new AsyncLocalStorage();
|
|
3
|
+
export function createInstructionSelectionLeg() {
|
|
4
|
+
let slot;
|
|
5
|
+
return {
|
|
6
|
+
run: (sessionId, fn) => {
|
|
7
|
+
slot = { sessionId, settled: false };
|
|
8
|
+
return legScope.run(slot, fn);
|
|
9
|
+
},
|
|
10
|
+
segment: () => slot?.segment,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export function settleLegInstructionStatement(statement, sessionId) {
|
|
14
|
+
const slot = legScope.getStore();
|
|
15
|
+
if (slot === undefined || slot.settled)
|
|
16
|
+
return;
|
|
17
|
+
if (slot.sessionId !== undefined && sessionId !== slot.sessionId)
|
|
18
|
+
return;
|
|
19
|
+
slot.settled = true;
|
|
20
|
+
if (statement.stated)
|
|
21
|
+
slot.segment = { selected: statement.file === null ? [] : [statement.file] };
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=instruction-selection.js.map
|
|
@@ -150,6 +150,24 @@ export declare const JSONL_REPLAY_SEATS: {
|
|
|
150
150
|
readonly tag: "server.send-file-ledger.corrupt-record-skipped";
|
|
151
151
|
readonly note: "F: a skipped ledger row means that issued link is missing from its tenant's listing (the stored object itself is untouched).";
|
|
152
152
|
};
|
|
153
|
+
readonly "approval-ask-audit": {
|
|
154
|
+
readonly direction: "fail-open";
|
|
155
|
+
readonly event: "approval_ask_audit_corrupt_read";
|
|
156
|
+
readonly tag: "server.approval-ask-audit.corrupt-record-skipped";
|
|
157
|
+
readonly note: "F: a skipped ask-audit record is one audit row missing from the boot crash-convergence read (an ask / settle / leg-close fact gone ⇒ that orphan is listed on a thinner basis or not at all, never a gate — the audit store gates nothing and the approval path never reads it back).";
|
|
158
|
+
};
|
|
159
|
+
readonly "workflow-notify-journal": {
|
|
160
|
+
readonly direction: "fail-open";
|
|
161
|
+
readonly event: "workflow_notify_journal_corrupt_read";
|
|
162
|
+
readonly tag: "server.workflow-notify-journal.corrupt-record-skipped";
|
|
163
|
+
readonly note: "F: a skipped notify-journal record is one run's pending entry (or its ack) missing from the boot replay. The recovery sweep walks the journal, so a lost pending line means that run's completion notify is not re-derived after a crash (the live in-process notify and the WorkflowStatus poll floor are untouched); a lost ack line means one extra idempotent re-delivery (the receiver dedups on runId). It gates no permission and changes no run.";
|
|
164
|
+
};
|
|
165
|
+
readonly "workflow-agent-session-index": {
|
|
166
|
+
readonly direction: "fail-open";
|
|
167
|
+
readonly event: "workflow_agent_session_ledger_line_rejected";
|
|
168
|
+
readonly tag: "server.workflow-agent-session-index.corrupt-record-skipped";
|
|
169
|
+
readonly note: "F: a skipped index line leaves that run on its previous known-good snapshot; a /decide for a park the line should have indexed finds no row and falls back to the legacy lane (an honest miss, never a mis-route — the redeem key is compared verbatim on the run record, not read from this index).";
|
|
170
|
+
};
|
|
153
171
|
readonly "user-input-ledger": {
|
|
154
172
|
readonly direction: "fail-open";
|
|
155
173
|
readonly event: "user_input_ledger_corrupt_read";
|
|
@@ -93,6 +93,24 @@ export const JSONL_REPLAY_SEATS = {
|
|
|
93
93
|
tag: "server.send-file-ledger.corrupt-record-skipped",
|
|
94
94
|
note: "F: a skipped ledger row means that issued link is missing from its tenant's listing (the stored object itself is untouched).",
|
|
95
95
|
},
|
|
96
|
+
"approval-ask-audit": {
|
|
97
|
+
direction: "fail-open",
|
|
98
|
+
event: "approval_ask_audit_corrupt_read",
|
|
99
|
+
tag: "server.approval-ask-audit.corrupt-record-skipped",
|
|
100
|
+
note: "F: a skipped ask-audit record is one audit row missing from the boot crash-convergence read (an ask / settle / leg-close fact gone ⇒ that orphan is listed on a thinner basis or not at all, never a gate — the audit store gates nothing and the approval path never reads it back).",
|
|
101
|
+
},
|
|
102
|
+
"workflow-notify-journal": {
|
|
103
|
+
direction: "fail-open",
|
|
104
|
+
event: "workflow_notify_journal_corrupt_read",
|
|
105
|
+
tag: "server.workflow-notify-journal.corrupt-record-skipped",
|
|
106
|
+
note: "F: a skipped notify-journal record is one run's pending entry (or its ack) missing from the boot replay. The recovery sweep walks the journal, so a lost pending line means that run's completion notify is not re-derived after a crash (the live in-process notify and the WorkflowStatus poll floor are untouched); a lost ack line means one extra idempotent re-delivery (the receiver dedups on runId). It gates no permission and changes no run.",
|
|
107
|
+
},
|
|
108
|
+
"workflow-agent-session-index": {
|
|
109
|
+
direction: "fail-open",
|
|
110
|
+
event: "workflow_agent_session_ledger_line_rejected",
|
|
111
|
+
tag: "server.workflow-agent-session-index.corrupt-record-skipped",
|
|
112
|
+
note: "F: a skipped index line leaves that run on its previous known-good snapshot; a /decide for a park the line should have indexed finds no row and falls back to the legacy lane (an honest miss, never a mis-route — the redeem key is compared verbatim on the run record, not read from this index).",
|
|
113
|
+
},
|
|
96
114
|
"user-input-ledger": {
|
|
97
115
|
direction: "fail-open",
|
|
98
116
|
event: "user_input_ledger_corrupt_read",
|
|
@@ -317,17 +317,29 @@ export declare const FAIL_OPEN_TAGS: {
|
|
|
317
317
|
readonly cls: "F";
|
|
318
318
|
readonly note: "S-582(`plugins/send-file-ledger.ts`,local 车道的发文件账本):一条账行读不出形(`42` / 缺 id·scope·objectKey 三元组 / 中间半截 JSON)⇒ 跳过它继续。最坏后果 = 那条已签发的链接在它租户的列表里**看不见**(对象本身没动;账本本来就不存 URL)。治理面少一行是可见性损失,不是放行 ⇒ F;但它恰是治理面要看的那一类事实,所以必须留痕 —— 修前零披露。";
|
|
319
319
|
};
|
|
320
|
+
readonly "server.approval-ask-audit.corrupt-record-skipped": {
|
|
321
|
+
readonly cls: "F";
|
|
322
|
+
readonly note: "S-967(`approval-ask-audit-store.ts`,local 车道 File ask 审计店的 boot 重放;登记名 `approval-ask-audit`):账本**中间**一行读不出形(`42` / 数组 / 缺键 / 词表外 `kind`·`outcome`·`orphanState` / 半截 JSON;撕尾不走本 tag)⇒ 跳过它继续。最坏后果按行种:丢 `ask` ⇒ 那只孤儿在崩溃收敛读面缺席(无身份可列);丢 `settle` ⇒ 该组按 pending 臂收(审批门在执行之前 ⇒ 若这条 settle 其实是 `allowed` 且工具已执行,`resumeSafe:true` 是错的 —— 与头注「双故障窗」同族);丢 `leg_closed` ⇒ decided 臂多收一行(保守方向);丢 `crash_converged` ⇒ 下一次 boot 重收(幂等);丢 `interrupted_by_shutdown` / `late_settle` ⇒ 成因注退回 `crashed_before_park` / 少一行取证。审计店不开门、不改任何审批结算 ⇒ F。修前:重放坏行只计入 `convergeCrashedAsks().corruptLines`(boot 日志一个数),**无逐条披露、无 tag**。";
|
|
323
|
+
};
|
|
324
|
+
readonly "server.workflow-notify-journal.corrupt-record-skipped": {
|
|
325
|
+
readonly cls: "F";
|
|
326
|
+
readonly note: "S-977(`orchestration/workflow-notify-journal.ts`,local 车道 File notify journal 的 boot 重放;登记名 `workflow-notify-journal`):账本**中间**一行读不出形(`42` / 数组 / 缺 runId·scope / `acked` 非布尔 / 半截 JSON;撕尾不走本 tag)⇒ 跳过它继续。最坏后果按行种:丢 `pending` 行(`record` 写下的那条)⇒ 那条 run 不在恢复积压里,崩溃丢掉的终态通告 boot 恢复扫描不再重导(live 进程内通告与 `WorkflowStatus` 轮询地板不受影响);丢 `acked` 行 ⇒ 该 run 读回 pending(或前一份已知良好的条目),多一次幂等重投(接收方按 runId 去重)。账本不开门、不改任何 run 的执行或授权 ⇒ F。修前:坏行 / 缺键行**静默**(解析失败 `continue`、只判 `typeof runId === \"string\"`)。";
|
|
327
|
+
};
|
|
328
|
+
readonly "server.workflow-agent-session-index.corrupt-record-skipped": {
|
|
329
|
+
readonly cls: "F";
|
|
330
|
+
readonly note: "S-977(`orchestration/workflow-agent-session-index.ts`,local 车道 workflow 出身 park 的 join 索引账本的 boot 重放;登记名 `workflow-agent-session-index`):账本**中间**一行读不出形(`42` / 数组 / 缺 `runId`·`rows` / 任一行成员缺身份位 / 半截 JSON;撕尾不走本 tag)⇒ **整行**跳过,那条 run 保留上一份已知良好的快照(不做「丢坏成员、留好成员」—— 那会铸出比真相少几条 park 的行集)。最坏后果 = 该 run 的 park 在索引里缺行 ⇒ `/decide` 找不到它、退回 legacy 腿(409 `conflict.resume_context_unavailable`):诚实 miss,不是错配 —— 赎回键由记录上的 `parks[]` 逐字比对,不读本索引。索引不开门 ⇒ F。修前:形不对的整行响亮(`workflow_agent_session_ledger_line_rejected`,同事件名保留)但**无 tag**,带换行的半截 JSON 静默 `continue`。";
|
|
331
|
+
};
|
|
320
332
|
readonly "server.user-input-ledger.append-failed": {
|
|
321
333
|
readonly cls: "F";
|
|
322
|
-
readonly note: "S-928(`src/user-input-ledger.ts`):200 承诺**之后**的一次账本写失败 —— detail 的 `op=` 点名是哪一种:`settle`(腿在本进程收场)/ `withdraw`(引擎没收下这次 steer)/ `converge`(收敛器判孤儿)/ `announce`(通告已投出,记「告知过」)。放行的最坏后果逐个说清:settle / withdraw 漏写 ⇒ 这次受理在账上仍是 open ——
|
|
334
|
+
readonly note: "S-928(`src/user-input-ledger.ts`):200 承诺**之后**的一次账本写失败 —— detail 的 `op=` 点名是哪一种:`settle`(腿在本进程收场)/ `withdraw`(引擎没收下这次 steer)/ `converge`(收敛器判孤儿)/ `announce`(通告已投出,记「告知过」)。放行的最坏后果逐个说清:settle / withdraw 漏写 ⇒ 这次受理在账上仍是 open —— 本进程下一次收敛扫描补结清(本进程写的、已不在活腿上 ⇒ leg_over);进程在那之前就崩了 ⇒ 下一次 boot 的收敛读 run 店判(S-969 L8 起两车道同一只判词:承载它的 run 正常翻面 / 已 park ⇒ leg_over 补结清、不告知;落款死亡判决或写者已死仍 running ⇒ crashed)—— 仍会多说一句的只剩两形:withdraw 漏写后那条腿崩了(一次没变成 200 的受理被告知一次);settle 漏写后本进程续跑了同一条 run、续跑腿崩了(run 行说的是同一 taskId 上**最新**那条腿)。方向都是多说,不漏;converge 漏写 ⇒ 留在 open,下一次扫描再判(延迟,不丢);announce 漏写 ⇒ 下一条 run 再说一遍(至多一次退化成至少一次)。都是**告知面**的偏差,不开任何门、不改任何 run 的执行 ⇒ F。计数非零 = 这台机器的账本写不动了(local:数据根盘满 / 只读;SQL:库不可达),steer 此刻多半也在回 503。";
|
|
323
335
|
};
|
|
324
336
|
readonly "server.user-input-ledger.read-failed": {
|
|
325
337
|
readonly cls: "F";
|
|
326
|
-
readonly note: "S-928(`src/user-input-ledger.ts` / `http/routes/sessions.ts`):一次账本**读**失败 —— `op=converge`(收敛扫描读不出 open 受理 ⇒ 本轮不收敛,下一个 tick 再来)/ `op=judge`(
|
|
338
|
+
readonly note: "S-928(`src/user-input-ledger.ts` / `http/routes/sessions.ts`):一次账本**读**失败 —— `op=converge`(收敛扫描读不出 open 受理 ⇒ 本轮不收敛,下一个 tick 再来)/ `op=judge`(判词要读 run 店 —— S-969 L8 起两车道都读;一趟内同一 taskId 只读一次,读失败 ⇒ 同 run 的每一行各记一笔、留在 open、下一次扫描再判)/ `op=announce`(新 run 首拍读不出本会话的待告知受理 ⇒ 这一拍不告知,run 照跑,下一条 run 再试)/ `op=session-view`(`GET /v1/sessions/:id` 的 additive 键 `userInputUndrained` 读不出 ⇒ 键缺席、会话视图照常 200)。放行的最坏后果 = 一次「你的输入因崩溃丢了」的告知被推迟,或会话视图上这一格读作零条;不阻断任何 run、不改任何回执。反方向(读失败就拒跑 run / 整只会话视图 500)是拿一个告知面的抖动去打掉主路径,方向更坏。";
|
|
327
339
|
};
|
|
328
340
|
readonly "server.user-input-ledger.corrupt-record-skipped": {
|
|
329
341
|
readonly cls: "F";
|
|
330
|
-
readonly note: "S-928(`plugins/user-input-ledger-file.ts`,local 车道 File 孪生的 boot 重放;登记名 `user-input-ledger`):账本中间一行读不出形(`42` / 缺键 / 词表外的 `kind`·`input`·`how`·`cause` / 半截 JSON;撕尾不走本 tag)⇒
|
|
342
|
+
readonly note: "S-928(`plugins/user-input-ledger-file.ts`,local 车道 File 孪生的 boot 重放;登记名 `user-input-ledger`):账本中间一行读不出形(`42` / 缺键 / 词表外的 `kind`·`input`·`how`·`cause` / 半截 JSON;撕尾不走本 tag)⇒ 跳过它继续。S-969 L6 起 SQL 孪生(`plugins/user-input-ledger-sql.ts` `readRows`)同一只 tag:三只读口取到的行上读不出的列(`input_kind` 词表外 —— 新版本写的输入族 / 手改;收敛行缺 `state_at_ms`)⇒ 逐行跳过、其余照交,`listOpen` 的续翻游标按原始行推进(修前整页抛:收敛断点不前进、同会话通告与读面一并失效);坏行留在表里 ⇒ 每读一次计一次,非零 = 表里有本版本读不懂的行。最坏后果按行种:丢 `accepted` ⇒ 那次受理若真随崩溃丢了,不会被告知(= 本账之前的状态);丢 `settled` ⇒ 该受理在账上仍 open,下一趟收敛按 run 行判(S-969 L8,两车道同一只判词):本进程写的 / run 行已正常收场、已 park、易手 ⇒ 补结清、不告知;只有 run 行仍 `running` 且持有者是写者(local)、带死亡落款且持有者是写者、或行不在(local:File 店藏了读不出的行)⇒ 当成崩溃丢失告知一次;丢 `converged` ⇒ 下一次 boot 重收一次(幂等);丢 `announced` ⇒ 再告知一次;丢 `erased`(S-965,7.111.0 起的会话级墓碑;缺 `sessionId` 的那一行**不**读成「擦全部」)⇒ 被删会话的受理行在本进程的折叠里复现 —— 只有身份 + 时刻(无用户文本),读面 / 通告按 sessionId 取,同一个 id 被重新登记时新住客可见上一位的 `crashed` 告知(= 7.110.x 无级联时的状态);撕尾的 `erased` 不在此列:墓碑写在会话本体删除**之前**,撕掉 ⇒ DELETE 没有成功、会话还在,幂等重试重写。全在告知面,不开门 ⇒ F。修前不存在(本账本 S-928 新立)。";
|
|
331
343
|
};
|
|
332
344
|
readonly "server.outbound.connect-observer-threw": {
|
|
333
345
|
readonly cls: "F";
|
|
@@ -290,17 +290,29 @@ export const FAIL_OPEN_TAGS = {
|
|
|
290
290
|
cls: "F",
|
|
291
291
|
note: "S-582(`plugins/send-file-ledger.ts`,local 车道的发文件账本):一条账行读不出形(`42` / 缺 id·scope·objectKey 三元组 / 中间半截 JSON)⇒ 跳过它继续。最坏后果 = 那条已签发的链接在它租户的列表里**看不见**(对象本身没动;账本本来就不存 URL)。治理面少一行是可见性损失,不是放行 ⇒ F;但它恰是治理面要看的那一类事实,所以必须留痕 —— 修前零披露。",
|
|
292
292
|
},
|
|
293
|
+
"server.approval-ask-audit.corrupt-record-skipped": {
|
|
294
|
+
cls: "F",
|
|
295
|
+
note: "S-967(`approval-ask-audit-store.ts`,local 车道 File ask 审计店的 boot 重放;登记名 `approval-ask-audit`):账本**中间**一行读不出形(`42` / 数组 / 缺键 / 词表外 `kind`·`outcome`·`orphanState` / 半截 JSON;撕尾不走本 tag)⇒ 跳过它继续。最坏后果按行种:丢 `ask` ⇒ 那只孤儿在崩溃收敛读面缺席(无身份可列);丢 `settle` ⇒ 该组按 pending 臂收(审批门在执行之前 ⇒ 若这条 settle 其实是 `allowed` 且工具已执行,`resumeSafe:true` 是错的 —— 与头注「双故障窗」同族);丢 `leg_closed` ⇒ decided 臂多收一行(保守方向);丢 `crash_converged` ⇒ 下一次 boot 重收(幂等);丢 `interrupted_by_shutdown` / `late_settle` ⇒ 成因注退回 `crashed_before_park` / 少一行取证。审计店不开门、不改任何审批结算 ⇒ F。修前:重放坏行只计入 `convergeCrashedAsks().corruptLines`(boot 日志一个数),**无逐条披露、无 tag**。",
|
|
296
|
+
},
|
|
297
|
+
"server.workflow-notify-journal.corrupt-record-skipped": {
|
|
298
|
+
cls: "F",
|
|
299
|
+
note: "S-977(`orchestration/workflow-notify-journal.ts`,local 车道 File notify journal 的 boot 重放;登记名 `workflow-notify-journal`):账本**中间**一行读不出形(`42` / 数组 / 缺 runId·scope / `acked` 非布尔 / 半截 JSON;撕尾不走本 tag)⇒ 跳过它继续。最坏后果按行种:丢 `pending` 行(`record` 写下的那条)⇒ 那条 run 不在恢复积压里,崩溃丢掉的终态通告 boot 恢复扫描不再重导(live 进程内通告与 `WorkflowStatus` 轮询地板不受影响);丢 `acked` 行 ⇒ 该 run 读回 pending(或前一份已知良好的条目),多一次幂等重投(接收方按 runId 去重)。账本不开门、不改任何 run 的执行或授权 ⇒ F。修前:坏行 / 缺键行**静默**(解析失败 `continue`、只判 `typeof runId === \"string\"`)。",
|
|
300
|
+
},
|
|
301
|
+
"server.workflow-agent-session-index.corrupt-record-skipped": {
|
|
302
|
+
cls: "F",
|
|
303
|
+
note: "S-977(`orchestration/workflow-agent-session-index.ts`,local 车道 workflow 出身 park 的 join 索引账本的 boot 重放;登记名 `workflow-agent-session-index`):账本**中间**一行读不出形(`42` / 数组 / 缺 `runId`·`rows` / 任一行成员缺身份位 / 半截 JSON;撕尾不走本 tag)⇒ **整行**跳过,那条 run 保留上一份已知良好的快照(不做「丢坏成员、留好成员」—— 那会铸出比真相少几条 park 的行集)。最坏后果 = 该 run 的 park 在索引里缺行 ⇒ `/decide` 找不到它、退回 legacy 腿(409 `conflict.resume_context_unavailable`):诚实 miss,不是错配 —— 赎回键由记录上的 `parks[]` 逐字比对,不读本索引。索引不开门 ⇒ F。修前:形不对的整行响亮(`workflow_agent_session_ledger_line_rejected`,同事件名保留)但**无 tag**,带换行的半截 JSON 静默 `continue`。",
|
|
304
|
+
},
|
|
293
305
|
"server.user-input-ledger.append-failed": {
|
|
294
306
|
cls: "F",
|
|
295
|
-
note: "S-928(`src/user-input-ledger.ts`):200 承诺**之后**的一次账本写失败 —— detail 的 `op=` 点名是哪一种:`settle`(腿在本进程收场)/ `withdraw`(引擎没收下这次 steer)/ `converge`(收敛器判孤儿)/ `announce`(通告已投出,记「告知过」)。放行的最坏后果逐个说清:settle / withdraw 漏写 ⇒ 这次受理在账上仍是 open ——
|
|
307
|
+
note: "S-928(`src/user-input-ledger.ts`):200 承诺**之后**的一次账本写失败 —— detail 的 `op=` 点名是哪一种:`settle`(腿在本进程收场)/ `withdraw`(引擎没收下这次 steer)/ `converge`(收敛器判孤儿)/ `announce`(通告已投出,记「告知过」)。放行的最坏后果逐个说清:settle / withdraw 漏写 ⇒ 这次受理在账上仍是 open —— 本进程下一次收敛扫描补结清(本进程写的、已不在活腿上 ⇒ leg_over);进程在那之前就崩了 ⇒ 下一次 boot 的收敛读 run 店判(S-969 L8 起两车道同一只判词:承载它的 run 正常翻面 / 已 park ⇒ leg_over 补结清、不告知;落款死亡判决或写者已死仍 running ⇒ crashed)—— 仍会多说一句的只剩两形:withdraw 漏写后那条腿崩了(一次没变成 200 的受理被告知一次);settle 漏写后本进程续跑了同一条 run、续跑腿崩了(run 行说的是同一 taskId 上**最新**那条腿)。方向都是多说,不漏;converge 漏写 ⇒ 留在 open,下一次扫描再判(延迟,不丢);announce 漏写 ⇒ 下一条 run 再说一遍(至多一次退化成至少一次)。都是**告知面**的偏差,不开任何门、不改任何 run 的执行 ⇒ F。计数非零 = 这台机器的账本写不动了(local:数据根盘满 / 只读;SQL:库不可达),steer 此刻多半也在回 503。",
|
|
296
308
|
},
|
|
297
309
|
"server.user-input-ledger.read-failed": {
|
|
298
310
|
cls: "F",
|
|
299
|
-
note: "S-928(`src/user-input-ledger.ts` / `http/routes/sessions.ts`):一次账本**读**失败 —— `op=converge`(收敛扫描读不出 open 受理 ⇒ 本轮不收敛,下一个 tick 再来)/ `op=judge`(
|
|
311
|
+
note: "S-928(`src/user-input-ledger.ts` / `http/routes/sessions.ts`):一次账本**读**失败 —— `op=converge`(收敛扫描读不出 open 受理 ⇒ 本轮不收敛,下一个 tick 再来)/ `op=judge`(判词要读 run 店 —— S-969 L8 起两车道都读;一趟内同一 taskId 只读一次,读失败 ⇒ 同 run 的每一行各记一笔、留在 open、下一次扫描再判)/ `op=announce`(新 run 首拍读不出本会话的待告知受理 ⇒ 这一拍不告知,run 照跑,下一条 run 再试)/ `op=session-view`(`GET /v1/sessions/:id` 的 additive 键 `userInputUndrained` 读不出 ⇒ 键缺席、会话视图照常 200)。放行的最坏后果 = 一次「你的输入因崩溃丢了」的告知被推迟,或会话视图上这一格读作零条;不阻断任何 run、不改任何回执。反方向(读失败就拒跑 run / 整只会话视图 500)是拿一个告知面的抖动去打掉主路径,方向更坏。",
|
|
300
312
|
},
|
|
301
313
|
"server.user-input-ledger.corrupt-record-skipped": {
|
|
302
314
|
cls: "F",
|
|
303
|
-
note: "S-928(`plugins/user-input-ledger-file.ts`,local 车道 File 孪生的 boot 重放;登记名 `user-input-ledger`):账本中间一行读不出形(`42` / 缺键 / 词表外的 `kind`·`input`·`how`·`cause` / 半截 JSON;撕尾不走本 tag)⇒
|
|
315
|
+
note: "S-928(`plugins/user-input-ledger-file.ts`,local 车道 File 孪生的 boot 重放;登记名 `user-input-ledger`):账本中间一行读不出形(`42` / 缺键 / 词表外的 `kind`·`input`·`how`·`cause` / 半截 JSON;撕尾不走本 tag)⇒ 跳过它继续。S-969 L6 起 SQL 孪生(`plugins/user-input-ledger-sql.ts` `readRows`)同一只 tag:三只读口取到的行上读不出的列(`input_kind` 词表外 —— 新版本写的输入族 / 手改;收敛行缺 `state_at_ms`)⇒ 逐行跳过、其余照交,`listOpen` 的续翻游标按原始行推进(修前整页抛:收敛断点不前进、同会话通告与读面一并失效);坏行留在表里 ⇒ 每读一次计一次,非零 = 表里有本版本读不懂的行。最坏后果按行种:丢 `accepted` ⇒ 那次受理若真随崩溃丢了,不会被告知(= 本账之前的状态);丢 `settled` ⇒ 该受理在账上仍 open,下一趟收敛按 run 行判(S-969 L8,两车道同一只判词):本进程写的 / run 行已正常收场、已 park、易手 ⇒ 补结清、不告知;只有 run 行仍 `running` 且持有者是写者(local)、带死亡落款且持有者是写者、或行不在(local:File 店藏了读不出的行)⇒ 当成崩溃丢失告知一次;丢 `converged` ⇒ 下一次 boot 重收一次(幂等);丢 `announced` ⇒ 再告知一次;丢 `erased`(S-965,7.111.0 起的会话级墓碑;缺 `sessionId` 的那一行**不**读成「擦全部」)⇒ 被删会话的受理行在本进程的折叠里复现 —— 只有身份 + 时刻(无用户文本),读面 / 通告按 sessionId 取,同一个 id 被重新登记时新住客可见上一位的 `crashed` 告知(= 7.110.x 无级联时的状态);撕尾的 `erased` 不在此列:墓碑写在会话本体删除**之前**,撕掉 ⇒ DELETE 没有成功、会话还在,幂等重试重写。全在告知面,不开门 ⇒ F。修前不存在(本账本 S-928 新立)。",
|
|
304
316
|
},
|
|
305
317
|
"server.outbound.connect-observer-threw": {
|
|
306
318
|
cls: "F",
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type WorkflowRun } from "@sema-agent/core";
|
|
2
|
+
import type { Logger } from "../observability/logger.js";
|
|
2
3
|
/** 一条索引行:**子会话 id 是主键**(会话 id 全局唯一 ⇒ 读口天然是单行精确查,无分页假阴性)。 */
|
|
3
4
|
export interface WorkflowAgentSessionRow {
|
|
4
5
|
/** parked 的那只 workflow 子代自己的会话 id(= `WorkflowAgentRun.sessionId` = 那条 checkpoint 行的 `sessionId`;
|
|
@@ -101,38 +102,26 @@ export declare function readAgentSessionLedgerLine(v: unknown): WorkflowAgentSes
|
|
|
101
102
|
* 单机车道的索引(`FileWorkflowRunStore` / `InMemoryWorkflowRunStore` 的同室孪生)。
|
|
102
103
|
*
|
|
103
104
|
* `root` 在场 ⇒ 追加式 JSONL 账本(与姊妹 {@link import("./workflow-notify-journal.js").FileWorkflowNotifyJournalStore}
|
|
104
|
-
* 逐字同形:0o700 目录 + 0o600
|
|
105
|
+
* 逐字同形:0o700 目录 + 0o600 账本、按行重放),重启后 park 仍可 join;缺席 ⇒ 纯内存
|
|
105
106
|
* (`WORKFLOW_RUN_STORE=memory` 的显式易失车道,与它的 run 店同寿命)。
|
|
106
107
|
*
|
|
107
108
|
* 账本的一行 = **一次 `syncRun` 的整份行集**(按 runId 后写覆盖),所以重放即收敛,不需要压缩腿。
|
|
109
|
+
*
|
|
110
|
+
* 追加 / 重放走本仓 JSONL 店的**共用口**(S-977;此前 ctor 里自写 `truncateTornTail` + 手写 `split("\n") + JSON.parse` 重放):
|
|
111
|
+
* 追加 = core `AppendLog`(惰性打开、撕尾在**打开与每次追加前**修 —— 修前只在 boot 修,运行期半写后的下一次成功写仍会被粘进残尾),
|
|
112
|
+
* 重放 = `replayJsonlSkipping`(登记座 `workflow-agent-session-index`:中间坏行 —— 含半截 JSON 与形不对的整行 —— 跳过 + 逐条披露 + F tag;
|
|
113
|
+
* 撕尾不计、不披露)。盘上字节 / 0o600 账本 / 0o700 目录与修前逐字同,升级零迁移。
|
|
108
114
|
*/
|
|
109
115
|
export declare class LocalWorkflowAgentSessionIndex implements WorkflowAgentSessionIndex {
|
|
110
116
|
private readonly fsyncEnabled;
|
|
111
|
-
/** 坏账本行的**响亮**出口(可选;缺席 ⇒ 那一行照样不入索引,只是没人听见)。形与 workflow 店族的
|
|
112
|
-
* `onWarn` 逐字同源(`workflow-completion-inbox.ts` 的那一只),不另立第二种披露通道。 */
|
|
113
|
-
private readonly onWarn?;
|
|
114
117
|
private readonly ledgerPath;
|
|
115
118
|
private readonly byRun;
|
|
116
119
|
private readonly bySession;
|
|
117
|
-
private
|
|
120
|
+
private log;
|
|
118
121
|
constructor(root?: string, fsyncEnabled?: boolean,
|
|
119
|
-
/** 坏账本行的**响亮**出口(可选;缺席 ⇒
|
|
120
|
-
*
|
|
121
|
-
onWarn?:
|
|
122
|
-
/**
|
|
123
|
-
* 打开账本时把**撕裂尾**(崩在 append 中途、末尾没有换行的那截字节)截回最后一个完整行边界。
|
|
124
|
-
*
|
|
125
|
-
* 🔴 为什么必须在**任何 append 之前**做(codex 修复验证轮 [medium],故障注入复现):残尾留在盘上时,
|
|
126
|
-
* 下一次 `syncRun` 会紧贴着它落字节 ⇒ `<残尾><新记录>` 在 replay 里是**一行**,JSON 解析失败被整行丢掉。
|
|
127
|
-
* 丢的**不是**那截未提交的残尾(丢它是对的),而是紧随其后那次**成功重试**写下的行 —— 于是「写失败了
|
|
128
|
-
* 下一次写会重试救回来」这条本模块与 `syncAgentSessionIndex` 都在依赖的性质当场失效,park 索引静默消失。
|
|
129
|
-
* 截尾之后 append 永远从一个干净的行边界开始,重试才真的救得回来。
|
|
130
|
-
*
|
|
131
|
-
* 截掉的只可能是**未提交**的字节(一条记录的耐久性以它那个换行为界,与 notify journal 同一条崩溃序),
|
|
132
|
-
* 所以这里不是丢数据;但它是一次真实的崩溃留痕,**响亮**一次([ref]:安全轴不许静默)。
|
|
133
|
-
*/
|
|
134
|
-
private truncateTornTail;
|
|
135
|
-
private replay;
|
|
122
|
+
/** 坏账本行的**响亮**出口(可选;缺席 ⇒ 重放属主退回 `console.warn`,不退回沉默)。形与日志座 `Logger["warn"]` 逐字同源,
|
|
123
|
+
* 不另立第二种披露通道。 */
|
|
124
|
+
onWarn?: Logger["warn"]);
|
|
136
125
|
/** 内存两张表的收敛(重放与写路径共用一份逻辑)。 */
|
|
137
126
|
private apply;
|
|
138
127
|
syncRun(runId: string, rows: readonly WorkflowAgentSessionRow[]): Promise<void>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { existsSync, fsyncSync, mkdirSync, openSync, readFileSync, truncateSync, writeSync } from "node:fs";
|
|
2
1
|
import { join } from "node:path";
|
|
2
|
+
import { AppendLog, ensureDir } from "@sema-agent/core";
|
|
3
|
+
import { replayJsonlSkipping } from "../observability/corrupt-read-seat.js";
|
|
3
4
|
const nonEmptyString = (v) => typeof v === "string" && v !== "";
|
|
4
5
|
export function readRunParks(run) {
|
|
5
6
|
if (typeof run !== "object" || run === null)
|
|
@@ -72,64 +73,27 @@ function readAgentSessionRow(v) {
|
|
|
72
73
|
return undefined;
|
|
73
74
|
return { sessionId, runId, agentKey, scope };
|
|
74
75
|
}
|
|
76
|
+
const LEDGER_LINE_SHAPE = {
|
|
77
|
+
what: "a workflow agent-session index line {runId, rows[]}",
|
|
78
|
+
read: readAgentSessionLedgerLine,
|
|
79
|
+
};
|
|
75
80
|
export class LocalWorkflowAgentSessionIndex {
|
|
76
81
|
fsyncEnabled;
|
|
77
|
-
onWarn;
|
|
78
82
|
ledgerPath;
|
|
79
83
|
byRun = new Map();
|
|
80
84
|
bySession = new Map();
|
|
81
|
-
|
|
85
|
+
log;
|
|
82
86
|
constructor(root, fsyncEnabled = true, onWarn) {
|
|
83
87
|
this.fsyncEnabled = fsyncEnabled;
|
|
84
|
-
this.onWarn = onWarn;
|
|
85
88
|
if (root === undefined) {
|
|
86
89
|
this.ledgerPath = undefined;
|
|
87
90
|
return;
|
|
88
91
|
}
|
|
89
92
|
const dir = join(root, "workflow-agent-sessions");
|
|
90
|
-
|
|
93
|
+
ensureDir(dir);
|
|
91
94
|
this.ledgerPath = join(dir, "index.jsonl");
|
|
92
|
-
this.
|
|
93
|
-
this.replay();
|
|
94
|
-
}
|
|
95
|
-
truncateTornTail() {
|
|
96
|
-
const path = this.ledgerPath;
|
|
97
|
-
if (path === undefined || !existsSync(path))
|
|
98
|
-
return;
|
|
99
|
-
const bytes = readFileSync(path);
|
|
100
|
-
if (bytes.length === 0 || bytes[bytes.length - 1] === 0x0a)
|
|
101
|
-
return;
|
|
102
|
-
const keep = bytes.lastIndexOf(0x0a) + 1;
|
|
103
|
-
truncateSync(path, keep);
|
|
104
|
-
this.onWarn?.("workflow_agent_session_ledger_torn_tail_truncated", {
|
|
105
|
-
path,
|
|
106
|
-
droppedBytes: bytes.length - keep,
|
|
107
|
-
note: "the last append never finished (no trailing newline) — those uncommitted bytes were cut back to the last complete line so the NEXT append starts on a clean boundary. Without the cut, the retry that follows would be glued onto the broken suffix and dropped as one unparsable line, i.e. the retry — not the torn write — is what would be lost.",
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
replay() {
|
|
111
|
-
if (this.ledgerPath === undefined || !existsSync(this.ledgerPath))
|
|
112
|
-
return;
|
|
113
|
-
for (const line of readFileSync(this.ledgerPath, "utf8").split("\n")) {
|
|
114
|
-
if (!line.trim())
|
|
115
|
-
continue;
|
|
116
|
-
let rec;
|
|
117
|
-
try {
|
|
118
|
-
rec = JSON.parse(line);
|
|
119
|
-
}
|
|
120
|
-
catch {
|
|
121
|
-
continue;
|
|
122
|
-
}
|
|
123
|
-
const entry = readAgentSessionLedgerLine(rec);
|
|
124
|
-
if (entry === undefined) {
|
|
125
|
-
this.onWarn?.("workflow_agent_session_ledger_line_rejected", {
|
|
126
|
-
path: this.ledgerPath,
|
|
127
|
-
note: "a committed ledger line did not read back as {runId, rows[]} — that run keeps its previous snapshot; a /decide for a park it should have indexed falls back to the legacy lane (honest miss, never a mis-route)",
|
|
128
|
-
});
|
|
129
|
-
continue;
|
|
130
|
-
}
|
|
95
|
+
for (const entry of replayJsonlSkipping(this.ledgerPath, "workflow-agent-session-index", LEDGER_LINE_SHAPE, onWarn).records)
|
|
131
96
|
this.apply(entry.runId, entry.rows);
|
|
132
|
-
}
|
|
133
97
|
}
|
|
134
98
|
apply(runId, rows) {
|
|
135
99
|
for (const old of this.byRun.get(runId) ?? []) {
|
|
@@ -145,11 +109,8 @@ export class LocalWorkflowAgentSessionIndex {
|
|
|
145
109
|
}
|
|
146
110
|
async syncRun(runId, rows) {
|
|
147
111
|
if (this.ledgerPath !== undefined) {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
writeSync(this.fd, `${JSON.stringify({ runId, rows })}\n`);
|
|
151
|
-
if (this.fsyncEnabled)
|
|
152
|
-
fsyncSync(this.fd);
|
|
112
|
+
this.log ??= new AppendLog(this.ledgerPath);
|
|
113
|
+
this.log.append({ runId, rows }, this.fsyncEnabled);
|
|
153
114
|
}
|
|
154
115
|
this.apply(runId, rows);
|
|
155
116
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type WorkflowRun, type WorkflowRunStore, type WorkflowRunStatus, type WorkflowRunSummary } from "@sema-agent/core";
|
|
2
2
|
import { type FleetEventBus } from "../fleet/fleet-bus.js";
|
|
3
3
|
import { type WorkflowAgentSessionIndex } from "./workflow-agent-session-index.js";
|
|
4
|
+
import type { Logger } from "../observability/logger.js";
|
|
4
5
|
/** A workflow completion notification's terminal payload — the bounded, redacted shape core's notifier seam
|
|
5
6
|
* carries, re-derivable from a durable {@link import("@sema-agent/core").WorkflowRun} on the recovery path. */
|
|
6
7
|
export interface WorkflowCompletionPayload {
|
|
@@ -201,6 +202,11 @@ export declare class WorkflowNotifyGate {
|
|
|
201
202
|
* appends, atomic single-line records. Single-instance / TOC-local: a cross-replica TiDB/PG port is a follow-on
|
|
202
203
|
* (the recovery sweep + gate are backend-agnostic).
|
|
203
204
|
*
|
|
205
|
+
* 追加 / 重放走本仓 JSONL 店的**共用口**(S-977;此前是第二 / 第三份私有实现):追加 = core `AppendLog`(惰性打开;单条 `writeSync`
|
|
206
|
+
* 循环写满、失败的写截回开写处;**撕尾在打开与每次追加前修**,所以崩在一次 append 中途之后的下一条成功写不会被粘进残尾),
|
|
207
|
+
* 重放 = `replayJsonlSkipping`(登记座 `workflow-notify-journal`:中间坏行跳过 + 逐条披露 + F tag;撕尾不计 —— 它是崩溃的正常落盘形;
|
|
208
|
+
* 末行 JSON 完整但缺换行的认下、下一次追加补换行)。盘上字节 / 0o600 账本 / 0o700 目录与修前逐字同,升级零迁移。
|
|
209
|
+
*
|
|
204
210
|
* The ledger only ever grows by one line per `record`/`ack`; an acked entry's line is not deleted (the replay
|
|
205
211
|
* folds it), so retention is a future compaction concern — the backlog `listPending` walks is bounded by
|
|
206
212
|
* IN-FLIGHT + un-swept runs, not history.
|
|
@@ -209,12 +215,9 @@ export declare class FileWorkflowNotifyJournalStore implements WorkflowNotifyJou
|
|
|
209
215
|
private readonly fsyncEnabled;
|
|
210
216
|
private readonly ledgerPath;
|
|
211
217
|
private readonly entries;
|
|
212
|
-
private
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
* (a crash mid-append) by dropping an unparsable trailing record — the same crash-safety FileWorkflowRunStore
|
|
216
|
-
* relies on (a partial append is simply not yet committed state). */
|
|
217
|
-
private replay;
|
|
218
|
+
private log;
|
|
219
|
+
/** @param warn 坏账本行的披露座(缺席 ⇒ 重放属主退回 `console.warn`,不退回沉默)。 */
|
|
220
|
+
constructor(root: string, fsyncEnabled?: boolean, warn?: Logger["warn"]);
|
|
218
221
|
/** Commit one entry: append the JSON line (fsync) THEN flip the in-memory map (crash-safe ordering — the
|
|
219
222
|
* durable record lands before the in-memory state the caller observes). */
|
|
220
223
|
private commit;
|
|
@@ -228,7 +231,7 @@ export declare class FileWorkflowNotifyJournalStore implements WorkflowNotifyJou
|
|
|
228
231
|
ack(runId: string, ackedAt: number): Promise<void>;
|
|
229
232
|
listPending(): Promise<WorkflowNotifyJournalEntry[]>;
|
|
230
233
|
get(runId: string): Promise<WorkflowNotifyJournalEntry | null>;
|
|
231
|
-
/** Release the append handle
|
|
234
|
+
/** Release the append handle — called on shutdown. core `AppendLog.close()` swallows its own `closeSync` error (never throws). */
|
|
232
235
|
close(): void;
|
|
233
236
|
/** Test/inspection: total entries (acked + pending). */
|
|
234
237
|
get size(): number;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { mkdirSync, readFileSync, existsSync, openSync, writeSync, fsyncSync, closeSync } from "node:fs";
|
|
2
1
|
import { join } from "node:path";
|
|
2
|
+
import { AppendLog, ensureDir } from "@sema-agent/core";
|
|
3
3
|
import { buildFleetWorkflowRow } from "../fleet/fleet-bus.js";
|
|
4
4
|
import { isTerminalWorkflowRowStatus, seedTerminalWorkflowRow } from "../fleet/fleet-terminal-window.js";
|
|
5
5
|
import { buildParkedAgentSessionRows, sameAgentSessionRows } from "./workflow-agent-session-index.js";
|
|
6
6
|
import { recordFailOpen } from "../observability/fail-open.js";
|
|
7
|
+
import { replayJsonlSkipping } from "../observability/corrupt-read-seat.js";
|
|
7
8
|
const SUMMARY_MAX = 500;
|
|
8
9
|
export function recoverySummary(status, error) {
|
|
9
10
|
if (status === "completed")
|
|
@@ -162,42 +163,31 @@ export class WorkflowNotifyGate {
|
|
|
162
163
|
return { scanned: pending.length, redelivered, stillRunning, abandoned };
|
|
163
164
|
}
|
|
164
165
|
}
|
|
166
|
+
const JOURNAL_ENTRY_SHAPE = {
|
|
167
|
+
what: "a notify-journal entry {runId: string, scope: string, acked: boolean}",
|
|
168
|
+
read(record) {
|
|
169
|
+
const { runId, scope, acked } = record;
|
|
170
|
+
if (typeof runId !== "string" || typeof scope !== "string" || typeof acked !== "boolean")
|
|
171
|
+
return undefined;
|
|
172
|
+
return record;
|
|
173
|
+
},
|
|
174
|
+
};
|
|
165
175
|
export class FileWorkflowNotifyJournalStore {
|
|
166
176
|
fsyncEnabled;
|
|
167
177
|
ledgerPath;
|
|
168
178
|
entries = new Map();
|
|
169
|
-
|
|
170
|
-
constructor(root, fsyncEnabled = true) {
|
|
179
|
+
log;
|
|
180
|
+
constructor(root, fsyncEnabled = true, warn) {
|
|
171
181
|
this.fsyncEnabled = fsyncEnabled;
|
|
172
182
|
const dir = join(root, "workflow-notify");
|
|
173
|
-
|
|
183
|
+
ensureDir(dir);
|
|
174
184
|
this.ledgerPath = join(dir, "journal.jsonl");
|
|
175
|
-
this.
|
|
176
|
-
|
|
177
|
-
replay() {
|
|
178
|
-
if (!existsSync(this.ledgerPath))
|
|
179
|
-
return;
|
|
180
|
-
const text = readFileSync(this.ledgerPath, "utf8");
|
|
181
|
-
for (const line of text.split("\n")) {
|
|
182
|
-
if (!line.trim())
|
|
183
|
-
continue;
|
|
184
|
-
let ev;
|
|
185
|
-
try {
|
|
186
|
-
ev = JSON.parse(line);
|
|
187
|
-
}
|
|
188
|
-
catch {
|
|
189
|
-
continue;
|
|
190
|
-
}
|
|
191
|
-
if (ev && typeof ev.runId === "string")
|
|
192
|
-
this.entries.set(ev.runId, ev);
|
|
193
|
-
}
|
|
185
|
+
for (const ev of replayJsonlSkipping(this.ledgerPath, "workflow-notify-journal", JOURNAL_ENTRY_SHAPE, warn).records)
|
|
186
|
+
this.entries.set(ev.runId, ev);
|
|
194
187
|
}
|
|
195
188
|
commit(entry) {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
writeSync(this.fd, `${JSON.stringify(entry)}\n`);
|
|
199
|
-
if (this.fsyncEnabled)
|
|
200
|
-
fsyncSync(this.fd);
|
|
189
|
+
this.log ??= new AppendLog(this.ledgerPath);
|
|
190
|
+
this.log.append(entry, this.fsyncEnabled);
|
|
201
191
|
this.entries.set(entry.runId, entry);
|
|
202
192
|
}
|
|
203
193
|
async record(input) {
|
|
@@ -226,14 +216,8 @@ export class FileWorkflowNotifyJournalStore {
|
|
|
226
216
|
return this.entries.get(runId) ?? null;
|
|
227
217
|
}
|
|
228
218
|
close() {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
closeSync(this.fd);
|
|
232
|
-
}
|
|
233
|
-
catch {
|
|
234
|
-
}
|
|
235
|
-
this.fd = undefined;
|
|
236
|
-
}
|
|
219
|
+
this.log?.close();
|
|
220
|
+
this.log = undefined;
|
|
237
221
|
}
|
|
238
222
|
get size() {
|
|
239
223
|
return this.entries.size;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type TaskOutcome as CoreTaskOutcome } from "@sema-agent/core";
|
|
2
2
|
/** The one write verb every outcome sink (TiDB/Pg ledger adapters + this File twin) exposes to main.ts,
|
|
3
3
|
* plus the OPTIONAL read aggregate backing `GET /v1/outcomes` (P2) — present on the SQL ledgers (their
|
|
4
4
|
* existing per-(signature, model) summary); absent here (the JSONL file IS the local dataset — a dashboard
|
|
@@ -18,7 +18,10 @@ export interface OutcomeSink {
|
|
|
18
18
|
}
|
|
19
19
|
export declare class FileOutcomeSink implements OutcomeSink {
|
|
20
20
|
private readonly path;
|
|
21
|
+
private log;
|
|
21
22
|
constructor(root: string);
|
|
22
23
|
recordCore(o: CoreTaskOutcome): Promise<void>;
|
|
24
|
+
/** 收追加口(`StoreBackend.close` 的优雅关闭腿;之后再写会重开)。core `AppendLog.close()` 自己吞 `closeSync` 的错,不抛。 */
|
|
25
|
+
dispose(): void;
|
|
23
26
|
}
|
|
24
27
|
//# sourceMappingURL=file-outcome-sink.d.ts.map
|