{"record":{"id":"4410abcb00dcd841","repo":"xai-org/grok-build","slug":"command-wrote-more-than-provider-stdout-cap-bytes","errorCode":null,"errorMessage":"command wrote more than {PROVIDER_STDOUT_CAP_BYTES} bytes to stdout","messagePattern":"command wrote more than (.+?) bytes to stdout","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codegen/xai-grok-shell/src/auth/auth_provider.rs","lineNumber":328,"sourceCode":"        if let Err(e) = err_res {\n            tracing::debug!(error = %e, \"auth provider: stderr capture failed (advisory)\");\n        }\n        out_res.map_err(|e| anyhow::anyhow!(\"reading command stdout: {e}\"))?;\n        child\n            .wait()\n            .await\n            .map_err(|e| anyhow::anyhow!(\"waiting on command: {e}\"))\n    };\n\n    let status = match tokio::time::timeout(timeout, capture).await {\n        Ok(res) => res?,\n        Err(_elapsed) => {\n            let _ = group.kill();\n            anyhow::bail!(\"command timed out after {}s\", timeout.as_secs());\n        }\n    };\n    if out_buf.len() as u64 > PROVIDER_STDOUT_CAP_BYTES {\n        anyhow::bail!(\"command wrote more than {PROVIDER_STDOUT_CAP_BYTES} bytes to stdout\");\n    }\n    Ok(std::process::Output {\n        status,\n        stdout: out_buf,\n        stderr: err_buf,\n    })\n}\n\nfn resolve_program(command: &str, cwd: Option<&std::path::Path>) -> std::path::PathBuf {\n    let path = std::path::Path::new(command);\n    if path.is_absolute() {\n        return path.to_path_buf();\n    }\n    if path.components().count() > 1\n        && let Some(dir) = cwd\n    {\n        return dir.join(path);\n    }","sourceCodeStart":310,"sourceCodeEnd":346,"githubUrl":"https://github.com/xai-org/grok-build/blob/bc7f02eddd3d84085849dc19ed216f11c23b0571/crates/codegen/xai-grok-shell/src/auth/auth_provider.rs#L310-L346","documentation":"After a provider command completes, run_capped enforces PROVIDER_STDOUT_CAP_BYTES on captured stdout. If the command emitted more than the cap, this error is raised and no Output is returned. The cap prevents unbounded memory growth from chatty or misbehaving credential commands.","triggerScenarios":"Calling mint_provider_token when the credential command writes more than PROVIDER_STDOUT_CAP_BYTES of stdout — e.g. a wrapper script that prints debug logs, banners, or dumps JSON blobs far larger than a token.","commonSituations":"Credential helpers that echo verbose logging to stdout instead of stderr, shell profile/RC files printing MOTD into non-interactive stdout, or a script accidentally cat-ing a large file.","solutions":["Silence the command's extra stdout output (redirect logs to stderr: cmd ... 1>&2)","Fix wrapper scripts so ONLY the token/JSON payload goes to stdout","Check shell init files (~/.bashrc, ~/.profile) for echo statements in non-interactive shells","Raise PROVIDER_STDOUT_CAP_BYTES only if your provider legitimately emits large payloads"],"exampleFix":"// before (wrapper.sh)\necho \"debug: fetching token...\"\necho \"$TOKEN\"\n// after\necho \"debug: fetching token...\" 1>&2\nprintf '%s' \"$TOKEN\"","handlingStrategy":"validation","validationCode":"// Check the helper emits only a short token payload\nlet probe = Command::new(\"provider-cred-helper\").arg(\"--print-token\").output()?;\nif probe.stdout.len() > 4096 {\n    eprintln!(\"helper stdout suspiciously large ({} bytes)\", probe.stdout.len());\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Route all diagnostics from wrapper scripts to stderr","Test credential commands in a clean non-interactive shell (env -i)","Keep stdout strictly to the token payload contract"],"tags":["subprocess","auth","stdout","limit"],"backgroundTag":"subprocess-output-over-cap","analyzedSha":"bc7f02eddd3d84085849dc19ed216f11c23b0571","analyzedAt":"2026-08-31T04:59:42.031Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}