{"record":{"id":"ba567c41eb1273be","repo":"abhigyanpatwari/GitNexus","slug":"codex-cli-returned-empty-output","errorCode":null,"errorMessage":"codex CLI returned empty output","messagePattern":"codex CLI returned empty output","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"gitnexus/src/core/wiki/local-cli-client.ts","lineNumber":158,"sourceCode":"    '-c',\n    'approval_policy=\"never\"',\n    '--color',\n    'never',\n    '--output-last-message',\n    outputPath,\n  ];\n\n  if (config.model) {\n    args.push('--model', config.model);\n  }\n  args.push('-');\n\n  try {\n    const response = await runLocalCLI('codex', commandInfo, args, config, fullPrompt, options);\n    const lastMessage = await fs.readFile(outputPath, 'utf-8').catch(() => '');\n    const content = (lastMessage || response.content).trim();\n    if (!content) {\n      throw new Error('codex CLI returned empty output');\n    }\n    return { content };\n  } finally {\n    await fs.rm(outputDir, { recursive: true, force: true }).catch(() => undefined);\n  }\n}\n\ninterface OpenCodeEvent {\n  type?: string;\n  message?: string;\n  error?: {\n    message?: string;\n    name?: string;\n    data?: {\n      message?: string;\n    };\n  };\n  part?: {","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/abhigyanpatwari/GitNexus/blob/aac7515d2a8c50a1f8f923c6fb77218b333560d6/gitnexus/src/core/wiki/local-cli-client.ts#L140-L176","documentation":"The codex CLI ran (`codex exec --sandbox read-only --cd <dir>`), then the client reads last-message.txt from the temp output dir and falls back to captured stdout; if both are empty/whitespace after trim, it throws. Codex is expected to write its final message to the output file — empty file plus empty stdout means the exec produced no final answer.","triggerScenarios":"Codex exec finishes without writing last-message.txt (auth failure, sandbox denial, model refusal with no text, or a CLI arg-schema change across versions making the invocation a no-op); stdout also empty so the fallback yields nothing.","commonSituations":"Codex CLI not signed in (exec exits quietly); version upgrades renaming the output-file convention or flags; read-only sandbox blocking a step the model insisted on, ending with no final message; prompt too large.","solutions":["Verify the CLI produces output manually: `codex exec 'say hi'` and check a non-empty final message","Complete `codex` login/consensus auth, then rerun the wiki command","Update or pin a known-good Codex CLI version if a release changed exec output behavior","Retry with `-v` (GITNEXUS_VERBOSE=1) to inspect the exact command and captured output"],"exampleFix":"# before\ngitnexus wiki --provider codex   # empty output\n\n# after\ncodex exec 'say hi'   # confirm non-empty final message\ngitnexus wiki --provider codex -v","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await callCodexLLM(prompt, config);\n} catch (err) {\n  if (err instanceof Error && err.message === 'codex CLI returned empty output') {\n    return callCodexLLM(prompt, config); // retry once — exec sometimes yields no final message\n  }\n  throw err;\n}","preventionTips":["Confirm `codex exec` writes a final message for a trivial prompt before a long run","Keep Codex CLI authenticated and updated; pin known-good versions in CI","Treat one retry as routine for local-CLI providers; only escalate on repeated empties"],"tags":["llm","codex-cli","empty-response","gitnexus"],"backgroundTag":"empty-cli-output","analyzedSha":"aac7515d2a8c50a1f8f923c6fb77218b333560d6","analyzedAt":"2026-08-20T23:29:22.980Z","schemaVersion":2},"datasetVersion":"2026-08-22T04:17:13.399Z"}