Repository navigation
Description
Summary
normalize_github_host_key() strips a URL scheme and splits the host on /, but never on :. GitHub's apps.json keys carry a client-id suffix (github.com:Iv1.b507a08c87ecfe98), so the comparison against "github.com" fails, the function returns None, and select_preferred_token() drops the entry via ?.
// crates/jcode-base/src/auth/copilot.rs:596
let host = host.split('/').next().unwrap_or_default().trim(); // never splits on ':'
let host = host.to_ascii_lowercase();
if host == "github.com" || host == "api.github.com" || host.ends_with(".github.com") {// crates/jcode-base/src/auth/copilot.rs:553
let normalized_host = normalize_github_host_key(host)?; // valid token silently droppedThis matters more now that GitHub writes credentials to apps.json rather than hosts.json.
Why it's more than cosmetic
Per the load_github_token() doc comment, apps.json is source 6, ahead of the trusted OpenCode/pi auth.json entries at source 7. When apps.json is discarded, jcode continues down the chain and can pick up a stale token from ~/.pi/agent/auth.json.
In my case that token had been revoked — GitHub returns 401 Bad credentials on the exchange — and the resulting failure surfaces to the user as:
The requested model is not supported. code: model_not_supported
A model-shaped error for an auth-shaped problem. jcode auth-test --provider copilot reported not_configured the whole time, while a perfectly valid token sat unread in apps.json.
This is made considerably harder to diagnose by #640, which emits a byte-identical model_not_supported message from an entirely unrelated cause. Fixing one changes nothing observable while the other is present.
Reproduce
- Authenticate GitHub Copilot such that credentials land in
~/.config/github-copilot/apps.json(current GitHub behaviour;hosts.jsonis no longer written) - Ensure
~/.pi/agent/auth.jsonholds an old or revokedgithub-copilottoken jcode --provider copilot→ HTTP 400, and auth reportsnot_configured
Setting COPILOT_GITHUB_TOKEN to the exact value from apps.json makes all four auth-test probes pass, confirming the token was valid throughout and only the file parser rejected it.
Suggested fix
Split the host on : before comparing, mirroring the existing / handling:
let host = host.split('/').next().unwrap_or_default().trim();
let host = host.split(':').next().unwrap_or_default().trim();github_host_priority() receives raw_host separately, so relative ordering between multiple entries is unaffected.
Two things worth addressing alongside it:
- Don't fail silently. A discarded credential file should log at WARN, naming the file and the rejected key. Nothing in the logs indicated
apps.jsonhad been read and thrown away. - Surface auth failures as auth failures. A failed token exchange currently reaches the user as
model_not_supported, which sends people debugging the wrong subsystem entirely.
A unit case for the key github.com:Iv1.b507a08c87ecfe98 would fit alongside the existing cases in copilot_auth_tests.rs.
Environment
jcode v0.61.1 (438789e), macOS, Copilot plus_monthly_subscriber_quota
Activity
[-][bug] Copilot apps.json credentials silently discarded: host key `github.com:<client-id>` fails normalization, falls through to stale token[/-][+][bug] Copilot ignores valid apps.json token: `github.com:<client-id>` key fails normalization[/+]almai commentedon Jul 28, 2026
Workaround
load_github_token()checks environment variables at steps 1–3, before any file source, so supplying the token directly bypasses the broken parser at step 6.Extract the valid token from
apps.json:python3 -c "import json;d=json.load(open('$HOME/.config/github-copilot/apps.json'));print(next(v['oauth_token'] for v in d.values() if isinstance(v,dict) and v.get('oauth_token')))"Then export it:
export COPILOT_GITHUB_TOKEN=ghu_…With that set, all four
jcode auth-test --provider copilotprobes pass.Two things that cost me time, worth flagging for anyone else hitting this:
The daemon holds the environment, not your shell. jcode clients attach to a background server, and the server makes the API calls. Sourcing the export into an existing shell does nothing for an already-running daemon. It has to be:
jcode server stop --force export COPILOT_GITHUB_TOKEN=ghu_… jcode --provider copilotPutting the export in a shell rc file is the durable version, since every daemon spawned from a login shell then inherits it.
Deleting the stale
~/.pi/agent/auth.jsonentry does not help.apps.jsonis still rejected by the normalization bug regardless, so jcode ends up with no credential at all rather than a bad one. The environment variable is the only route that actually works while this is open.1jehuang commentedon Jul 28, 2026
Confirmed and fixed in #643, using your suggested fix: the host is now split on
:as well as/, sogithub.com:Iv1.<client-id>keys fromapps.jsonnormalize correctly instead of being silently dropped. Added a unit case for that exact key alongside the existing ones incopilot_auth_tests.rs.Your framing of why this is more than cosmetic was the useful part: the silent drop is what let a stale, revoked token from a lower-priority source win. #640 is fixed in the same PR, so the byte-identical
model_not_supportedconfusion should be gone from both directions.The two follow-ups you raised are both fair and not addressed here:
model_not_supported.Neither is a one-liner, and (2) touches error mapping across the provider, so I left them out rather than bundling them into this fix. Thanks for an unusually well-researched report.
— Jcode agent (automated triage), on behalf of @1jehuang
fix(copilot): use Copilot catalog ids and accept apps.json client-id …
fix(copilot): use Copilot catalog ids and accept apps.json client-id …
fix(copilot): use Copilot catalog ids and accept apps.json client-id …
fix(copilot): use Copilot catalog ids and accept apps.json client-id …