Skip to content

feat(weights): tip-track /v1/weights/latest via leaf supersede + reseal - #121

Merged
echobt merged 2 commits into
mainfrom
feat/realtime-weights-tip
Aug 11, 2026
Merged

feat(weights): tip-track /v1/weights/latest via leaf supersede + reseal#121
echobt merged 2 commits into
mainfrom
feat/realtime-weights-tip

Conversation

@echobt

@echobtechobt commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Gateway tip leaves supersede when payload_digest changes for the same (challenge_id, epoch, miner_hotkey); identical digest stays 409-as-ok. PG uses upsert_raw_weight_tip (SECURITY DEFINER) so base_app keeps no direct UPDATE grant.
  • seal_epochreseals tip when merkle/final_vector change (append epoch_bundle.revision); no-op if identical. Validators still Match only sealed: true.
  • Design re-emits tip every emitter tick (+ award path); Memory scores_for_epoch matches 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

  • Mid-epoch revision / vector_digest changes are intentional tip-tracking.
  • Unsealed live aggregation is not served as Match input.

Test plan

  • cargo fmt / clippy on touched crates
  • gateway raw_weights S4/S5 + sealer tip reseal
  • design emit plan tip re-emit
  • prism-emit epoch_semantics tip refresh
  • xtask spec-check + loc-cap
  • CI green
  • After merge: promote digests → staging/prod pins; restart gateway+challenges; install 2m timer; verify Design window winners match /v1/weights/latest (UID 94 drops unless back in window)

Summary by CodeRabbit

  • New Features

    • Current epoch data can be refreshed when scores or payloads change.
    • Changed submissions supersede the existing tip and return HTTP 202.
    • Bundle resealing creates revisions when sealed data changes.
    • Responses indicate whether a submission superseded prior data.
  • Bug Fixes

    • Identical replays remain safely handled with HTTP 409.
    • Score projections carry forward the latest eligible results.
    • Repeated epoch ticks refresh the current tip instead of becoming no-ops.
  • Documentation

    • Updated API, architecture, deployment, and bundle behavior documentation.

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.
@coderabbitai

coderabbitaiBot commented Aug 11, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 192dcacd-fd8a-4eb4-860e-1dafa64c9c16

📥 Commits

Reviewing files that changed from the base of the PR and between 3e334ce and 7c16975.

📒 Files selected for processing (1)
  • crates/prism-challenge/tests/e2e_orchestrate_sim.rs

📝 Walkthrough

Walkthrough

The 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.

Changes

Tip supersession and resealing

Layer / File(s)Summary
Current-tip emission
crates/design-challenge-task/src/emit.rs, crates/design-challenge/src/lib.rs, crates/design-store/src/store.rs, crates/prism-emit/..., crates/challenge-common/src/submit.rs, docs/PRISM.md, crates/prism-challenge/tests/e2e_orchestrate_sim.rs
The current epoch is re-emitted on later ticks. Tip refreshes reuse assigned rows and preserve the emit cursor.
Digest-based raw-weight storage
crates/db/..., crates/gateway-core/src/weights_store.rs, crates/gateway/src/weights.rs, crates/gateway-store-pg/src/lib.rs, crates/gateway/tests/raw_weights.rs, crates/db/tests/gateway_store.rs
Changed payload digests supersede the existing row. Identical digests remain conflicts. HTTP responses expose superseded.
Revisioned tip sealing
crates/gateway/src/sealer.rs, crates/gateway-store-pg/src/lib.rs, crates/gateway/tests/sealer.rs
Existing seals are rebuilt from current rows. Unchanged bundles keep their revision. Changed Merkle roots or final vectors create a new revision.
Operational and distribution contracts
deploy/..., docs/ARCHITECTURE.md, docs/BUNDLE_SPEC.md
The real-epoch sealer runs every two minutes. Documentation defines tip revisions, no-op reseals, and latest sealed bundle selection.

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
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check nameStatusExplanation
Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.
Title check✅ PassedThe title clearly summarizes the main change: tracking /v1/weights/latest through tip-leaf supersession and resealing.
Docstring Coverage✅ PassedDocstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check✅ PassedCheck skipped because no linked issues were found for this pull request.
Out of Scope Changes check✅ PassedCheck skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/realtime-weights-tip

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 lift

Make 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::insert and upsert_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 lift

Propagate bundle persistence failures.

put_revision returns bytes after self.seal() fails. seal_epoch then 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_revision return a Result and propagate the error through seal_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

📥 Commits

Reviewing files that changed from the base of the PR and between b4037f1 and 3e334ce.

📒 Files selected for processing (23)
  • crates/challenge-common/src/submit.rs
  • crates/db/.sqlx/query-14604982a6b089a47e32e4fa7189819526eca2c8fbf5840d857a0c2aad37edeb.json
  • crates/db/migrations/0017_raw_weight_tip_supersede.sql
  • crates/db/src/lib.rs
  • crates/db/src/store.rs
  • crates/db/tests/gateway_store.rs
  • crates/design-challenge-task/src/emit.rs
  • crates/design-challenge/src/lib.rs
  • crates/design-store/src/store.rs
  • crates/gateway-core/src/weights_store.rs
  • crates/gateway-store-pg/src/lib.rs
  • crates/gateway/src/sealer.rs
  • crates/gateway/src/weights.rs
  • crates/gateway/tests/raw_weights.rs
  • crates/gateway/tests/sealer.rs
  • crates/prism-emit/src/lib.rs
  • crates/prism-emit/tests/epoch_semantics.rs
  • deploy/AGENTS.md
  • deploy/scripts/prod-real-seal.sh
  • deploy/systemd/base-real-seal.timer
  • docs/ARCHITECTURE.md
  • docs/BUNDLE_SPEC.md
  • docs/PRISM.md
💤 Files with no reviewable changes (1)
  • crates/db/.sqlx/query-14604982a6b089a47e32e4fa7189819526eca2c8fbf5840d857a0c2aad37edeb.json

) RETURNS uuid
LANGUAGE plpgsql
SECURITY DEFINER
SET search_path = public

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🗄️ 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.

Suggested change
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.

@echobt
echobt merged commit f46129e into mainAug 11, 2026
3 checks passed
Sign up for freeto 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.

1 participant

@echobt