Skip to content

fix(models): allow headless device-code login - #128457

Closed
gaoanze888 wants to merge 3 commits into
openclaw:mainfrom
gaoanze888:gaoanze888/models-auth-device-code-nontty
Closed

gaoanze888 wants to merge 3 commits into
openclaw:mainfrom
gaoanze888:gaoanze888/models-auth-device-code-nontty

Conversation

@gaoanze888

@gaoanze888 gaoanze888 commented Aug 24, 2026 •

Copy link
Copy Markdown

Closes #113326

What Problem This Solves

Fixes an issue where openclaw models auth login --provider openai --method device-code was rejected in non-interactive shells before the provider-owned device-code flow could start.

Why This Change Was Made

The non-TTY guard now resolves the requested provider and method first, then permits only methods whose provider-declared auth capability is kind: "device_code". Other login methods, including a method whose id happens to be device-code but is not a device-code capability, still require an interactive TTY.

User Impact

Headless operators and agents can start provider device-code recovery from the CLI without weakening the TTY boundary for interactive provider auth flows.

Evidence

  • pnpm test src/commands/models/auth.test.ts
  • pnpm check:changed -- src/commands/models/auth.ts src/commands/models/auth.test.ts
  • autoreview --mode local --engine pi --thinking high → clean

Regression coverage includes both the accepted provider-declared kind: "device_code" path and a same-id non-device OAuth method rejection.

Redacted real command proof from this branch:

$ OPENCLAW_STATE_DIR=/tmp/openclaw-pr128457-state \
  pnpm openclaw models auth login --provider openai --method device-code --profile-id openai:proof < /dev/null
[security] blocked URL fetch ([redacted]) targetOrigin=https://[redacted-url] reason=Blocked: resolves to private/internal/special-use IP address
◇  OpenAI device code failed
Blocked: resolves to private/internal/special-use IP address
◇  OAuth help ─────────────────────────────────────────────────────────────╮
│  Trouble with device code login? See https://[redacted-url]              │
╰──────────────────────────────────────────────────────────────────────────╯

This proves the non-TTY command reaches the provider-owned OpenAI device-code flow instead of failing at models auth login requires an interactive TTY. The actual provider network request was stopped by the local URL safety policy before any account code/token was exposed.

AI-assisted implementation; I reviewed the auth guard change and validation output.

@clawsweeper

clawsweeper Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added commands Command implementations size: XS labels Aug 24, 2026
@clawsweeper clawsweeper Bot added 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. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 24, 2026
@clawsweeper

clawsweeper Bot commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 26, 2026, 2:53 AM ET / 06:53 UTC.

ClawSweeper review

What this changes

The PR lets provider-declared headless-safe authentication methods run from models auth login without a TTY and marks OpenAI device-code login as eligible.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

The focused repair is correct: non-TTY login remains fail-closed unless the resolved provider method explicitly opts in. The prior public-contract documentation finding is addressed; this PR now needs normal SDK-contract review and exact-head checks.

Priority: P2
Reviewed head: 745f6f5a44fb32288adf48bb4c0eea9b05a9c9a8
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Focused repair with direct terminal proof and targeted guard coverage; the remaining decision is the public SDK contract plus exact-head validation.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The PR includes a redacted after-fix terminal trace showing piped stdin reaches the provider-owned device-code flow instead of failing at the TTY guard.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The PR includes a redacted after-fix terminal trace showing piped stdin reaches the provider-owned device-code flow instead of failing at the TTY guard.
Evidence reviewed 8 items Core guard: The resolved method is checked for explicit headless: true before the auth method runs; all other non-TTY methods still fail.
Provider-owned opt-in: Only OpenAI’s device-code descriptor receives the new opt-in.
Real callee behavior: The OpenAI device-code implementation uses progress, notes, URL opening, and external device confirmation; it does not request terminal input.
Findings None None.
Security None None.

Live Verification

Command: pnpm openclaw models auth login --provider openai --method does-not-exist ‹ /dev/null

Result: FAIL (failed) — step 1 run pnpm openclaw models auth login --provider openai --method does-not-exist ‹ /dev/null: terminal run was blocked by the previous command: terminal command failed with exit status 1: "pnpm openclaw models auth login --provider openai --method does-not-exist ‹ /dev/null"

$ node scripts/run-node.mjs models auth login --provider openai --method does-not-exist
[openclaw] Building TypeScript (dist is stale: missing_build_stamp - build stamp missing).
[openclaw] Building bundled plugin assets.
[canvas] build: node scripts/bundle-a2ui.mjs
[log] ‹DIR›/a2ui.bundle.js  chunk │ size: 399.96 kB
[log] ‹DIR›/a2ui-v0.9.bundle.js  chunk │ size: 615.66 kB
[log]
[success] rolldown v1.2.0 Finished in 81.28 ms
[diffs] build: node --import tsx ../../scripts/build-diffs-viewer-runtime.mts curated
[diffs-language-pack] build: node --import tsx ../../scripts/build-diffs-viewer-runtime.mts full
[discord] build: node --import tsx ../../scripts/build-discord-activity-sdk.mts
[tsdown-build] invocation 1/2 finished in 0.6s
node_modules/playwright-core/lib/coreBundle.js (65821:28) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
       ╭─[ node_modules/playwright-core/lib/coreBundle.js:65821:29 ]
       │
 65821 │               const value = eval(ˋ(${expr})ˋ);
       │                             ──┬─
       │                               ╰─── Use of direct ˋevalˋ here.
       │
       │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
───────╯

node_modules/playwright-core/lib/coreBundle.js (65828:28) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
       ╭─[ node_modules/playwright-core/lib/coreBundle.js:65828:29 ]
       │
 65828 │               const value = eval(ˋ(${expr})ˋ);
       │                             ──┬─
       │                               ╰─── Use of direct ˋevalˋ here.
       │
       │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
───────╯

node_modules/web-tree-sitter/web-tree-sitter.js (2343:30) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
      ╭─[ node_modules/web-tree-sitter/web-tree-sitter.js:2343:31 ]
      │
 2343 │           ASM_CONSTS[start] = eval(func);
      │                               ──┬─
      │                                 ╰─── Use of direct ˋevalˋ here.
      │
      │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
──────╯

node_modules/web-tree-sitter/web-tree-sitter.js (2366:32) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
      ╭─[ node_modules/web-tree-sitter/web-tree-sitter.js:2366:33 ]
      │
 2366 │           moduleExports[name] = eval(func);
      │                                 ──┬─
      │                                   ╰─── Use of direct ˋevalˋ here.
      │
      │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
──────╯

[tsdown-build] invocation 2/2 finished in 11.3s
[plugin-control-plane-loads] verified 35 built modules with native require and checked doctor closures
runtime-postbuild: 11 phases completed in 3370ms (slowest: built plugin control-plane loads 2684ms)
│
◇

OpenClaw 2026.8.1 (745f6f5) — I've seen your commit messages. We'll work on that together.

Unknown auth method. Run openclaw models auth login --provider openai without --method to choose interactively.
[ELIFECYCLE] Command failed with exit code 1.

Assertions:

  • FAIL expect_output: Unknown auth method

How this fits together

The models-auth CLI resolves a provider plugin and selected auth method, then runs it to persist an auth profile. OpenAI’s device-code method displays verification instructions, polls for external confirmation, and returns an OAuth profile.

flowchart LR
  A[Headless CLI command] --> B[Resolve provider and auth method]
  B --> C{Headless-safe method?}
  C -->|No| D[TTY-required error]
  C -->|Yes| E[OpenAI device-code flow]
  E --> F[Verification instructions]
  F --> G[Saved OpenAI auth profile]
Loading

Decision needed

Question Recommendation
Should ProviderAuthMethod.headless become the public plugin contract for allowing a non-TTY models auth login flow? Adopt the explicit provider opt-in: Accept the documented no-terminal-input contract and keep the core default fail-closed behavior.

Why: The implementation is mechanically sound, but this exported capability determines when third-party provider code may bypass a core interactive-safety guard.

Before merge

  • Resolve merge risk (P1) - headless is a new public provider-auth capability: external plugins can opt into bypassing the CLI TTY guard, so maintainers must accept the documented no-terminal-input guarantee as the contract boundary.
  • Complete next step (P2) - A maintainer must decide whether the new exported provider-auth capability is the intended permanent SDK contract; no mechanical repair remains.
Agent review details

Security

None.

PR surface

Source +17, Tests +58. Total +75 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 3 19 2 +17
Tests 1 58 0 +58
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 77 2 +75

Review metrics

Metric Value Why it matters
Production and test delta production +17 net (+19/-2), tests +58 The production growth is the generic provider-auth capability and its OpenAI opt-in; focused tests cover the new allow and deny paths.
Provider-auth API 1 optional capability added headless changes the exported provider-method contract and can affect plugin behavior in automation.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #113326
Summary: This PR is the candidate fix for the issue’s missing non-TTY OpenAI device-code refresh path; its separate auth-store messaging concern remains outside this patch.

Members:

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

Merge-risk options

Maintainer options:

  1. Accept the explicit opt-in contract (recommended)
    Merge after accepting headless as the provider-owned no-terminal-input contract and after exact-head checks complete.
  2. Redesign the public surface
    Pause this PR if maintainers do not want third-party provider methods to declare non-TTY eligibility through the SDK.

Technical review

Best possible solution:

Land the generic provider-owned opt-in after accepting that SDK contract and confirming exact-head checks, while preserving the default TTY requirement for every method that does not opt in.

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

Yes, by source: the documented OpenAI --device-code shortcut maps to the selected method, while the former top-level non-TTY guard rejected it before resolution. The PR’s redacted terminal trace shows the repaired branch reaches the provider flow.

Is this the best way to solve the issue?

Yes: resolving the requested method first and requiring explicit provider-owned eligibility is narrower and safer than allowing any method named device-code.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against fc64c5704a77.

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR includes a redacted after-fix terminal trace showing piped stdin reaches the provider-owned device-code flow instead of failing at the TTY guard.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: This repairs a bounded headless provider-auth workflow without evidence of a widespread current outage.
  • merge-risk: 🚨 compatibility: The exported provider-auth method shape gains a new opt-in capability for external plugins.
  • merge-risk: 🚨 auth-provider: The change permits provider authentication without a terminal only after provider-declared eligibility.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR includes a redacted after-fix terminal trace showing piped stdin reaches the provider-owned device-code flow instead of failing at the TTY guard.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR includes a redacted after-fix terminal trace showing piped stdin reaches the provider-owned device-code flow instead of failing at the TTY guard.

Evidence

What I checked:

Likely related people:

  • Vincent Koc: Authored the historical OpenAI device-code feature used by this repair. (role: introduced device-code authentication; confidence: high; commits: da86ce788778; files: extensions/openai/provider-contract-api.ts, extensions/openai/openai-chatgpt-provider.ts)
  • Jason (Json): Authored the later CLI auth refresh work in the persistence path this command invokes. (role: recent model-auth contributor; confidence: medium; commits: 9b2bb9c0a624; files: src/commands/models/auth.ts)
  • pashpashpash: Authored the change making ChatGPT login the default OpenAI auth path adjacent to this device-code flow. (role: OpenAI auth-flow contributor; confidence: medium; commits: 3b44dfc367af; files: extensions/openai/provider-contract-api.ts)

Rank-up moves

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

  • Accept or reject the exported headless provider-auth contract.
  • Wait for exact-head required checks to finish green.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (5 earlier review cycles)
  • reviewed 2026-08-24T02:15:30.022Z sha 520bd9bca7c59471e07df6b3cd280d39992684cb :: needs real behavior proof before merge. :: [P1] Gate the TTY exception on the resolved device-code capability
  • reviewed 2026-08-24T02:47:46.972Z sha fadcebb18f399bfb993e45ab86083b6b8a887673 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-24T10:18:41.681Z sha 2f18c84 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-25T11:19:39.172Z sha 2f18c84 :: found issues before merge. :: [P1] Require explicit headless eligibility for device-code methods
  • reviewed 2026-08-26T02:41:38.172Z sha 179696b :: found issues before merge. :: [P2] Document the public headless provider-auth contract

@gaoanze888

This comment was marked as spam.

@clawsweeper

clawsweeper Bot commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@gaoanze888

This comment was marked as spam.

@clawsweeper

clawsweeper Bot commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 24, 2026
@gaoanze888

This comment was marked as spam.

@clawsweeper

clawsweeper Bot commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 25, 2026
@gaoanze888

This comment was marked as spam.

@gaoanze888

This comment was marked as spam.

@clawsweeper

clawsweeper Bot commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@gaoanze888

This comment was marked as spam.

@gaoanze888

This comment was marked as spam.

@clawsweeper

clawsweeper Bot commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 26, 2026
@gaoanze888

This comment was marked as spam.

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

Labels

commands Command implementations extensions: openai 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. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Standalone codex CLI login and gateway 'openai' profile are separate auth stores, and there is no headless way to refresh the gateway one

1 participant