[Bug] Codex device auth READY but resource tools return AUTH_REQUIRED for domestic ap-singapore env
Summary
With @cloudbase/[email protected] in Codex, device authentication reports READY, but resource/control-plane tools return AUTH_REQUIRED after binding a domestic-site CloudBase environment whose region is ap-singapore.
Adding an explicit project config with site: "domestic" immediately fixes all resource tools without another login:
{
"site": "domestic",
"region": "ap-singapore",
"envId": "<redacted-env-id>"
}
This looks like a site-resolution / credential-slot regression for the region shared by both domestic and international sites.
Environment
- Host: Windows, Codex desktop/native plugin
- CloudBase plugin wrapper:
0.2.0 - MCP package:
@cloudbase/[email protected] - npm package
gitHead:0f6b73dcc952fe518e31ed6346ae87521b697309 - Node.js:
v24.19.0 - npm:
12.0.2 - CloudBase site:
domestic - CloudBase region:
ap-singapore tcbCLI was not installed or used
No credentials, account IDs, environment IDs, device codes, request IDs, or user identifiers are included in this report.
Steps to reproduce
- Start the local MCP server through the Codex plugin:
{ "command": "npx", "args": ["-y", "@cloudbase/cloudbase-mcp@latest"] } - Use a domestic-site Tencent Cloud account with a CloudBase environment in
ap-singapore. - Do not create
.cloudbase/project.jsonand do not setTCB_SITE. - Run device authentication:
auth(action="start_auth", authMode="device") - Complete the browser authorization.
- Bind the known environment:
auth(action="set_env", envId="<redacted-env-id>") - Confirm auth status:
{ "auth_status": "READY", "credential_scope": "account", "current_region": "ap-singapore", "current_env_id": "<redacted-env-id>" } - Call either:
envQuery(action="info", envId="<redacted-env-id>") callCloudApi(service="tcb", action="DescribeEnvs", region="ap-singapore")
Actual behavior
Both resource/control-plane calls return:
{
"ok": false,
"code": "AUTH_REQUIRED",
"message": "当前未登录,请先调用 auth 工具完成认证。"
}
Restarting Codex, explicitly rebinding the environment, logging out, and completing a fresh device authorization do not fix the issue.
Expected behavior
After auth(status) reports READY and set_env succeeds, resource tools should use the same valid credential and access the bound domestic-site Singapore environment.
If the site cannot be inferred safely, the tool should return an actionable SITE_REQUIRED / ambiguous-site error instead of incorrectly reporting that the user is not logged in.
Verified workaround
Create .cloudbase/project.json:
{
"site": "domestic",
"region": "ap-singapore",
"envId": "<redacted-env-id>"
}
The next envQuery(action="info", ...) call succeeds immediately in the same MCP process and returns the expected environment state. No new login and no tcb CLI are required.
Source-level analysis
The behavior matches the published 2.32.2 source at 0f6b73dc...:
- Credentials are split into
domestic/intlslots; legacy flat credentials are treated as domestic: - The device branch of
auth(start_auth)calls the toolboxloginByWebAuth()directly instead of theensureLogin()path that performs site-slot merging: set_envapplies the matched region, but does not persist a site:ap-singaporebelongs to both sites; when site is unspecified, the resolver defaults the ambiguous region tointl:- Resource managers read the site-specific login state and throw
AUTH_REQUIREDwhen the inferredintlslot is empty: - The project config workaround is an explicitly supported source of
site,region, andenvId:
Possible fixes
- Persist the resolved/authenticated site together with the region during
set_env. - Route the device-auth branch through the same site-slot merge used by
ensureLogin(), or explicitly store the returned credential in the resolved site slot. - When
ap-singaporeis ambiguous and exactly one credential slot is usable, prefer that slot or return a structured ambiguous-site diagnostic. - Add a regression test for: domestic account +
ap-singapore+ device auth +set_env+envQuery(info).
Thank you for this exceptionally detailed report 🙏 — especially the source-level analysis, which located the exact chain correctly and saved us a lot of investigation time.
We have verified every point against the latest main branch and confirmed the bug is real. The root cause matches your analysis:
- The device-flow branch calls toolbox's
loginByWebAuth()directly, bypassing the site-slot merge insideensureLogin(), so the credential stays in flat format (equivalent to the domestic slot) set_envonly persistsTCB_REGIONand never writes any site informationap-singaporeexists in the region lists of both domestic and intl sites, andresolveSite()defaults ambiguous regions tointl(to preserve existing international-site behavior)- Resource tools resolve
site=intlviagetCloudBaseManager()→resolveSiteAndRegion(), find the intl slot empty, and incorrectly reportAUTH_REQUIRED - Meanwhile
auth(status)callspeekLoginState()with no arguments, which defaults to the domestic slot, finds the flat credential, and reportsREADY
Root cause in one sentence: status reads the domestic slot while resource tools read the intl slot — the two sides disagree.
We adopt all of your proposed fix directions and plan to fix it as follows:
- Persist the resolved site along with the region when
set_envbinds an environment (eliminating ambiguity for subsequent calls) - Merge the credential into the correct site slot after device-flow login completes (aligning with the
ensureLogin()merge behavior) - When the region is ambiguous and only one slot has a usable credential, prefer that slot; when both slots are usable, return a structured ambiguity error (
SITE_REQUIRED) instead of incorrectly reporting "not logged in" - Add a regression test: domestic account + ap-singapore + device auth + set_env + envQuery(info)
Thanks again — the workaround verification (explicit site: "domestic" in .cloudbase/project.json) was very valuable to us.