Expand description
Unified task store — SQLite as single source of truth.
TaskStore replaces the legacy internal_tasks table and GitHub labels as the
authoritative task state. External backends (GitHub, Linear) become sync adapters
that mirror state changes outward.
Uses sqlx for async SQLite access with file-based migrations.
All task state, metrics, KV, and rate limits flow through this module.
§Safety Warning: Never Use SELECT *
Using SELECT * with sqlx-sqlite’s prepared statement cache can cause OOB
(out-of-bounds) panics when the schema changes (e.g., new migration adds a column).
The issue occurs because:
- SQLite caches prepared statements with column metadata at prepare time
- When a migration adds a new column,
sqlite3_column_count()returns the updated count - The cached statement’s column metadata vector was built with the old count
- Accessing column index N when only N columns exist (0..N-1) causes a panic
Solution: Always use explicit column lists via constants like TASK_COLS,
CONTROL_MESSAGE_COLS, JOB_STATE_COLS, etc. See tasks.rs and control.rs
for examples. CI will fail if SELECT * is detected in store files.
Structs§
- Agent
Stat - Agent statistics from metrics.
- Chat
Cost Summary - Cost summary for a chat session.
- Complete
Run - Parameters for completing a run.
- Control
Message - A message in the control session conversation history.
- Cost
ByGroup - Cost breakdown by a grouping dimension (agent, model, etc.).
- Cost
Estimate - Cost estimate in USD.
- Cost
Period - Cost data for a single time period.
- Cost
Summary - Cost summary across multiple time periods.
- Error
Stat - Error type distribution for pattern detection.
- High
Review Cycle Task - Task with high review cycle count (persistent review loop).
- Insert
Task Metric - Parameters for inserting a new task metric record.
- JobState
- Runtime state for a scheduled job, stored in SQLite (not in .orch.yml).
- Memory
Entry - A single memory entry from a task attempt.
- Metrics
Summary - Metrics summary for the CLI output.
- Model
Pricing - Per-1M token pricing in USD.
- NewTask
- Parameters for creating a new task.
- RunToken
Usage - Token usage for a run.
- Slow
Task Info - Slow task info for pattern detection.
- Start
Run - Parameters for starting a new run.
- Store
Route - Parameters for storing a route result.
- Task
- Unified task record — single row in the
taskstable. - Task
Activity - A single task lifecycle activity event.
- TaskRun
- A single run (agent execution, review, or routing attempt).
- Task
Store - The unified task store backed by SQLite (via sqlx).
- Token
Usage - Token usage for an agent run.
- Upsert
External - Parameters for upserting an external task.
Enums§
Functions§
- default_
db_ path - Default database path:
~/.orch/orch.db - get_
cost_ estimate - Get cost estimate from the store.
- get_
cost_ estimate_ result - Get cost estimate from the store, surfacing DB read errors.
- get_
recent_ memory - Get recent memory entries for a task.
- get_
recent_ memory_ result - Get recent memory entries for a task, surfacing DB read errors.
- get_
task_ field - Read a specific string field from a task record.
- get_
task_ field_ direct - Read a specific string field from a task record (store always available).
- get_
token_ usage - Get token usage from the store.
- get_
token_ usage_ result - Get token usage from the store, surfacing DB read errors.
- opt_
store_ get_ task - Load the full
Taskrecord from the store. - opt_
store_ get_ task_ by_ id - Load the full
Taskrecord from the store. - parse_
since_ duration - Parse a human-readable duration string into an RFC3339 timestamp representing
now - duration. - pricing_
for_ model - Resolve model pricing using a built-in table and normalized model aliases.
- resolve_
store_ id - Resolve a task’s numeric store ID from its external identifier.
- review_
session_ expected - set_
review_ session_ expected - store_
increment - Increment a counter in the task store.
- store_
increment_ by_ id - Increment a counter in the task store.
- store_
log_ activity - Append a lifecycle activity event to a task timeline.
- store_
reset_ counters - Reset all task counters in the task store.
- store_
reset_ failure_ counters - Reset transient failure/retry counters, preserving
review_cycles. - store_
set - Write fields to the task store.
- store_
set_ by_ id - Write fields to the task store.
- store_
set_ result - Write fields to the task store, returning an error if the write fails.
- store_
set_ result_ by_ id - Write fields to the task store, returning an error if the write fails.
- store_
touch_ updated_ at - Touch
updated_atto now so the stuck-task timer is reset after a session exits. - store_
touch_ updated_ at_ by_ id - Touch
updated_atto now so the stuck-task timer is reset after a session exits.
Type Aliases§
- Store
Result - Result type for helpers that distinguish “not found” from “read error”.