Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion .github/ci-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,23 @@
"pr_preview": false
},
"prediction-swarm": {
"deploys": ["swarm-twitter", "swarm-verifier", "swarm-filter"],
"deploys": [
"swarm-twitter",
"swarm-judge",
"swarm-verifier",
"swarm-filter"
],
"pr_preview": false,
"preview_domain": "predictionswarm.com"
},
"swarm-twitter": {
"pr_preview": false,
"prod_only": true
},
"swarm-judge": {
"pr_preview": false,
"prod_only": true
},
"swarm-verifier": {
"pr_preview": false,
"prod_only": true
Expand Down
2 changes: 1 addition & 1 deletion apps/torus-wallet/next-env.d.ts
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.
65 changes: 65 additions & 0 deletions atlas/migrations/prediction_swarm/20260105202138.sql
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
);
Comment on lines +2 to +20
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Remove DEFAULT uuidv7() from foreign key column parsed_prediction_id.

Line 4 specifies DEFAULT uuidv7() for parsed_prediction_id, but this column is a foreign key referencing parsed_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

‼️ 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
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 TABLE "public"."verification_claim" (
"id" uuid NOT NULL DEFAULT uuidv7(),
"parsed_prediction_id" uuid NOT NULL,
"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
);
🤖 Prompt for AI Agents
In @atlas/migrations/prediction_swarm/20260105202138.sql around lines 2-20, The
migration creates verification_claim.parsed_prediction_id with a DEFAULT
uuidv7(), but parsed_prediction_id is a foreign key to parsed_prediction(id) so
the default will generate non-existent IDs and cause FK violations; remove the
DEFAULT uuidv7() from the parsed_prediction_id column definition in the CREATE
TABLE for "verification_claim" (leave it NOT NULL) so callers must provide a
valid parsed_prediction_id that exists in "parsed_prediction" (no changes to the
FK constraint "verification_claim_parsed_prediction_id_parsed_prediction_id_fk"
otherwise).

-- 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
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Remove DEFAULT uuidv7() from nullable foreign key accepted_claim_id.

The accepted_claim_id column is nullable (correct), but the DEFAULT uuidv7() is problematic. If an INSERT doesn't explicitly provide this column, it would generate a random UUID that likely doesn't exist in verification_claim, causing FK violations. For nullable FKs, the default should be NULL (implicit when no DEFAULT is specified).

🔎 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

‼️ 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
-- 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;
-- Modify "verdict" table
ALTER TABLE "public"."verdict" ADD COLUMN "accepted_claim_id" uuid NULL, 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;
🤖 Prompt for AI Agents
In @atlas/migrations/prediction_swarm/20260105202138.sql around lines 27-28, The
ALTER TABLE statement adds a nullable foreign key column "accepted_claim_id" to
table "public"."verdict" but sets DEFAULT uuidv7(), which will generate
non-existent UUIDs and cause FK violations; update the migration so the ALTER
TABLE adds "accepted_claim_id" uuid NULL with no DEFAULT (leave default as NULL)
and still add the FOREIGN KEY constraint
"verdict_accepted_claim_id_verification_claim_id_fk" referencing
"public"."verification_claim" ("id").

-- 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
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Remove DEFAULT uuidv7() from foreign key column in verifier_feedback.

Same issue as verification_claim: line 32 has "parsed_prediction_id" uuid NOT NULL DEFAULT uuidv7() which is inappropriate for a foreign key column.

🔎 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

‼️ 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
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
);
CREATE TABLE "public"."verifier_feedback" (
"id" uuid NOT NULL DEFAULT uuidv7(),
"parsed_prediction_id" uuid NOT NULL,
"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
);
🤖 Prompt for AI Agents
In @atlas/migrations/prediction_swarm/20260105202138.sql around lines 30-43, The
foreign key column parsed_prediction_id in the verifier_feedback table should
not generate its own UUID; remove the DEFAULT uuidv7() from the column
definition so it remains "parsed_prediction_id uuid NOT NULL" and keep the
existing foreign key constraint
("verifier_feedback_parsed_prediction_id_parsed_prediction_id_fk") intact; apply
the same change pattern used for verification_claim to avoid auto-generating
UUIDs for referenced IDs.

-- 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
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Remove DEFAULT uuidv7() from foreign key column topic_id.

Line 54 has "topic_id" uuid NOT NULL DEFAULT uuidv7() which should not have a default for a foreign key column.

The ON DELETE NO ACTION choice for the topic FK is appropriate for preserving registration history.

🔎 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

‼️ 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
-- 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
);
-- 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,
"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
);
🤖 Prompt for AI Agents
In @atlas/migrations/prediction_swarm/20260105202138.sql around lines 50-61, The
migration creates table verifier_topic_registration with topic_id defined as
uuid NOT NULL DEFAULT uuidv7(), but foreign key columns should not supply a
default; remove the DEFAULT uuidv7() from the topic_id column definition so
topic_id is declared as "topic_id" uuid NOT NULL and keep the existing FK
constraint referencing prediction_topic(id) (preserving ON DELETE NO ACTION).

-- 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");
3 changes: 2 additions & 1 deletion atlas/migrations/prediction_swarm/atlas.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
h1:zgOElHPnrTchPb+gb2wPJygPOHJwa/MVSSghPyDnX7A=
h1:8hG9KyqunMoyK3ggRLphPfYFaoH2ZAgKRy/dyvci3v4=
20251118085426_baseline.sql h1:yYt/F7QkBCF92mhKeZN8/T6ljcYJN+1s3M/gBNv5MxI=
20251120161044_rename_goal.sql h1:V0EM07MmeCsc4naTIRBXiLxYtEbHQ0AQI4GzxmkUfxU=
20251120161127.sql h1:27i5PAjofmV/DRHMWKybpF5ncgpQTwdaMFUay959YSg=
Expand All @@ -11,3 +11,4 @@ h1:zgOElHPnrTchPb+gb2wPJygPOHJwa/MVSSghPyDnX7A=
20251126135959.sql h1:ouWxe6r2q3MV48Z18j7vX4m6hDypY8XOpv8V9/1HdpU=
20251128161908.sql h1:qcYrYrusemufBSPM9Mbj/On++3GrjxfItjfTwEOGOus=
20251130132124.sql h1:kkYoKrMn7ITv2IuWGxrLBaCkpPC6zqt4C+ZVYw1BlA0=
20260105202138.sql h1:56oSvxIQl+Ca6uecSbIpxST7pSFNNnNvhDyvPQ7/vGk=
36 changes: 36 additions & 0 deletions atlas/migrations/webapps/20260105111457_open_verification.sql
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);
17 changes: 17 additions & 0 deletions atlas/migrations/webapps/20260105140000_verifier_feedback.sql
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
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 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$" | sort

Repository: 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 -20

Repository: 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 -10

Repository: 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 -15

Repository: 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 -20

Repository: 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 -100

Repository: 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 -10

Repository: renlabs-dev/torus-ts

Length of output: 4413


🏁 Script executed:

#!/bin/bash
# Read the atlas.hcl configuration
cat ./atlas.hcl

Repository: renlabs-dev/torus-ts

Length of output: 1194


This migration references schema objects from the prediction_swarm environment but is defined in the webapps environment—they use separate databases and this will fail during migration.

The verifier_feedback table references failure_cause_enum and parsed_prediction(id), which are only defined in the prediction_swarm environment's database schema. The atlas.hcl configuration shows these are separate dev databases (dev-webapps vs dev-prediction-swarm). Either:

  1. Move the failure_cause_enum type and parsed_prediction table definition to the webapps environment, or
  2. Define the verifier_feedback table in the prediction_swarm environment instead.
🤖 Prompt for AI Agents
In @atlas/migrations/webapps/20260105140000_verifier_feedback.sql around lines
1-17, The migration creates verifier_feedback but depends on failure_cause_enum
and parsed_prediction which live in the prediction_swarm DB (per atlas.hcl
dev-webapps vs dev-prediction-swarm), so this will fail; either move/define
failure_cause_enum and the parsed_prediction table into the webapps schema
before creating verifier_feedback, or instead add this verifier_feedback
migration to the prediction_swarm environment so it runs against the DB that
already contains failure_cause_enum and parsed_prediction; update the migration
placement accordingly and ensure REFERENCES parsed_prediction(id) and
failure_cause_enum resolve in the same target DB.

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);
2 changes: 2 additions & 0 deletions packages/db/src/schema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ export * from "./memory";

export * from "./swarm-filter";

export * from "./swarm-verifier";

export * from "./context-schemas";
105 changes: 101 additions & 4 deletions packages/db/src/schema/memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Specify onDelete behavior for the foreign key.

The acceptedClaimId reference lacks an onDelete clause, which could lead to referential integrity issues if a verification claim is deleted while still referenced by a verdict.

Consider either:

  • onDelete: "set null" to preserve the verdict but clear the claim reference
  • onDelete: "restrict" to prevent deletion of claims referenced by verdicts
🔎 Recommended fix
-    acceptedClaimId: uuidv7("accepted_claim_id").references(
-      () => verificationClaimSchema.id,
-    ),
+    acceptedClaimId: uuidv7("accepted_claim_id").references(
+      () => verificationClaimSchema.id,
+      { onDelete: "set null" }
+    ),
📝 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
acceptedClaimId: uuidv7("accepted_claim_id").references(
() => verificationClaimSchema.id,
),
acceptedClaimId: uuidv7("accepted_claim_id").references(
() => verificationClaimSchema.id,
{ onDelete: "set null" }
),
🤖 Prompt for AI Agents
In @packages/db/src/schema/memory.ts around lines 376-378, The foreign key
definition for acceptedClaimId (uuidv7("accepted_claim_id").references(() =>
verificationClaimSchema.id)) lacks an onDelete behavior; update the
acceptedClaimId foreign key declaration to include an explicit onDelete clause
(choose either "set null" to preserve verdicts but null the claim reference, or
"restrict" to prevent deletion of referenced verificationClaim rows) and adjust
the column nullability if using "set null" so verdict records can have a
nullable acceptedClaimId.

...timeFields(),
},
(t) => [
Expand Down Expand Up @@ -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 ====

/**
Expand Down
12 changes: 12 additions & 0 deletions packages/db/src/schema/swarm-verifier.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { integer, text } from "drizzle-orm/pg-core";

Check warning on line 1 in packages/db/src/schema/swarm-verifier.ts

View workflow job for this annotation

GitHub Actions / lint

'integer' is defined but never used. Allowed unused vars must match /^_/u
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(),
});
Loading