| 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 | - There is no typed search spec in the runtime today. A Rust prototype |
| 23 | (`WorkflowSearchSpec`) validated and froze the TOML shape below, but nothing |
| 24 | consumed it, so it was removed in 0.10.1 (#6517) rather than left to read as |
| 25 | live infrastructure. The evaluator host described below should reintroduce a |
| 26 | spec together with its first real caller. |
| 27 | - `operate_best_of_n.workflow.js` supports `strategy: "search"` for 2–16 |
| 28 | structured independent candidates and one read-only reviewer. The stable |
| 29 | shared instructions precede the candidate-specific suffix to favor provider |
| 30 | prefix caching. |
| 31 | - `BranchTournament` preserves its historical cost-first default but now |
| 32 | supports explicit score-first ordering. Pareto selection remains available |
| 33 | in the typed Workflow core. |
| 34 | |
| 35 | ## Security and truth boundary |
| 36 | |
| 37 | The JS starter does not own the shell or evaluator. It therefore cannot turn a |
| 38 | command mentioned in a prompt into a hidden, runtime-owned gate. Candidate |
| 39 | self-verdicts and claimed commands are untrusted. Until the evaluator host seam |
| 40 | lands, the starter produces generation and review evidence only. |
| 41 | |
| 42 | The evaluator host must: |
| 43 | |
| 44 | 1. freeze a real Git baseline and evaluator before admitting candidates; |
| 45 | 2. give every writer its own worktree and the same public evidence; |
| 46 | 3. revoke writer authority before injecting hidden tests or scorer details; |
| 47 | 4. apply each patch to a clean baseline, reject forbidden/test changes, then |
| 48 | run hard gates before performance scoring; |
| 49 | 5. record commands, exit codes, environment, token/cache/cost usage, artifacts, |
| 50 | promotion reasons, and failures on top of fleet receipts; |
| 51 | 6. replay the provisional winner cleanly and run an independent read-only |
| 52 | adversarial review; and |
| 53 | 7. return `NONE` when all candidates fail and never apply or merge a winner |
| 54 | without a later explicit user action. |
| 55 | |
| 56 | ## Provider presets |
| 57 | |
| 58 | The abstraction remains provider-neutral. A DeepSeek Flash preset can exploit |
| 59 | its automatically managed prefix cache by keeping shared instructions, |
| 60 | experiment rules, repository evidence, and the response contract stable, with |
| 61 | the candidate id last. Preliminary scouts can use lower effort while promoted |
| 62 | implementers/finalists use high or max effort. |
| 63 | |
| 64 | Record both the requested API model id and the resolved provider version. |
| 65 | Provider account concurrency is not Runtime worker concurrency: the runtime keeps its |
| 66 | 16-live-worker ceiling, handles 429 responses and keep-alives outside the |
| 67 | deterministic VM, and stops new admissions when the shared budget is exhausted. |
| 68 | |
| 69 | ## Proposed authoring shape |
| 70 | |
| 71 | ```toml |
| 72 | name = "speed-up-certificate" |
| 73 | objective = "Reduce runtime without changing exact results" |
| 74 | population = 32 |
| 75 | rounds = [32, 8, 3, 1] |
| 76 | concurrency = 16 |
| 77 | integration_policy = "review_only" |
| 78 | |
| 79 | [worker] |
| 80 | provider = "deepseek" |
| 81 | model = "deepseek-v4-flash" |
| 82 | reasoning_effort = "high" |
| 83 | write_authority = "worktree_write" |
| 84 | write_roots = ["code"] |
| 85 | |
| 86 | [budget] |
| 87 | max_cost_microusd = 5000000 |
| 88 | max_tokens = 10000000 |
| 89 | |
| 90 | [hard_gates] |
| 91 | commands = [ |
| 92 | "PYTHONWARNINGS=error python certificate.py", |
| 93 | "git diff --exit-code -- expected_result.json", |
| 94 | ] |
| 95 | forbid_test_changes = true |
| 96 | protected_paths = ["tests", "expected_result.json"] |
| 97 | |
| 98 | [score] |
| 99 | command = "./scripts/benchmark_candidate.sh" |
| 100 | direction = "minimize" |
| 101 | metric = "median_runtime_ms" |
| 102 | trials = 5 |
| 103 | tie_breakers = ["diff_lines", "cost_microusd"] |
| 104 | |
| 105 | [selection] |
| 106 | policy = "pareto" |
| 107 | retain_diversity = true |
| 108 | ``` |
| 109 | |
| 110 | This shape is a design proposal: nothing parses it today and it is not a |
| 111 | runnable CLI promise. The next runtime slice is the evaluator host and |
| 112 | aggregate receipt, which must freeze the baseline, requested and resolved |
| 113 | model ids, public evidence hash, evaluator hash, and the complete spec before |
| 114 | admitting candidates; after that, the natural-language authoring layer can |
| 115 | safely compile a user's request into this shape. |
| 116 |