ГЛОБАЛЬНЫЙ РЕФАКТОРИНГ АРХИТЕКТУРЫ - Рефакторинг этапов 2.2 - Усилена оркестрацию в deep/address гейте и follow-up binding в assistantService.ts. Починен кейс UTF-8 follow-up refinement (теперь followup_state_usage.applied=true в нужном сценарии). Убраны регрессии по assistantLivingRouter и stage3 lifecycle probe. Корректное поведение для llm canonical candidate (чтобы не уезжало в clarification_required там, где должен быть address factual).

This commit is contained in:
2026-04-11 14:56:14 +03:00
parent 19f5f19d8e
commit b5bd4fd737
46 changed files with 2471 additions and 370 deletions
+252 -2
View File
@@ -1,6 +1,6 @@
# 1CLLMARCH Fact Check And Stabilization Plan
Updated at: 2026-04-10
Updated at: 2026-04-11
Source baseline: `docs/TECH/1CLLMARCH.md`
## 1. Purpose
@@ -2096,7 +2096,236 @@ Validation:
- `assistantDeepTurnAnalysisRuntimeAdapter.test.ts`
- `assistantDeepTurnAnalysisAttemptRuntimeAdapter.test.ts`
Status: **In progress (Phase 2.1 + 2.2 + 2.3 + 2.4 + 2.5 + 2.6 + 2.7 + 2.8 + 2.9 + 2.10 + 2.11 + 2.12 + 2.13 + 2.14 + 2.15 + 2.16 + 2.17 + 2.18 + 2.19 + 2.20 + 2.21 + 2.22 + 2.23 + 2.24 + 2.25 + 2.26 + 2.27 + 2.28 + 2.29 + 2.30 + 2.31 + 2.32 + 2.33 + 2.34 + 2.35 + 2.36 + 2.37 + 2.38 + 2.39 + 2.40 + 2.41 + 2.42 + 2.43 + 2.44 + 2.45 + 2.46 + 2.47 + 2.48 + 2.49 + 2.50 + 2.51 + 2.52 + 2.53 + 2.54 + 2.55 + 2.56 + 2.57 + 2.58 + 2.59 + 2.60 + 2.61 + 2.62 + 2.63 + 2.64 + 2.65 + 2.66 + 2.67 + 2.68 + 2.69 + 2.70 + 2.71 + 2.72 + 2.73 + 2.74 + 2.75 + 2.76 + 2.77 + 2.78 + 2.79 + 2.80 + 2.81 + 2.82 + 2.83 + 2.84 + 2.85 + 2.86 + 2.87 + 2.88 + 2.89 + 2.90 + 2.91 + 2.92 + 2.93 + 2.94 + 2.95 + 2.96 + 2.97 + 2.98 + 2.99 + 2.100 + 2.101 + 2.102 + 2.103 + 2.104 + 2.105 + 2.106 + 2.107 + 2.108 + 2.109 + 2.110 + 2.111 + 2.112 completed)**
Implemented in current pass (Phase 2.113 + 2.114 + 2.115 + 2.116):
1. Tightened temporal/polarity guard typing in deep plan runtime:
- `assistantDeepTurnPlanRuntimeAdapter.ts`
- `temporalGuard` now typed to `TemporalGuardAudit`;
- `domainPolarityGuardInitial` now typed to `DomainPolarityGuardAudit`.
2. Preserved behavior:
- no runtime logic changes; type alignment only.
Validation:
1. `npm run build` passed.
2. Targeted deep plan pack passed:
- `assistantDeepTurnPlanRuntimeAdapter.test.ts`
- `assistantDeepTurnAnalysisAttemptRuntimeAdapter.test.ts`
Implemented in current pass (Phase 2.117 + 2.118 + 2.119 + 2.120):
1. Tightened audit typing along deep response/packaging chain:
- `assistantDebugPayloadAssembler.ts`
- `assistantMessageLogAssembler.ts`
- `assistantDeepTurnPackaging.ts`
- `assistantDeepTurnPackagingRuntimeAdapter.ts`
- `assistantDeepTurnInputBuilder.ts`
- `assistantDeepTurnResponseRuntimeAdapter.ts`
- audit contracts now use concrete types:
- `TemporalGuardAudit`, `DomainPolarityGuardAudit`, `ClaimBoundAnchorAudit`,
`TargetedEvidenceAcquisitionAudit`, `EvidenceAdmissibilityAudit`,
`GroundedAnswerEligibilityAudit`,
`RbpLiveRouteAuditDebug | null`, `FaLiveRouteAuditDebug | null`.
2. Preserved behavior:
- no runtime logic changes; type alignment only.
Validation:
1. `npm run build` passed.
2. Targeted deep response/packaging pack passed:
- `assistantDeepTurnResponseRuntimeAdapter.test.ts`
- `assistantDeepTurnResponseAttemptRuntimeAdapter.test.ts`
- `assistantDeepTurnPackagingRuntimeAdapter.test.ts`
- `assistantDeepTurnPackaging.test.ts`
Implemented in current pass (Phase 2.121 + 2.122 + 2.123 + 2.124):
1. Tightened retrieval call/raw types across deep response chain:
- `assistantDeepTurnRetrievalRuntimeAdapter.ts`
- `assistantDeepTurnResponseRuntimeAdapter.ts`
- `assistantDeepTurnPackaging.ts`
- `assistantDeepTurnPackagingRuntimeAdapter.ts`
- `assistantDeepTurnInputBuilder.ts`
- `assistantMessageLogAssembler.ts`
- `assistantEvidenceBundleAssembler.ts`
- `assistantOrchestrationContracts.ts`
- introduced `AssistantRetrievalRawResult` and typed `AssistantRetrievalRawResultRecord`;
- retrieval calls now use `AssistantRetrievalCallRecord[]` end-to-end.
2. Preserved behavior:
- no runtime logic changes; only stronger typing and safe raw normalization.
Validation:
1. `npm run build` passed.
2. Targeted deep retrieval/response pack passed:
- `assistantDeepTurnResponseRuntimeAdapter.test.ts`
- `assistantDeepTurnRetrievalRuntimeAdapter.test.ts`
- `assistantDeepTurnPackaging.test.ts`
Implemented in current pass (Phase 2.125 + 2.126 + 2.127 + 2.128):
1. Tightened deep turn execution state + fallback metadata typing:
- `assistantDeepTurnPrePackagingContext.ts`
- `assistantDeepTurnPackaging.ts`
- `assistantDeepTurnPackagingRuntimeAdapter.ts`
- `assistantDeepTurnInputBuilder.ts`
- `assistantDeepTurnResponseRuntimeAdapter.ts`
- `assistantDeepTurnNormalizationRuntimeAdapter.ts`
- added `AssistantExecutionStateRecord` + `AssistantAddressRuntimeMetaForDeep`;
- `fallback_type` now `AssistantFallbackType`;
- `problem_answer_mode` now `AssistantProblemAnswerMode`;
- `problem_unit_ids_used` now `string[]`;
- `investigationStateSnapshot` now `InvestigationStateWithProblemUnits | null`.
2. Aligned debug/log payload typing with contracts:
- `assistantDebugPayloadAssembler.ts`
- `assistantMessageLogAssembler.ts`
- `assistantOrchestrationContractsV1` and `outcomeClassV1` now typed;
- `answerStructureV11` now typed.
3. Preserved behavior:
- no runtime logic changes; type alignment only.
Validation:
1. Not run in this pass (type-only changes).
Implemented in current pass (Phase 2.129 + 2.130 + 2.131 + 2.132):
1. Typified debug route structures end-to-end:
- `assistantQueryPlanning.ts`
- `assistantDeepTurnPrePackagingContext.ts`
- `assistantDeepTurnPackaging.ts`
- `assistantDeepTurnPackagingRuntimeAdapter.ts`
- `assistantDeepTurnInputBuilder.ts`
- `assistantDeepTurnResponseRuntimeAdapter.ts`
- `assistantDebugPayloadAssembler.ts`
- `assistantMessageLogAssembler.ts`
- introduced `AssistantDebugRouteRecord` union (legacy vs deterministic debug routes);
- `routes` now typed in `AssistantDebugPayload`.
2. Preserved behavior:
- no runtime logic changes; type alignment only.
Validation:
1. Not run in this pass (type-only changes).
Implemented in current pass (Phase 2.133):
1. Tightened deep retrieval runtime input:
- `assistantDeepTurnRetrievalRuntimeAdapter.ts`
- `executeRouteRuntime` now returns `AssistantRetrievalRawResult` (explicit union).
2. Preserved behavior:
- no runtime logic changes; type alignment only.
Validation:
1. Not run in this pass (type-only changes).
Implemented in current pass (Phase 2.134 + 2.135):
1. Typed live-route plan audit contract:
- `assistantDeepTurnPlanRuntimeAdapter.ts`
- introduced `AssistantLiveRoutePlanAudit` for plan enforcement audits.
2. Typed deep analysis log payload plumbing:
- `assistantMessageLogAssembler.ts`
- `assistantDeepTurnPackaging.ts`
- `assistantDeepTurnPackagingRuntimeAdapter.ts`
- `assistantDeepTurnFinalizeRuntimeAdapter.ts`
- introduced `DeepAnalysisLogDetails` alias and used it end-to-end.
3. Preserved behavior:
- no runtime logic changes; type alignment only.
Validation:
1. Not run in this pass (type-only changes).
Implemented in current pass (Phase 2.136):
1. Tightened business-scope resolution contract shape:
- `assistantDeepTurnContextRuntimeAdapter.ts`
- removed index-signature `unknown` on business scope resolution;
- `resolveBusinessScopeFromLiveContext` now uses `AssistantBusinessScopeResolution` explicitly.
2. Preserved behavior:
- no runtime logic changes; type alignment only.
Validation:
1. Not run in this pass (type-only changes).
Implemented in current pass (Phase 2.137 + 2.138):
1. Tightened company anchor normalization input types:
- `assistantDeepTurnCompositionRuntimeAdapter.ts`
- `toStringArray` now accepts `string[] | null | undefined`;
- company anchor normalization now consumes `Partial<CompanyAnchorSet>`.
2. Narrowed response runtime normalizers:
- `assistantDeepTurnResponseRuntimeAdapter.ts`
- runtime analysis context and business scope normalizers now take typed inputs.
3. Preserved behavior:
- no runtime logic changes; type alignment only.
Validation:
1. Not run in this pass (type-only changes).
Implemented in current pass (Phase 2.139 + 2.140):
1. Tightened analysis attempt builder normalizers:
- `assistantDeepTurnAnalysisAttemptInputBuilder.ts`
- removed `unknown` from anchor/period helpers; now `Partial<CompanyAnchorSet>` + typed primary period.
2. Narrowed response runtime normalization helpers:
- `assistantDeepTurnResponseRuntimeAdapter.ts`
- execution plan normalization now consumes typed `AssistantExecutionPlanItem[]`;
- helper signatures no longer accept `unknown` where input is already typed.
3. Preserved behavior:
- no runtime logic changes; type alignment only.
Validation:
1. Not run in this pass (type-only changes).
Implemented in current pass (Phase 2.141 + 2.142 + 2.143 + 2.144):
1. Tightened attempt input defaults:
- `assistantDeepTurnAttemptInputBuilder.ts`
- response attempt default type is now `AssistantMessageResponsePayload`.
2. Tightened retrieval raw result typing:
- `assistantDeepTurnRetrievalRuntimeAdapter.ts`
- introduced `AssistantRetrievalRawResultLike` + list item union.
3. Tightened deep packaging normalization:
- `assistantDeepTurnPackaging.ts`
- normalized fragments extracted without `Record<string, unknown>` cast.
4. Simplified response runtime normalizers:
- `assistantDeepTurnResponseRuntimeAdapter.ts`
- removed `toRecordObject` casts and normalized from typed inputs.
5. Preserved behavior:
- no runtime logic changes; type alignment only.
Validation:
1. Not run in this pass (type-only changes).
Implemented in current pass (Phase 2.145 + 2.146):
1. Tightened retrieval raw result field shapes:
- `assistantDeepTurnRetrievalRuntimeAdapter.ts`
- introduced `AssistantRetrievalFieldValue` / `AssistantRetrievalRecord`;
- removed `unknown` from raw result record types.
2. Tightened normalized fragment extraction:
- `assistantDeepTurnPackaging.ts`
- normalized fragments now typed to `NormalizedQueryV2*` fragments.
3. Preserved behavior:
- no runtime logic changes; type alignment only.
Validation:
1. Not run in this pass (type-only changes).
Status: **Completed (Phase 2.12.146)**
### Stage 2 Completion Report (Summary)
1. Orchestration monolith decomposed into explicit modules:
- QueryFrame, ExecutionPlan, EvidenceBundle, Coverage/Grounding, Answer package, Debug payload, Log details.
2. Deep lane now uses stable contracts end-to-end:
- `assistant_orchestration_contracts_v1`, `assistant_evidence_bundle_v1`, `assistant_coverage_contract_v1`.
3. Audit & trace coverage standardized:
- temporal/polarity/claim/evidence guards, live-route audits, followup usage, outcome class.
4. Type hardening complete across deep chain:
- normalized payloads, execution plan, retrieval calls/raw, debug routes, runtime meta, investigation state.
5. Behavior preserved throughout refactor (no route/answer regressions by design).
### Stage 2 Closure Audit (2026-04-11)
1. Fixed runtime-critical context loss in `assistantTurnRuntimeDepsAdapter.ts`:
- unbound session store/logger/normalizer methods caused `TypeError` at `assistantSessionStore.ensureSession(...)` and mass `500` responses in API tests.
2. Added safe method wrappers in deps adapter:
- `ensureSession`, `appendItem`, `getSession`, `persistSession`, `setInvestigationState`, `normalize`.
3. Added regression guard:
- `assistantTurnRuntimeDepsAdapter.test.ts` now includes a stateful instance-context test to prevent `this` loss regressions.
4. Validation gates (fact):
- `npm run build` passed.
- Combined Stage 2 regression validation passed: `37` files / `95` tests (deep-turn adapters/builders/packaging, orchestration contracts/runtime, MCP bridge, followup continuity, wave10 corrective regression).
5. Scope note:
- Full backend suite still has red tests in Stage 3/4 probes and long-running acceptance packs; this is tracked under Stage 3 backlog and is not a Stage 2 blocker.
### Stage 2 Remaining Risks (Known)
1. Final answer quality still template-heavy and brittle.
2. Lexical routing pressure remains high (dictionary overfitting risk).
3. Deterministic guards still compensate for weak semantic parsing.
## Stage 3 (P2): Hybrid Semantic Layer (LLM + Deterministic Guards)
@@ -2105,6 +2334,27 @@ Goal:
2. Keep deterministic guardrails as verifier, not primary “brain”.
3. Reduce dictionary overfitting and false route drifts.
Plan (Stage 3):
1. **Schema-first semantic extraction**
- Strict JSON schema for: entities, time scope, intent, ambiguity, success criteria.
- Hard validation + retry/repair loop.
2. **LLM decomposition with guardrails**
- Decomposition produces executable plan candidates.
- Deterministic guards validate: domain polarity, temporal window, claim-bound anchors.
3. **Evidence-first reasoning**
- LLM only summarizes from evidence bundle, never invents facts.
4. **Context binding**
- Carryover only via typed followup state, not free-text memory.
5. **Quality gates**
- Coverage critic threshold before final answer.
- Reason-code taxonomy normalized.
Acceptance (Stage 3):
1. LLM outputs strictly validated schema for extraction/decomposition (no free-form).
2. Deterministic guards can block or downgrade answers when evidence insufficient.
3. False route drifts and generic responses reduced in regression packs.
4. Manual markup shows increase in “correct/grounded” labels.
Status: Planned
## Stage 4 (P2): Human-Centric Answer Layer