v1/mode: override knobs + staffing native runner + pass 2/3/4 harnesses
lakehouse/auditor 1 blocking issue: todo!() macro call in tests/real-world/scrum_master_pipeline.ts

Setup for the corpus-tightening experiment sweep (J 2026-04-26 — "now
is the only cheap window before the corpus gets large and refactoring
costs go up").

Override params on /v1/mode/execute (additive — old callers unaffected):
  force_matrix_corpus      — Pass 2: try alternate corpora per call
  force_relevance_threshold — Pass 2: sweep filter strictness
  force_temperature         — Pass 3: variance test

New native mode `staffing_inference_lakehouse` (Pass 4):
  - Same composer architecture as codereview_lakehouse
  - Staffing framing: coordinator producing fillable|contingent|
    unfillable verdict + ranked candidate list with playbook citations
  - matrix_corpus = workers_500k_v8
  - Validates that modes-as-prompt-molders generalizes beyond code
  - Framing explicitly says "do NOT fabricate workers" — the staffing
    analog of the lakehouse mode's symbol-grounding requirement

Three sweep harnesses:
  scripts/mode_pass2_corpus_sweep.ts — 4 corpora × 4 thresholds × 5 files
  scripts/mode_pass3_variance.ts     — 3 files × 3 temps × 5 reps
  scripts/mode_pass4_staffing.ts     — 5 fill requests through staffing mode

Each appends per-call rows to data/_kb/mode_experiments.jsonl which
mode_compare.ts already aggregates with grounding column.

Pass 1 (10 files × 5 modes broad sweep) currently running via the
existing scripts/mode_experiment.ts — gateway restart deferred until
it completes so the new override knobs aren't enabled mid-experiment.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
root
2026-04-26 01:55:12 -05:00
co-authored by Claude Opus 4.7
parent 52bb216c2d
commit 56bf30cfd8
5 changed files with 408 additions and 5 deletions
+44 -2
View File
@@ -51,6 +51,7 @@ const VALID_MODES: &[&str] = &[
"codereview_isolation", // file + pathway only (no matrix)
"codereview_matrix_only", // file + matrix only (no pathway)
"codereview_playbook_only", // pathway only, NO file content (lossy ceiling)
"staffing_inference_lakehouse", // staffing-domain composer (Pass 4)
];
/// Whether a mode is handled natively in this gateway vs proxied to
@@ -63,6 +64,7 @@ fn is_native_mode(mode: &str) -> bool {
| "codereview_isolation"
| "codereview_matrix_only"
| "codereview_playbook_only"
| "staffing_inference_lakehouse"
)
}
@@ -82,6 +84,7 @@ pub struct EnrichmentFlags {
pub enum ReviewerFraming {
Adversarial, // forensic, ranked findings + verdict (lakehouse default)
Generic, // "review this" — no codebase priors (null baseline)
Staffing, // staffing-domain coordinator framing (Pass 4)
}
fn flags_for_mode(mode: &str) -> EnrichmentFlags {
@@ -114,6 +117,18 @@ fn flags_for_mode(mode: &str) -> EnrichmentFlags {
use_relevance_filter: false,
framing: ReviewerFraming::Adversarial,
},
"staffing_inference_lakehouse" => EnrichmentFlags {
// Staffing reuses the same composer architecture but with
// domain-specific framing. file_content here = the request
// payload (e.g. "fill 2 welders in Toledo OH"), bug_fingerprints
// surface prior playbook patterns from this geo+role, matrix
// pulls candidate workers + city/state demand chunks.
include_file_content: true,
include_bug_fingerprints: true,
include_matrix_chunks: true,
use_relevance_filter: true,
framing: ReviewerFraming::Staffing,
},
// Default (codereview_lakehouse): everything on.
_ => EnrichmentFlags {
include_file_content: true,
@@ -404,6 +419,20 @@ pub struct ExecuteRequest {
/// runner uses its built-in forensic-review framing.
#[serde(default)]
pub user_question: Option<String>,
/// Override the matrix corpus the runner queries. Defaults to the
/// task_class's matrix_corpus from modes.toml. Use for the corpus-
/// tightening experiment (Pass 2 of the 2026-04-26 mode sweep).
#[serde(default)]
pub force_matrix_corpus: Option<String>,
/// Override the relevance filter threshold (default 0.3). Setting
/// to 0 keeps every chunk; raising rejects more aggressively. Used
/// to find the threshold sweet spot per task class.
#[serde(default)]
pub force_relevance_threshold: Option<f64>,
/// Override the LLM temperature (default 0.1). Used by Pass 3
/// variance testing to measure run-to-run stability.
#[serde(default)]
pub force_temperature: Option<f64>,
}
#[derive(Serialize, Debug, Default)]
@@ -442,10 +471,20 @@ proven. Do NOT hedge.";
const FRAMING_GENERIC: &str = "You are a code reviewer. Read the file below and produce a \
markdown review with findings.";
const FRAMING_STAFFING: &str = "You are a senior staffing coordinator for a light-industrial \
labor agency. You receive a fill request (role × count × city × deadline) and have access \
to historical playbook patterns from prior fills in this geo, plus a corpus of candidate \
workers + demand signals. Produce a markdown plan with: (1) one-line verdict (fillable | \
contingent | unfillable), (2) ranked candidate list with name, city, role, distance, prior \
fill citations from the playbook, (3) risks (double-booking, eligibility gaps, geo stretch) \
with severity + confidence percent, (4) playbook reference IDs you used. Be precise — only \
recommend candidates whose names appear in the matrix data; do NOT fabricate workers.";
fn framing_text(f: ReviewerFraming) -> &'static str {
match f {
ReviewerFraming::Adversarial => FRAMING_ADVERSARIAL,
ReviewerFraming::Generic => FRAMING_GENERIC,
ReviewerFraming::Staffing => FRAMING_STAFFING,
}
}
@@ -485,6 +524,9 @@ pub async fn execute(
));
}
// Caller can override the matrix corpus per-call (Pass 2 corpus
// tightening). Falls back to modes.toml default.
let matrix_corpus = req.force_matrix_corpus.clone().or(matrix_corpus);
let flags = flags_for_mode(&mode);
let mut sources = EnrichmentSources {
matrix_corpus: matrix_corpus.clone(),
@@ -621,7 +663,7 @@ pub async fn execute(
let body = serde_json::json!({
"focus_file": { "path": req.file_path, "content": file_content },
"chunks": chunks_for_filter,
"threshold": 0.3,
"threshold": req.force_relevance_threshold.unwrap_or(0.3),
});
match client
.post("http://localhost:3800/relevance")
@@ -723,7 +765,7 @@ pub async fn execute(
{ "role": "system", "content": framing_text(flags.framing) },
{ "role": "user", "content": user_prompt },
],
"temperature": 0.1,
"temperature": req.force_temperature.unwrap_or(0.1),
"max_tokens": 4096,
});
let chat_client = match reqwest::Client::builder()