Skip to content

feature(models): allow headless device-code auth login - #184579

Open
nocodet888-arch wants to merge 1 commit into
openclaw:mainfrom
nocodet888-arch:feature/headless-device-code-login
Open

nocodet888-arch wants to merge 1 commit into
openclaw:mainfrom
nocodet888-arch:feature/headless-device-code-login

Conversation

@nocodet888-arch

@nocodet888-arch nocodet888-arch commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Related: #113326

What Problem This Solves

openclaw models auth login --provider openai --device-code is documented for remote/headless VMs, but non-TTY shells were rejected before the provider-owned device-code flow could start, so operators could not recover an expired Codex/OpenAI gateway profile without an interactive terminal.

User Impact

When a provider marks an auth method headless: true (OpenAI Codex --device-code / --method device-code), the terminal CLI can run models auth login without a TTY if --provider and --method resolve directly to that method. Interactive OAuth/API-key methods still require a TTY. Core and Gateway hosted login keep their caller-owned prompters (no stdin TTY requirement). After a successful headless CLI login, existing model-policy restrictions are kept without opening the consent picker.

Why This Change Was Made

Headless admission is CLI-scoped only: shared runModelsAuthLoginFlowCore / runModelsAuthLoginFlowForGateway no longer inspect process.stdin.isTTY. The CLI resolves provider+method before admitting non-TTY execution, rejects unresolved CLI-backed provider fallback pickers, and completes model access in keep mode so headless login cannot hang on prompter.select. OpenAI's device-code method opts into provider-owned headless.

Evidence

  • Changed: src/plugins/provider-authentication.types.ts, extensions/openai/provider-contract-api.ts, src/commands/models/auth.ts, src/commands/models/auth-model-policy.ts, src/commands/models/auth.test.ts, src/commands/models/auth-model-policy.test.ts, docs/cli/models.md
  • Unit: node scripts/run-vitest.mjs src/commands/models/auth.test.ts src/commands/models/auth-model-policy.test.ts — 46 + 8 passed (headless admission, CLI-backed picker rejection, fresh/imported keep-without-prompt, Core/Gateway hosted OAuth without TTY)
  • Packaged/source CLI proof below on Node 24.22.1

Real behavior proof

Behavior or issue addressed

Non-TTY models auth login --provider openai --device-code must enter the provider device-code flow instead of failing with the interactive-TTY gate. Missing provider, unresolved CLI-backed providers, and non-headless methods must still refuse non-TTY shells before opening pickers. Hosted Core/Gateway OAuth must keep working without terminal stdin. Existing model restrictions must be preserved without a post-login picker on the headless CLI path.

Canonical reachability path

Production CLI modelsAuthLoginCommand → runModelsAuthLoginFlow(..., "cli") → direct provider+method resolution → headless gate → OpenAI runOpenAICodexDeviceCode. Hosted callers use "core" / "gateway" entrypoints and skip the stdin gate.

Shared helper / provider constraint check

Adds optional ProviderAuthMethod.headless owned by the provider contract. Does not weaken TTY for interactive OAuth/API-key/setup-token. Does not change auth selection, persistence, or Gateway refresh ownership. Does not apply stdin policy inside shared Core/Gateway login.

Real environment tested

Source CLI via node --import ./scripts/tsx.mjs src/entry.ts on Node 24.22.1; isolated OPENCLAW_STATE_DIR; stdin not a TTY (</dev/null).

Exact steps or command run after this patch

export PATH="/home/box/.local/node-v24.22.1-linux-x64/bin:$PATH"
STATE=$(mktemp -d); export OPENCLAW_STATE_DIR="$STATE" OPENCLAW_CONFIG_PATH="$STATE/openclaw.json"; echo '{}' > "$OPENCLAW_CONFIG_PATH"
node --import ./scripts/tsx.mjs src/entry.ts models auth login --provider openai --device-code </dev/null; echo EXIT:$?
node --import ./scripts/tsx.mjs src/entry.ts models auth login --provider openai </dev/null; echo EXIT:$?
node --import ./scripts/tsx.mjs src/entry.ts models auth login --provider openai --method oauth </dev/null; echo EXIT:$?
node --import ./scripts/tsx.mjs src/entry.ts models auth login </dev/null; echo EXIT:$?
node --import ./scripts/tsx.mjs src/entry.ts models auth login --provider claude-cli --method device-code </dev/null; echo EXIT:$?
node scripts/run-vitest.mjs src/commands/models/auth.test.ts src/commands/models/auth-model-policy.test.ts --reporter=verbose

Evidence after fix

# A) --device-code non-TTY: past TTY gate into device-code owner (network SSRF sandbox blocks auth.openai.com — post-gate proof; exit 1 from provider fetch block)
◇  Provider sign-in …
◇  Existing CLI sign-in … Continue with sign-in …
[security] blocked URL fetch (openai-chatgpt-device-code) targetOrigin=https://auth.openai.com reason=Blocked: resolves to private/internal/special-use IP address
◇  OpenAI device code failed
Blocked: resolves to private/internal/special-use IP address
EXIT:1

# B) --provider only non-TTY (auto-resolves OAuth; exit 1) — headless gate
models auth login requires an interactive TTY unless the resolved provider auth method explicitly supports headless execution. …
EXIT:1

# C) --method oauth non-TTY (exit 1) — resolved method not headless
models auth login requires an interactive TTY unless the resolved provider auth method explicitly supports headless execution. …
EXIT:1

# D) missing --provider non-TTY (exit 1) — no provider picker
models auth login cannot open the provider picker because --provider is missing and stdin is not an interactive TTY.
EXIT:1

# E) CLI-backed provider fallback non-TTY (exit 1) — no fallback picker
models auth login cannot open the provider picker because provider "claude-cli" does not expose a directly selectable OpenClaw auth flow and stdin is not an interactive TTY.
EXIT:1

# Unit
✓ allows explicit provider device-code login without an interactive TTY
✓ rejects non-TTY login when a provider uses the device-code id for a non-headless method
✓ rejects non-TTY login without an explicit provider
✓ rejects non-TTY CLI-backed provider fallback before opening a picker
✓ keeps existing model restrictions without prompting after fresh headless credentials
✓ keeps existing model restrictions without prompting after imported headless credentials
✓ keeps core-hosted OAuth available without a TTY
✓ keeps Gateway-hosted OAuth available without a TTY
✓ keeps restrictions in keep mode without prompting
Test Files  2 passed (2)
     Tests  54 passed (54)

Remaining live-proof gap

This sandbox cannot complete a full OpenAI device authorization (SSRF policy blocks auth.openai.com). Credential persistence after operator approval and a live restriction readback therefore remain covered by the focused regressions above (fresh + imported keep-without-prompt), not by a completed live login.

Notes for reviewers

@clawsweeper

clawsweeper Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation commands Command implementations extensions: openai size: S labels Oct 26, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:feature Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:feature Preliminary submission classification; full source review pending. labels Oct 26, 2026
@clawsweeper

clawsweeper Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

Allow provider-approved device-code login without terminal input while preserving existing model restrictions.

Example: Run openclaw models auth login --provider openai --device-code &lt;/dev/null on a remote VM.

  • Before: The CLI rejects the command because stdin is not an interactive TTY.
  • After: The CLI starts OpenAI device authorization and keeps existing model restrictions without opening a picker.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The implementation is focused and source-consistent, but the real CLI evidence covers admission rather than successful completion.
Proof confidence 🦪 silver shellfish (2/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Needs a maintainer decision · Fix scope: Partial
User problem: Remote operators cannot run the documented device-code recovery command from a shell without terminal input.
Reason: The CLI repair has clear value and correctly uses Related for the broader issue, but the public headless capability and prompt-free completion policy lack a recorded owner decision.

Merge readiness

⛔ Blocked before merge - 2 items remain

This PR addresses a documented headless-login failure that remains on current main; no concrete introduced bug was found, but the public capability needs an owner decision.

Priority: P2
Reviewed head: 148c48444dc06e398263a6d44604980e1d3a6c32
Owner decision: Required. See Decision needed.

Decision needed

  • Question: Should ProviderAuthMethod expose an optional headless capability that admits non-TTY CLI login and preserves restrictions without a consent picker?
  • Recommendation: Approve the provider-owned opt-in: Accept headless as an explicit no-terminal-input capability while retaining TTY requirements for other methods.
  • Why: This expands the public provider contract and deliberately changes CLI completion behavior; no owner approval of this direction was found in the reviewed discussion.

Before merge

  • Add real behavior proof - The isolated source-CLI trace proves non-TTY admission and interactive-case rejection, but the blocked OpenAI request never issues a code or reaches completion; provide redacted terminal output, logs, or a recording of successful non-TTY authorization, saved-profile readback, and preserved restrictions without a picker, keeping API keys, IPs, phone numbers, and non-public endpoints private. After adding proof, update the PR body, then request a new review with @clawsweeper re-review. The PR author or someone with repository write access can request it.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.

Findings

None.

Tests

  • Missing end-to-end proof: The supplied CLI run stops before authorization succeeds, and no base-red/head-green execution of the added regressions is shown.
Agent review details

How this fits together

The model-auth CLI selects a provider method, invokes its authentication flow, persists credentials through existing owners, and completes model-access handling.

flowchart TD
  A[Model auth CLI] --> B[Provider and method selection]
  B --> C[CLI headless admission]
  C --> D[Provider device authorization]
  D --> E[Existing credential persistence]
  E --> F[Gateway auth refresh]
  F --> G[Keep model restrictions]
Loading

Technical review

Best possible solution:

Keep the focused CLI repair and existing persistence owners, subject to approval of the optional provider capability.

Do we have a high-confidence way to reproduce the issue?

Current-main source deterministically rejects non-TTY device-code login before provider dispatch, despite the documented remote-login command; no target code or tests were run during this review.

Is this the best way to solve the issue?

The patch is a focused repair using existing authentication and model-policy owners, with explicit provider opt-in preferable to assuming every device-code method avoids prompts.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against b4e7ddf159ec.

Provenance checked

  • CLI terminal admission changes intended behavior with a stated reason (6084421: Provider-auth plugins originally exposed an interactive login command; the original patch installed its unconditional terminal guard.)
  • Provider model-access completion changes intended behavior with a stated reason (feat(auth): ask before showing restricted provider models #144468: Save credentials before asking whether to widen model visibility, and never widen restrictions without current consent.)
  • Hosted login entry points keeps the original intent (77edfe7: Share the existing provider login and persistence flow with non-TTY channel callers.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Ayaan Zaidi: Raw commit 047c925 adds src/commands/models/auth-model-policy.ts:102 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 047c925cff7e; files: src/commands/models/auth-model-policy.ts)
  • Peter Steinberger: Raw commit 89c01cd adds extensions/openai/provider-contract-api.ts:104 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 89c01cd979ef; files: extensions/openai/provider-contract-api.ts)

PR surface

Source +60, Tests +159, Docs 0. Total +219 across 7 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 4 76 16 +60
Tests 2 159 0 +159
Docs 1 1 1 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 236 17 +219

Review metrics

Metric Value Why it matters
Public provider capability 1 optional field ProviderAuthMethod.headless adds provider-controlled eligibility for non-TTY CLI login.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #113326
Summary: This PR targets the issue's non-TTY login failure while leaving its separate credential-store concerns outside scope.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Labels

Label changes:

  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit. Replaced prior rating: 🧂 unranked krab.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🦪 silver shellfish, so this older rating label is no longer current.

Label justifications:

  • P2: The change repairs an advanced headless authentication workflow with interactive and hosted alternatives available.
  • merge-risk: 🚨 compatibility: The optional headless field expands the public provider-method behavior contract and needs owner acceptance.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit. Replaced prior rating: 🧂 unranked krab.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Complete the successful non-TTY login scenario described in the proof assessment.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (2 earlier review cycles)
  • reviewed 2026-10-26T12:09:46.836Z sha b57231a40927ac101c4a9830502d33b026046a4d :: needs real behavior proof before merge. :: [P1] Keep the terminal guard out of hosted login flows | [P2] Complete headless login without the model-access picker | [P2] Reject provider fallback pickers before admitting non-TTY login
  • reviewed 2026-10-26T16:17:26.521Z sha 2093efb9902f994688f8aec29aeba0052d8ebfc5 :: needs real behavior proof before merge. :: none

Reviewed October 26, 2026, 7:56 PM ET / 23:56 UTC (Revision 3).

@nocodet888-arch

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Repaired for the three findings:

  1. TTY/headless admission is CLI-entrypoint only; Core/Gateway no longer consult process.stdin.isTTY.
  2. Headless CLI completes model access in keep mode (no prompter.select) for fresh and imported credentials.
  3. Non-TTY CLI rejects unresolved CLI-backed provider fallback / missing provider before opening pickers.

New head: 2093efb9902f994688f8aec29aeba0052d8ebfc5. PR body Real behavior proof refreshed.

@nocodet888-arch
nocodet888-arch force-pushed the feature/headless-device-code-login branch from b57231a to 2093efb Compare October 26, 2026 16:09
@clawsweeper

clawsweeper Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:feature Preliminary submission classification; full source review pending. and removed merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. clawsweeper:intake:feature Preliminary submission classification; full source review pending. labels Oct 26, 2026
@nocodet888-arch
nocodet888-arch force-pushed the feature/headless-device-code-login branch from 2093efb to 148c484 Compare October 26, 2026 23:40
@nocodet888-arch

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Rebased onto current main (head 148c48444dc) to clear inherited doctor.warns-state-directory-is-missing.e2e red fixed upstream by #184784. Feature surface and Real behavior proof unchanged; maintainer product decision on ProviderAuthMethod.headless still required.

@clawsweeper

clawsweeper Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added the clawsweeper:intake:feature Preliminary submission classification; full source review pending. label Oct 26, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Nov 3, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clawsweeper:intake:feature Preliminary submission classification; full source review pending. commands Command implementations docs Improvements or additions to documentation extensions: openai merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: M status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant