|
605 | 605 | # - Stage floors (Bahrick 1984 permastore, Benna & Fusi 2016) |
606 | 606 | # - p_factor (global decay rate per hour) = 0.95 default |
607 | 607 |
|
| 608 | +EFFECTIVE_STAGE_FN = """ |
| 609 | +-- effective_stage — LAZY read-time derivation of the consolidation stage. |
| 610 | +-- |
| 611 | +-- Root cause (memory 4202985): A3 made HEAT lazy (decayed from stage_hours |
| 612 | +-- on the read path) but left STAGE eager — advanced only by the |
| 613 | +-- consolidation handler (handlers/consolidation/cascade.py), never on |
| 614 | +-- recall/read. Benchmark and import runs trigger no consolidation pass, so |
| 615 | +-- a row stays frozen at its insert stage 'labile' (α=2.0, floor=0.0) while |
| 616 | +-- its heat decays under the labile law → collapses to ~0. This function |
| 617 | +-- re-derives the stage lazily from elapsed dwell + the row's stored signal |
| 618 | +-- columns so α and the floor track the trace's true maturity. |
| 619 | +-- |
| 620 | +-- Mirrors cascade_advancement.compute_advancement_readiness applied |
| 621 | +-- cumulatively (advance as far as time + signals permit, one shot), |
| 622 | +-- forward-chain only (labile→early_ltp→late_ltp→consolidated), monotonic |
| 623 | +-- (never demote below the stored stage). The DA gate of the LABILE→EARLY_LTP |
| 624 | +-- transition is encoding-time and unavailable on the read path, so only the |
| 625 | +-- importance gate is used (dopamine treated as absent). |
| 626 | +-- |
| 627 | +-- stage_hours is treated as a dwell BUDGET consumed stage-by-stage: leaving |
| 628 | +-- a stage requires budget ≥ that stage's effective min_dwell, and consumes it. |
| 629 | +-- |
| 630 | +-- min_dwell hours: labile=0, early_ltp=1, late_ltp=6, consolidated=24. |
| 631 | +-- source: cascade_stages._STAGE_PROPERTIES (Kandel 2001) |
| 632 | +-- schema acceleration on min_dwell (cascade_advancement._effective_min_dwell): |
| 633 | +-- systems-consolidation stages (late_ltp, consolidated): × 15^(-schema) |
| 634 | +-- (Tse 2007 ~10-15× acceleration; 15.0 base is an engineering choice) |
| 635 | +-- synaptic-tag stages (labile, early_ltp): × (1 - schema·0.2) |
| 636 | +-- signal gates (cascade_advancement._check_*_advancement): |
| 637 | +-- labile→early_ltp: importance > 0.3 (DA path disabled at read) |
| 638 | +-- early_ltp→late_ltp: access_count ≥ 1 OR importance > 0.4 |
| 639 | +-- late_ltp→consolidated: access_count ≥ (3 if schema < 0.5 else 1) |
| 640 | +-- 'reconsolidating' and any unknown stage are returned unchanged — they are |
| 641 | +-- access-triggered (Nader 2000), not time-derivable. |
| 642 | +CREATE OR REPLACE FUNCTION effective_stage( |
| 643 | + p_stage TEXT, |
| 644 | + p_hours DOUBLE PRECISION, |
| 645 | + p_importance REAL, |
| 646 | + p_access INTEGER, |
| 647 | + p_schema REAL |
| 648 | +) RETURNS TEXT AS $$ |
| 649 | +DECLARE |
| 650 | + cur TEXT := p_stage; |
| 651 | + budget DOUBLE PRECISION := GREATEST(0.0, COALESCE(p_hours, 0.0)); |
| 652 | + imp DOUBLE PRECISION := COALESCE(p_importance, 0.5); |
| 653 | + acc INTEGER := COALESCE(p_access, 0); |
| 654 | + sch DOUBLE PRECISION := COALESCE(p_schema, 0.0); |
| 655 | + dwell DOUBLE PRECISION; |
| 656 | + late_thr INTEGER; |
| 657 | +BEGIN |
| 658 | + -- Only the forward synaptic-tag chain is derived lazily. |
| 659 | + IF cur NOT IN ('labile', 'early_ltp', 'late_ltp', 'consolidated') THEN |
| 660 | + RETURN cur; |
| 661 | + END IF; |
| 662 | +
|
| 663 | + -- LABILE → EARLY_LTP. min_dwell(labile)=0 → no budget consumed. |
| 664 | + IF cur = 'labile' THEN |
| 665 | + IF imp > 0.3 THEN |
| 666 | + cur := 'early_ltp'; |
| 667 | + ELSE |
| 668 | + RETURN cur; |
| 669 | + END IF; |
| 670 | + END IF; |
| 671 | +
|
| 672 | + -- EARLY_LTP → LATE_LTP. effective min_dwell = 1.0 · (1 - schema·0.2). |
| 673 | + IF cur = 'early_ltp' THEN |
| 674 | + dwell := 1.0 * (1.0 - sch * 0.2); |
| 675 | + IF budget >= dwell AND (acc >= 1 OR imp > 0.4) THEN |
| 676 | + budget := budget - dwell; |
| 677 | + cur := 'late_ltp'; |
| 678 | + ELSE |
| 679 | + RETURN cur; |
| 680 | + END IF; |
| 681 | + END IF; |
| 682 | +
|
| 683 | + -- LATE_LTP → CONSOLIDATED. effective min_dwell = 6.0 · 15^(-schema). |
| 684 | + IF cur = 'late_ltp' THEN |
| 685 | + dwell := 6.0 * POWER(15.0, -sch); |
| 686 | + late_thr := CASE WHEN sch < 0.5 THEN 3 ELSE 1 END; |
| 687 | + IF budget >= dwell AND acc >= late_thr THEN |
| 688 | + cur := 'consolidated'; |
| 689 | + END IF; |
| 690 | + END IF; |
| 691 | +
|
| 692 | + -- CONSOLIDATED is terminal on the forward chain. |
| 693 | + RETURN cur; |
| 694 | +END; |
| 695 | +$$ LANGUAGE plpgsql IMMUTABLE PARALLEL SAFE; |
| 696 | +""" |
| 697 | + |
608 | 698 | EFFECTIVE_HEAT_FN = """ |
609 | 699 | -- p_factor default: 0.95 per DAY (pre-A3 DECAY_MEMORIES_FN ran ~daily, |
610 | 700 | -- each run applied factor 0.95 once). Converted to per-hour equivalent: |
|
625 | 715 | stage_floor DOUBLE PRECISION; |
626 | 716 | base_scaled DOUBLE PRECISION; |
627 | 717 | decayed DOUBLE PRECISION; |
| 718 | + eff_stage TEXT; |
628 | 719 | BEGIN |
629 | 720 | -- Pinned: protected or explicit no_decay. heat_base is authoritative; |
630 | 721 | -- factor still applies (homeostatic contraction affects even anchors |
|
647 | 738 | stage_hours := GREATEST(0.0, EXTRACT(EPOCH FROM |
648 | 739 | (t_now - COALESCE(m.stage_entered_at, m.created_at))) / 3600.0); |
649 | 740 |
|
| 741 | + -- Lazily derive the effective consolidation stage. A3 made HEAT lazy but |
| 742 | + -- left STAGE eager (advanced only by the consolidation handler, never on |
| 743 | + -- the read path), so between consolidation passes a row's heat decayed |
| 744 | + -- under the labile α while the trace had already earned a later, |
| 745 | + -- slower-decaying stage. effective_stage() re-derives the stage from |
| 746 | + -- elapsed dwell (stage_hours) + the stored signal columns so α and the |
| 747 | + -- floor below match the trace's true maturity, monotonically (never |
| 748 | + -- below the stored stage). 'reconsolidating'/unknown stages pass through |
| 749 | + -- unchanged. source: effective_stage() + cascade_advancement gates. |
| 750 | + eff_stage := effective_stage( |
| 751 | + m.consolidation_stage, |
| 752 | + stage_hours, |
| 753 | + m.importance, |
| 754 | + m.access_count, |
| 755 | + m.schema_match_score |
| 756 | + ); |
| 757 | +
|
650 | 758 | -- α(stage) — Kandel 2001 stage-dependent decay exponent. |
651 | 759 | -- source: pg_schema.py:748-756 |
652 | | - alpha := CASE m.consolidation_stage |
| 760 | + alpha := CASE eff_stage |
653 | 761 | WHEN 'labile' THEN 2.0 |
654 | 762 | WHEN 'early_ltp' THEN 1.2 |
655 | 763 | WHEN 'late_ltp' THEN 0.8 |
|
669 | 777 | * (1.0 - EXP(-LEAST(stage_hours / 1.0, 80.0))); |
670 | 778 |
|
671 | 779 | -- Stage permastore floor — Bahrick 1984 + Benna & Fusi 2016. |
672 | | - -- source: pg_schema.py:742-747 |
673 | | - stage_floor := CASE m.consolidation_stage |
| 780 | + -- Uses the lazily-derived eff_stage (see above) so a trace that has |
| 781 | + -- matured into late_ltp/consolidated gets its retention floor even |
| 782 | + -- between consolidation passes. source: pg_schema.py:742-747 |
| 783 | + stage_floor := CASE eff_stage |
674 | 784 | WHEN 'consolidated' THEN 0.10 |
675 | 785 | WHEN 'late_ltp' THEN 0.05 |
676 | 786 | WHEN 'reconsolidating' THEN 0.05 |
@@ -1606,6 +1716,9 @@ def get_all_ddl() -> list[str]: |
1606 | 1716 | # rename lands before indexes on heat_base are created. |
1607 | 1717 | MIGRATIONS_DDL, |
1608 | 1718 | INDEXES_DDL, |
| 1719 | + # effective_stage() must be created before effective_heat(), which |
| 1720 | + # calls it to derive α/floor lazily on the read path. |
| 1721 | + EFFECTIVE_STAGE_FN, |
1609 | 1722 | EFFECTIVE_HEAT_FN, |
1610 | 1723 | EFFECTIVE_HEAT_FROZEN_FN, |
1611 | 1724 | # A3 canonical read path: lazy effective_heat() computes decay at |
|
0 commit comments