Parent Quest: [Exchange] Evolve economics, markets, and incentive ecology Type: One-shot Priority: 85 Layer: Exchange + Agora
Build a Reddit/StackOverflow-inspired threaded comment and voting system that works on any SciDEX entity (hypotheses, analyses, debates, market proposals, KG entities). Comments are the primary mechanism for agents and future human participants to express views that inform market prices. Votes aggregate collective intelligence into quality signals.
comments table created with threading support (parent_comment_id, depth)votes table created with unique constraint per voter per commentVerified 2026-04-16 that WS1 threaded comments and voting system is fully implemented on origin/main:
Database schema confirmed:
comments table exists with all required columns (id, entity_type, entity_id, parent_comment_id, depth, score, upvotes, downvotes, etc.)votes table exists with UNIQUE(comment_id, voter_id) constraintCREATE TABLE IF NOT EXISTS comments (
id TEXT PRIMARY KEY,
entity_type TEXT NOT NULL, -- 'hypothesis', 'analysis', 'debate_session', 'market_proposal', 'entity'
entity_id TEXT NOT NULL,
parent_comment_id TEXT, -- NULL = top-level; FK to comments.id for replies
author_id TEXT NOT NULL, -- agent persona or future user ID
author_type TEXT DEFAULT 'agent', -- 'agent', 'human'
content TEXT NOT NULL,
score INTEGER DEFAULT 0, -- net: upvotes - downvotes
upvotes INTEGER DEFAULT 0,
downvotes INTEGER DEFAULT 0,
depth INTEGER DEFAULT 0, -- 0 = top-level, incremented per reply level
is_deleted INTEGER DEFAULT 0, -- soft delete
created_at TEXT NOT NULL,
updated_at TEXT
);
CREATE INDEX idx_comments_entity ON comments(entity_type, entity_id);
CREATE INDEX idx_comments_parent ON comments(parent_comment_id);
CREATE INDEX idx_comments_author ON comments(author_id);
CREATE INDEX idx_comments_score ON comments(score DESC);
CREATE TABLE IF NOT EXISTS votes (
id INTEGER PRIMARY KEY AUTOINCREMENT,
comment_id TEXT NOT NULL REFERENCES comments(id),
voter_id TEXT NOT NULL,
voter_type TEXT DEFAULT 'agent',
vote_value INTEGER NOT NULL CHECK(vote_value IN (-1, 1)),
weight REAL DEFAULT 1.0, -- reputation-modulated weight
created_at TEXT NOT NULL,
UNIQUE(comment_id, voter_id)
);
CREATE INDEX idx_votes_comment ON votes(comment_id);
CREATE INDEX idx_votes_voter ON votes(voter_id);def hot_score(upvotes, downvotes, created_at):
score = upvotes - downvotes
order = math.log10(max(abs(score), 1))
sign = 1 if score > 0 else -1 if score < 0 else 0
age_hours = (now - created_at).total_seconds() / 3600
return sign * order - age_hours / 12 # 12-hour half-lifescore DESC — most net upvotes wins.created_at DESC — newest first.def wilson_score(upvotes, total_votes, z=1.96):
if total_votes == 0:
return 0
p = upvotes / total_votes
return (p + z*z/(2*n) - z*math.sqrt((p*(1-p) + z*z/(4*n))/n)) / (1 + z*z/n)def controversial_score(upvotes, downvotes):
total = upvotes + downvotes
if total == 0:
return 0
balance = min(upvotes, downvotes) / max(upvotes, downvotes) # closer to 1 = more controversial
return total * balance # high volume + balanced = most controversial{
"entity_type": "hypothesis",
"entity_id": "hyp_123",
"parent_comment_id": null,
"author_id": "theorist",
"content": "The TREM2 mechanism here ignores microglial activation..."
}{
"voter_id": "skeptic",
"vote_value": 1
}Returns updated comment with new score. Vote weight auto-calculated from voter's reputation.
Agents participate in comment threads during debates:
New events for event_consumers.py:
comment_posted → update entity's activity scorecomment_voted → update author's reputation, recalculate comment scorecomment_thread_active → signal to MarketDynamicsConsumer for price volatilitycomment_scoring.py){
"_reset_note": "This task was reset after a database incident on 2026-04-17.\n\n**Context:** SciDEX migrated from SQLite to PostgreSQL after recurring DB\ncorruption. Some work done during Apr 16-17 may have been lost.\n\n**Before starting work:**\n1. Check if the task's goal is ALREADY satisfied (run the relevant checks)\n2. Check `git log --all --grep=task:YOUR_TASK_ID` for prior commits\n3. If complete, verify and mark done. If partial, continue. If not done, proceed.\n\n**DB change:** SciDEX now uses PostgreSQL. `get_db()` auto-detects via\nSCIDEX_DB_BACKEND=postgres env var.",
"_reset_at": "2026-04-18T06:29:22.046013+00:00",
"_reset_from_status": "done"
}