Move the built request rather than clone it
perfloop/grok-build · AVOIDABLE COPY
https://perfloop.ai/t/oss/case_vvqa4n0a1r
Verdict
VERIFIED · settled 2026-07-26
What happened: Validated. Moving the populated ConversationRequest into run_turn_via_sampler reduced the blocked handoff’s median live request bytes from 8,971,021 to 7,920,866 (11.71%, p=0.0000108), exceeding the 10% goal. The populated request-handoff check passed, and the MvpAgent::prompt entry guard held at 1/1. This reaches the seam-local ownership ceiling: the outer request has no later use after the sampler await, while the sampler’s retry-owned request remains required.
Hypothesis
An ownership-path static check of `turn.rs:1948`, `sampler_turn.rs:982-997`, and `xai-grok-sampler/src/handle.rs:113-145` showed that this method finishes mutating `request`, calls `run_turn_via_sampler(request.clone())`, and never uses the original afterward; the callee takes ownership and forwards it in `SamplerCommand::Submit`. `ConversationRequest` derives `Clone` over item/tool vectors, owned headers, optional JSON schema, and trace data; in particular, each `ToolSpec` owns strings and a `serde_json::Value`, so a populated request clone constructs independently owned vector elements rather than merely copying a request header. This clone runs once for each model submission, including repeated tool-loop, compaction, and auth-resubmission iterations, with larger requests increasing the possible cost. The check is static and did not measure allocation, CPU, or latency. A case session should reproduce an ACP prompt with large history/tool schemas and multiple tool-loop submissions, collect an allocation or CPU profile (or clone-count instrumentation), and verify that bytes/CPU attributed to `ConversationRequest::clone` fall while sampler payloads and turn outcomes remain unchanged.
Change to test: After the final request mutations, pass `request` by value to `run_turn_via_sampler` instead of calling `.clone()`, preserving the existing ownership transfer into `submit_and_collect`.
Where it lives
perfloop/grok-build · crates/codegen/xai-grok-shell/src/session/acp_session_impl/notification_drain.rs
Evidence
Timeline
2026-07-22· Case opened2026-07-26· Attempt selected