Don't rewrite it in Rust. Rewrite the 5% that's slow: profile your app, port the hot functions with your coding agent, prove they behave the same. Python, JS/TS, Ruby, Java, Kotlin, Go, PHP, C/C++, C#, R.
Rust agent-skillsai-agentsclaude-codeclaude-code-plugincodexdeveloper-toolsffimcpmcp-servernapi-rsnodejsoptimizationperformanceprofilerpyo3pythonrewrite-it-in-rustrubyrusttypescript
verify: delete the working copy of held-out calls
Milosz6505903fce90
diff --git a/README.md b/README.mdindex a5dcb3c..459b1a6 100644--- a/README.md+++ b/README.md@@ -58,7 +58,7 @@ Or step by step:That port looked right but compared bytes instead of characters. 148 of 500 real calls caught it. On top of the recorded calls, fast-anything derives extra cases and lets the original answer them: edge cases (NaN, ±infinity, -0.0, zero and ±1, non-ASCII text, empty and up to 16× bigger inputs) and shrunk inputs (tiny and random slices). Nothing is enabled until every case matches: same values (floats within 1e-9 of their size or of the largest value in the same list, -0.0 not 0.0), errors where the original errors. A port that is right but slower per call than the original (calling into Rust costs more than the work saved) isn't enabled either. `FAST_ANYTHING_DISABLE=1` runs the original any time.-Every 5th recorded call (from 5 calls up) is held out of the crate folder the agent works in: verify replays it too but reports a mismatch there without the values, so a port that special-cases the calls it was shown still fails.+Every 5th recorded call (from 5 calls up) is held out of the crate folder the agent works in: verify replays it too but reports a mismatch there without the values, so a port that special-cases the calls it was shown still fails. verify deletes its working copy of those calls when it's done. It's a guard against a port fitted to the calls it was shown, not a sandbox: an agent that goes looking can still read them in `.fast/holdout`.## Resultsdiff --git a/src/backend.rs b/src/backend.rsindex e97085c..d251df5 100644--- a/src/backend.rs+++ b/src/backend.rs@@ -367,13 +367,29 @@ pub fn replay(ctx: &Ctx, port: &Port) -> Result<Replay> {text.push('\n');}text.push_str(&fs::read_to_string(ctx.holdout(port)).context("reading the held-out calls")?);- let verify_dir = ctx.fast.join("verify").join(dir.file_name().unwrap_or_default());+ let verify_dir = verify_dir(ctx, port);fs::create_dir_all(&verify_dir)?;let cases = verify_dir.join("cases.jsonl");fs::write(&cases, text)?;Ok(Replay { cases, out: verify_dir.join("verify.json"), held_out })}+fn verify_dir(ctx: &Ctx, port: &Port) -> PathBuf {+ ctx.fast.join("verify").join(ctx.crate_dir(port).file_name().unwrap_or_default())+}++/// After the runner reports: count and redact the held-out calls, then remove .fast/verify/<port>/,+/// whose cases and report show their values. Without held-out calls verify.json stays in the crate.+pub fn finish_replay(ctx: &Ctx, port: &Port, visible: usize, v: &mut Verify) -> Result<()> {+ v.held_out = ctx.held_out(port);+ redact_held_out(v, &port.func, visible);+ let dir = verify_dir(ctx, port);+ if v.held_out > 0 && dir.exists() {+ fs::remove_dir_all(&dir).with_context(|| format!("removing {}", dir.display()))?;+ }+ Ok(())+}+/// Failures among the held-out calls (replayed right after the `visible` lines of recordings.jsonl)/// lose their values, so neither the output nor the agent's next prompt shows them.pub fn redact_held_out(v: &mut Verify, func: &str, visible: usize) {@@ -675,6 +691,67 @@ mod tests {let _ = fs::remove_dir_all(&root);}+ #[test]+ fn verify_leaves_no_held_out_values_behind() {+ let root = std::env::temp_dir().join(format!("fa-holdout-finish-{}", std::process::id()));+ let _ = fs::remove_dir_all(&root);+ fs::create_dir_all(&root).unwrap();+ let ctx = Ctx::open(&root).unwrap();+ let mut port = Port {+ id: "app.f".into(),+ file: "app.py".into(),+ module: "app".into(),+ func: "f".into(),+ ext: "fa_app_f".into(),+ crate_dir: ".fast/ports/app.f".into(),+ recorded: 4,+ calls_seen: 4,+ verify: None,+ enabled: false,+ lang: Lang::Python,+ owner: None,+ line: 1,+ sources: vec![],+ };+ let dir = ctx.crate_dir(&port);+ fs::create_dir_all(&dir).unwrap();+ let recordings = dir.join("recordings.jsonl");+ let failed = |case: usize| Verify {+ built: true,+ total: 12,+ failed: 1,+ passed: 11,+ failures: vec![crate::state::Failure {+ case,+ call: "f(4007)".into(),+ expected: "4007".into(),+ got: "0".into(),+ }],+ ..Verify::default()+ };++ // Without held-out calls the report stays in the crate folder.+ fs::write(&recordings, (0..4).map(call).collect::<Vec<_>>().join("\n") + "\n").unwrap();+ let r = replay(&ctx, &port).unwrap();+ fs::write(&r.out, "{}").unwrap();+ let mut v = failed(2);+ finish_replay(&ctx, &port, 4, &mut v).unwrap();+ assert!(dir.join("verify.json").exists());+ assert_eq!((v.held_out, v.failures[0].call.as_str()), (0, "f(4007)"));++ port.recorded = 12;+ fs::write(&recordings, (0..12).map(call).collect::<Vec<_>>().join("\n") + "\n").unwrap();+ hold_out(&recordings, &ctx.holdout(&port)).unwrap();+ let r = replay(&ctx, &port).unwrap();+ fs::write(&r.out, "{\"failures\":[{\"call\":\"f(4007)\"}]}").unwrap();+ let mut v = failed(10);+ finish_replay(&ctx, &port, 10, &mut v).unwrap();+ assert!(!r.cases.exists() && !r.out.exists() && !ctx.fast.join("verify/app.f").exists());+ assert_eq!((v.total, v.passed, v.failed, v.held_out), (12, 11, 1, 2));+ assert_eq!(v.failures[0].call, "(held out) f(…)");+ let _ = fs::remove_dir_all(&root);+ }+#[test]fn held_out_failures_lose_their_values() {let failure = |case: usize, value: &str| crate::state::Failure {diff --git a/src/pipeline.rs b/src/pipeline.rsindex a6689cf..adf0fa8 100644--- a/src/pipeline.rs+++ b/src/pipeline.rs@@ -184,8 +184,7 @@ pub fn verify(root: &Path, id: Option<&str>) -> Result<(String, Verify)> {));let visible = util::count_lines(&ctx.crate_dir(&port).join("recordings.jsonl"));let mut v = port.lang.verify(&ctx, &port)?;- v.held_out = ctx.held_out(&port);- backend::redact_held_out(&mut v, &port.func, visible);+ backend::finish_replay(&ctx, &port, visible, &mut v)?;v}};