Repository navigation
Conversation
The DoiT-provided AI access request read the cached DoiT token directly and never ran restish's auth handler, so once the access token expired it got a 401 and told the user to run dci login, even though the stored refresh token was still valid. Refresh the token first, the same way other requests do, without ever falling back to the browser login.
taltultc
left a comment
There was a problem hiding this comment.
The test covers the refreshed bearer reaching the AI access request. Please address the two inline findings before merge.
| if cli.Cache == nil { | ||
| return "", nil | ||
| } | ||
| reloadCredentialCache() |
There was a problem hiding this comment.
🔴 Credential cache
After the parent refreshes once, Viper keeps returning its bearer even when a child updates the cache. This also leaves the old bearer in use after logout or an account switch. Please honor the disk change and add a regression test for that sequence.
There was a problem hiding this comment.
Fixed in e94f226. The refresh no longer uses restish's TokenHandler and never touches cli.Cache. It loads cache.json into a private viper and writes the renewed token back through it, so nothing lands in the override layer and a later login or logout on disk always wins. Regression test: "after a refresh, a login or logout on disk still wins" (refresh, then a child login, then a child logout).
| if err != nil { | ||
| return "", err | ||
| } | ||
| if err := oauth.TokenHandler(source, key, probe); err != nil { |
There was a problem hiding this comment.
🟠 Refresh cancellation
A stalled token endpoint keeps the turn waiting even after cancellation. Please pass the turn context to the refresh HTTP request and give it a timeout.
There was a problem hiding this comment.
Fixed in e94f226. The refresh is now our own request, built with NewRequestWithContext on the turn's ctx plus a 15s timeout (aiDCIRefreshTimeout). Tests cover a stalled endpoint returning on cancel and on timeout.
There was a problem hiding this comment.
Beyond the inline findings, I also checked whether hard-coding dci:default in aiDCIBearer breaks users on a non-default restish profile. It doesn't: main.go pins rsh-profile to "default" (line 785) and rejects --profile/--rsh-profile arguments (line 935), so dci:default is the only cache key a session can have.
Extended reasoning...
One candidate was ruled out: the hard-coded dci:default key can't miss a profile's token, because the CLI forces the restish profile to "default" and rejects the profile flags.
Findings marked 🟡 are optional suggestions and need no follow-up push.
Address review on #214: the refresh no longer writes into cli.Cache's viper override layer (which shadowed later logins and logouts on disk), is bounded by the turn context and a 15s timeout, honors the OAuth params in apis.json, short-circuits DCI_API_KEY, and reports token-endpoint outages separately from an expired session.
There was a problem hiding this comment.
I reviewed the new commit, which replaces restish's TokenHandler with a direct refresh, and found no bugs. It is OAuth session-refresh code and another reviewer's change request is still open, so a human should look at it too.
What was reviewed:
- aiDCIBearer: the DCI_API_KEY check now runs first, the cache is read from and written to a scratch viper, and cli.Cache's override layer is never touched.
- aiRefreshDCIToken: limited by ctx plus a 15s timeout, 4xx and other failures map to separate errors, and the form fields match restish v0.21.2's refresh request.
- aiDCIOAuthParams reads token_url, client_id, scopes and extra params from apis.json and falls back to the main.go constants.
Extended reasoning...
The change touches ai_credentials.go, its tests, and the OAuth constants in main.go. It adds a refresh_token POST to the DoiT token endpoint and writes the renewed tokens back to restish's cache.json, which makes it authentication and credential-storage code. The latest commit rewrites the refresh path and appears to address the earlier inline concerns about the override layer, the missing timeout, apis.json params, error messages and the API-key path. A CHANGES_REQUESTED review from another reviewer predates that commit, and only that reviewer can confirm it is resolved, so approval is not appropriate.
Problem
With DoiT-provided access,
dci aiasks the DoiT API for a temporary Anthropic token. That request read the cached DoiT access token straight from the cache and never refreshed it, unlike every other request, which goes through restish's auth handler. Once the token expired (after an hour),dci aifailed with "your DoiT session has expired — run dci login", although the stored refresh token was still valid. Running any ordinary command refreshed it and madedci aiwork again.Fix
aiDCIBearer(ai_credentials.go) returns the bearer for that request, renewing an expired one first:DCI_API_KEYis returned as-is, with no refresh.cache.jsonis loaded into a private viper, and the refreshed token is written back through it.cli.Cacheis never touched, so a/login, account switch or logout done by a child process always wins, and the TUI picks the new token up on its next reload. Restish'soauth.TokenHandleris deliberately not used: it stores into viper's override layer, whichReadInConfignever clears, and it would write from the session goroutine while the TUI readscli.Cache.RefreshTokenSourcesends, bounded by the turn's context (Esc cancels it) and a 15s timeout. It never falls back to the browser login.token_url,client_id,scopes, extra params) are read from the dci profile inapis.json, like restish's handler. ThewriteConfigvalues, now shared constants inmain.go, are the fallback.Test plan
TestAIDCIBearerRefresh, 15 cases):dci login;dci loginwithout dialing;apis.jsonparams are honored;DCI_API_KEYis never refreshed.go vet .,go test .,go test -raceon the AI testsdci ai --quietwith this build answered. The cached expiry moved forward one hour,cache.jsonstayed 0600, and a followingdci list-budgetsused the renewed token without refreshing again.