Skip to content

fix: dont override meta on invalidation#328

Open
matheus1lva wants to merge 5 commits intomainfrom
fix/dont-override-meta
Open

fix: dont override meta on invalidation#328
matheus1lva wants to merge 5 commits intomainfrom
fix/dont-override-meta

Conversation

@matheus1lva
Copy link
Collaborator

@matheus1lva matheus1lva commented Jan 30, 2026

Summary

This PR improves the robustness of metadata fetching and ingestion. It modifies metadata fetching functions in meta.ts to return undefined instead of blank objects on failure, avoiding valid data override with empty strings. It also updates the snapshot ingestion loader to filter out undefined meta values, preserving existing database records when transient errors occur.

How to review

Start with packages/ingest/abis/yearn/lib/meta.ts to see the logic change (returning undefined on catch).
Then check packages/ingest/load/index.ts to see how upsertSnapshot filters undefined values from snapshot.hook before merging.
Review packages/ingest/abis/yearn/lib/meta.spec.ts and packages/ingest/abis/yearn/2/strategy/snapshot/hook.spec.ts for test coverage.
Ignore local config changes if present.

Test plan

  • Automated: npx mocha abis/yearn/2/strategy/snapshot/hook.spec.ts verify hook process handles validation failure gracefully.
  • Manual: Ingestion of valid/invalid vaults to ensure no data loss (verified via unit/integration tests).

@vercel
Copy link

vercel bot commented Jan 30, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
kong Ready Ready Preview, Comment Jan 31, 2026 11:25pm

Request Review

Copy link
Collaborator

@murderteeth murderteeth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

This PR partially addresses the bug where metadata parsing failures cause valid data to be overwritten with empty values. The current implementation handles individual item validation failures, but does not fully solve the original issue.

What Works ✅

  • Individual items that fail Zod schema validation are now skipped instead of crashing the entire extractMetas function
  • Failed items are logged for debugging

Critical Issues 🚨

1. Outer functions still return empty objects on failure

The catch blocks in getVaultMeta, getStrategyMeta, and getTokenMeta (lines 8-46) still return empty string values when errors occur:

catch(error) {
  return {
    displayName: '',
    displaySymbol: '',
    description: '',
    protocols: []
  }
}

Per the bug report, these should return undefined so the loader can preserve existing data.

2. Loader merge logic is unchanged

The PR description mentions filtering undefined values in load/index.ts, but no changes were made to the loader. The current merge:

snapshot.hook = { ...currentHook, ...snapshot.hook }

will still overwrite existing meta with empty strings when failures occur.

3. PR description doesn't match actual changes

  • Description says: "return undefined instead of blank objects on failure" - not implemented
  • Description says: "updates the snapshot ingestion loader to filter out undefined meta values" - not implemented
  • Description references tests - but only 1 file changed

@matheus1lva
Copy link
Collaborator Author

wut, i forgot to push the load update T.T

When getVaultMeta fails, the new hook's meta would be empty but would
still overwrite the existing meta. Now we explicitly merge meta fields
so existing values are preserved when the new meta is null/undefined.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Copy link
Collaborator

@murderteeth murderteeth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous review concerns are addressed — meta functions now return undefined on failure, extractMetas handles individual parse errors gracefully, and the loader preserves existing meta when new meta is falsy.

One remaining edge case in the merge logic at packages/ingest/load/index.ts:107:

meta: snapshot.hook.meta ? { ...currentHook.meta, ...snapshot.hook.meta } : currentHook.meta

When both getVaultMeta and getTokenMeta fail, vault hooks return meta: { token: undefined }. This object is truthy so the merge branch runs, but spreading { token: undefined } overwrites currentHook.meta.token. When pg serializes to jsonb, undefined is dropped and the existing token data is lost.

Fix — strip undefined values before merging by round-tripping through JSON (no fidelity loss since this goes straight to jsonb):

meta: snapshot.hook.meta
  ? { ...currentHook.meta, ...JSON.parse(JSON.stringify(snapshot.hook.meta)) }
  : currentHook.meta

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants