Problem
Agent registration and management actions persist to DB via fire-and-forget fetch().catch(() => {}). If the DB write fails:
- On-chain tx succeeded but DB cache is out of sync
- User sees "success" but agent data isn't cached
- Subsequent page loads fall back to RPC or show stale data
agent-register/route.ts has no 23505 conflict handling for rapid re-registration
Affected locations:
- `AgentRegister.tsx` lines 105-117 — agent-register fire-and-forget
- `AgentManage.tsx` — agent-update fire-and-forget after URI update, wallet bind/unbind
- `agents/page.tsx` line 89 — cacheAgentById fire-and-forget
- `AgentDashboard.tsx` line 106 — cacheAgentById fire-and-forget
Fix
- Await the DB writes in AgentRegister and AgentManage — don't fire-and-forget
- Show "on-chain OK, cache failed — will sync on next visit" if DB write fails (don't show full error, just a warning)
- Add 23505 conflict handling in `agent-register/route.ts` — if row exists, update instead of failing
- Add retry logic for `cacheAgentById` — retry once on failure before giving up
Files to modify
- `src/components/AgentRegister.tsx` — await DB write, show warning on failure
- `src/components/AgentManage.tsx` — await DB writes, show warning on failure
- `src/app/api/user/agent-register/route.ts` — add 23505 conflict handling
- `src/app/agents/page.tsx` — add retry for cacheAgentById
- `src/components/AgentDashboard.tsx` — add retry for cacheAgentById
Branch
`task/634-agent-cache-reliability`
Acceptance criteria
Self-Verification (T3)
Problem
Agent registration and management actions persist to DB via fire-and-forget
fetch().catch(() => {}). If the DB write fails:agent-register/route.tshas no 23505 conflict handling for rapid re-registrationAffected locations:
Fix
Files to modify
Branch
`task/634-agent-cache-reliability`
Acceptance criteria
Self-Verification (T3)
npm run dev, register a new agent on /agents pageuserstable after registrationnpm run build— no errors