Skip to content

Commit c490828

Browse files
committed
docs(task): add operator runbook and update tool inventory
1 parent 1a2749c commit c490828

File tree

4 files changed

+150
-3
lines changed

4 files changed

+150
-3
lines changed

CLAUDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ uv run memory-access
3939
- **`normalizer.py`** — LLM decomposition/classification via Anthropic API (or Bedrock). Uses `DECOMPOSE_PROMPT` and `CLASSIFY_PROMPT`
4040
- **`embeddings.py`** — Embedding generation (OpenAI or Bedrock Titan), L2-normalized float32 vectors. `create_embedding_engine()` factory selects provider.
4141
- **`storage.py`**`InsightStore` class: SQLite persistence, migration system, subject indexing, knowledge graph queries
42-
- **`server.py`**`MemoryAccessApp` orchestrator + MCP tool definitions (9 tools: `store_insight`, `search_insights`, `list_insights`, `update_insight`, `forget`, `search_by_subject`, `related_insights`, `add_subject_relation`, `get_subject_relations`)
42+
- **`server.py`**`MemoryAccessApp` orchestrator + MCP tool definitions (insights, subject graph, knowledge bases, and task-state orchestration tools)
4343

4444
### Database
4545

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ To use AWS Bedrock instead of OpenAI/Anthropic APIs:
126126
}
127127
```
128128

129-
## MCP Tools (12 tools)
129+
## MCP Tools (21 tools)
130130

131131
### Storage
132132

@@ -152,6 +152,18 @@ To use AWS Bedrock instead of OpenAI/Anthropic APIs:
152152
- **`search_knowledge_base`** — Search external documentation by semantic similarity. Optionally filter by KB name.
153153
- **`list_knowledge_bases`** — List all knowledge bases with descriptions and chunk counts.
154154

155+
### Task orchestration
156+
157+
- **`create_task`** — Create a task with DB-enforced lifecycle state.
158+
- **`assign_task_locks`** — Acquire active locks for resources (exact + path-prefix conflict detection).
159+
- **`release_task_locks`** — Release active locks for a task (optionally scoped to resources).
160+
- **`add_task_dependencies`** — Add dependency edges between tasks.
161+
- **`transition_task`** — Atomically transition state with optimistic concurrency (`expected_version`).
162+
- **`append_task_event`** — Append audit/worklog events (append-only at DB level).
163+
- **`get_task`** — Fetch a task by ID.
164+
- **`list_tasks`** — List tasks with optional status filter.
165+
- **`list_task_events`** — List append-only events for a task.
166+
155167
## Semantic Frames
156168

157169
Insights are normalized into one of six canonical frames:

docs/task-state-runbook.md

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
# Task State Machine Runbook
2+
3+
Operational guide for the SQLite-backed task state machine used by `memory-access`.
4+
5+
## Scope
6+
7+
This runbook covers:
8+
- Task lifecycle transitions
9+
- Lock and dependency troubleshooting
10+
- Validation queries
11+
- Migration verification
12+
13+
## Lifecycle
14+
15+
Allowed states:
16+
- `todo`
17+
- `in_progress`
18+
- `blocked`
19+
- `done`
20+
- `failed`
21+
- `canceled`
22+
23+
Allowed transitions are DB-enforced by trigger:
24+
- `todo -> in_progress|blocked|failed|canceled`
25+
- `in_progress -> done|blocked|failed|canceled`
26+
- `blocked -> in_progress|failed|canceled`
27+
- `done|failed|canceled` are terminal
28+
29+
## Locking Rules
30+
31+
Active locks are stored in `task_locks`.
32+
Conflicts are DB-enforced for both:
33+
- exact same resource
34+
- path-prefix overlap (for example, `src` conflicts with `src/a.py`)
35+
36+
## Troubleshooting
37+
38+
### `LockConflict`
39+
40+
Meaning: lock acquisition violated exact or path-prefix overlap rules.
41+
42+
Actions:
43+
1. List active locks for the resource prefix.
44+
2. Release stale locks for completed/canceled tasks.
45+
3. Retry lock assignment.
46+
47+
### `DependencyNotMet`
48+
49+
Meaning: attempted to transition to `in_progress` while at least one dependency is not `done`.
50+
51+
Actions:
52+
1. Query dependency states.
53+
2. Complete or fail dependency tasks.
54+
3. Retry transition.
55+
56+
### `InvalidTransition`
57+
58+
Meaning: transition is not in allowed state graph.
59+
60+
Actions:
61+
1. Fetch task state/version.
62+
2. Use a legal transition path.
63+
64+
### `ConcurrencyConflict`
65+
66+
Meaning: optimistic version check failed (`expected_version` stale).
67+
68+
Actions:
69+
1. Re-read task row.
70+
2. Retry transition with latest `version`.
71+
72+
## Validation SQL
73+
74+
All examples assume SQLite shell connected to the target DB.
75+
76+
### Show migration version
77+
78+
```sql
79+
SELECT MAX(version) AS latest_version FROM schema_versions;
80+
```
81+
82+
### Inspect tasks
83+
84+
```sql
85+
SELECT task_id, status, owner, retry_count, version, updated_at
86+
FROM tasks
87+
ORDER BY updated_at DESC
88+
LIMIT 50;
89+
```
90+
91+
### Inspect active locks
92+
93+
```sql
94+
SELECT id, task_id, resource, active, created_at
95+
FROM task_locks
96+
WHERE active = 1
97+
ORDER BY resource;
98+
```
99+
100+
### Inspect task dependencies + current dependency state
101+
102+
```sql
103+
SELECT td.task_id,
104+
td.depends_on_task_id,
105+
t.status AS depends_on_status
106+
FROM task_dependencies td
107+
JOIN tasks t ON t.task_id = td.depends_on_task_id
108+
ORDER BY td.task_id, td.depends_on_task_id;
109+
```
110+
111+
### Inspect recent task events
112+
113+
```sql
114+
SELECT task_id, event_type, actor, payload, created_at
115+
FROM task_events
116+
ORDER BY created_at DESC
117+
LIMIT 100;
118+
```
119+
120+
## Migration Verification Procedure
121+
122+
1. Back up the DB file.
123+
2. Start the app once to trigger migrations.
124+
3. Validate:
125+
- `schema_versions` latest includes the task migrations.
126+
- Task tables/triggers exist.
127+
4. Run one smoke transition flow:
128+
- create task
129+
- `todo -> in_progress`
130+
- `in_progress -> done`
131+
132+
## Type Stub Decision
133+
134+
`src/memory_access/orm_models.pyi` is intentionally kept.
135+
Reason: Peewee field accessors are dynamic; the stub improves static checking and editor hints for `TaskStore` and callers.

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)