Uh oh!
There was an error while loading. Please reload this page.
feat(weights): tip-track /v1/weights/latest via leaf supersede + reseal - #121
Conversation
Make sealed tip weights follow live Design/Prism scores: supersede leaves on digest change, reseal tip with revision++, and continuously re-emit tip leaves. Validators still Match only sealed:true.
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe change enables repeated current-tip emissions, digest-based raw-weight supersession, and revisioned resealing. Identical submissions remain conflicts. Changed tip data updates storage and creates a new sealed bundle revision. ChangesTip supersession and resealing
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant EpochEmitter
participant Gateway
participant RawWeightStore
participant EpochSealer
participant BundleStore
EpochEmitter->>Gateway: re-submit current tip projection
Gateway->>RawWeightStore: insert or supersede raw weight by digest
RawWeightStore-->>Gateway: return row and superseded flag
Gateway-->>EpochEmitter: return acceptance or conflict
EpochSealer->>RawWeightStore: read current tip rows
EpochSealer->>BundleStore: store changed seal revision
BundleStore-->>EpochSealer: return revised bundle
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
crates/gateway/src/weights.rs (1)
121-140: 🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy liftMake supersession detection atomic.
Lines 121-124 read the prior row before the write. If two changed leaves arrive for an absent key, both requests can read no row. The second database upsert replaces the first row, but its response still reports
superseded: false.Return an inserted-versus-superseded outcome from
RawWeightStore::insertandupsert_raw_weight_tip. Build the HTTP acknowledgement from that write outcome. Add a parallel-submission test.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@crates/gateway/src/weights.rs` around lines 121 - 140, Move supersession detection into the atomic write path: update RawWeightStore::insert and upsert_raw_weight_tip to return whether the write inserted or replaced an existing row, and build the HTTP acknowledgement from that result instead of the pre-read superseded check. Add a test covering parallel submissions for the same absent key, verifying the first reports inserted and the replacing write reports superseded.crates/gateway-store-pg/src/lib.rs (1)
276-285: 🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy liftPropagate bundle persistence failures.
put_revisionreturnsbytesafterself.seal()fails.seal_epochthen decodes those bytes and reports a successful reseal. A changed tip can therefore appear sealed although PostgreSQL did not store the new revision.Make
BundleStore::put_revisionreturn aResultand propagate the error throughseal_epoch. Do not acknowledge a seal until persistence succeeds.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@crates/gateway-store-pg/src/lib.rs` around lines 276 - 285, Change BundleStore::put_revision to return a Result and propagate self.seal failures instead of returning bytes on error. Update seal_epoch and any affected callers to handle the Result, ensuring reseal acknowledgment occurs only after PostgreSQL persistence succeeds.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@crates/db/migrations/0017_raw_weight_tip_supersede.sql`:
- Line 23: Update the migration’s SECURITY DEFINER helper around SET search_path
so it remains bound to the trusted migration schema instead of forcing lookup to
public. Capture and use the migration search path, or schema-qualify the target
table, ensuring the helper reads the isolated raw_weight_snapshot table while
preserving the existing security boundary.
---
Outside diff comments:
In `@crates/gateway-store-pg/src/lib.rs`:
- Around line 276-285: Change BundleStore::put_revision to return a Result and
propagate self.seal failures instead of returning bytes on error. Update
seal_epoch and any affected callers to handle the Result, ensuring reseal
acknowledgment occurs only after PostgreSQL persistence succeeds.
In `@crates/gateway/src/weights.rs`:
- Around line 121-140: Move supersession detection into the atomic write path:
update RawWeightStore::insert and upsert_raw_weight_tip to return whether the
write inserted or replaced an existing row, and build the HTTP acknowledgement
from that result instead of the pre-read superseded check. Add a test covering
parallel submissions for the same absent key, verifying the first reports
inserted and the replacing write reports superseded.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 2222c708-bfb9-46f7-b1ac-222e44a8f2d6
📒 Files selected for processing (23)
crates/challenge-common/src/submit.rscrates/db/.sqlx/query-14604982a6b089a47e32e4fa7189819526eca2c8fbf5840d857a0c2aad37edeb.jsoncrates/db/migrations/0017_raw_weight_tip_supersede.sqlcrates/db/src/lib.rscrates/db/src/store.rscrates/db/tests/gateway_store.rscrates/design-challenge-task/src/emit.rscrates/design-challenge/src/lib.rscrates/design-store/src/store.rscrates/gateway-core/src/weights_store.rscrates/gateway-store-pg/src/lib.rscrates/gateway/src/sealer.rscrates/gateway/src/weights.rscrates/gateway/tests/raw_weights.rscrates/gateway/tests/sealer.rscrates/prism-emit/src/lib.rscrates/prism-emit/tests/epoch_semantics.rsdeploy/AGENTS.mddeploy/scripts/prod-real-seal.shdeploy/systemd/base-real-seal.timerdocs/ARCHITECTURE.mddocs/BUNDLE_SPEC.mddocs/PRISM.md
💤 Files with no reviewable changes (1)
- crates/db/.sqlx/query-14604982a6b089a47e32e4fa7189819526eca2c8fbf5840d857a0c2aad37edeb.json
| ) RETURNS uuid | ||
| LANGUAGE plpgsql | ||
| SECURITY DEFINER | ||
| SET search_path = public |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
Bind the helper to the migration schema.
Line 23 forces object lookup to public. test_pool_with_url migrates a generated schema after setting <schema>, public in crates/db/src/lib.rs Lines 282-304. The helper can then access public.raw_weight_snapshot instead of the isolated table, or fail when that table is absent.
Capture the trusted migration search path, or schema-qualify the target table without weakening the SECURITY DEFINER boundary.
Proposed fix
-SET search_path = public+SET search_path FROM CURRENT📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| SET search_path = public | |
| SET search_path FROM CURRENT |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@crates/db/migrations/0017_raw_weight_tip_supersede.sql` at line 23, Update
the migration’s SECURITY DEFINER helper around SET search_path so it remains
bound to the trusted migration schema instead of forcing lookup to public.
Capture and use the migration search path, or schema-qualify the target table,
ensuring the helper reads the isolated raw_weight_snapshot table while
preserving the existing security boundary.
Uh oh!
There was an error while loading. Please reload this page.
Summary
payload_digestchanges for the same(challenge_id, epoch, miner_hotkey); identical digest stays 409-as-ok. PG usesupsert_raw_weight_tip(SECURITY DEFINER) sobase_appkeeps no direct UPDATE grant.seal_epochreseals tip when merkle/final_vectorchange (appendepoch_bundle.revision); no-op if identical. Validators still Match onlysealed: true.scores_for_epochmatches PG latest-rating (epoch <= target). Prism tip-refreshes WTA each tick after cursor lands (OWNER_ARCH stays off).base-real-seal.timer→ 2 min; docs: BUNDLE_SPEC §9, ARCHITECTURE, PRISM, deploy/AGENTS.Consensus
revision/vector_digestchanges are intentional tip-tracking.Test plan
cargo fmt/ clippy on touched crates/v1/weights/latest(UID 94 drops unless back in window)Summary by CodeRabbit
New Features
Bug Fixes
Documentation