Commit 7fefaa3
committed
fix(cloud): a lapsed token is renewed outside the chat too — not shown as "API 401"
The access token lives 8 hours; the session behind it outlives it. Chat and the
agent renew a lapsed token on a gateway 401 and send the request again. Nothing
else did. Seven other requests go out on a provider prepProviderRequest resolved,
and each was sent exactly once: inline edit, Agent Sketch (Run, the board command,
Generate flow), inline completion, Compact and the session-memory summary. The
adapters retry a 502/503/504 and nothing else, prepProviderRequest only reads the
stored token, and the session check runs on the webview's `ready` and on regaining
focus. So in gateway mode — the default — a token that lapsed while the window
stayed focused failed all seven, for a request chat would have carried through:
"LevelCode AI edit failed: OpenAI API 401: Signature has expired".
They now go through providers/authRetry.js: one renew-and-retry, built once in
extension.js from prepProviderRequest, refreshGatewayToken and isAuthError, and
handed to aiEdit.js, sketch.js and inlineComplete.js in the deps they already
take. A caller wired without it sends exactly as it did.
- Only a gateway request, only an auth error, only before any of the answer has
arrived, never after Stop or Cancel, and once. A BYOK request is never refreshed
and never retried, whatever its error says.
- It ends no session. The refresh endpoint answering 401 still does that, alone.
authRetry finds out by asking for a provider again: `signedOut` becomes the
session sentence, coded 'session_expired' — so inline edit puts "Sign in" on the
toast, as it does for a request refused up front. A renewal that merely failed
keeps the tokens and rethrows the request's own error, unchanged.
- One renewal at a time among its callers. The nodes of a Sketch level fail
together: they wait on one refresh instead of racing for one refresh token, and
the renewed token is written onto the run's request, so the nodes after them
never see the 401. A request refused on a token renewed since is just sent again.
- Ghost text stays silent, and may start a renewal once a minute at most: a
gateway that keeps answering 401 must not turn typing into a stream of refreshes.
Compact and the session-memory summary are the same gap in extension.js itself,
one wrapped call each. The "OpenAI" in the error above is real — these callers
pass no `label` to the adapter — and stays: no existing wording changes here.
prepProviderRequest, handleSend and the agent's hook are untouched.
Verified: 46 suites, 872 cases, 0 failing. authRetry.test.js is new (31 cases) and
pins the rule against a stand-in host. authRetryCallers.test.js is new (68 cases)
and RUNS it end to end: the real aiEdit.js, sketch.js and inlineComplete.js behind
a minimal `vscode` mock, the real adapters, and the host sliced out of
extension.js, with only the network faked — every caller through renewed, renewal
failed, renewal refused and BYOK. With any one caller put back as it was, that
suite fails on the 401 above; 40 breakages in all — each caller reverted, each
rule of authRetry removed, each option a caller passes dropped — fail a case each.
node --check is clean on the seven files, and tsc --checkJs reports nothing new.
Trial-merged into develop (4e49295): no conflicts, 48 suites, 884 cases, 0 failing.
Not run in the editor: nothing here has met a live gateway, and no toast or Sketch
notification has been seen on screen.1 parent 76445f5 commit 7fefaa3
7 files changed
Lines changed: 1537 additions & 52 deletions
File tree
- extensions/levelcode-ai
- providers
- test
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
107 | 108 | | |
108 | 109 | | |
109 | 110 | | |
110 | | - | |
| 111 | + | |
111 | 112 | | |
112 | 113 | | |
113 | 114 | | |
| |||
147 | 148 | | |
148 | 149 | | |
149 | 150 | | |
150 | | - | |
151 | | - | |
152 | | - | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
153 | 156 | | |
154 | | - | |
| 157 | + | |
155 | 158 | | |
156 | 159 | | |
157 | 160 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
613 | 614 | | |
614 | 615 | | |
615 | 616 | | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
616 | 635 | | |
617 | 636 | | |
618 | 637 | | |
| |||
1106 | 1125 | | |
1107 | 1126 | | |
1108 | 1127 | | |
1109 | | - | |
1110 | | - | |
| 1128 | + | |
| 1129 | + | |
| 1130 | + | |
1111 | 1131 | | |
1112 | 1132 | | |
1113 | | - | |
| 1133 | + | |
1114 | 1134 | | |
1115 | 1135 | | |
1116 | 1136 | | |
| |||
1837 | 1857 | | |
1838 | 1858 | | |
1839 | 1859 | | |
1840 | | - | |
1841 | | - | |
1842 | | - | |
| 1860 | + | |
| 1861 | + | |
| 1862 | + | |
| 1863 | + | |
| 1864 | + | |
1843 | 1865 | | |
1844 | 1866 | | |
1845 | | - | |
| 1867 | + | |
1846 | 1868 | | |
1847 | 1869 | | |
1848 | 1870 | | |
| |||
3339 | 3361 | | |
3340 | 3362 | | |
3341 | 3363 | | |
3342 | | - | |
| 3364 | + | |
3343 | 3365 | | |
3344 | 3366 | | |
3345 | 3367 | | |
| |||
3378 | 3400 | | |
3379 | 3401 | | |
3380 | 3402 | | |
| 3403 | + | |
3381 | 3404 | | |
3382 | 3405 | | |
3383 | 3406 | | |
| |||
3397 | 3420 | | |
3398 | 3421 | | |
3399 | 3422 | | |
| 3423 | + | |
3400 | 3424 | | |
3401 | 3425 | | |
3402 | 3426 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
58 | 59 | | |
59 | 60 | | |
60 | 61 | | |
61 | | - | |
| 62 | + | |
| 63 | + | |
62 | 64 | | |
63 | 65 | | |
64 | 66 | | |
| |||
124 | 126 | | |
125 | 127 | | |
126 | 128 | | |
127 | | - | |
128 | | - | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
129 | 134 | | |
130 | 135 | | |
131 | | - | |
| 136 | + | |
132 | 137 | | |
133 | | - | |
| 138 | + | |
| 139 | + | |
134 | 140 | | |
135 | 141 | | |
136 | 142 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
0 commit comments