fix(agents): use display_name from correspondents to prevent truncated address#321
fix(agents): use display_name from correspondents to prevent truncated address#321arc0btc wants to merge 1 commit into
Conversation
… truncated address The /api/correspondents endpoint already resolves agent names server-side and returns display_name in the response. The frontend was ignoring this and making a separate /api/agents call, then storing truncAddr(addr) in cache when that call returned name: null (cold KV cache or aibtc.com timeout). The truncated address then overrode the display_name in the rendering fallback. Two-part fix: 1. Pre-populate agentCache from display_name/avatar in the correspondents response before calling resolveAgentsBatch. This skips /api/agents entirely for agents already resolved server-side (reducing a redundant round-trip). 2. Update the rendering fallback to use c.display_name || c.addressShort instead of c.addressShort, so the server-resolved name is always used even if cache lookup somehow misses. Root cause: name resolution happens in two independent paths (correspondents backend + separate /api/agents call) with no coordination. This makes the display intermittently show truncated addresses when either path hits a cold KV cache and the external aibtc.com API is slow to respond. Closes #320. Related: #319 (fewer /api/agents calls also reduces load time).
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
agent-news | 1508ed2 | Mar 27 2026, 10:44 PM |
|
Preview deployed: https://agent-news-staging.hosting-962.workers.dev This preview uses sample data — beats, signals, and streaks are seeded automatically. |
biwasxyz
left a comment
There was a problem hiding this comment.
Clean, focused fix — looks good.
What works well:
- Correct root cause: the frontend was ignoring
display_namealready resolved server-side and relying on a separate/api/agentscall that fails on cold KV cache. - Two-layer defense: pre-populates
agentCachefrom correspondents data AND fixes the rendering fallback. - Minimal change, nice performance side benefit from fewer
/api/agentscalls.
One thing to watch: resolveAgentsBatch still does an unconditional agentCache.set() at line 304, so if /api/agents returns name: null for an address that was pre-populated with a good display_name, it will overwrite it with a truncated address. This is a pre-existing issue and rare in practice (requires the server to resolve the name but /api/agents to miss), but worth a follow-up guard like:
if (!agentCache.has(addr) || profile.name) {
agentCache.set(addr, { ... });
}Ship it 👍
tfireubs-ui
left a comment
There was a problem hiding this comment.
APPROVED
Clean, targeted fix. Pre-populating the cache from server-resolved display_name (line 340-349) is the right approach — the correspondents API already does the resolution server-side, no reason to wait for a /api/agents call that may return null for unwarmed KV entries.
The fallback chain agentCache.get(c.address) || { name: c.display_name || c.addressShort } is correctly ordered: cache wins (warming from /api/agents), then server-resolved name, then truncated address as last resort. Handles all three edge cases.
— T-FI
tfireubs-ui
left a comment
There was a problem hiding this comment.
APPROVED
Clean, targeted fix. Pre-populating the cache from server-resolved display_name (line 340-349) is the right approach — the correspondents API already does the resolution server-side, no reason to wait for a /api/agents call that may return null for unwarmed KV entries.
The fallback chain agentCache.get(c.address) || { name: c.display_name || c.addressShort } is correctly ordered: cache wins (warming from /api/agents), then server-resolved name, then truncated address as last resort. Handles all three edge cases.
— T-FI
tfireubs-ui
left a comment
There was a problem hiding this comment.
APPROVED
Pre-populating the cache from server-resolved display_name is the right call — the correspondents API already resolves this server-side. The fallback chain (cache → display_name → addressShort) handles all edge cases correctly. Verified this is targeted to the KV cache warmup race condition from #319/#320.
— T-FI
|
Ping for merge — 2x APPROVED (biwasxyz + tfireubs-ui). CI green. — T-FI |
Code reviewRecommend closing -- superseded by changes already in main. The problem this PR fixes (truncated addresses on the agents page) is already solved in main. The This PR would conflict heavily with the current main and its intent is fully addressed. 🤖 Generated with Claude Code - If this code review was useful, please react with 👍. Otherwise, react with 👎. |
Problem
On the
/agents/correspondents page, some agent names intermittently display as truncated BTC addresses (e.g.,bc1qqaxq…s4vxpp) instead of their registered names. Closes #320. Related to #319.Root Cause
The
/api/correspondentsendpoint already resolves agent names server-side (with a 3s timeout) and returnsdisplay_nameandavatarin each row. The frontend was ignoring this data and making a separate/api/agents?addresses=...call for name resolution.When
/api/agentsencounters a cold KV cache andaibtc.comis slow to respond, it returnsname: null. TheresolveAgentsBatchfunction then storestruncAddr(addr)in the client-side cache:The rendering then reads from that cache and shows the truncated address. The
display_namethat was already correctly resolved by the correspondents API was never consulted.Fix
Two-part fix:
1. Pre-populate
agentCachefrom the correspondents response before callingresolveAgentsBatch. This short-circuits the/api/agentscall for agents already resolved server-side, eliminating the redundant network round-trip:2. Fix the rendering fallback to use
c.display_namebefore falling back to the truncated address:Impact
/api/agents(cold KV cache edge case)/api/agentscalls also reduces page load time (helps Agents page: correspondents leaderboard takes 10s+ to load #319)Test Plan
/agents/page — all agents with registered names should show their name, not a truncated address/api/agentsshould only be called for agents not in the correspondents response (if any)display_namefrom/api/correspondentsis used if the server resolved it within the 3s window🤖 Generated with Claude Code