basquetWi + New ticket
terra TERRA-78

Retire/reactivate writes archive rows with no actor or reason: RETIRE_SQL runs on a bare pool.query so setArchiveContext cannot reach it, and terra_29 will break the feature outright

Todo high ctcoder-terra-cc

MEASURED by db-terra-cc 2026-08-17 from source (archive-context.ts, cirugia-retire-actions.ts, cirugia-retire-core.ts), surfaced by audit BLOCK finding #1 on terra_29. RETIRE_SQL (cirugia-retire-core.ts:185-216) is one WITH-UPDATE-INSERT run through a bare pool.query() in setCirugiaActive (cirugia-retire-actions.ts:71-78): no client checkout, no transaction, no setArchiveContext() call. setArchiveContext writes its GUCs transaction-locally via set_config(...,true), so as currently called it CANNOT reach that statement. TWO SEPARATE CONSEQUENCES, do not collapse them. LIVE TODAY: retire/reactivate is shipped (TERRA-56, 490b014, v0.24.0) and every archive row it writes goes in with no actor and no reason, because the GUCs the sink reads are never set. That is an attribution gap on real clinical bookkeeping, happening now, with no guard to catch it. ON APPLY: terra_29 makes archive context mandatory via fn_terraRequireArchiveContext(). The moment it applies, every retire/reactivate RAISEs. The feature breaks outright, it does not degrade. FIX (db-terra-cc: application code, not DB): checkout a client, BEGIN, setArchiveContext(client, actor.id, reason), client.query(RETIRE_SQL, ...), COMMIT. Confined to cirugia-retire-actions.ts. cirugia-retire-core.ts stays dependency-free by design - its own header says "use server" module, unimportable by node --test - so do not pull the pool into it. ORDERING IS FIXED AND IS THE POINT: this ships FIRST, terra_29 applies SECOND. PM has held terra_29 on exactly this. Applying the guard against an unfixed writer is the shape terra keeps paying for. Note the node-side transaction caveat: this is a client-checkout BEGIN around a single statement to carry txn-local GUCs, which is the sanctioned shape - it is NOT a node-side BEGIN + lock + decide, which stays banned. BLOCKED ON A LANE, NOT ON A DECISION: terra has zero registered push lanes as of 2026-08-17T15:14Z (coder-terra-cc dropped off roster, coder02-terra-cc absent since 07-30). Relaunch asked of Elazar.

Sub-tickets

No sub-tickets.
+ Add sub-ticket

Questions

No questions.

Activity

  • wi-cli-venus created · 7h ago
  • wi-cli-venus blocked · 7h ago
    Blocked on a lane, not a decision: terra has zero registered push lanes as of 2026-08-17T15:14Z. Relaunch of coder-terra-cc asked of Elazar.
  • wi-cli-venus unblocked · 7h ago
    coder-terra-cc back on roster (re-registered 2026-08-17T18:33Z, confirmed by ack + roster read). Dispatched.
bug
7h ago by wi-cli-venus
7h ago