{"record":{"id":"e3880524a13aa391","repo":"Hmbown/CodeWhale","slug":"same-batch-first-use-hydrates-instead-of-executing","errorCode":null,"errorMessage":"same-batch first use hydrates instead of executing","messagePattern":"same-batch first use hydrates instead of executing","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/tools/subagent/tests.rs","lineNumber":7929,"sourceCode":"            &mut surface,\n            &request_active,\n            TOOL_SEARCH_NAME,\n            json!({\"query\": \"web\", \"match\": \"regex\"}),\n        )\n        .await\n        .expect(\"child-local search\");\n    assert!(result.result.content.contains(\"\\\"tool_name\\\":\\\"Web\\\"\"));\n    let same_batch = registry\n        .execute_from_surface(\n            \"agent_scout\",\n            \"\",\n            &mut surface,\n            &request_active,\n            \"Web\",\n            json!({\"action\": \"search\", \"query\": \"codewhale\"}),\n        )\n        .await\n        .expect(\"same-batch first use hydrates instead of executing\");\n    assert!(same_batch.result.content.contains(\"deferred\"));\n    assert!(model_tool_names(model_request_tools(&mut surface)).contains(\"Web\"));\n}\n\n#[tokio::test]\nasync fn small_surface_fork_context_survives_fresh_child_discovery() {\n    let registry = small_surface_registry(FleetRole::Builder);\n    let context = SubAgentForkContext {\n        messages: vec![\n            Message {\n                role: Role::Assistant,\n                content: vec![ContentBlock::ToolUse {\n                    id: \"search-1\".to_string(),\n                    name: TOOL_SEARCH_NAME.to_string(),\n                    input: json!({\"query\": \"web\"}),\n                    caller: None,\n                    thought_signature: None,\n                }],","sourceCodeStart":7911,"sourceCodeEnd":7947,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/tools/subagent/tests.rs#L7911-L7947","documentation":"A panic from `.expect(\"same-batch first use hydrates instead of executing\")` in the deferred-tools test. It executes a first direct use of the deferred `Web` tool within the same request batch and asserts that the registry hydrates the tool into the request surface (returns a \"deferred\" notice) rather than executing it; an `Err` from `execute_from_surface`, or a content mismatch afterwards, panics here. It pins the hydration-before-execution contract for first-use of deferred tools.","triggerScenarios":"`execute_from_surface` for `Web` with `{action: \"search\", query: \"codewhale\"}` returns `Err` — Web was already hydrated (state drift from the earlier tool_search call), the tool is missing from the deferred catalog, or the arguments fail validation — or the result content no longer contains \"deferred\".","commonSituations":"A change in hydration semantics (executing instead of hydrating) breaks the contract; earlier test steps left the surface in a hydrated state; argument schema for the Web tool changed.","solutions":["Inspect the `Err` (swap `.expect` for a `panic!(\"...: {e:?}\")` wrapper) to identify whether execution or argument validation failed","Check `surface.active_names` before the call — if Web was already hydrated by the preceding tool_search batch, the test's premise changed and the fixture needs a fresh surface","If the contract changed intentionally (first use now executes), update the assertion content and test name; otherwise restore hydration-on-first-use in the registry"],"exampleFix":"// before\n.await\n.expect(\"same-batch first use hydrates instead of executing\");\n// after (diagnose)\n.await\n.unwrap_or_else(|e| panic!(\"same-batch hydration failed: {e:?}\"));","handlingStrategy":"try-catch","validationCode":"assert!(!surface.active_names.contains(&\"Web\".to_string()),\n    \"Web already active; first-use hydration path cannot be exercised\");","typeGuard":null,"tryCatchPattern":"let same_batch = registry.execute_from_surface(...).await\n    .unwrap_or_else(|e| panic!(\"same-batch first use failed: {e:?}\"));","preventionTips":["Construct a fresh SubAgentToolSurface for each hydration-contract assertion","Surface the tool error content in the panic message for diagnosability","Pin the hydration-before-execution contract with a comment and a dedicated test","Grep hydration semantics changes for downstream deferred-tool tests"],"tags":["rust","async","deferred-tools","test-assertion"],"backgroundTag":"api-request-failed","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-22T06:17:15.046Z"}