fix: use accounts endpoint for account metadata#128
Conversation
@loongphy/codex-auth-darwin-arm64
@loongphy/codex-auth-darwin-x64
@loongphy/codex-auth-linux-arm64
@loongphy/codex-auth-linux-x64
@loongphy/codex-auth-win32-arm64
@loongphy/codex-auth-win32-x64
@loongphy/codex-auth
commit: |
Greptile SummaryThis PR replaces the legacy Node.js-based HTTP layer with
Confidence Score: 5/5Safe to merge; the curl migration is well-scoped, the account parser is correct, and the previously-flagged guard for all-invalid items has been added. The account parser correctly handles empty-items, all-invalid-items, null names, and empty names. The curl output parsing uses lastIndexOfScalar on the last newline which is robust even when the response body itself contains newlines or embedded status-like strings. Proxy configuration, executable resolution, and error propagation all follow established patterns in the codebase. src/api/http_node.zig — the batch command now runs all requests sequentially; worth a second look if multi-account refresh latency becomes a user complaint. Important Files Changed
Sequence DiagramsequenceDiagram
participant Caller
participant http_node.zig
participant curl
participant ChatGPT API
Note over Caller,ChatGPT API: Single GET
Caller->>http_node.zig: runGetJsonCommand(endpoint, token, acct_id)
http_node.zig->>http_node.zig: resolveCurlExecutableForLaunchAlloc()
http_node.zig->>http_node.zig: maybeConfigureCurlProxy(env_map)
http_node.zig->>curl: spawn [--silent --show-error --location --max-time 5 --write-out newline+http_code]
curl->>ChatGPT API: GET /backend-api/accounts
ChatGPT API-->>curl: {items:[...]} HTTP 200
curl-->>http_node.zig: "stdout = body + newline + 200"
http_node.zig->>http_node.zig: parseCurlHttpOutput() split on last newline
http_node.zig-->>Caller: "HttpResult{body, status_code}"
Note over Caller,ChatGPT API: Batch GET — sequential, no concurrency
loop for each request
http_node.zig->>curl: spawn curl for request[i]
curl->>ChatGPT API: GET /backend-api/... (usage)
ChatGPT API-->>curl: response
curl-->>http_node.zig: stdout
http_node.zig->>http_node.zig: parseCurlHttpOutput()
end
http_node.zig-->>Caller: "BatchHttpResult{items[]}"
Prompt To Fix All With AIFix the following 1 code review issue. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 1
src/api/http_node.zig:153-155
**`max_concurrency` silently ignored in batch path**
`runCurlGetJsonBatchCommand` accepts `max_concurrency` but discards it with `_ = max_concurrency`, making all batch requests fully sequential. The old Node.js implementation honoured a concurrency of up to 3 in parallel workers. With the curl implementation every account refresh is a separate `curl` child-process spawn executed one-after-another, so refresh latency now scales linearly with the number of stored accounts. The docs have already removed the "maximum concurrency of 3" note, but the public function signature still accepts the parameter — callers that pass a value > 1 expecting parallelism will silently get none.
Reviews (4): Last reviewed commit: "fix: use curl for API refresh [skip ci]" | Re-trigger Greptile |
Summary
GET /backend-api/accounts.curlwith no Node fetch fallback; missing curl now reportsCurlRequired/curl is required....items[].idanditems[].name; treat empty or unusableitemsresponses as no-op so stored names are left unchanged.codex-auth/<version>User-Agent and documentCODEX_AUTH_CURL_EXECUTABLE.Verification
HOME=/tmp/codex-auth-curl zig build --build-file /coding/codex-auth/build.zig --cache-dir /tmp/codex-auth-curl/zig-cache --global-cache-dir /tmp/codex-auth-curl/zig-global-cache --prefix /tmp/codex-auth-curl/zig-out testHOME=/tmp/codex-auth-curl zig build --build-file /coding/codex-auth/build.zig --cache-dir /tmp/codex-auth-curl/zig-cache --global-cache-dir /tmp/codex-auth-curl/zig-global-cache --prefix /tmp/codex-auth-curl/zig-out run -- listzig build run -- listagainst the local Business/Plus auth setup returned successfully.Notes
curlreturned HTTP 200 for/backend-api/accountswith bothcodex-auth/<version>andcodex-cliUAs, while Node fetch returned Cloudflare 403 unless using a browser User-Agent. This PR intentionally does not spoof browser or Codex CLI identity.[skip ci], so GitHub did not schedule new status checks for those pushes.