fix(discovery): replace require() with ESM import for viem in cache writer#217
Open
uibeka wants to merge 1 commit intoConway-Research:mainfrom
Open
fix(discovery): replace require() with ESM import for viem in cache writer#217uibeka wants to merge 1 commit intoConway-Research:mainfrom
uibeka wants to merge 1 commit intoConway-Research:mainfrom
Conversation
…riter
setCachedCard uses require("viem") to import keccak256 and toBytes for
computing agent card hashes before caching to SQLite. Since the project
is ESM ("type": "module"), require() throws ReferenceError at runtime,
silently failing every cache write.
Replace with a static ESM import. This enables the discovered_agents_cache
table to actually populate, giving agents persistent discovery results
across wake cycles without redundant on-chain scans.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
7bbcd6f to
1567a71
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Agent discovery cache writes silently fail on every call. The
discovered_agents_cacheSQLite table is never populated, forcing agents to perform full on-chain Transfer event scans (2081+ events, ~6 seconds) on everydiscover_agentscall. Logs show 20+require is not definederrors per discovery call (one per agent card enrichment).Root Cause
setCachedCardinsrc/registry/discovery.tsusesrequire("viem")to importkeccak256andtoBytesfor computing agent card hashes. The project is ESM ("type": "module"in package.json, all imports use.jsextensions), sorequire()is not available. The error is caught by the surrounding try-catch and silently swallowed, making the failure invisible except in verbose logs.Fix
Replace
require("viem")with a standard ESM import. Thekeccak256andtoBytesfunctions are imported at the top of the file, consistent with how other modules in the codebase import fromviem.Impact
discovered_agents_cachetable populates correctlyReferenceErrorstack traces per discovery call from logsviemis already a project dependencyTesting
pnpm build— zero errors (import resolves correctly)pnpm test— all 1005 existing tests pass (27 test files)Note: Related Issue (Not Fixed Here)
During investigation, we observed that agents using
data:URIs for inline ERC-8004 agent cards are blocked by SSRF protection (isAllowedUrionly allowshttps:andipfs:).data:URIs don't make network requests and pose no SSRF risk, but they're a legitimate pattern for inline agent metadata. Happy to open a separate issue or PR if the team wants to supportdata:URIs for agent cards.