Revision: 1 Last modified: 2026-12-04T19:00:00Z
store.py is the workable-items database access layer for the Issues mirror. The database is the
source of truth (anchor §11.4.93), and this module is the only place the mirror reads it.
Its access discipline is narrow on purpose:
- Read-only on items. The mirror never modifies a workable item.
- Writes only
issue_sync_map— the mirror's own sync-state table — created on demand (CREATE TABLE IF NOT EXISTS, lossless). - The consumer's own store may bump
schema_versionseparately; this module does not interfere.
The database can hold both an open (Issues) row and a Fixed row for the same item id. When it does,
the open row wins. Without that rule the mirror would alternate between two representations of one
item depending on row order, producing phantom drift on every run.
CREATE TABLE IF NOT EXISTS issue_sync_map (
atm_id TEXT NOT NULL, tracker TEXT NOT NULL, host TEXT NOT NULL, repo TEXT NOT NULL,
issue_number INTEGER, issue_url TEXT,
content_hash TEXT, last_synced_at TEXT, state TEXT, last_error TEXT,
PRIMARY KEY (atm_id, tracker, host, repo))The primary key is the quadruple (atm_id, tracker, host, repo), which is what lets one item be
mirrored to several hosts independently — each with its own recorded hash, state and last error.
python3with the standard-librarysqlite3module.- A readable DB at the configured path (default
docs/workable_items.db). - Write access only for the
issue_sync_maptable.
from issue_sync import store
con = store.open_db(db_path) # read access to items, write to issue_sync_map
rows = con.execute(f"SELECT {store.FIELDS} FROM ...")UNCONFIRMED: the precise helper names (open_db, and any reader/writer wrappers) beyond MAP_DDL and
FIELDS were not read while writing this guide. Confirm before depending on one:
python3 -c "import issue_sync.store as s; print([n for n in dir(s) if not n.startswith('_')])".
| Name | Kind | Contract |
|---|---|---|
MAP_DDL |
string | The CREATE TABLE IF NOT EXISTS issue_sync_map statement. |
FIELDS |
string | atm_id, type, status, title, severity, description, current_location, forensic_anchor, body_md — the columns the mirror reads. |
Note that FIELDS is the columns read, not the columns sent: payload.py's allowlist decides what
leaves the process. The two are intentionally different.
A library, so no exit codes. Failures surface through the caller as the package's 2 (cannot determine)
when the DB is unreadable — never as "in sync".
- Both an open row and a
Fixedrow for oneatm_id. The open row wins; this is the documented collapse rule. - A missing
issue_sync_maptable. Created on demand, losslessly. - A DB that cannot be read. Cannot determine (
2) — an unreadable DB is never an empty mirror. - A pre-existing
issue_sync_mapwith a narrower schema.IF NOT EXISTSwill not alter it; a genuine schema change is a migration, not a silent rewrite. - A consumer that bumps
schema_version. Out of this module's scope; it does not manage the consumer's schema. - Several legs for one item. Independent rows keyed by
(atm_id, tracker, host, repo). last_errorpopulated. The leg is recorded as failing rather than silently retried forever.
- Opens the SQLite DB.
- Ensures
issue_sync_mapexists (MAP_DDL). - Reads items with
FIELDS, collapsing duplicateatm_idrows in favour of the open one. - Records per-leg sync state (hash, issue number/URL, state, last error) into
issue_sync_map. - Never writes to an item row.
Used by engine.py, inbound.py, cli.py, pipeline.py and offline_status.py (which compares
current content hashes against issue_sync_map).
Related: payload.py (what may be sent), inbound.py (read-only inbound), offline_status.py
(offline pending report).
See also docs/scripts/engine.md, docs/scripts/offline_status.md and docs/scripts/payload.md.
2026-12-04 — python3 -c "import ast;ast.parse(open('scripts/issue_sync/store.py').read())" → exit 0.
python3 -c "import issue_sync.store as s; print('issue_sync_map' in s.MAP_DDL)" prints True.