Skip to content

Await agent DB writes and handle cache failures gracefully #634

@realproject7

Description

@realproject7

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

  1. Await the DB writes in AgentRegister and AgentManage — don't fire-and-forget
  2. Show "on-chain OK, cache failed — will sync on next visit" if DB write fails (don't show full error, just a warning)
  3. Add 23505 conflict handling in `agent-register/route.ts` — if row exists, update instead of failing
  4. 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

  • Agent register awaits DB write and shows warning if it fails
  • Agent manage actions await DB writes
  • agent-register route handles 23505 conflicts gracefully
  • cacheAgentById retries once on failure
  • On-chain success is never blocked by DB failure
  • Build passes

Self-Verification (T3)

  • Run npm run dev, register a new agent on /agents page
  • Check browser console — no silent fetch failures
  • Verify agent data appears in Supabase users table after registration
  • On /agents Manage tab, update agent URI — verify success message appears
  • Bind/unbind wallet — verify success message appears
  • Temporarily break the DB endpoint (wrong URL) — verify UI shows warning, not false success
  • Run npm run build — no errors

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent/T3Assigned to T3 builder agent

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions