返回 CodeWhale
wf_a3_partial_failure_synthesis.workflow.js
根目录 / docs / examples / dogfood-automatic / wf_a3_partial_failure_synthesis.workflow.js
1 /**
2 * #4131 WF-A3 — partial failure + synthesis.
3 *
4 * parallel() uses all-settled semantics: a failed slot becomes null; the run
5 * continues so a synthesizer can still produce an operator summary. The slot
6 * is null but not anonymous — `slots.errors` carries `{ index, kind, message }`
7 * for every drop, so the summary can name what was lost instead of guessing.
8 *
9 * Run: /workflow run docs/examples/dogfood-automatic/wf_a3_partial_failure_synthesis.workflow.js
10 *
11 * For pure VM proof without model spend, use workflow-js unit tests:
12 * cargo test -p codewhale-workflow-js --locked parallel_fan_out_maps_one_failure_to_null_slot
13 */
14 export default async function () {
15 phase("Parallel scouts");
16 const slots = await parallel([
17 () =>
18 task({
19 description: "Return the string READY_A. Read-only.",
20 label: "scout-a",
21 type: "explore",
22 }),
23 () => { throw new Error("Demonstration: scout B could not produce a result"); },
24 () =>
25 task({
26 description: "Return the string READY_C. Read-only.",
27 label: "scout-c",
28 type: "explore",
29 }),
30 ]);
31
32 phase("Synthesize");
33 const surviving = (slots || []).filter((s) => s != null);
34 // The typed failure ledger: which slot died, and of what.
35 const dropped = (slots.errors || []).map(
36 (e) => `slot ${e.index} (${e.kind}): ${e.message}`,
37 );
38 for (const line of dropped) {
39 log(`dropped: ${line}`);
40 }
41 const summary = await task({
42 label: "synthesizer",
43 type: "review",
44 description: [
45 "Build one operator-facing summary from the surviving scout results.",
46 "Explicitly note which parallel slot failed, and why.",
47 `slot_count=${(slots || []).length} surviving=${surviving.length}`,
48 "dropped_slots:",
49 dropped.length ? dropped.join("\n") : "(none)",
50 "slots_json:",
51 JSON.stringify(slots),
52 ].join("\n"),
53 });
54
55 return {
56 scenario: "WF-A3",
57 slots,
58 surviving_count: surviving.length,
59 dropped_slots: dropped,
60 summary,
61 };
62 }
63
63 lines JAVASCRIPT