Repository navigation
Description
Context
Spike 0002 (.agents/plans/contrail/spikes/0002-database-engine.md) has not started. Round 27 narrowed it to Postgres only, with a timebox of about 3.5 days. D1 became a desk review, and so did DO-SQLite, which the spike frames as one object per workspace (spike file lines 5, 12-14; ADR-0040:113; Q-0040.1, QUESTIONS.md:73). The Postgres side is live: CNPG thrust-pg and thrust-pg-dev, reached through a Workers VPC service and Hyperdrive (ADR-0094; research/0010 §11-12; bead plane-byd.4), and spike 0001 Stage 2 ran on it (research/0004 §10). The contract suite is HTTP-only and target-agnostic, with four targets (scripts/contract.sh:5: native-memory | native-pg | worker-memory | worker-cf) and a bench pass (crates/thrust-contract-tests/src/bin/bench.rs). The Worker already uses Durable Object SQLite (crates/thrust-worker/src/durable.rs:34,57, workers-rs 0.8.7). ADR-0040 is proposed.
Problem
FR-04: since round 27 the Postgres path has picked up four costs.
- The Hyperdrive statement-flow constraint is documented behaviour, so every statement stays typed and uncached (
crates/thrust-adapters-postgres/src/lib.rs:53-64;research/0004§10.4 F1), and advisory locks are unsupported. - TLS is not authenticated (
cert_verification_mode = disabled, ADR-0094:111,120; Q-0094.9;plane-byd.9). - Availability now includes
woven-o11y(research/0010§6 risks 1 and 7; Q-0094.4). - The first database-backed request on a fresh isolate takes 595 to 615 ms (
research/0004:387, F7), against p95 < 500 ms.
The round-11 rejection of DO-SQLite (ADR-0040:67,97) assumed one object per workspace. An instance-level object, which fits single-org (ADR-0003), was never weighed. FR-16: step 6 (the Rust data layer) is already decided by FR-07, and the Stage 2b items have no home (Q-0006.6, QUESTIONS.md:359). FR-22: the counter upsert is the first statement of the create transaction (crates/thrust-adapters-postgres/src/lib.rs:399-414), so its row lock is held for the whole transaction. Create p95 is 559 ms at c=8 against 296 ms at c=1 (research/0004:383).
Proposal
Rewrite spike 0002 as handoff item A3.1 specifies (ADR-0040 round-29 note):
- Two cells, both driven by the existing contract suite and
bench:worker-pg: the slice on CNPG through Hyperdrive, i.e. today'sworker-cftarget on the real platform (wrangler.stage2.toml). The sequence number is allocated in its own short transaction, or last withUPDATE ... RETURNING(FR-22).worker-do: one instance-levelAppDoholding SQLite. ThefetchWorker forwards to it, and the axum router and use-cases run inside it over a SQLite adapter. The native twin runs the same SQL onrusqlite. Known gap:sql.exec()rejectsBEGINandSAVEPOINT, and workers-rs 0.8.7 exposesStorage::transaction(an async'staticclosure,src/durable.rs:635) but nottransactionSync. The cell has to show how ADR-0045's explicitTxmaps onto that.
- Keep steps 2, 3, 4, 7 and 9, and drop step 6 (FR-07). Add the Stage 2b items from Q-0006.6: Hyperdrive caching on versus off, using a separate config (
research/0010:301); a bench from a distant region; a 24-hour cost reconciliation; one real Email send. - Exit criteria, per cell:
- no duplicate
sequence_idin 10k creates from at least 50 parallel writers (R-F2); - FTS plus trigram (
pg_trgm, or the FTS5trigramtokenizer on the DO); - list p95 < 300 ms from the origin's region;
- a migration story;
- a projected cost.
- no duplicate
- Decision rule: Postgres stays the default if the DO cell fails any criterion. If both cells pass, the owner decides (Q-0040.6, Track C of the handoff). Timebox: 3.5 + 3 days.
Acceptance criteria
-
spikes/0002-database-engine.mdis rewritten with both cells, exit criteria per cell and the decision rule; the status row inspikes/README.mdis updated. -
scripts/contract.shacceptsworker-doand a native SQLite twin, and the main pass is green on each. The/_infovacuity guard (scripts/contract.sh:160-180) shows each run used the adapter set it claims. - The 50-writer, 10k-create test passes on both cells and fails against the
mutant_dup_sequencebuild (scripts/mutants.sh:31), which is the control. -
benchcreate p95 at c=1 and c=8 is recorded forworker-pgwith the FR-22 allocation order, next to 296 and 559 ms (research/0004§10.3). - A new research note gives FTS parity, list p95, the migration story and cost for each cell. ADR-0040 is decided, or stays
proposedwith the reason, and Q-0040.1 and Q-0006.6 are answered. - Every resource the spike created is listed and torn down, as in
research/0004§10.7.
References
- Review: .agents/plans/contrail/reviews/2026-10-19-fable-architecture-review.md (FR-04, FR-16, FR-22)
- Handoff:
.agents/plans/contrail/reviews/2026-10-19-fable-handoff-PROMPT.mditem A3.1 .agents/plans/contrail/spikes/0002-database-engine.md; ADR-0040 (adrs/data/base/0040-system-of-record-database.md:67,97,113), ADR-0041, ADR-0043, ADR-0044, ADR-0045, ADR-0094:111,120- Q-0040.1 (
QUESTIONS.md:73), Q-0006.6 (QUESTIONS.md:359), Q-0094.4, Q-0094.9, Q-0040.6 (proposed in the handoff, Track C); SPEC R-F2 (SPEC.md:51) research/0004§10.3 and §10.4 (F1, F7);research/0010§6 and §11crates/thrust-worker/src/durable.rs:34,57;crates/thrust-adapters-postgres/src/lib.rs:399-414;crates/thrust-contract-tests/tests/contract.rs:196(today's 20-writer test)- Beads: plane-byd.4
Blocked by: #35
Finding: FR-04, FR-16
Activity
Scopethe argument of every repository andTxmethod #35verify_ca(infra repo work, tracked here) #41GET /healthz?deep=1through the database and astatus.wovenprobe; SLO measured on it #42feat(worker): worker-do, the instance-level Durable Object cell
docs: engine cells results (research 0011) and the spike 0002 record
feat(db): engine pass, search routes and the FR-22 order; spike 0002 …
chore(tools): bring the compat-inventory and spike-0004 scripts into …