-
Notifications
You must be signed in to change notification settings - Fork 1
refac(pred-swarm): open verifier #448
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| /// <reference types="next" /> | ||
| /// <reference types="next/image-types/global" /> | ||
| import "./.next/dev/types/routes.d.ts"; | ||
| import "./.next/types/routes.d.ts"; | ||
|
|
||
| // NOTE: This file should not be edited | ||
| // see https://nextjs.org/docs/app/api-reference/config/typescript for more information. |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,65 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -- Create "verification_claim" table | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CREATE TABLE "public"."verification_claim" ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "id" uuid NOT NULL DEFAULT uuidv7(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "parsed_prediction_id" uuid NOT NULL DEFAULT uuidv7(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "verifier_agent_id" character varying(256) NOT NULL, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "verifier_agent_signature" text NOT NULL, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "claim_outcome" boolean NOT NULL, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "confidence" numeric NOT NULL, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "reasoning" text NOT NULL, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "sources" jsonb NULL, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "timeframe_start_utc" timestamptz NULL, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "timeframe_end_utc" timestamptz NULL, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "timeframe_precision" character varying(32) NULL, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "created_at" timestamptz NOT NULL DEFAULT now(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "updated_at" timestamptz NOT NULL DEFAULT now(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "deleted_at" timestamptz NULL, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| PRIMARY KEY ("id"), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CONSTRAINT "verification_claim_unique_verifier" UNIQUE ("parsed_prediction_id", "verifier_agent_id"), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CONSTRAINT "verification_claim_parsed_prediction_id_parsed_prediction_id_fk" FOREIGN KEY ("parsed_prediction_id") REFERENCES "public"."parsed_prediction" ("id") ON UPDATE NO ACTION ON DELETE CASCADE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -- Create index "verification_claim_created_at_idx" to table: "verification_claim" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CREATE INDEX "verification_claim_created_at_idx" ON "public"."verification_claim" ("created_at"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -- Create index "verification_claim_parsed_prediction_id_idx" to table: "verification_claim" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CREATE INDEX "verification_claim_parsed_prediction_id_idx" ON "public"."verification_claim" ("parsed_prediction_id"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -- Create index "verification_claim_verifier_agent_id_idx" to table: "verification_claim" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CREATE INDEX "verification_claim_verifier_agent_id_idx" ON "public"."verification_claim" ("verifier_agent_id"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -- Modify "verdict" table | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ALTER TABLE "public"."verdict" ADD COLUMN "accepted_claim_id" uuid NULL DEFAULT uuidv7(), ADD CONSTRAINT "verdict_accepted_claim_id_verification_claim_id_fk" FOREIGN KEY ("accepted_claim_id") REFERENCES "public"."verification_claim" ("id") ON UPDATE NO ACTION ON DELETE NO ACTION; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+27
to
+28
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove DEFAULT uuidv7() from nullable foreign key The 🔎 Proposed fix-ALTER TABLE "public"."verdict" ADD COLUMN "accepted_claim_id" uuid NULL DEFAULT uuidv7(), ADD CONSTRAINT ...
+ALTER TABLE "public"."verdict" ADD COLUMN "accepted_claim_id" uuid NULL, ADD CONSTRAINT ...📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -- Create "verifier_feedback" table | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CREATE TABLE "public"."verifier_feedback" ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "id" uuid NOT NULL DEFAULT uuidv7(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "parsed_prediction_id" uuid NOT NULL DEFAULT uuidv7(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "verifier_agent_id" character varying(256) NOT NULL, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "verifier_agent_signature" text NOT NULL, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "failure_cause" "public"."failure_cause_enum" NOT NULL, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "reason" text NOT NULL, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "created_at" timestamptz NOT NULL DEFAULT now(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "updated_at" timestamptz NOT NULL DEFAULT now(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "deleted_at" timestamptz NULL, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| PRIMARY KEY ("id"), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CONSTRAINT "verifier_feedback_unique" UNIQUE ("parsed_prediction_id", "verifier_agent_id"), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CONSTRAINT "verifier_feedback_parsed_prediction_id_parsed_prediction_id_fk" FOREIGN KEY ("parsed_prediction_id") REFERENCES "public"."parsed_prediction" ("id") ON UPDATE NO ACTION ON DELETE CASCADE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+30
to
+43
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove DEFAULT uuidv7() from foreign key column in verifier_feedback. Same issue as 🔎 Proposed fix CREATE TABLE "public"."verifier_feedback" (
"id" uuid NOT NULL DEFAULT uuidv7(),
- "parsed_prediction_id" uuid NOT NULL DEFAULT uuidv7(),
+ "parsed_prediction_id" uuid NOT NULL,
"verifier_agent_id" character varying(256) NOT NULL,📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -- Create index "verifier_feedback_agent_idx" to table: "verifier_feedback" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CREATE INDEX "verifier_feedback_agent_idx" ON "public"."verifier_feedback" ("verifier_agent_id"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -- Create index "verifier_feedback_failure_cause_idx" to table: "verifier_feedback" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CREATE INDEX "verifier_feedback_failure_cause_idx" ON "public"."verifier_feedback" ("failure_cause"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -- Create index "verifier_feedback_prediction_idx" to table: "verifier_feedback" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CREATE INDEX "verifier_feedback_prediction_idx" ON "public"."verifier_feedback" ("parsed_prediction_id"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -- Create "verifier_topic_registration" table | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CREATE TABLE "public"."verifier_topic_registration" ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "id" uuid NOT NULL DEFAULT uuidv7(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "verifier_agent_id" character varying(256) NOT NULL, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "topic_id" uuid NOT NULL DEFAULT uuidv7(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "created_at" timestamptz NOT NULL DEFAULT now(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "updated_at" timestamptz NOT NULL DEFAULT now(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "deleted_at" timestamptz NULL, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| PRIMARY KEY ("id"), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CONSTRAINT "verifier_topic_unique" UNIQUE ("verifier_agent_id", "topic_id"), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CONSTRAINT "verifier_topic_registration_topic_id_prediction_topic_id_fk" FOREIGN KEY ("topic_id") REFERENCES "public"."prediction_topic" ("id") ON UPDATE NO ACTION ON DELETE NO ACTION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+50
to
+61
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove DEFAULT uuidv7() from foreign key column Line 54 has The 🔎 Proposed fix CREATE TABLE "public"."verifier_topic_registration" (
"id" uuid NOT NULL DEFAULT uuidv7(),
"verifier_agent_id" character varying(256) NOT NULL,
- "topic_id" uuid NOT NULL DEFAULT uuidv7(),
+ "topic_id" uuid NOT NULL,
"created_at" timestamptz NOT NULL DEFAULT now(),📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -- Create index "verifier_topic_agent_idx" to table: "verifier_topic_registration" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CREATE INDEX "verifier_topic_agent_idx" ON "public"."verifier_topic_registration" ("verifier_agent_id"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -- Create index "verifier_topic_topic_idx" to table: "verifier_topic_registration" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CREATE INDEX "verifier_topic_topic_idx" ON "public"."verifier_topic_registration" ("topic_id"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| -- Open verification: verification claims and topic registration | ||
|
|
||
| CREATE TABLE IF NOT EXISTS verification_claim ( | ||
| id UUID PRIMARY KEY DEFAULT uuidv7(), | ||
| parsed_prediction_id UUID NOT NULL REFERENCES parsed_prediction(id) ON DELETE CASCADE, | ||
| verifier_agent_id VARCHAR(256) NOT NULL, | ||
| verifier_agent_signature TEXT NOT NULL, | ||
| claim_outcome BOOLEAN NOT NULL, | ||
| confidence DECIMAL NOT NULL, | ||
| reasoning TEXT NOT NULL, | ||
| sources JSONB, | ||
| timeframe_start_utc TIMESTAMP WITH TIME ZONE, | ||
| timeframe_end_utc TIMESTAMP WITH TIME ZONE, | ||
| timeframe_precision VARCHAR(32), | ||
| created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(), | ||
| updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(), | ||
| deleted_at TIMESTAMP WITH TIME ZONE | ||
| ); | ||
|
|
||
| CREATE TABLE IF NOT EXISTS verifier_topic_registration ( | ||
| id UUID PRIMARY KEY DEFAULT uuidv7(), | ||
| verifier_agent_id VARCHAR(256) NOT NULL, | ||
| topic_id UUID NOT NULL REFERENCES prediction_topic(id), | ||
| created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(), | ||
| updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(), | ||
| deleted_at TIMESTAMP WITH TIME ZONE, | ||
| UNIQUE(verifier_agent_id, topic_id) | ||
| ); | ||
|
|
||
| ALTER TABLE verdict ADD COLUMN IF NOT EXISTS accepted_claim_id UUID REFERENCES verification_claim(id); | ||
|
|
||
| CREATE INDEX IF NOT EXISTS verification_claim_parsed_prediction_id_idx ON verification_claim(parsed_prediction_id); | ||
| CREATE INDEX IF NOT EXISTS verification_claim_verifier_agent_id_idx ON verification_claim(verifier_agent_id); | ||
| CREATE INDEX IF NOT EXISTS verification_claim_created_at_idx ON verification_claim(created_at); | ||
| CREATE INDEX IF NOT EXISTS verifier_topic_agent_idx ON verifier_topic_registration(verifier_agent_id); | ||
| CREATE INDEX IF NOT EXISTS verifier_topic_topic_idx ON verifier_topic_registration(topic_id); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| -- Verifier feedback table for per-verifier feedback on predictions | ||
| CREATE TABLE IF NOT EXISTS verifier_feedback ( | ||
| id UUID PRIMARY KEY DEFAULT uuidv7(), | ||
| parsed_prediction_id UUID NOT NULL REFERENCES parsed_prediction(id) ON DELETE CASCADE, | ||
| verifier_agent_id VARCHAR(256) NOT NULL, | ||
| verifier_agent_signature TEXT NOT NULL, | ||
| failure_cause failure_cause_enum NOT NULL, | ||
| reason TEXT NOT NULL, | ||
| created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(), | ||
| updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(), | ||
| deleted_at TIMESTAMP WITH TIME ZONE, | ||
| UNIQUE(parsed_prediction_id, verifier_agent_id) | ||
| ); | ||
|
|
||
| CREATE INDEX IF NOT EXISTS verifier_feedback_prediction_idx ON verifier_feedback(parsed_prediction_id); | ||
| CREATE INDEX IF NOT EXISTS verifier_feedback_agent_idx ON verifier_feedback(verifier_agent_id); | ||
| CREATE INDEX IF NOT EXISTS verifier_feedback_failure_cause_idx ON verifier_feedback(failure_cause); | ||
|
Comment on lines
+1
to
+17
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Check for failure_cause_enum definition in migrations
rg "CREATE TYPE.*failure_cause_enum" atlas/migrations/ -A 5
# Also check for parsed_prediction table
rg "CREATE TABLE.*parsed_prediction" atlas/migrations/ -B 2 -A 10
# List migration files in order
ls -1 atlas/migrations/webapps/ | grep -E "^[0-9]+_.*\.sql$" | sortRepository: renlabs-dev/torus-ts Length of output: 6034 🏁 Script executed: #!/bin/bash
# Read the actual verifier_feedback.sql file
cat atlas/migrations/webapps/20260105140000_verifier_feedback.sql
# Check if these directories share the same schema
echo "=== Checking migration directory structure ==="
ls -la atlas/migrations/
# Check for any schema-specific setup in webapps directory
rg "CREATE SCHEMA\|SET search_path" atlas/migrations/webapps/ | head -20Repository: renlabs-dev/torus-ts Length of output: 1255 🏁 Script executed: #!/bin/bash
# Look for atlas configuration
find atlas -name "*.toml" -o -name "*.yaml" -o -name "*.yml" -o -name "*.json" | head -20
# Check for README or documentation in migrations
find atlas -name "README*" -o -name "*.md" | head -20
# Look for any initialization or schema setup scripts
rg "migration_status\|migrations.version" atlas/migrations/ -l
# Check if there are any env-specific migration directories
ls -la atlas/migrations/webapps/ | head -10Repository: renlabs-dev/torus-ts Length of output: 661 🏁 Script executed: #!/bin/bash
# Search for migration runner code
rg "prediction_swarm|webapps" --type ts --type tsx -l | head -20
# Look for any migration setup or initialization code
rg "migrations.*prediction_swarm\|migrations.*webapps" -l | head -20
# Check for any database configuration
find . -name "*.ts" -o -name "*.js" | xargs rg -l "DATABASE_URL\|db.*connection\|migration" 2>/dev/null | grep -E "src/|config/" | head -15Repository: renlabs-dev/torus-ts Length of output: 91 🏁 Script executed: #!/bin/bash
# Search for migration runner code in TypeScript files
rg "prediction_swarm|webapps" -t js -t ts -l 2>/dev/null | head -20
# Look for database/atlas setup
fd -e ts -e js | xargs rg "migration.*path\|MIGRATION" 2>/dev/null | head -30
# Check root directory for config files
cat tsconfig.json 2>/dev/null | head -20
# Look for packages structure
ls -la packages/ 2>/dev/null | head -20Repository: renlabs-dev/torus-ts Length of output: 763 🏁 Script executed: #!/bin/bash
# Check the db package for migration setup
ls -la packages/db/
# Look for atlas or migration configuration
find packages/db -type f | head -20
# Search for references to prediction_swarm or webapps migrations
rg "prediction_swarm|webapps.*migration" packages/ 2>/dev/null | head -20
# Check for any database client setup
cat packages/db/src/*.ts 2>/dev/null | head -100Repository: renlabs-dev/torus-ts Length of output: 4339 🏁 Script executed: #!/bin/bash
# Check for any documentation about the migration structure
cat packages/db/creating-items-in-database.md
# Look for any atlas or migration runner configuration
find . -name "atlas.hcl" -o -name "atlas.yaml" -o -name ".atlas*" 2>/dev/null
# Check if there's a script that runs these migrations in order
find . -name "*.sh" -type f | xargs grep -l "migration\|atlas" 2>/dev/null | head -10Repository: renlabs-dev/torus-ts Length of output: 4413 🏁 Script executed: #!/bin/bash
# Read the atlas.hcl configuration
cat ./atlas.hclRepository: renlabs-dev/torus-ts Length of output: 1194 This migration references schema objects from the The
🤖 Prompt for AI Agents |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| -- Add unique constraint to verification_claim table | ||
| -- Ensures each verifier can only submit one claim per prediction | ||
| ALTER TABLE verification_claim | ||
| ADD CONSTRAINT verification_claim_unique_verifier | ||
| UNIQUE (parsed_prediction_id, verifier_agent_id); |
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -289,11 +289,77 @@ export const predictionTopicSchema = createTable( | |||||||||||||||
| ], | ||||||||||||||||
| ); | ||||||||||||||||
|
|
||||||||||||||||
| // ==== Verdicts ==== | ||||||||||||||||
| // ==== Verification Claims ==== | ||||||||||||||||
|
|
||||||||||||||||
| /** | ||||||||||||||||
| * Source evidence for verification claims | ||||||||||||||||
| */ | ||||||||||||||||
| export interface ClaimSource { | ||||||||||||||||
| url: string; | ||||||||||||||||
| title?: string; | ||||||||||||||||
| snippet?: string; | ||||||||||||||||
| retrievedAt: string; | ||||||||||||||||
| archiveUrl?: string; | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| /** | ||||||||||||||||
| * Claims submitted by open verifiers asserting a prediction's outcome. | ||||||||||||||||
| * Each verifier can submit one claim per prediction. | ||||||||||||||||
| * The verdict system evaluates claims to produce final verdicts. | ||||||||||||||||
| */ | ||||||||||||||||
| export const verificationClaimSchema = createTable( | ||||||||||||||||
| "verification_claim", | ||||||||||||||||
| { | ||||||||||||||||
| id: uuidv7("id").primaryKey(), | ||||||||||||||||
| parsedPredictionId: uuidv7("parsed_prediction_id") | ||||||||||||||||
| .notNull() | ||||||||||||||||
| .references(() => parsedPredictionSchema.id, { onDelete: "cascade" }), | ||||||||||||||||
| verifierAgentId: ss58Address("verifier_agent_id").notNull(), | ||||||||||||||||
| verifierAgentSignature: text("verifier_agent_signature").notNull(), | ||||||||||||||||
| claimOutcome: boolean("claim_outcome").notNull(), | ||||||||||||||||
| confidence: decimal("confidence").notNull(), | ||||||||||||||||
| reasoning: text("reasoning").notNull(), | ||||||||||||||||
| sources: jsonb("sources").$type<ClaimSource[]>(), | ||||||||||||||||
| timeframeStartUtc: timestampz("timeframe_start_utc"), | ||||||||||||||||
| timeframeEndUtc: timestampz("timeframe_end_utc"), | ||||||||||||||||
| timeframePrecision: varchar("timeframe_precision", { length: 32 }), | ||||||||||||||||
| ...timeFields(), | ||||||||||||||||
| }, | ||||||||||||||||
| (t) => [ | ||||||||||||||||
| unique("verification_claim_unique_verifier").on( | ||||||||||||||||
| t.parsedPredictionId, | ||||||||||||||||
| t.verifierAgentId, | ||||||||||||||||
| ), | ||||||||||||||||
| index("verification_claim_parsed_prediction_id_idx").on( | ||||||||||||||||
| t.parsedPredictionId, | ||||||||||||||||
| ), | ||||||||||||||||
| index("verification_claim_verifier_agent_id_idx").on(t.verifierAgentId), | ||||||||||||||||
| index("verification_claim_created_at_idx").on(t.createdAt), | ||||||||||||||||
| ], | ||||||||||||||||
| ); | ||||||||||||||||
|
|
||||||||||||||||
| /** | ||||||||||||||||
| * Tracks which topics a verifier has registered to verify. | ||||||||||||||||
| * Used for weighting claims from topic specialists. | ||||||||||||||||
| */ | ||||||||||||||||
| export const verifierTopicRegistrationSchema = createTable( | ||||||||||||||||
| "verifier_topic_registration", | ||||||||||||||||
| { | ||||||||||||||||
| id: uuidv7("id").primaryKey(), | ||||||||||||||||
| verifierAgentId: ss58Address("verifier_agent_id").notNull(), | ||||||||||||||||
| topicId: uuidv7("topic_id") | ||||||||||||||||
| .notNull() | ||||||||||||||||
| .references(() => predictionTopicSchema.id), | ||||||||||||||||
| ...timeFields(), | ||||||||||||||||
| }, | ||||||||||||||||
| (t) => [ | ||||||||||||||||
| unique("verifier_topic_unique").on(t.verifierAgentId, t.topicId), | ||||||||||||||||
| index("verifier_topic_agent_idx").on(t.verifierAgentId), | ||||||||||||||||
| index("verifier_topic_topic_idx").on(t.topicId), | ||||||||||||||||
| ], | ||||||||||||||||
| ); | ||||||||||||||||
|
|
||||||||||||||||
| // TODO: I don't think the JSON for the conclusion works | ||||||||||||||||
| // Some of our queries are more complicated than this allows | ||||||||||||||||
| // We shall see | ||||||||||||||||
| // ==== Verdicts ==== | ||||||||||||||||
|
|
||||||||||||||||
| /** | ||||||||||||||||
| * Stores verdicts for predictions | ||||||||||||||||
|
|
@@ -307,6 +373,9 @@ export const verdictSchema = createTable( | |||||||||||||||
| .references(() => parsedPredictionSchema.id), | ||||||||||||||||
| verdict: boolean("verdict").notNull(), // True if prediction came true, false otherwise | ||||||||||||||||
| context: jsonb("context").notNull().$type<VerdictContext>(), // Context explaining the verdict | ||||||||||||||||
| acceptedClaimId: uuidv7("accepted_claim_id").references( | ||||||||||||||||
| () => verificationClaimSchema.id, | ||||||||||||||||
| ), | ||||||||||||||||
|
Comment on lines
+376
to
+378
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Specify The Consider either:
🔎 Recommended fix- acceptedClaimId: uuidv7("accepted_claim_id").references(
- () => verificationClaimSchema.id,
- ),
+ acceptedClaimId: uuidv7("accepted_claim_id").references(
+ () => verificationClaimSchema.id,
+ { onDelete: "set null" }
+ ),📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||
| ...timeFields(), | ||||||||||||||||
| }, | ||||||||||||||||
| (t) => [ | ||||||||||||||||
|
|
@@ -429,6 +498,34 @@ export const parsedPredictionFeedbackSchema = createTable( | |||||||||||||||
| ], | ||||||||||||||||
| ); | ||||||||||||||||
|
|
||||||||||||||||
| /** | ||||||||||||||||
| * Stores per-verifier feedback on predictions. | ||||||||||||||||
| * When a verifier submits feedback, that prediction is excluded from their claimable list. | ||||||||||||||||
| */ | ||||||||||||||||
| export const verifierFeedbackSchema = createTable( | ||||||||||||||||
| "verifier_feedback", | ||||||||||||||||
| { | ||||||||||||||||
| id: uuidv7("id").primaryKey(), | ||||||||||||||||
| parsedPredictionId: uuidv7("parsed_prediction_id") | ||||||||||||||||
| .notNull() | ||||||||||||||||
| .references(() => parsedPredictionSchema.id, { onDelete: "cascade" }), | ||||||||||||||||
| verifierAgentId: ss58Address("verifier_agent_id").notNull(), | ||||||||||||||||
| verifierAgentSignature: text("verifier_agent_signature").notNull(), | ||||||||||||||||
| failureCause: failureCauseEnum("failure_cause").notNull(), | ||||||||||||||||
| reason: text("reason").notNull(), | ||||||||||||||||
| ...timeFields(), | ||||||||||||||||
| }, | ||||||||||||||||
| (t) => [ | ||||||||||||||||
| unique("verifier_feedback_unique").on( | ||||||||||||||||
| t.parsedPredictionId, | ||||||||||||||||
| t.verifierAgentId, | ||||||||||||||||
| ), | ||||||||||||||||
| index("verifier_feedback_prediction_idx").on(t.parsedPredictionId), | ||||||||||||||||
| index("verifier_feedback_agent_idx").on(t.verifierAgentId), | ||||||||||||||||
| index("verifier_feedback_failure_cause_idx").on(t.failureCause), | ||||||||||||||||
| ], | ||||||||||||||||
| ); | ||||||||||||||||
|
|
||||||||||||||||
| // ==== Credit System ==== | ||||||||||||||||
|
|
||||||||||||||||
| /** | ||||||||||||||||
|
|
||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import { integer, text } from "drizzle-orm/pg-core"; | ||
| import { createTable, ss58Address, timeFields } from "./utils"; | ||
|
|
||
| /** | ||
| * Tracks the last processed cursor for each verifier instance. | ||
| * Prevents reprocessing the same predictions on restart. | ||
| */ | ||
| export const verifierCursorStateSchema = createTable("verifier_cursor_state", { | ||
| verifierAgentId: ss58Address("verifier_agent_id").primaryKey(), | ||
| lastCursor: text("last_cursor").notNull(), | ||
| ...timeFields(), | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove DEFAULT uuidv7() from foreign key column
parsed_prediction_id.Line 4 specifies
DEFAULT uuidv7()forparsed_prediction_id, but this column is a foreign key referencingparsed_prediction(id). A random default UUID would almost certainly not exist in the referenced table, causing FK violations. The default should be removed so the column must be explicitly provided.🔎 Proposed fix
CREATE TABLE "public"."verification_claim" ( "id" uuid NOT NULL DEFAULT uuidv7(), - "parsed_prediction_id" uuid NOT NULL DEFAULT uuidv7(), + "parsed_prediction_id" uuid NOT NULL, "verifier_agent_id" character varying(256) NOT NULL,📝 Committable suggestion
🤖 Prompt for AI Agents