Add authenticated upload, review, retry and knowledge-selection HTTP flows with bounded JSON processing and frozen OCR policy. Preserve Gemini/OpenAI provider selection and fenced lifecycle semantics; retain FAQ preambles and uncertain vision candidates, and expose opt-in uncalibrated voice transport diagnostics. Include frontend integration examples, aligned contracts and deterministic regressions. Validation: 1767 provider-free tests passed; all 404 PostgreSQL scenarios have passing evidence across the documented runs.
12 KiB
Ingestion and voice admission repair — 2026-10-09
This scoped implementation supersedes the relevant ingestion/admission blockers in the Phase 4 operational report. It does not certify real provider quality, browser audio or public HTTPS/WSS, and does not complete Phase 4. No paid calls were made during this repair.
Observable behavior
Initial unstyled FAQ titles and introductory paragraphs are document-wide context. Every included pair retains that context, its text and original locators, including pairs under later formal headings. Explicit heading ancestry and exclusive pair context remain; detached prose after pairs and unresolved relationships still fail. Factual authority approval is independent of extraction and remains mandatory. The original extraction is never shortened or rewritten to make ingestion pass.
Gemini/OpenRouter recognition complete=false or warnings preserve nonempty legible blocks. Global diagnostics and an explicit incomplete-recognition marker are retained as block metadata, never injected into source text. These force the existing exact extraction review even if the job's frozen OCR supervisor policy is false. Pending review publishes no chunks. Approval/rejection uses existing D06/D07, source/profile/ evidence digests, backend reviewer identity, checks and deduplication. Approved retry resumes the same job/candidate without repeating vision. Human completeness approval must be genuine: missing content is a reason to reject, not an invitation to guess.
Malformed/empty responses, native truncation/blocking, model/provenance/relationship violations, unreadable source text and resource limits remain fatal. OpenRouter now also rejects multiple choices and explicit non-stop finish reasons. Warning wording alone, including uncertainty about a margin, is a review diagnostic. Source text containing replacement characters or unresolved PDF font identifiers is still invalid.
VOICE_TRANSPORT_TESTING=false remains the deployment default. Explicit true permits
transport testing without finalized offline calibration. V01 constructs configured
embedding transport after replay recovery, validating identity, credentials and
request limits without inference. The existing session execution-profile JSON pins
embedding identity and mode: transport_testing, with no distance or calibration ID.
Create/recovery/poll expose calibration_status: uncalibrated; calibrated reservations
report calibrated, and legacy reservations without search metadata report unknown.
F01 exposes the status and testing policy, and does not advertise testing availability
with an invalid embedding request policy. The delivered example client accepts these
additive fields; actual developer UI integration remains pending.
Authenticated WebSocket admission still checks Origin, owner/auth session, expiry, access epoch, provider/model/voice and exact frozen search profile before opening a provider connection. Disabling testing rejects an uncalibrated stream before provider invocation. Replays keep their original identity and diagnostic status. Calibration or policy changes cannot silently turn an existing reservation into another mode. Shared canonical search still returns error/CALIBRATION_REQUIRED with no sources; no invented fallback threshold, calibration report or alternate retrieval is created. Operators can test streaming and greetings without claiming document-grounded answers.
Acceptance and reproduction
Regression sources:
tests/unit/test_ingestion_admission_repairs.py: 100-pair title/condition retention, independent factual approval, unstyled Word introduction, both native vision adapters' incomplete/global/block diagnostics, fatal OpenRouter output, pending cutoff policy and search-service construction without uncalibrated evidence.tests/integration/test_ingestion_admission_repairs.py: real isolated database, zero publication before review, D07 replay, same-job D04 resume without a second vision call, inactive ready publication, Word/text factual review, authenticated Gemini/OpenAI synthetic streaming, reservation replay and policy-disable rejection, safe F01 diagnostics and configured embedding availability.- Existing vision/OCR/source tests were updated only where the requested contract changes their expected behavior. Genuine corrupt source text remains terminal; detached FAQ prose and all worker/tenant/replay/fencing coverage remain.
Commands from the repository root (synthetic provider tests, no paid work):
.venv/bin/python -m pytest tests/unit/test_ingestion_admission_repairs.py tests/unit/test_phase5_repairs.py tests/unit/test_gemini_vision.py tests/unit/test_ocr_policy.py tests/unit/test_phase3_repairs.py -q -p no:cacheprovider --tb=short
.venv/bin/python -m pytest -m 'not postgres' -q -p no:cacheprovider --tb=short
docker run --rm -d --name rag-admission-regression-test --tmpfs /var/lib/postgresql/data -e POSTGRES_PASSWORD=fixture -e POSTGRES_DB=rag_admission_test -p 127.0.0.1:55469:5432 pgvector/pgvector:pg16
export TEST_DATABASE_URL=postgresql+psycopg://postgres:fixture@127.0.0.1:55469/rag_admission_test
.venv/bin/python -m pytest tests/integration/test_ingestion_admission_repairs.py --require-postgres -q -p no:cacheprovider --tb=short
.venv/bin/python -m pytest -m postgres --require-postgres -q -p no:cacheprovider --tb=short
# Final regression run reuses the two unchanged large-review cases that passed above.
.venv/bin/python -m pytest -m postgres --require-postgres -q -k 'not test_large_eligible_review_persists_and_replays' -p no:cacheprovider --tb=short --junitxml=/tmp/admission-postgres-final.xml
docker stop rag-admission-regression-test
git diff --check
The approved original DOCX also passed an offline PageBlockExtractor.extract_for_review
and factual_context_units diagnostic: 201 blocks, 100 pairs, all 201 review blocks,
and the initial block appears in every pair context. Original SHA-256:
6ce416719802136d16c82e153bf0671af5bb87b441cc5fed144ebd253d647f23.
No database connection, human approval, publication or provider invocation was made.
The diagnostic used an inert explicit database URL because the real .env lacks a
host-run database URL. This is structural repair evidence, not factual acceptance.
Initial provider-free regression attempts failed settings validation inside the socket-restricted sandbox; permitted execution outside it resolved that prerequisite. The first complete run then found old warning-only terminal assertions (including its nested isolation-suite run). Two PostgreSQL warning-only assertions also described the superseded contract. Revised tests require review for diagnostics and terminal failure for genuinely corrupt text. Final results are recorded below.
Remaining runtime acceptance
Real Gemini Live and OpenAI audio quality were not run. Neither adapter was switched or removed; Gemini remains the temporary default. OpenAI still requires its dedicated key. Recognition changes were tested with deterministic native response fixtures; the prior paid infographic attempt was not repeated to spend credits. The developer's actual frontend remains under development, and browser/hardware/public deployment acceptance remains not_run. Pending real calibration, human decisions and unseen labels remain explicit quality prerequisites even when transport testing is enabled.
The real .env still needs its compatible database/request-limit configuration before
its backend transport can operate; changing admission does not repair or fabricate
those settings. Set the explicit testing flag and restart only after configuring them.
Health routes never construct or invoke providers. Applied migrations 0001–0005,
original inputs, stored profiles, tenant isolation, atomic publication, request keys
and lease fencing are preserved; no database schema changes or dependencies added.
Executed results
- Focused final unit command above: 124 passed, 4.36 s. New repair source: 16 passed, 1.56 s; broader extraction plus new source: 56 passed, 3.99 s.
- Final complete provider-free suite: 1767 passed, two existing Windows-path skips, 403 PostgreSQL cases deselected at collection, 25 existing warnings, 168.38 s. Its nested ambient-configuration isolation suite also passed.
- New final database repair source: 7 passed, 16.72 s. Earlier six-scenario version passed in 12.60 s; final six plus existing F01 checks passed 8, 19.37 s. Strengthened corrupt-text database regressions: 2 passed, 1.94 s.
- Complete initial database run: 401 passed / 2 obsolete assertion failures,
zero skips, 1763 deselected, four warnings, 680.43 s. Both existing
test_large_eligible_review_persists_and_replays[False/True]cases passed in this run. Final recheck excludes only those two already executed unchanged cases, includes the updated terminal-text assertions and newly added F01 case, and produces per-case durations in/tmp/admission-postgres-final.xml. This reuse is explicit, not a claim of a single final all-cases green invocation.
Database prerequisites: PostgreSQL 16.15, pgvector 0.8.7, dedicated
rag_admission_test on task-owned tmpfs container, never the existing database.
AST parsing, local repair/handoff links and git diff --check passed. All ten
protected input/migration files match the prior SHA-256 baseline, including every
applied migration 0001–0005 and all four supplied originals. The 55-case restored
tests/unit/test_phase3_repairs.py remains byte-identical.
Affected runtime files: app/modules/documents/chunking.py,
app/infrastructure/gemini_vision.py, app/infrastructure/openrouter_vision.py,
app/modules/documents/extraction.py, app/modules/documents/worker.py,
app/modules/voice/configuration.py, app/modules/voice/lifecycle.py,
app/api/v1/live.py, app/api/v1/dependencies.py, app/api/v1/knowledge.py.
Configuration/docs: .env.example, API catalog, implementation guide, reference
map, frontend backend handoff, operations guide, Phase 4 report and this repair
report. Existing test changes are limited to test_gemini_vision.py,
test_phase5_repairs.py, test_phase3.py, test_ocr_policy.py and integration
test_phase5.py; the two new repair test sources are listed above. Unrelated
working-tree changes were retained.
Final database recheck: 402 passed, zero skips, 1771 deselected (1769
non-PostgreSQL cases plus the two previously passed large-review cases), four
existing warnings, 357.63 s. Combined with those two actual earlier passes,
all 404 current PostgreSQL scenarios have executed passing evidence. The
complete initial run with two superseded assertions is retained above; this is
coverage across executions, not a claim that its exit status was successful.
Temporary logs: /tmp/admission-provider-free-final.log,
/tmp/admission-targeted-unit-final.log, /tmp/admission-targeted-complete.log,
/tmp/admission-postgres.log, /tmp/admission-postgres-final.log.
Cleanup inspection found zero remaining application test schemas, zero public
tables and zero additional test databases. The task-owned tmpfs database container
was then stopped/removed. Existing containers and prior acceptance volumes were
not modified. For container deployment, rebuild the application image to include
this source change before restarting the API with the explicit testing policy;
worker startup still requires an approved queue and spending bounds. The operator
app.voice_smoke remains a calibrated search/voice-quality diagnostic; this policy
amendment applies to authenticated V01/WebSocket connectivity testing.