Skip to content

fix(providers): skip interactive re-auth prompt in non-interactive environments - #471

Merged
codemie-ai merged 4 commits into
mainfrom
EPMCDME-13953_non-interactive-sso
Aug 7, 2026
Merged

fix(providers): skip interactive re-auth prompt in non-interactive environments#471
codemie-ai merged 4 commits into
mainfrom
EPMCDME-13953_non-interactive-sso

Conversation

@vadimvlasenko

Copy link
Copy Markdown
Collaborator

Summary

CLI hangs (and crashes with Error [ERR_USE_AFTER_CLOSE]: readline was closed) when SSO
re-authentication is needed but no TTY is attached — e.g. CI, automation, piped invocations. This
fixes it: the shared auth-failure gate now detects a non-interactive environment and fails fast
with a clear message instead of attempting an inquirer prompt.

Changes

  • feat(utils): new isNonInteractiveEnvironment() utility (src/utils/interactive.ts) — single
    source of truth for !process.stdin.isTTY.
  • fix(providers): handleAuthValidationFailure (src/providers/core/auth-validation.ts) now
    skips promptForReauth entirely when non-interactive, falling into the same clean-failure path
    already used for providers with no promptForReauth (e.g. JWT). One edit fixes all three call
    sites (AgentCLI.handleRun, cli/commands/profile/index.ts, utils/auth.ts:getAuthenticatedClient)
    and every current/future ProviderSetupSteps implementer.
  • docs: new "Non-Interactive Environments (CI/Automation)" section in docs/AUTHENTICATION.md.
  • chore: SDLC planning artifacts (spec, plan, technical analysis, complexity assessments, code
    review verdicts, QA report) under docs/superpowers/tasks/2026-08-06-non-interactive-sso/.

Testing

  • Tests added/updated — 8 new tests (3 for the utility, 5 for the guard: TTY present/absent x
    promptForReauth present/absent, plus a null-setupSteps case)
  • Manual testing done — reproduced the exact bug live in this session (a non-interactive
    codemie call with expired SSO creds hung and crashed with ERR_USE_AFTER_CLOSE) before the
    fix landed

Checklist

  • Code follows project standards
  • CI is green (npm run ci gates: license-check, lint, typecheck, build, unit — 2636 passed,
    integration — 213 passed)
  • No merge conflicts with main

Closes EPMCDME-13953.

Single source of truth for "can we prompt the user right now?", based on
process.stdin.isTTY. Used to guard interactive prompts (e.g. inquirer) that
would otherwise hang or crash (ERR_USE_AFTER_CLOSE) when no TTY is attached
to stdin (CI, automation, piped input).

Part of EPMCDME-13953.
…vironments

handleAuthValidationFailure now checks isNonInteractiveEnvironment() before
calling setupSteps.promptForReauth. In a non-interactive context (no TTY),
the interactive prompt is skipped entirely and the provider is treated the
same way as one with no promptForReauth implementation at all -- printing
the actionable failure message and returning a clean, non-hanging result.

Fixes the CLI hanging (and crashing with ERR_USE_AFTER_CLOSE) when SSO
re-authentication is needed but no TTY is available, e.g. in CI/automation.

Fixes EPMCDME-13953.
Adds a "Non-Interactive Environments (CI/Automation)" section to
docs/AUTHENTICATION.md explaining the auto-detect fail-fast behavior,
its message, and the JWT Bearer Authorization workaround for CI use.

Part of EPMCDME-13953.
Spec, plan, technical analysis, complexity assessments, code review
verdicts, and QA report for EPMCDME-13953, produced by the sdlc-standard
flow.

Part of EPMCDME-13953.
@codemie-ai
codemie-ai merged commit 5b2de4b into main Aug 7, 2026
9 of 10 checks passed
@codemie-ai
codemie-ai deleted the EPMCDME-13953_non-interactive-sso branch August 7, 2026 12:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants