Skip to content

Commit d094a34

Browse files
author
Mateusz
committed
Snapshot(WIP): unification-of-request-processing
1 parent aa3828d commit d094a34

99 files changed

Lines changed: 6343 additions & 3384 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.kiro/specs/unification-of-request-processing/design.md renamed to .kiro/specs/archive/unification-of-request-processing/design.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -531,9 +531,9 @@ This matrix may evolve during implementation, but the classification dimensions
531531
|----------------|-------------------|-------------------------------------------|
532532
| Boundary compatibility | `tests/integration/transport/fastapi/test_response_adapters_integration.py`, `tests/unit/test_transport_adapters.py` | canonical-path boundary regressions for unchanged streaming and non-streaming contracts |
533533
| Dedup short-circuit and completion classification | `tests/unit/core/services/test_backend_request_manager_deduplication.py`, `tests/integration/test_backend_request_manager_e2e.py` | gate-enabled regressions that prove canonical adoption preserves the current classification rules |
534-
| Empty-response and empty-stream recovery | `tests/unit/core/services/test_backend_non_streaming_response_handler.py`, integration coverage, streaming-handler coverage | explicit canonical-path recovery regressions before Phase 1 or Phase 2 promotion |
535-
| Loop detection and cancel callback | `tests/unit/core/services/test_backend_streaming_response_handler.py`, `tests/integration/test_end_to_end_loop_detection.py` | canonical-path regressions for cancellation chunk emission and callback invocation |
536-
| Tool-call retry coordination | `tests/unit/core/services/test_backend_non_streaming_response_handler.py`, `tests/unit/core/services/test_tool_call_retry_coordinator.py` | adapter or canonical-path regressions proving retry limits and mode-correct behavior remain intact |
534+
| Empty-response and empty-stream recovery | `tests/unit/core/services/test_canonical_post_backend_response_pipeline.py`, `tests/unit/core/services/test_post_backend_single_stream_runtime.py`, `tests/unit/core/services/test_backend_streaming_failopen_terminal.py`, `tests/unit/core/services/test_backend_streaming_middleware_and_recovery.py`, `tests/integration/test_backend_request_manager_e2e.py` | explicit canonical-path recovery regressions before Phase 1 or Phase 2 promotion |
535+
| Loop detection and cancel callback | `tests/unit/core/services/test_backend_streaming_loop_quality_metadata.py`, `tests/unit/core/services/test_backend_streaming_middleware_and_recovery.py`, `tests/integration/test_end_to_end_loop_detection.py` | canonical-path regressions for cancellation chunk emission and callback invocation |
536+
| Tool-call retry coordination | `tests/unit/core/services/test_backend_streaming_middleware_and_recovery.py`, `tests/unit/core/services/test_tool_call_retry_coordinator.py`, `tests/integration/test_backend_request_manager_e2e.py` | adapter or canonical-path regressions proving retry limits and mode-correct behavior remain intact |
537537
| Quality verifier semantics | `tests/unit/core/services/test_quality_verifier_stream_verifier.py`, `tests/unit/core/services/test_response_processor_quality_verifier.py`, `tests/integration/test_quality_verifier_integration.py` | canonical-path validation for skip-verification, recall, and streaming decision flow |
538538
| Gate defaults and diagnostics | none dedicated yet | tests for config defaults, path-selection metadata, and stage diagnostics |
539539

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Canonical feature migration status and explicit exceptions
2+
3+
This document records Wave 4.2 migration progress and the bounded exceptions
4+
that remain mode-sensitive during the transition.
5+
6+
## Migrated priority features
7+
8+
- `ResponseLoggingFeature`
9+
- Uses `FeatureLifecycleContext` via compatibility bridge.
10+
- Reads terminal state, finish reason, request id, backend, and model metadata.
11+
- `ContentFilterFeature`
12+
- Uses `FeatureLifecycleContext` via compatibility bridge.
13+
- Keeps behavior identical while adding typed lifecycle-aware diagnostics.
14+
15+
## Explicit bounded exceptions (kept mode-sensitive for now)
16+
17+
- `EmptyResponseFeature`
18+
- Depends on stream terminal detection and retry budgets.
19+
- Remains in existing safeguard path until connector migration fully stabilizes.
20+
- `ToolCallReactor` / swallowed-tool handling
21+
- Requires terminal and retry-state coordination with request-level control flow.
22+
- Loop/cancellation guards in streaming handler
23+
- Intentionally remain in the streaming safeguard layer.
24+
25+
## Removal policy
26+
27+
- Duplicated feature logic is removed only when canonical behavior is equivalence-tested.
28+
- Exception features stay isolated in current layers and are covered by regression tests.

.kiro/specs/unification-of-request-processing/gap-analysis.md renamed to .kiro/specs/archive/unification-of-request-processing/gap-analysis.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@
3333

3434
**Representative existing verification surface**
3535
- `tests/unit/core/services/test_backend_request_manager_deduplication.py`
36-
- `tests/unit/core/services/test_backend_non_streaming_response_handler.py`
37-
- `tests/unit/core/services/test_backend_streaming_response_handler.py`
36+
- `tests/unit/core/services/test_canonical_post_backend_response_pipeline.py`
37+
- `tests/unit/core/services/test_post_backend_single_stream_runtime.py`
38+
- `tests/unit/core/services/test_backend_streaming_failopen_terminal.py`
39+
- `tests/unit/core/services/test_backend_streaming_middleware_and_recovery.py`
3840
- `tests/unit/core/services/test_quality_verifier_stream_verifier.py`
3941
- `tests/unit/core/services/test_response_processor_quality_verifier.py`
4042
- `tests/integration/test_backend_request_manager_e2e.py`
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Implementation Orchestration Contract
2+
3+
This file defines the lead/specialist split used for `unification-of-request-processing` execution waves.
4+
5+
## Agent Roles
6+
7+
- **Lead orchestrator**
8+
- Owns wave admission/exit criteria.
9+
- Decides sequencing and rollback actions.
10+
- Approves `tasks.md` checkbox updates after evidence is complete.
11+
- **Traceability specialist**
12+
- Maps each task to requirement IDs and design invariants.
13+
- Flags out-of-scope edits before coding starts.
14+
- **RED specialist**
15+
- Adds failing tests first for each wave/task.
16+
- Confirms failures represent missing behavior rather than test defects.
17+
- **GREEN specialist**
18+
- Implements minimum code required to pass the new tests.
19+
- Keeps migration gates default-off unless a task explicitly requires stage enablement.
20+
- **Refactor specialist**
21+
- Improves structure after green without changing behavior.
22+
- **Verification specialist**
23+
- Runs per-file QA (`ruff`, `black`, `mypy`), targeted tests, then broader suites.
24+
- Provides pass/fail evidence for wave closure.
25+
26+
## Handoff Checklist (Per Task)
27+
28+
1. Traceability map recorded (requirements + invariants).
29+
2. RED test added and failing.
30+
3. GREEN implementation merged.
31+
4. Refactor completed (if needed).
32+
5. QA commands and tests are green.
33+
6. Lead updates `tasks.md` checkbox.
34+
35+
## Failure Handling Contract
36+
37+
- Freeze next-wave work on broad regression.
38+
- Keep migration gates default-off.
39+
- Reproduce with minimal targeted tests.
40+
- Resume only after the current wave gate turns green again.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Migration retirement notes (request-processing unification)
2+
3+
## Retired from production startup
4+
5+
- **Feature parity registry initialization** no longer runs from `post_build_hooks`. The global parity registry and `initialize_feature_parity_registry` remain as an **optional** helper for tests, audits, and local diagnostics (see `post_build_actions.initialize_feature_parity_registry` docstring).
6+
- **CI parity enforcement** no longer assumes registry population via `get_or_build_service_provider`. Quality tests seed the registry explicitly when they need `verify_parity()`, and assert typed `FeatureLifecycleContext` coverage where appropriate.
7+
8+
## Runtime shape (post-retirement)
9+
10+
- `BackendRequestManager` always uses the canonical post-backend pipeline (`PostBackendResponseCoordinator` + `EnvelopeCompatibilityAdapter`) for both requested modes.
11+
- `enable_core_canonical_path` is retained for compatibility/validation semantics but no longer switches execution to a legacy split-handler branch.
12+
- `CorePathDecision.retire_legacy_dual_path` remains a configuration snapshot in diagnostics when `emit_path_selection_metadata` is enabled.
13+
14+
## Compatibility shims retained
15+
16+
- `initialize_feature_parity_registry` and `src.core.interfaces.feature_parity` registry APIs unchanged for callers that opt in explicitly.
17+
- **Current runtime**: `BackendRequestManager` always selects the canonical post-backend path; transport adaptation to streaming/non-streaming happens only at the boundary via `EnvelopeCompatibilityAdapter`.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Phase 0 Audit - Manager Cut Line and Feature Classification
2+
3+
This document records the Phase 0 audit required before canonical convergence work.
4+
5+
## 1.1 Manager/Handler Cut-Line Characterization
6+
7+
## Scope Baseline
8+
9+
- The canonicalization cut line starts in `BackendRequestManager.process_backend_request()` **after** `IBackendProcessor.process_backend_request()` returns.
10+
- Dedup short-circuit and preflight retry-limit checks remain above the cut line.
11+
- Transport adaptation remains below the cut line (`response_adapters` layer).
12+
13+
## Current Responsibility Inventory
14+
15+
| Area | Current owner | Notes for migration |
16+
|---|---|---|
17+
| Dedup registration + duplicate short-circuit | `BackendRequestManager` | Must remain pre-backend and pre-gate. |
18+
| Streaming completion classification (disconnect/terminal/error) | `BackendRequestManager` stream wrapper | Must remain preserved until canonical equivalent is proven. |
19+
| Non-streaming post-processing and retry orchestration | `BackendNonStreamingResponseHandler` | Candidate for coordinator convergence. |
20+
| Streaming post-processing, loop controls, verifier buffering | `BackendStreamingResponseHandler` | Candidate for coordinator convergence with explicit safeguards. |
21+
| Tool-call retry coordination | `ToolCallRetryCoordinator` + handlers | Mode-sensitive cases must remain explicit until unified safely. |
22+
| Empty-response/empty-stream recovery | `EmptyResponseFeature` + handlers | Cannot be treated as generic chunk logic during migration. |
23+
| Quality-verifier control flow | request processor + streaming verifier + handlers | Keep parity-sensitive behavior pinned with tests. |
24+
25+
## Phase 1 Boundary Decision
26+
27+
- **In scope for first convergence:** post-backend-response handling branch currently split by requested mode.
28+
- **Out of scope for Phase 1:** backend processor contract replacement, connector stream-first bridge, transport response object changes.
29+
- **Fallback policy:** legacy split handlers stay available for rollback while gate is default-off.
30+
31+
## Explicit Migration Exceptions (Phase 0)
32+
33+
- Tool-call retry and empty-response recovery remain mode-sensitive until canonical feature/context migration.
34+
- Completion-state classification remains in existing stream wrapper until tested canonical equivalent exists.
35+
36+
## 1.2 Response-Processing Feature Audit and Migration Classification
37+
38+
## Classification Rules
39+
40+
- `chunk-safe`: can run on canonical chunk stream with no end-of-stream assumptions.
41+
- `terminal-sensitive`: depends on terminal chunk markers or finish reason.
42+
- `full-response-sensitive`: requires accumulated response materialization.
43+
- `explicit-exception`: temporary bounded mode-specific behavior during migration.
44+
45+
## Feature Inventory and Strategy
46+
47+
| Feature / behavior | Classification | Canonical strategy |
48+
|---|---|---|
49+
| Response logging / content filtering | chunk-safe | Bridge through canonical stream-first feature pipeline. |
50+
| Empty-response recovery | terminal-sensitive | Keep explicit safeguard path until canonical coordinator feature parity is proven. |
51+
| Tool-call retry coordination | terminal-sensitive | Keep explicit collaborator; migrate only with dedicated adapter coverage. |
52+
| Loop detection / cancellation chunk emission | terminal-sensitive | Preserve dedicated streaming behavior; migrate with explicit tests. |
53+
| Structured output enforcement | full-response-sensitive | Use canonical adapter path for non-streaming accumulation context. |
54+
| Quality-verifier stream verification and recall behavior | terminal-sensitive | Keep dedicated verifier collaborator during early migration. |
55+
| Usage/metadata propagation | full-response-sensitive | Preserve envelope metadata via canonical handle before adapter conversion. |
56+
57+
## Bridge Eligibility Summary
58+
59+
- **Bridge-safe now:** response logging, content filtering (chunk-safe).
60+
- **Dedicated canonical adapter required:** structured output enforcement.
61+
- **Explicit temporary exception required:** empty-response recovery, loop detection, tool-call retry, quality-verifier flow.
62+
63+
## Phase 0 Exit Preconditions
64+
65+
- Cut line is fixed at manager post-backend-response branch.
66+
- Feature classifications above are treated as migration constraints for tasks `4.1` and `4.2`.
67+
- New gate defaults remain off; diagnostics expose active path and stage (`migration_stage`, `canonical_path_used`, `feature_canonical_used`, `connector_stream_first_used`).
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Provider capability matrix (request-processing unification)
2+
3+
This artifact supports Wave **6.1** (connector stream-first cohort planning). It describes how each **backend connector** relates to the **canonical internal handle** and the **stream-first migration framework** (`request_processing_unification.connector_stream_first`), not full connector audits.
4+
5+
## Legend
6+
7+
| Capability | Meaning |
8+
|------------|---------|
9+
| **Native HTTP streaming** | Connector can call upstream with streamed HTTP and expose `StreamingResponseEnvelope`. |
10+
| **Non-stream HTTP** | Connector supports blocking JSON (`ResponseEnvelope`) for `stream=false`. |
11+
| **Stream-first eligible** | Suitable for cohort opt-in under canonical path: manager may set `stream=true` upstream for a non-streaming client when the backend key is listed in `connector_stream_first`; unlisted backends are not implicitly forced. |
12+
| **Framework status** | Whether stream-first is implemented only at the **manager/gate** boundary (current incremental rollout) vs connector-native stream-first return. |
13+
14+
## Matrix
15+
16+
| Backend key (config / routing) | Native HTTP streaming | Non-stream HTTP | Stream-first eligible (cohort) | Framework notes |
17+
|-------------------------------|----------------------|-----------------|-------------------------------|-------------------|
18+
| `openai` | Yes | Yes | Cohort-gated | Boundary framework: forced upstream `stream` only when this backend key is explicitly opted into the cohort (canonical path is always selected). |
19+
| `anthropic` | Yes | Yes | Cohort-gated | Same boundary contract; provider-specific parsing stays in connector/handler layers. |
20+
| `gemini` | Yes | Yes | Cohort-gated | Same. |
21+
| `azure_openai` | Yes | Yes | Cohort-gated | Same. |
22+
| `groq` | Yes | Yes | Cohort-gated | Same. |
23+
| `cohere` | Yes | Yes | Cohort-gated | Same. |
24+
| `mistral` | Yes | Yes | Cohort-gated | Same. |
25+
| `deepseek` | Yes | Yes | Cohort-gated | Same. |
26+
| `xai` | Yes | Yes | Cohort-gated | Same. |
27+
| `ollama` | Yes | Yes | Cohort-gated | Same. |
28+
| `vertex` / `google` | Yes | Yes | Cohort-gated | Same. |
29+
| `bedrock` | Yes | Yes | Cohort-gated | Same. |
30+
| `other / custom` | Varies | Varies | **Off by default** | Opt in per routed `backend` string only when validated for the deployment; otherwise no implicit stream forcing occurs. |
31+
32+
## Connector entry contract (target)
33+
34+
- Upstream transport may be streaming or blocking; the **manager** selects canonical post-processing using explicit `PostBackendProcessingMode`.
35+
- Cohort opt-in is **config-only** and **default off**; absent an explicit backend key entry, stream-first stays disabled. The manager always uses the canonical post-backend path.
36+
- Provider-specific metadata remains on `StreamingResponseEnvelope` / handler metadata until fully absorbed by canonical handles (future waves).
37+
38+
## Maintenance
39+
40+
Update this matrix when a connector is **validated** for stream-first cohort promotion or when native capabilities change.

.kiro/specs/unification-of-request-processing/requirements.md renamed to .kiro/specs/archive/unification-of-request-processing/requirements.md

File renamed without changes.

.kiro/specs/unification-of-request-processing/research.md renamed to .kiro/specs/archive/unification-of-request-processing/research.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@
4343
### Handler asymmetry is the main migration challenge
4444
- **Context**: Determine whether the two handlers can be trivially merged into one stream-first coordinator.
4545
- **Sources Consulted**:
46-
- `src/core/services/backend_non_streaming_response_handler.py`
46+
- `src/core/services/post_backend_response_coordinator.py`
4747
- `src/core/services/backend_request_manager/streaming_response_handler.py`
48-
- `tests/unit/core/services/test_backend_non_streaming_response_handler.py`
49-
- `tests/unit/core/services/test_backend_streaming_response_handler.py`
48+
- `tests/unit/core/services/test_canonical_post_backend_response_pipeline.py`
49+
- `tests/unit/core/services/test_backend_streaming_middleware_and_recovery.py`
5050
- **Findings**:
5151
- The non-streaming handler owns empty-response retry, structured-output enforcement, metadata filtering, and non-stream tool-call retry coordination.
5252
- The streaming handler owns middleware wrapping, quality-verifier buffering, loop detection, empty-stream recovery, tool-call retry coordination, status extraction, and stream lifecycle behavior.
@@ -121,8 +121,9 @@
121121
- **Context**: Determine whether the codebase already has enough behavioral evidence to support characterization-first migration.
122122
- **Sources Consulted**:
123123
- `tests/unit/core/services/test_backend_request_manager_deduplication.py`
124-
- `tests/unit/core/services/test_backend_non_streaming_response_handler.py`
125-
- `tests/unit/core/services/test_backend_streaming_response_handler.py`
124+
- `tests/unit/core/services/test_canonical_post_backend_response_pipeline.py`
125+
- `tests/unit/core/services/test_backend_streaming_failopen_terminal.py`
126+
- `tests/unit/core/services/test_backend_streaming_middleware_and_recovery.py`
126127
- `tests/unit/core/services/test_quality_verifier_stream_verifier.py`
127128
- `tests/unit/core/services/test_response_processor_quality_verifier.py`
128129
- `tests/integration/test_backend_request_manager_e2e.py`
@@ -181,13 +182,14 @@
181182

182183
## References
183184
- `src/core/services/backend_request_manager_service.py` — current split branch and dedup completion wrapper
184-
- `src/core/services/backend_non_streaming_response_handler.py`non-stream safeguard ownership
185+
- `src/core/services/post_backend_response_coordinator.py`canonical post-backend safeguard orchestration
185186
- `src/core/services/backend_request_manager/streaming_response_handler.py` — streaming safeguard ownership
186187
- `src/core/services/response_pipeline.py` — existing internal stream-first unification precedent
187188
- `src/core/services/streaming/non_streaming_adapter.py` — non-stream-as-stream adaptation precedent
188189
- `src/core/transport/fastapi/response_adapters.py` — transport boundary behavior and disconnect cleanup
189190
- `src/connectors/gemini_base/orchestrator.py` — proven stream-first accumulation example in connectors
190191
- `tests/unit/core/services/test_backend_request_manager_deduplication.py` — streaming dedup and completion tracking invariants
191-
- `tests/unit/core/services/test_backend_non_streaming_response_handler.py` — non-stream retry and validation invariants
192-
- `tests/unit/core/services/test_backend_streaming_response_handler.py` — loop detection, cancel callback, and streaming safeguard invariants
192+
- `tests/unit/core/services/test_canonical_post_backend_response_pipeline.py` — canonical post-backend pipeline invariants
193+
- `tests/unit/core/services/test_backend_streaming_failopen_terminal.py` — streaming fail-open and terminal error semantics
194+
- `tests/unit/core/services/test_backend_streaming_middleware_and_recovery.py` — streaming safeguards, loop metadata, and recovery paths
193195
- `tests/integration/transport/fastapi/test_response_adapters_integration.py` — boundary compatibility coverage

.kiro/specs/unification-of-request-processing/spec.json renamed to .kiro/specs/archive/unification-of-request-processing/spec.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"feature_name": "unification-of-request-processing",
33
"created_at": "2026-04-10T12:00:00Z",
4-
"updated_at": "2026-04-10T18:05:00Z",
4+
"updated_at": "2026-04-12T19:15:00Z",
55
"language": "en",
6-
"phase": "tasks-approved",
6+
"phase": "implementation-complete",
77
"approvals": {
88
"requirements": {
99
"generated": true,

0 commit comments

Comments
 (0)