Commit c419c75
bgagent
fix(oauth): refresh-token race recovery + log gaps from review
Addresses the blocker + critical items from PR review:
- Refresh-token race (review blocker). Linear rotates refresh_tokens
on every use; concurrent Lambdas/agents racing the same secret will
all read the same expiring token and one's refresh will succeed
while the others get `invalid_grant`. On `invalid_grant`, re-read
the secret from Secrets Manager (bypassing cache). If the
refresh_token has changed, another caller already rotated; use the
freshly-read token (or retry refresh once if it's also expiring).
If unchanged, the refresh_token is permanently rejected and the
workspace needs re-onboarding. Implemented in both the TS resolver
(linear-oauth-resolver.ts) and Python resolver (config.py).
- Unguarded bedrock_agentcore import in agent/src/server.py
(review critical). The bare `from bedrock_agentcore.runtime.context
import BedrockAgentCoreContext` inside `_run_task_background` killed
the entire pipeline thread with no diagnostic if the SDK was
missing or its module structure changed. Wrap in
try/except (ImportError, AttributeError) and log via _warn_cw —
the Linear token resolver has its own SM fallback, so the agent
can proceed without the workload-token bridge.
- Cache invalidation on fetch-level refresh failure (review high).
The TS resolver's `invalidateLinearOauthCache()` only ran in the
`!resp.ok` branch; if `fetch()` itself threw (timeout, DNS), the
catch returned null without invalidating, leaving the stale
expiring token cached for 60s and hammering Linear's token
endpoint. Move invalidate into the fetch-level catch too.
- Malformed expires_at log (review medium). The Python `_is_expiring`
caught `ValueError` and silently returned True, masking
consistently-bad writes. Add a WARN log so operators see the bad
data instead of just an unexplained refresh on every task.
- Positive-path refresh log (review non-blocking aws-samples#5). Added
INFO-level breadcrumb on successful refresh in both resolvers
so operators diagnosing intermittent 401s have a trace of which
workspace refreshed and to what expiry.
11/11 existing resolver unit tests still pass; will add tests for
the new race-recovery branch in a followup commit.1 parent eaf7c55 commit c419c75
3 files changed
Lines changed: 219 additions & 17 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
104 | 104 | | |
105 | 105 | | |
106 | 106 | | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
107 | 114 | | |
108 | 115 | | |
109 | 116 | | |
110 | | - | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
111 | 127 | | |
| 128 | + | |
112 | 129 | | |
113 | 130 | | |
114 | 131 | | |
115 | | - | |
| 132 | + | |
116 | 133 | | |
117 | 134 | | |
118 | 135 | | |
| |||
131 | 148 | | |
132 | 149 | | |
133 | 150 | | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
134 | 165 | | |
135 | 166 | | |
136 | | - | |
| 167 | + | |
137 | 168 | | |
138 | 169 | | |
139 | | - | |
| 170 | + | |
140 | 171 | | |
141 | 172 | | |
142 | 173 | | |
| |||
161 | 192 | | |
162 | 193 | | |
163 | 194 | | |
164 | | - | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
165 | 257 | | |
166 | 258 | | |
167 | 259 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
398 | 398 | | |
399 | 399 | | |
400 | 400 | | |
401 | | - | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
402 | 411 | | |
403 | | - | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
404 | 420 | | |
405 | 421 | | |
406 | 422 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
237 | 237 | | |
238 | 238 | | |
239 | 239 | | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
240 | 254 | | |
241 | 255 | | |
242 | 256 | | |
243 | 257 | | |
244 | 258 | | |
245 | 259 | | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
246 | 324 | | |
247 | 325 | | |
248 | 326 | | |
249 | 327 | | |
250 | | - | |
| 328 | + | |
251 | 329 | | |
252 | 330 | | |
253 | 331 | | |
| |||
269 | 347 | | |
270 | 348 | | |
271 | 349 | | |
272 | | - | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
273 | 357 | | |
274 | 358 | | |
275 | 359 | | |
276 | 360 | | |
277 | 361 | | |
278 | 362 | | |
279 | 363 | | |
280 | | - | |
| 364 | + | |
281 | 365 | | |
282 | 366 | | |
283 | 367 | | |
| |||
287 | 371 | | |
288 | 372 | | |
289 | 373 | | |
290 | | - | |
291 | 374 | | |
292 | | - | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
293 | 379 | | |
294 | 380 | | |
295 | 381 | | |
| |||
300 | 386 | | |
301 | 387 | | |
302 | 388 | | |
303 | | - | |
| 389 | + | |
304 | 390 | | |
305 | 391 | | |
306 | 392 | | |
| |||
328 | 414 | | |
329 | 415 | | |
330 | 416 | | |
331 | | - | |
332 | | - | |
333 | | - | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
334 | 420 | | |
335 | 421 | | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
336 | 430 | | |
337 | 431 | | |
338 | | - | |
| 432 | + | |
339 | 433 | | |
340 | 434 | | |
341 | 435 | | |
| |||
0 commit comments