Fix auth middleware
workspace/agent
You
Agent
gpt-o3Found a race in the refresh path: concurrent callers can invalidate a still-valid access token. Applying a serialized refresh gate and keeping credentials until a hard 401.
- 01 Serialize refresh behind one in-flight promise
- 02 Clear session only on hard 401
- 03 Cover concurrent refresh in unit tests
// shared refresh latch
let refreshing: Promise<Token> | null = null
if (refreshing) return refreshing
refreshing = refreshSession()
finally { refreshing = null }
You
Agent
gpt-o3Scanned the client layer. Two helpers were treating refresh failures the same as expired sessions. Updating them to distinguish hard logout from retryable refresh errors.
→ lib/api/client.ts
→ lib/api/auth-errors.ts
→ hooks/useSession.ts
- if (res.status === 401) clearSession()
+ if (res.status === 401 && isHardAuthFailure(res)) {
+ clearSession()
+ throw new AuthError('session_expired')
+ }
+ return retryWithRefresh(req)
You
Agent
gpt-o3Wrote the PR note and kicked off the auth tests. Concurrent refresh cases are covered; waiting on the suite before marking the session done.
Refresh is serialized behind a single in-flight promise so parallel 401s reuse one token exchange. Cookies stay until a hard auth failure, which avoids logout loops during brief refresh windows.
Soft 401s retry once after refresh; only explicit hard failures clear the session.
$ pnpm test auth --runInBand
PASS middleware/session.test.ts
PASS lib/api/client.test.ts
PASS hooks/useSession.test.ts
✓ 14 passed (1.8s)
it('shares one refresh across concurrent callers', async () => {
const a = ensureSession()
const b = ensureSession()
await Promise.all([a, b])
expect(refreshSession).toHaveBeenCalledTimes(1)
})
Auth suite is green. Remaining work is a quick pass on the deploy checklist, then this session can move to Done.
You
Agent
gpt-o3 WorkingAdded a release-notes todo and parked follow-ups. Summary of what shipped in this session:
- middleware/session.ts — serialized refresh latch
- lib/api/client.ts — hard vs soft 401 handling
- lib/api/auth-errors.ts — shared failure helpers
- middleware/session.test.ts — concurrent refresh coverage
- □ Mention refresh latch in release notes
- □ Verify staging SSO after deploy
You
Agent
Claude 4 SonnetMapped three duplicated validators across checkout, upgrade, and invoice update. Next pass consolidates them into a shared schema and updates the upgrade confirm step.
- 01 Extract shared billing schema
- 02 Wire upgrade + checkout forms
- 03 Add field-level error copy
You
Agent
gpt-4.1Shipped a collapsible inspector with Diff and Terminal tabs. Layout keeps the transcript dominant and only opens the panel when a tool result is selected.
- Added inspector shell beside transcript
- Synced selection from tool chips
- Persisted open/closed state per session
Agent can edit files and run tools in this workspace.
Session overview
Live metrics for the active agent run
Updated · just now
Tokens
48.2k
+12% vs last run
Cost
$1.84
gpt-o3 · session
Duration
14m 22s
3 turns · running
Success
96.4%
27 / 28 tool calls
Token burn
Input vs output over this session
Prompt share of burn: 65% · completion 35%
Cost mix
Where this session spent budget
Projected end cost if pace holds: $2.10–$2.35
Run history
Turns, tools, and spend for this session
-
14:02:11
12.4k $0.61 ok
Refresh gate plan + patch
model · gpt-o3 · 2 tool calls
-
14:06:48
1.1k $0.04 ok
Read middleware/session.ts
tool · read_file
-
14:08:03
3.8k $0.18 ok
Apply serialized refresh latch
tool · apply_patch
-
14:11:27
2.2k $0.09 retry
Unit tests · concurrent refresh
tool · shell · npm test
-
14:13:55
2.0k $0.08 ok
Re-run tests after latch fix
tool · shell · npm test
Tool performance
Latency and reliability by tool
-
apply_patch
842ms avg · 100%
-
read_file
124ms avg · 100%
-
shell
2.4s avg · 87%
Nightly repo sync
automations/scheduled · cron 0 2 * * *
Overview
Last 30 days of scheduled sync performance
Success rate
98.7%
+1.2% vs prior month
Last run
02:04
Completed · 4m 12s
Avg duration
3m 48s
p95 · 6m 02s
Next run
Tonight
in 6h 38m
Pipeline steps
Live stage completion for the last successful run
1. Clone mirrors
2. Fetch remotes
3. Sync branches
4. Notify Team Chat
Trigger & targets
What kicks this workflow off
- Schedule
- 0 2 * * *
- Timezone
- America/Los_Angeles
- Repos
- 12 mirrored
- Timeout
- 15 minutes
Status legend
Recent runs
Click a row action to open logs
Tonight’s activity
Events from the latest scheduled run
Scheduler fired nightly job
Cron matched 0 2 * * * for America/Los_Angeles.
Cloned 12 mirror repos
Workspace cache warmed; 3 repos reused from yesterday.
Synced 18 refs across remotes
Fast-forwarded main on agent and billing.
Posted summary to #ops-bots
Team Chat notification delivered · run marked succeeded.