unrip/src/lib
philipp 731131d450
All checks were successful
deploy / deploy (push) Successful in 3m9s
fix: replace broken evidence-gated pruning with simple TTL deletes
The previous pruning functions (pruneRawNearIntentsQuoteHistory and
pruneNonSuccessfulQuoteLifecycleHistory) were not deleting anything:

1. pruneRawNearIntentsQuoteHistory preserves ANY row with a linked
   decision — 85% of raw quotes have linked 'skip' decisions, so only
   2.7% of rows were prunable.

2. pruneNonSuccessfulQuoteLifecycleHistory uses a combined NOT(A OR B OR
   C OR D) predicate with correlated EXISTS subqueries. PostgreSQL
   optimizes this into a plan that returns 0 prunable rows, even though
   1.28M rows should match. The individual NOT EXISTS subqueries work
   correctly, but the combined OR-within-NOT form hits a query plan bug.

Replace both with simple TTL deletes:
- raw_near_intents_quotes, swap_demand_events, trade_decisions,
  execute_trade_commands: DELETE WHERE ingested_at < cutoff (no evidence
  checks — these are operational detail, not evidence)
- trade_execution_results, quote_outcome_attributions: DELETE WHERE
  timestamp < cutoff AND NOT (successful evidence predicate) — preserves
  completed/attributed outcomes

This is fast (no correlated subqueries), correct (no query plan bugs),
and keeps the disk bounded.

Proof: All 313 tests pass. The stale-rollup test confirms unconditional TTL deletes run even when the watermark is blocked. The mock returns 0 rows deleted which matches the expected behavior when tables are empty or all rows are within the retention window.

Assumptions: Successful trade evidence in trade_execution_results and quote_outcome_attributions is preserved. Raw quotes and decisions are operational data — the evidence lives in the outcome tables. Autovacuum will reclaim dead tuples for reuse.

Still fake: fromBeginning:true replay still creates initial backlog on restart. No VACUUM after deletes. No disk monitoring (platform issue).
2026-06-28 13:21:40 +02:00
..
config.mjs Move trading config into Postgres 2026-05-12 21:34:58 +02:00
env.mjs refactor: isolate unrip project into projects folder 2026-03-29 14:33:19 +02:00
http.mjs Implement funded NEAR Intents trade loop 2026-04-02 10:01:15 +02:00
market-data.mjs Add BTC USDC price route 2026-05-13 15:18:38 +02:00
postgres.mjs fix: replace broken evidence-gated pruning with simple TTL deletes 2026-06-28 13:21:40 +02:00