chore(cleanup): complete post-pickup hygiene, consolidation, and review fixes for 3lang depth unification

- Remove retired HANDOFF-antigravity-2026-07-01.md stray.
- Harden enrich_assessments_with_depth (remove fragile __dict__ fallback; best-effort only).
- Explicit _last_node_depths in ChatRuntime; clean direct propagation from pipeline (remove hasattr/setattr dance + bare excepts).
- Add clarifying propagation contract comments.
- Update plan.md with cleanup section.
- All targeted tests + SHA/claims checks green post-edit.
- Tree clean, ready to roll.

Addresses remaining MEDIUM items from code-reviewer run.
This commit is contained in:
Shay 2026-07-08 07:26:03 -07:00
parent 05348e5a79
commit 0e6dada09b
4 changed files with 29 additions and 18 deletions

View file

@ -608,6 +608,7 @@ class ChatRuntime:
pack_ids = tuple(config.input_packs)
self.config = resolved_config
self._last_node_depths: dict | None = None # 3-lang PropGraph depth propagation (he/grc roots) to contemplate paths; set by pipeline
manifests = []
manifolds = []
entries = []
@ -889,7 +890,7 @@ class ChatRuntime:
if self.config.auto_contemplate and candidates_to_save:
from teaching.contemplation import contemplate
vault_probe = _vault_probe_for_context(self._context) if self._context else None
depth = getattr(self, '_last_node_depths', None) # from PropGraph for 3-lang
depth = getattr(self, '_last_node_depths', None) # from pipeline PropGraph depth (3-lang root propagation contract)
candidates_to_save = [
contemplate(c, vault_probe=vault_probe, depth=depth)
for c in candidates_to_save

View file

@ -495,19 +495,21 @@ class CognitiveTurnPipeline:
oov_geometric_context = {}
oov_geometric_context["graph_anti_unify"] = graph_anti_unify(topo, node_depths)
except Exception:
# Best-effort telemetry only; anti-unify failure must not affect main path.
pass
# Capture depths (post-enrich) to attrs for recognize chaining (AC1) + runtime contemplate depth= (real).
# Propagation contract (3-lang depth on PropGraph spine): pipeline (after OOV/PropGraph construction)
# writes to runtime so that runtime.contemplate() and teaching paths can forward it without
# re-resolving packs. This is the current minimal cross-component channel; see review notes for
# future narrowing via explicit DepthCarrier or context object.
if node_depths:
self._current_node_depths = node_depths
if effective_graph and effective_graph.nodes:
self._current_agent_node_id = effective_graph.nodes[0].node_id
self._last_node_depths = node_depths
if hasattr(self.runtime, "_last_node_depths"):
try:
setattr(self.runtime, "_last_node_depths", node_depths)
except Exception:
pass
# Direct assignment now that runtime explicitly declares the attr (cleanup of hasattr/setattr dance)
self.runtime._last_node_depths = node_depths
# Track last node id for correction-intent chaining
if graph.nodes:

12
plan.md
View file

@ -102,3 +102,15 @@ All skeptic gaps addressed (pipeline recog/ctx/attrs, runtime depth pass, teachi
- Next if more R&D: extend root-aware to additional construction/derivation call sites for 3lang frames; add he/grc construction exemplars; wire depth into more geometric proposal paths; prep PR (push to forgejo remote, use tea pulls).
- Invariants re-confirmed: immutability (replace/new), exact, no drift repair, fresh trace stable, core lanes green.
- Pickup seeds (NEW_SESSION_PROMPT.txt, docs/session-compacts/2026-07-06-compact.md, COMPACT_STRATEGY.md) can now be archived per strategy.
## 2026-07-08 Cleanup, Consolidation & Hygiene (post-pickup)
- Tree fully cleaned: retired HANDOFF-antigravity stray removed from legacy/.
- Addressed remaining code-review MEDIUM items (minimal targeted changes):
- `recognition/depth_canonical.py`: removed risky `__dict__` reconstruction fallback in `enrich_assessments_with_depth`. Now pure best-effort via `replace`; on failure keeps original (safer for frozen/slots ContractAssessment post-CGA).
- `chat/runtime.py`: explicit `self._last_node_depths = None` declaration in `__init__`.
- `core/cognition/pipeline.py`: direct assignment for depth propagation (removed hasattr/setattr/try dance); added clear contract comment; improved graph_anti_unify best-effort comment.
- Duplication already consolidated (get_node_depths delegates to build_node_depths).
- Verifs post-cleanup: spine/anti/depth/construction key tests 35+ passed; SHA pins match canonical reports; claims test green (9/9 overall).
- All changes small, preserve immutability + invariants, no behavior change for 3-lang paths.
- Branch ready: clean working tree, on top of latest forgejo/main, conventional history, documented.
- No other stray artifacts, .gitkeeps, or report cruft introduced by this slice.

View file

@ -91,9 +91,12 @@ def build_node_depths(nodes: Sequence[Any]) -> dict[str, dict]:
def enrich_assessments_with_depth(assessments: Tuple[Any, ...], depth: dict | None) -> Tuple[Any, ...]:
"""Immutable enrichment of assessments with root note using dataclasses.replace if possible.
"""Immutable enrichment of assessments with root note using dataclasses.replace.
Returns new tuple, no mutation of input.
Returns a new tuple. Enrichment is best-effort: if an assessment does not
support replace (e.g. non-dataclass or frozen in an incompatible way), the
original item is kept without the depth note. No __dict__ reconstruction
is performed (avoids producing invalid objects for slots/frozen types).
"""
if not depth:
return assessments
@ -107,16 +110,9 @@ def enrich_assessments_with_depth(assessments: Tuple[Any, ...], depth: dict | No
try:
new_a = replace(a, explanation=(getattr(a, "explanation", "") or "") + note)
except Exception:
# create copy for annotation (avoid mutate original/frozen)
try:
if hasattr(a, '__dict__'):
new_a = type(a)(**a.__dict__)
if hasattr(new_a, 'explanation'):
new_a.explanation = (getattr(new_a, 'explanation', '') or '') + note
else:
new_a = a
except Exception:
new_a = a
# Best-effort only; do not synthesize copies that could violate
# frozen/slots invariants after CGA substrate types.
new_a = a
new_ass.append(new_a)
else:
new_ass.append(a)