feat(sprint6b-D): soft-insertion counter + message meta_json

- thread_state.soft_insertion_count: растёт при боковом ответе (soft_insertion=true
  в STATE_JSON без смены шага/слотов), сбрасывается при продвижении или handoff
- При soft_insertion_count >= 3 в системный промпт ветки добавляется SOFT_INSERTION_NUDGE
  — явная инструкция вернуть пациента к вопросу текущего шага
- state_machine.parse_branch_response читает флаг soft_insertion из STATE_JSON
- Новая колонка message.meta_json: {router_intent_code, served_intent_code, step_code, events}
  — хранит снимок маршрутизации каждой реплики ассистента
- «Песочница»: бейджи событий (sticky / soft_insertion / hard_handoff / resumed /
  routing_loop / validation_blocked) над каждым ответом ассистента

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
AR 15 M4
2026-04-25 20:24:22 +05:00
parent 3c71372ec8
commit 85c3ec0222
12 changed files with 257 additions and 13 deletions
+5
View File
@@ -39,6 +39,7 @@ async def load_snapshot(session: AsyncSession, thread_id: int) -> dict:
"current_step_code": None,
"slots": {},
"handoff_count": 0,
"soft_insertion_count": 0,
"suspended_intent": None,
"resumable_step_code": None,
"resumable_slots": {},
@@ -57,6 +58,7 @@ async def load_snapshot(session: AsyncSession, thread_id: int) -> dict:
"current_step_code": state.current_step_code,
"slots": _parse_slots(state.slots_json),
"handoff_count": state.handoff_count,
"soft_insertion_count": state.soft_insertion_count,
"suspended_intent": state.suspended_intent,
"resumable_step_code": state.resumable_step_code,
"resumable_slots": resumable_slots,
@@ -72,6 +74,7 @@ async def upsert(
slots: dict,
step_code: str | None = None,
handoff_count: int = 0,
soft_insertion_count: int = 0,
suspended_intent: str | None = None,
resumable_step_code: str | None = None,
resumable_slots: dict | None = None,
@@ -93,6 +96,7 @@ async def upsert(
current_step_code=step_code,
slots_json=slots_raw,
handoff_count=handoff_count,
soft_insertion_count=soft_insertion_count,
suspended_intent=suspended_intent,
resumable_step_code=resumable_step_code,
resumable_slots_json=resumable_raw,
@@ -105,6 +109,7 @@ async def upsert(
state.current_step_code = step_code
state.slots_json = slots_raw
state.handoff_count = handoff_count
state.soft_insertion_count = soft_insertion_count
state.suspended_intent = suspended_intent
state.resumable_step_code = resumable_step_code
state.resumable_slots_json = resumable_raw