Skip to content

Execution failed: Error: missing finish_reason for choice 0 — exits non-zero after successful completion #1572

@maxbeizer

Description

@maxbeizer

Description

The Copilot CLI exits with code 1 after successfully completing all requested work, due to:

Execution failed: Error: missing finish_reason for choice 0

This appears to be a missing or malformed finish_reason in the API response for the final message, causing the CLI to treat a successful session as a failure.

Reproduction

  1. Run a prompt where the agent completes in a single turn (e.g., one tool call + short response)
  2. The agent produces correct output and all tool calls succeed
  3. CLI crashes with the error above and exits code 1

This has reproduced consistently across multiple runs with the same prompt and model.

Observed behavior

From the agent stdio log:

● tool-call-1
  └ {"total_count":0,"incomplete_results":false}

[Agent responds correctly based on tool results]

● tool-call-2
  └ {"result":"success"}

Execution failed: Error: missing finish_reason for choice 0

Both tool calls return success. The agent's response is correct and complete. The error occurs after the agent finishes its work.

Impact

  • Any automation relying on exit code treats this as a failure
  • Creates false-positive failure alerts in CI/CD pipelines using Copilot CLI
  • Reproducible across multiple runs with identical inputs

Environment

  • Copilot CLI: v0.42.14
  • Model: claude-sonnet-4.5
  • Platform: GitHub Actions (ubuntu-latest)
  • Session stats: 1 turn, ~42.8k input tokens, ~547 output tokens

Expected behavior

If all tool calls succeed and the agent produces a valid response, the CLI should exit 0. A missing finish_reason field in the API response should not cause a hard failure.


Internal context (Hubbers only): https://gist.ghe.io/b4b61cea82fa4e6385c3ff03865ef2ab

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions