Skip to content

[BUG] [v0.0.7] cortex github run ignores GITHUB_TOKEN / GITHUB_REPOSITORY / GITHUB_EVENT_PATH environment variables despite error messages claiming they are supported #53414

Description

@nightmare0329

Summary

cortex github run error messages advertise GITHUB_TOKEN, GITHUB_REPOSITORY, and GITHUB_EVENT_PATH as environment-variable fallbacks, but the code never reads these env vars. In GitHub Actions contexts — where these variables are set automatically — the command always fails with a misleading "set env var" error.

Root cause

github_cmd.rs run_github_agent() errors out if flags are missing, but never reads env vars:

// github_cmd.rs lines 263-278
let token = args.token.ok_or_else(|| {
    anyhow::anyhow!("GitHub token required. Set GITHUB_TOKEN env var or use --token")
    // ^^ Says to set GITHUB_TOKEN env var — but std::env::var("GITHUB_TOKEN") is NEVER called
})?;

let repository = args.repository.ok_or_else(|| {
    anyhow::anyhow!("Set GITHUB_REPOSITORY env var or use --repository")
    // ^^ GITHUB_REPOSITORY env var is never read
})?;

let event_path = args.event_path.ok_or_else(|| {
    anyhow::anyhow!("Set GITHUB_EVENT_PATH env var or use --event-path")
    // ^^ GITHUB_EVENT_PATH env var is never read
})?;

Reproduction

# In GitHub Actions, GITHUB_TOKEN, GITHUB_REPOSITORY, GITHUB_EVENT_PATH are set automatically.
# Despite the error message, these env vars do NOT satisfy the requirement:
export GITHUB_TOKEN=ghp_xxx
export GITHUB_REPOSITORY=owner/repo
export GITHUB_EVENT_PATH=/github/workflow/event.json

cortex github run --event issue_comment
# Error: GitHub token required. Set GITHUB_TOKEN env var or use --token
# (Even though GITHUB_TOKEN IS set — it is just never read)

Fix

Read env var fallbacks before erroring:

let token = args.token
    .or_else(|| std::env::var("GITHUB_TOKEN").ok())
    .ok_or_else(|| anyhow::anyhow!("..."))?;

File

src/cortex-cli/src/github_cmd.rs lines 263-278 (run_github_agent)

Metadata

Metadata

Assignees

No one assigned

    Labels

    invalidThis doesn't seem right

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions