Grand Diomande Research · Full HTML Reader

Task Board + Ledger Architecture

> Deterministic multi-agent task system with evidence-gated completion, terminal state locks, and append-only audit ledger.

Agents That Account for Themselves architecture technical paper candidate score 40 .md

Full Public Reader

Task Board + Ledger Architecture

> Deterministic multi-agent task system with evidence-gated completion, terminal state locks, and append-only audit ledger.

---

Hard Rules (enforced in database)

1. Every task has a UUID (`mac_tasks.id`)
2. Every task lives in Supabase `mac_tasks` table
3. DONE requires real proof — output (>50 chars), commit hash, or verified URL
4. Placeholder URLs are rejected (localhost, [ip], example.com)
5. Parent tasks cannot close while children are still open
6. Once a task is DONE, it stays DONE — no status regression
7. Every state transition is logged to append-only `task_events` ledger

---

Execution Path

intake → classify → store → claim → execute → complete (with evidence)
┌─────────────┐     ┌──────────────┐     ┌───────────┐
│  Discord     │────▶│  Classifier   │────▶│  Supabase │
│  SMS         │     │  (model +     │     │ mac_tasks │
│  Telegram    │     │   type +      │     │  INSERT   │
│  Nexus UI    │     │   platform)   │     │  pending  │
└─────────────┘     └──────────────┘     └─────┬─────┘
                                                │
                         ┌──────────────────────┘
                         ▼
                  ┌──────────────┐     ┌──────────────┐
                  │  Agent Pool   │────▶│  Execution    │
                  │  (poll+claim) │     │  Claude/      │
                  │  status:      │     │  Gemini/      │
                  │  running      │     │  Codex        │
                  └──────────────┘     └──────┬───────┘
                                               │
                         ┌─────────────────────┘
                         ▼
                  ┌───────────────────────┐
                  │  complete_task_with_   │
                  │  evidence() RPC        │
                  │                        │
                  │  ┌─ Evidence Gate ───┐ │
                  │  │ output > 50 chars │ │
                  │  │ commit hash       │ │
                  │  │ verified URL      │ │
                  │  └──────────────────┘ │
                  │  ┌─ Dependency Gate ┐ │
                  │  │ all children     │ │
                  │  │ complete/failed  │ │
                  │  └──────────────────┘ │
                  │  ┌─ Terminal Lock ──┐ │
                  │  │ not already done │ │
                  │  └──────────────────┘ │
                  └───────────┬───────────┘
                     Pass ✓   │   Block ✗
                  ┌───────────┴───────────┐
                  ▼                       ▼
           ┌────────────┐         ┌────────────┐
           │  COMPLETE   │         │  BLOCKED    │
           │  terminal   │         │  logged to  │
           │  locked     │         │  task_events│
           └────────────┘         └────────────┘

---

Enforcement Path

status change → terminal lock → evidence gate → dependency gate → audit log
┌──────────┐   status   ┌──────────────────┐
│  Agent    │──────────▶│  BEFORE trigger    │
│  UPDATE   │           │  enforce_terminal  │
└──────────┘           │  _state()          │
                        └────────┬─────────┘
                          Pass   │   Block (revert NEW.status)
                                 ▼
                        ┌──────────────────┐
                        │  AFTER trigger    │
                        │  log_task_event() │
                        └────────┬─────────┘
                                 ▼
                        ┌──────────────────┐
                        │  task_events      │
                        │  (append-only)    │
                        │  INSERT only      │
                        └──────────────────┘

---

State Tables

mac_tasks (materialized state)

ColumnTypePurpose
`id`uuidPrimary key
`task_content`textThe task prompt
`project_path`textTarget project directory
`source`textOrigin: discord, sms, telegram, api
`status`textpending → running → complete/failed
`claimed_by`textDevice that claimed (mac1, mac4, cloud-vm)
`parent_task_id`uuidFK to parent (for subtasks)
`team_id`uuidTeam grouping ID
`team_role`textteam_lead, worker, aggregator
`model_preference`textRequested model
`model_used`textActual model that responded
`output`textTask result
`commit_hash`textGit evidence
`evidence_url`textURL evidence
`evidence_type`textoutput, commit, url, or multiple
`exit_code`intProcess exit code
`attempt_count`intCurrent attempt number
`max_attempts`intMax retries before terminal fail
`error_log`textAppend-only failure log
`timeout_at`timestamptzAuto-reclaim deadline
`relay_from`textPrevious device (on handoff)
`relay_to`textTarget device (on handoff)
`relay_reason`texttimeout, manual, capability
`admissibility_token`textHMAC policy compliance proof
`discord_thread_id`textLinked Discord thread
`result_delivered`boolPrevents duplicate delivery
Timestampstimestamptzcreated_at, started_at, completed_at

task_events (append-only audit ledger)

ColumnTypePurpose
`id`uuidEvent ID
`task_id`uuidFK to mac_tasks
`event_type`textcreated, claimed, completed, failed, reclaimed, evidence_blocked, terminal_blocked, dependency_blocked
`from_status`textPrevious status
`to_status`textNew status
`agent_id`textWho triggered the transition
`evidence`jsonbEvidence payload (has_output, has_commit, has_url)
`metadata`jsonbContext (relay info, block reasons, etc.)
`created_at`timestamptzWhen the event occurred

RLS: SELECT + INSERT only. No UPDATE. No DELETE. Ledger is immutable.

---

Status Transitions

                    ┌──────────┐
                    │  pending  │
                    └────┬─────┘
                         │ claim
                    ┌────▼─────┐
           ┌────── │  running  │ ──────┐
           │        └────┬─────┘        │
           │ timeout     │ complete     │ fail
           │ (reclaim)   │ (evidence)   │
           │             │              │
     ┌─────▼────┐  ┌────▼─────┐  ┌────▼─────┐
     │  pending  │  │ complete │  │  failed   │
     │  (retry)  │  │ TERMINAL │  │           │
     └──────────┘  └──────────┘  └──────────┘

Terminal states: `complete` (always), `failed` (when attempt_count >= max_attempts)

---

Triggers

TriggerTimingFunctionPurpose
`trg_enforce_terminal_state`BEFORE UPDATE`enforce_terminal_state()`Blocks status regression on complete/exhausted-failed tasks
`trg_log_task_event`AFTER INSERT/UPDATE`log_task_event()`Records every transition to task_events ledger

---

RPC Functions

`complete_task_with_evidence(task_id, output, commit_hash, evidence_url, agent_id)`

Gated completion with 4 checks:
1. Terminal lock: Already complete? Reject.
2. Evidence gate: At least one of output (>50 chars), commit hash (>=7 chars), or valid URL.
3. URL validation: Reject localhost, [ip], example.com, /smoke/, /remediate/.
4. Dependency gate: If parent task, all children must be complete or failed.

Returns `{success: true, task_id, evidence_type, evidence_count}` or `{success: false, error: "reason"}`.

`reclaim_timeout_tasks(caller_device)`

Auto-reclaims stalled tasks where `timeout_at < NOW()`. Resets to pending, increments attempt_count, logs relay chain.

---

Config Reference

VariableSourceDefault
`SUPABASE_URL`env
`SUPABASE_ANON_KEY`env
`SUPABASE_SERVICE_KEY`env
Task tableSupabase`mac_tasks`
Event tableSupabase`task_events`
Thread tableSupabase`discord_threads`
Device tableSupabase`mesh_devices`

---

Smoke Test Results (2026-03-01)

TestInputExpectedActualStatus
AComplete with no evidenceevidence_blockedevidence_blockedPASS
BComplete with valid output (>50 chars)success, type=outputsuccess, type=outputPASS
CRegress complete → runningterminal_blocked, status stays completeterminal_blocked, status=completePASS
DParent complete with open childdependency_blocked (1 open)dependency_blocked (1 open)PASS
EParent complete after all children donesuccess, type=multiplesuccess, type=multiple (3 evidence)PASS
FComplete with localhost URLevidence_blocked (placeholder)evidence_blocked (placeholder)PASS
GAudit trail checkAll transitions logged11 events, all correctPASS

Promotion Decision

Promote into a technical note or architecture paper with implementation anchors.

Source Anchor

Comp-Core/docs/TASK-ARCHITECTURE.md

Detected Structure

Method · Evaluation · Architecture