返回 CodeWhale
WORKFLOW_EXPERIMENTAL_SEARCH.md
根目录 / docs / WORKFLOW_EXPERIMENTAL_SEARCH.md
1 # Workflow experimental search
2
3 Workflow remains the scheduler; Fleet and Runtime still own child routing and
4 worktrees. The checked-in `.codewhale/workflows/operate_best_of_n.workflow.js` has an
5 optional host evaluator for completed search candidates. With no `evaluator`
6 argument, its existing Best-of-N generation and reviewer path runs as before.
7
8 ## Verified candidate slice
9
10 The version 1 JSON spec freezes a clean Git HEAD, objective, write scope,
11 protected paths, trusted case bundles, Linux bubblewrap policy, and aggregate
12 evaluation wall-time bound. The clock counts candidate capture, gate execution,
13 and sealed replay. It pauses during model generation between candidates. Each
14 receipt records its execution start, remaining-budget deadline and stop reason.
15 Keep the spec and case bundles outside the candidate repository. A case
16 bundle is an array of `{"input": ..., "expected": ...}` objects. At least one
17 public and one held-out gate must each require a nonzero number of cases.
18
19 ```json
20 {
21 "version": 1,
22 "objective": "Increment the input integer",
23 "baseline_sha": "<full output of git rev-parse HEAD>",
24 "allowed_write_roots": ["candidate.py"],
25 "protected_paths": ["tests"],
26 "isolation_backend": "linux-bwrap",
27 "max_wall_secs": 60,
28 "hard_gates": [
29 {
30 "candidate_argv": ["/usr/bin/python3", "candidate.py"],
31 "cases_path": "/trusted/public.json",
32 "timeout_secs": 10,
33 "min_tests": 1,
34 "holdout": false
35 },
36 {
37 "candidate_argv": ["/usr/bin/python3", "candidate.py"],
38 "cases_path": "/trusted/heldout.json",
39 "timeout_secs": 10,
40 "min_tests": 1,
41 "holdout": true
42 }
43 ]
44 }
45 ```
46
47 Invoke the existing `workflow` tool, or use the CLI `workflow-tool --input-json`
48 equivalent. For `source_path`, place the checked-in Workflow file inside the
49 active workspace or `~/.codewhale/workflows`; the host hashes the actual loaded
50 script bytes and compares them with the checked-in authorized SHA-256 constant.
51 Alternatively, pass that file's exact text as
52 `script`, as the native E2E below does.
53
54 When the checked-in Workflow changes, calculate
55 `sha256sum .codewhale/workflows/operate_best_of_n.workflow.js`, update
56 `AUTHORIZED_WORKFLOW_SHA256` in `verified_candidate/mod.rs`, and run the
57 repository-script identity test plus `cargo package -p codewhale-engine --locked`.
58 The repository script path appears only in the test source, which is excluded
59 from the published crate.
60
61 ```json
62 {
63 "action": "run",
64 "source_path": ".codewhale/workflows/operate_best_of_n.workflow.js",
65 "args": {
66 "strategy": "search",
67 "brief": "Increment the input integer",
68 "n": 2,
69 "writeRoots": ["candidate.py"],
70 "evaluator": {"manifestPath": "/trusted/evaluator.json"}
71 }
72 }
73 ```
74
75 The ordinary model and provider configuration still controls candidate writers.
76 The host freezes the evaluator before starting the Workflow. Once a candidate
77 task has terminated successfully, the host verifies its Git common directory
78 and starting HEAD, seals its complete tree difference, and runs the public
79 cases. A public PASS is independently materialized and replayed against public
80 and held-out cases. The Workflow returns each receipt with
81 `promotion: "proposal_only"`; it does not choose, apply, push, or merge code.
82
83 The case bundles are the trusted oracle. The candidate command receives one
84 JSON input on stdin and emits one JSON value on stdout. The host compares that
85 value with the frozen expected value and counts the cases it actually ran.
86 Candidate self-verdicts, shell output, and claimed test counts are never the
87 oracle. The oracle is read by the host, not imported into the candidate
88 process. Held-out gates run under `holdout_confidentiality: "feedback_only"`:
89 candidate-facing receipts report gate verdicts and counts without exposing
90 held-out case inputs or expected outputs, while per-case replay evidence stays
91 inside the private host-owned run directory.
92
93 ## Isolation and retained evidence
94
95 Candidate commands run only on Linux with the strict bubblewrap backend.
96 The capability probe must establish a private network namespace, inaccessible
97 host marker and actual spec/case paths, writable private scratch, and read-only
98 sealed source mount.
99 The process owner applies CPU, address-space, file-size, descriptor and process
100 limits. The evaluator sets `RLIMIT_NPROC` to 4096, which the maintainer verified
101 with about 180 existing tasks for the ordinary user. Linux counts the user's
102 tasks outside the sandbox, so the previous value of 32 prevented bubblewrap
103 from creating its namespaces. This is a per-evaluator value, not a sandbox-local
104 process count. PID namespace isolation, `--die-with-parent`, cancellation and
105 timeout retain the descendant boundary. The probe reports `processes_rlimit:
106 4096` for the evaluator policy.
107 The evaluator clears the host environment and closes inherited file
108 descriptors before the sandbox starts. Missing bubblewrap or an unsuccessful
109 probe rejects the run.
110
111 The private run-owned directory (mode 0700 on Unix) is reported as `run_root` and named
112 `codewhale-evaluator-workflow_*` in the system temporary directory. It retains
113 the frozen baseline blobs, sealed artifact manifests and blobs, manifest,
114 receipts, and bounded stdout/stderr logs so evidence remains reviewable after
115 the writer worktree disappears. Fleet/Runtime own writer worktrees and their
116 normal cleanup; the evaluator never deletes them. Each evaluation's
117 materialized candidate and scratch directories use temporary directory
118 ownership and are removed when the evaluation ends, including on failure or
119 cancellation. An unsuccessful freeze removes the new run directory. After
120 archiving evidence, the operator
121 may delete that exact run directory; restart cleanup must identify the
122 `manifest.json` run id before removing anything. There is no automatic
123 cross-process replay API in this slice.
124
125 The sealed artifact records added, modified, deleted, binary, and
126 executable-mode source changes. Its frozen capture policy excludes untracked
127 files under the root `target/` directory and untracked files in any
128 `__pycache__/` directory; these generated paths are listed in artifact and
129 receipt provenance and are not materialized for replay. Tracked files and
130 protected paths are always captured, even in those directories. Other ignored
131 files, including out-of-scope writes, remain subject to the normal scope check.
132 Excluded generated files still pass file-type and hardlink checks before the
133 capture policy omits their content.
134 The candidate tree hash covers the included source tree; the artifact manifest
135 hash also covers the exclusion list. Receipts bind spec, baseline Git SHA and
136 tree identity, case bundle
137 hashes, artifact and candidate tree hashes, sandbox probe, and native binary
138 SHA256, plus bubblewrap and gate executable hashes. Per-case receipts include
139 the resolved sandbox command, exit/stop reason, and log paths. Replays compare
140 identities against the frozen spec and prior receipt.
141 Missing or conflicting evidence yields `UNKNOWN`, `REJECTED`, or an explicit
142 error, never a PASS.
143
144 Limits are 4 MiB per file, 64 MiB for the baseline or candidate tree, 8 MiB
145 of changed content, 4,096 included files, 36,864 scanned files, 256 cases per
146 gate, and at most 12 gates.
147 The sandbox has per-process and per-case bounds; there is no aggregate scratch
148 or host-memory quota. Windows, macOS, and Linux hosts without working
149 bubblewrap are unsupported for this evaluator. A candidate can run only an
150 absolute executable with one repo-relative program path argument in this
151 version. These restrictions deliberately keep the trusted execution surface
152 small.
153
154 Policy genomes, mutation, selection, strategy transfer, model-turn planning,
155 and promotion research remain separate from this evaluator.
156
157 For a repeatable Linux run using a local scripted provider, a synthetic Git
158 workspace, both public and held-out cases, and the real CLI entry:
159
160 ```sh
161 python3 scripts/e2e/verified-candidate-native-e2e.py \
162 --codewhale target/debug/codewhale \
163 --workflow-source .codewhale/workflows/operate_best_of_n.workflow.js \
164 --source-sha "$(git rev-parse HEAD)" \
165 --output /tmp/codewhale-evaluator-native-e2e-new
166 ```
167
168 The output directory must be absent before the run. Its `receipt.json`, CLI
169 logs, provider request ledger, and copied `sealed-evidence/` allow the result
170 to be inspected and repeated with a fresh output path.
171
171 lines MARKDOWN