返回 CodeWhale
WORKFLOW_EXPERIMENTAL_SEARCH.md
根目录 / docs / WORKFLOW_EXPERIMENTAL_SEARCH.md
1 # Workflow Experimental Search
2
3 Experimental search is an option for **Workflow**, not a fourth mode and not a
4 second scheduler. Fleet owns the roster and deterministic member selection.
5 Runtime owns execution routes, concurrency, leases, and receipts. Workflow owns
6 the frozen order: independent generation, evaluation, selection, repair, and
7 verification.
8
9 The product vocabulary is Fleet (roster and selected member), Workflow (what
10 order), Lane (one running Workflow), Runtime (where/how/authority), and Operate
11 (the mode). Do not introduce
12 "WhaleFlow" as a current synonym.
13
14 ## Current foundation
15
16 - The imperative Workflow VM admits at most 1,000 tasks per run and 16 live
17 tasks at once. The host's per-run concurrency gate is a semaphore sized
18 `WORKFLOW_MAX_CONCURRENT = 16` (`codewhale-workflow-js`); additional
19 `task()` spawns block on that gate until a live slot frees, then route
20 through fleet. A larger declared population therefore queues at the gate,
21 not through fleet itself.
22 - `WorkflowSearchSpec` is a provider-neutral TOML/Rust authoring boundary. It
23 validates bounded worktree writes, rounds, budgets, mandatory anti-test-
24 weakening posture, hard-gate commands, deterministic scoring, selection, and
25 review-only integration.
26 - `hard_gates.commands` and `score.command` are parsed and validated only;
27 nothing in this slice executes them. Runtime-owned gate execution and
28 benchmark scoring are the evaluator host seam described below.
29 - Freezing a spec records one deterministic search id and preregistration hash
30 over the baseline commit, requested and resolved model ids, public evidence
31 hash, evaluator hash, and the complete spec.
32 - `operate_best_of_n.workflow.js` supports `strategy: "search"` for 2–16
33 structured independent candidates and one read-only reviewer. The stable
34 shared instructions precede the candidate-specific suffix to favor provider
35 prefix caching.
36 - `BranchTournament` preserves its historical cost-first default but now
37 supports explicit score-first ordering. Pareto selection remains available
38 in the typed Workflow core.
39
40 ## Security and truth boundary
41
42 The JS starter does not own the shell or evaluator. It therefore cannot turn a
43 command mentioned in a prompt into a hidden, runtime-owned gate. Candidate
44 self-verdicts and claimed commands are untrusted. Until the evaluator host seam
45 lands, the starter produces generation and review evidence only.
46
47 The evaluator host must:
48
49 1. freeze a real Git baseline and evaluator before admitting candidates;
50 2. give every writer its own worktree and the same public evidence;
51 3. revoke writer authority before injecting hidden tests or scorer details;
52 4. apply each patch to a clean baseline, reject forbidden/test changes, then
53 run hard gates before performance scoring;
54 5. record commands, exit codes, environment, token/cache/cost usage, artifacts,
55 promotion reasons, and failures on top of fleet receipts;
56 6. replay the provisional winner cleanly and run an independent read-only
57 adversarial review; and
58 7. return `NONE` when all candidates fail and never apply or merge a winner
59 without a later explicit user action.
60
61 ## Provider presets
62
63 The abstraction remains provider-neutral. A DeepSeek Flash preset can exploit
64 its automatically managed prefix cache by keeping shared instructions,
65 experiment rules, repository evidence, and the response contract stable, with
66 the candidate id last. Preliminary scouts can use lower effort while promoted
67 implementers/finalists use high or max effort.
68
69 Record both the requested API model id and the resolved provider version.
70 Provider account concurrency is not Runtime worker concurrency: the runtime keeps its
71 16-live-worker ceiling, handles 429 responses and keep-alives outside the
72 deterministic VM, and stops new admissions when the shared budget is exhausted.
73
74 ## Example authoring shape
75
76 ```toml
77 name = "speed-up-certificate"
78 objective = "Reduce runtime without changing exact results"
79 population = 32
80 rounds = [32, 8, 3, 1]
81 concurrency = 16
82 integration_policy = "review_only"
83
84 [worker]
85 provider = "deepseek"
86 model = "deepseek-v4-flash"
87 reasoning_effort = "high"
88 write_authority = "worktree_write"
89 write_roots = ["code"]
90
91 [budget]
92 max_cost_microusd = 5000000
93 max_tokens = 10000000
94
95 [hard_gates]
96 commands = [
97 "PYTHONWARNINGS=error python certificate.py",
98 "git diff --exit-code -- expected_result.json",
99 ]
100 forbid_test_changes = true
101 protected_paths = ["tests", "expected_result.json"]
102
103 [score]
104 command = "./scripts/benchmark_candidate.sh"
105 direction = "minimize"
106 metric = "median_runtime_ms"
107 trials = 5
108 tie_breakers = ["diff_lines", "cost_microusd"]
109
110 [selection]
111 policy = "pareto"
112 retain_diversity = true
113 ```
114
115 This file is authoring input, not yet a runnable CLI promise. The next runtime
116 slice is the evaluator host and aggregate receipt; after that, the natural-
117 language authoring layer can safely compile a user's request into this shape.
118
118 lines MARKDOWN