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