Writes a read subtree onto the eval branch as a sequence of SHORT statements (parent → child, so
any partial write is a referentially-consistent prefix), then episode-stamps the cloned charts.
Deliberately NOT one big transaction: the branch connects through the transaction-mode pooler,
which is hostile to long transactions, and the insert-only semantics (on conflict do nothing)
already make a re-run resume idempotently — it fills in whatever a failed run didn't reach.
Out-of-subtree FKs are nulled and secrets scrubbed on the way in; jsonb columns are wrapped so
postgres.js parses them as JSON rather than typing a bare scalar (see toJsonb). A cloned
patient is a frozen snapshot — a re-clone never overwrites existing rows nor clobbers
entity-scoped parents shared with other clones. Owns the branch connection (destroy in finally).
Writes a read subtree onto the eval branch as a sequence of SHORT statements (parent → child, so any partial write is a referentially-consistent prefix), then episode-stamps the cloned charts. Deliberately NOT one big transaction: the branch connects through the transaction-mode pooler, which is hostile to long transactions, and the insert-only semantics (
on conflict do nothing) already make a re-run resume idempotently — it fills in whatever a failed run didn't reach. Out-of-subtree FKs are nulled and secrets scrubbed on the way in; jsonb columns are wrapped so postgres.js parses them as JSON rather than typing a bare scalar (seetoJsonb). A cloned patient is a frozen snapshot — a re-clone never overwrites existing rows nor clobbers entity-scoped parents shared with other clones. Owns the branch connection (destroyinfinally).