orthonym.assembly.nested_memo#
Note
Internal API. Names and behaviour may change between releases.
Replay-memo for NESTED naming calls (a performance pass, a lever).
A nested name_compound(...) inside an outer name has three side effects the
outer molecule’s tier and abstention decisions read: (1) the provenance ContextVars
(clear_provenance runs only in name_tiered, and general_ring_prefix /
suffix_free_prefix_name / stereo_unexpressed are set-only), (2) the shared
perf/analysis/work budgets (_budget_scope shares them across nested name),
(3) the return value. A plain memo hit would skip (1) and (2) and could flip the outer
tier or move a PerfBudgetExceeded trip.
This helper reproduces (1) EXACTLY via a provenance TOUCHED-log (a performance pass):
it records which vars the call WROTE — not merely which net-CHANGED — so a var written
to a value it already held, or written A->B->A, is still replayed to the value the fresh
call left (a before/after delta would record it as untouched and leave a stale value on a
later hit in a different ambient context). It records (2) the units each budget lost and
replays them. Scope-bound through assembly.memo (fail-open outside a scope; verify
mode recomputes).
- orthonym.assembly.nested_memo.cached_nested_call(namespace, key, fn, *, replay_budgets=True)#
Return
fn’s result for(namespace, key); on a hit replay the EXACT provenance vars the call touched and its budget units. Exceptions propagate uncached.Only the RESULT is stored under
namespace(soORTHONYM_MEMO=verifycompares names — an honest incomplete-key oracle); the context-relative replay metadata lives in the scope-bound side store, which verify never compares.replay_budgets=False: a hit replays the provenance only and charges no budget unit. The recorded units are the fresh call’s COLD cost; for a memo placed over a whole-pipeline sub-namer (the peptide substitutive attempts) the unmemoised repeat that a hit stands for runs WARM (the scope’s fragment cache and plain memos already hold its sub-results) and costs almost nothing, so replaying the cold cost on every hit charges the budget for work that neither the memoised nor the unmemoised code does. Measured (ChEBI 12-residue peptides, fresh process): the whole-molecule attempt cost 145 analysis calls cold and 0, 0, 0 on its three unmemoised repeats; the replay charged 4 x 145 and more against the 500-call budget, which then aborted the naming (PerfBudgetExceeded -> abstain). A hit does no work, so it spends none; every fresh computation still charges its own work, so the hang budgets still bound the call.