fix: upsert scoped Norgate metadata instead of replacing whole table#22
Merged
Conversation
A scoped `cotdata-update --metadata --symbols DC ZO KE EMD NKD` run REPLACED the entire metadata/contract_specs.parquet with only those rows, dropping the other 42 markets' contract specs (Norgate_Symbol, tick/point value, margin, …) and breaking position-sizing / cost lookups across the deploy book. Contract specs live in ONE Symbol-keyed table (unlike prices/COT, which are one parquet per symbol), so a subset write must upsert, not overwrite. - store.upsert_metadata: read existing → replace/add requested Symbols → keep the rest → write the union (manifest reflects the union count). - norgate.update_metadata: scoped run (`symbols` given) upserts by Symbol; no-symbols run still regenerates the full registry and replaces the table. - Tests: scoped update preserves unlisted markets; full update replaces; upsert on empty store behaves like a plain write. Other metadata writers (prices, COT) are per-symbol files, so they have no replace-vs-merge exposure — only contract_specs shares one table. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Bug
cotdata-update --metadata --symbols DC ZO KE EMD NKDreplaced the entiremetadata/contract_specs.parquetwith only those 5 rows, dropping the other 42 markets' contract specs (Norgate_Symbol, tick/point value, margin, …). This broke contract-spec lookups (position sizing, cost calc) across the deploy book. Confirmed: 42 rows → 5 after that run.Root cause
Contract specs live in one Symbol-keyed table (unlike prices/COT, which are one parquet per symbol).
norgate.update_metadata(symbols=…)built a specs frame for only the requested symbols and wrote it viastore.write_metadata, which atomically replaces the whole file. A subset write therefore erased every unlisted market.Fix
store.upsert_metadata— read existing → replace/add requestedSymbols → keep the rest → write the union (manifest reflects the union count).norgate.update_metadata— a scoped run (symbolsgiven) now upserts by Symbol; a no-symbols run still regenerates the full registry and replaces the table.Other writers checked
write_pricesand the COT writers all write per-symbol/per-name files, so they have no replace-vs-merge exposure —contract_specswas the only single-table-for-all-symbols writer.Tests (55 pass)
update_metadataupserts end-to-end through a tmp storeOperational note
Immediate recovery (already done): re-run
cotdata-update --metadatawith no--symbolson the Norgate/Windows box → regenerates all 47. This change prevents recurrence.🤖 Generated with Claude Code