# Phase 165.4-05 Summary

Status: implemented in working tree

## Goal

Open `165.4 / 999.77` by detecting repeated theorem-facing retry loops and
injecting a bounded strategy-change intervention before the same approach is
repeated again.

The slice should make retry loops visible through the runtime bundle and carry
that state into `loop_state` so repeated proof/derivation stalls become durable
protocol state instead of implicit frustration.

## What Landed

- new loop-detection module:
  - `knowledge_hub/loop_detection_support.py`
- loop detection now reads topic-local theory metrics from:
  - `runtime/topics/<topic_slug>/theory_operations.jsonl`
- repeated theorem-facing retry evidence is grouped by:
  - candidate / artifact id
  - source operation kind
  - retry count from derived `derivation_retry` events
- current intervention threshold:
  - `3` repeated attempts on the same theorem-facing approach
- new runtime artifact:
  - `runtime/topics/<topic_slug>/loop_detection.json`
  - `runtime/topics/<topic_slug>/loop_detection.md`
- runtime bundle now exposes top-level `loop_detection`
- `runtime_protocol.generated.md` now renders a dedicated `Loop detection`
  section
- when loop detection is active, `loop_detection.md` is appended to
  `must_read_now`
- `topic_loop_support.py` now syncs the final `loop_detection` payload back into
  `loop_state.json` and `loop_history.jsonl`
- suggestion kinds currently include:
  - `source_recovery`
  - `prerequisite_closure`
  - `change_strategy`

## Verification

- `python -m pytest research/knowledge-hub/tests/test_runtime_profiles_and_projections.py -q`
- `python -m pytest research/knowledge-hub/tests/test_aitp_service.py -q`
- `python -m pytest research/knowledge-hub/tests/test_maintainability_budgets.py -q`
- `python -m pytest research/knowledge-hub/tests -q`

## Outcome

`165.4` now has an intervention slice on top of the earlier metrics work:

- repeated theorem-facing retries are promoted into explicit runtime state
- the operator/agent gets a concrete strategy-change suggestion instead of
  silently reusing the same blocked route
- loop evidence now survives through both the runtime bundle and the persisted
  loop-state ledger

## Notes

- maintainability budget for `knowledge_hub/runtime_bundle_support.py` was
  adjusted from `2300` to `2360` lines after adding the new loop-detection
  governance surface; rationale was updated in
  `research/knowledge-hub/maintainability_budgets.json`

## Remaining Open Work Inside 165.4

- `999.78` manifest-as-truth-source
