Commit Graph

485 Commits

Author SHA1 Message Date
iomgaa d80feafb93 test: pin the reason behind rejected document packages
The outer exception boundary also absorbs accidental TypeError and KeyError, so asserting only the exception class could not tell an explicit validation from a lucky failure. Assert the reason for nested blocks and guard every rejection against an accidental cause.
2026-10-22 00:41:51 -04:00
iomgaa 6691e52195 docs: document parse_document and bump version to 1.3.11
Changelog, README (install pin, capability table, usage, deployment recipe, operations notes, known limits), env example, architecture, roadmap, the M3 design erratum and the CHSAnalyzer3 consumption notes.
2026-10-22 00:23:47 -04:00
iomgaa c4dd403e0f test: add live PDF document parsing checks
Slow, opt-in, serial single-page documents built in the test itself. Covers the document entrance, the PDF text-recognition fix, and that corrupt documents do not open the breaker.
2026-10-22 00:14:54 -04:00
iomgaa 42b7f0defc docs: register parse_document in telemetry schema and alignment targets 2026-10-22 00:07:54 -04:00
iomgaa 80bb8aba71 feat: add OcrClient.parse_document with full governance
Reuses the existing retry, breaker, limiter and telemetry loop; the transport capability is checked once before the statistics boundary. Legacy entrances keep their error text. Tests cover the document path through the real transport so parser exceptions, deadlines and probe bookkeeping are proven end to end.
2026-10-22 00:01:45 -04:00
iomgaa 61cace71c4 feat: add parse_document to the MonkeyOCR transport
Unrecognizable bytes are rejected before any request. The result package is downloaded as a stream with a cumulative size cap, and error statuses are classified before the size check. Parsing runs in a worker thread so cancellation and call deadlines stay effective. parse_layout shares the first protocol stage without behavior change.
2026-10-21 23:50:51 -04:00
iomgaa 0357d5afb3 feat: let document calls treat deterministic parse failures as rejected input
The service wraps every failure, including its own 400s, as a 500 with a parsing-failed detail. Only a fixed set of known bad-input markers is narrowed to a rejected request, and only when the caller passes markers; the shared default classification is unchanged.
2026-10-21 23:43:02 -04:00
iomgaa 3db7d9979c feat: parse document result packages from middle json only
Content comes from the middle json and its paired markdown; the content list is deliberately ignored because it escapes markdown characters. The external-data exception boundary covers both reading and structure parsing so no native exception escapes the OCR client. The layout parser is unchanged.
2026-10-21 23:35:47 -04:00
iomgaa c13c4fd28f fix: label PDF uploads by content instead of a fixed image name
The service dispatches on the upload filename extension. A PDF sent as image.jpg made /ocr/text return a success response with hallucinated text. Only PDFs are relabelled; everything else keeps the legacy image label.
2026-10-21 23:26:49 -04:00
iomgaa 398b16e136 feat: add OCR document types and ports
OcrDocumentElement extends the layout element with text; OcrDocumentResult stays independent because the parent's defaulted call_stats forbids a required markdown field. OcrDocumentTransport is a separate Protocol so existing OcrTransport implementers keep passing isinstance.
2026-10-21 23:20:53 -04:00
iomgaa b31df842a8 docs: fold plan review findings into OCR document plan 2026-10-21 23:14:22 -04:00
iomgaa 944b3f3798 docs: add implementation plan for OCR document parsing
Ten tasks covering types and ports, upload sniffing, package parsing, rejected-input classification, transport, client, registration, live checks, docs and verification.
2026-10-21 22:51:10 -04:00
iomgaa 1f08194b96 docs: record approval of OCR document design and rebuild wiki index
Index rebuild also registers the previously unlisted 1.3.10 design and plan.
2026-10-21 22:40:53 -04:00
iomgaa fb67b68440 docs: fold independent review findings into OCR document design
Adds live-service and server-source evidence, structure contract, exception and resource boundaries, corrected breaker analysis, and the Codex review record.
2026-10-21 22:16:50 -04:00
iomgaa 4117eae501 docs: add OCR document parsing design for issue 34
Root-cause analysis from live MonkeyOCR probes: upload label is not detected, output carries no content, and deterministic bad-input 500s are treated as transient. Proposes parse_document with content-sniffed upload type and middle.json-only extraction.
2026-10-21 21:55:01 -04:00
iomgaa 25a90ebd05 chore: merge 1.3.10 unified completion verdict (#30/#31) v1.3.10 2026-10-15 00:38:40 -04:00
iomgaa 1201a04449 chore: date 1.3.10 changelog for release 2026-10-15 00:38:19 -04:00
iomgaa abcdf6930e fix: address completion verdict review findings
- fidelity cacheability also requires a non-empty projected body, so
  think-tag-only answers are no longer cached
- a no-argument tool sent with arguments null only is a deterministic
  dialect: ResultInvalid tool_arguments_null instead of retried
- text mode treats choice index null as 0 and no longer lets False pose
  as 0
- null-only tool_calls elements no longer produce an empty tool_calls
  list; non-stream fidelity checks role before the verdict; warning
  paths are length-bounded
- docs: ARCHITECTURE 7.8 field counts, README cache/watchdog wording,
  CHANGELOG notes, review record in the design, hook note in the plan

Red: 8 new tests failed before this change (e.g.
test_openai_cacheable_requires_projected_body,
test_null_arguments_tool_is_result_invalid_stream,
test_text_mode_choice_index_null_is_zero[None-True]).
2026-10-15 00:28:20 -04:00
iomgaa 31942f55f1 docs: document completion verdict and bump version to 1.3.10
CHANGELOG 1.3.10 (unreleased) with behaviour-change and breaking
sections, README capability rows and a 1.3.10 section, ARCHITECTURE
section 15 plus 6.2/7 updates, schema doc for the stream_end column,
migration impact notes, ROADMAP entry, .env.example MISSING_DONE
semantics, and a revision pointer on the 1.3.9 design. Follow-ups
filed as #32 and #33.
2026-10-15 00:03:15 -04:00
iomgaa 779a9b29a3 feat: record stream end mode in telemetry
llm_calls gains a nullable stream_end TEXT column (auto backfill,
manual-mode trimming as in 1.3.8). TelemetryRecorder.record_llm_call
takes a new required keyword stream_end; the emitter reads it from the
response on attempt rows and writes NULL for failed, cache-hit and
terminal rows.

Red: 18 tests in tests/unit/test_telemetry.py and test_ports.py failed
against the pre-change source (missing column, 38-field signature,
stream_end absent from emitted rows).
2026-10-14 23:54:11 -04:00
iomgaa 48ba36dd94 fix: gate cache writes and reads on a shared cacheability verdict
Cacheable is now a strict subset of deliverable: salvaged streams,
content-less results and length/filter/unknown finishes are delivered
but never written, and the read path applies the same verdict to the
stored values before hit overrides (invalid stream_end or non-string
finish read as a miss; 1.3.9 fidelity entries fall back to the
completion's finish). Hits reset stream_end. The legacy
_has_completion_output helper is folded into _is_cacheable.

Red: 13 tests in tests/unit/test_cache.py failed before this change
(uncacheable results were written and replayed; new fields not reset).
2026-10-14 23:39:50 -04:00
iomgaa 39a319e34e fix: judge stream completion by finish reason and trailing usage
Both transport paths now share one verdict: a stream is complete on
[DONE] or on finish_reason followed by measured usage and a clean EOF
(both modes; missing_done only governs real truncation). Outcomes follow
the design's first-match table: upstream_error finishes stay transient,
fidelity mode delivers reasoning-only/length results, text mode raises
ResultInvalid for content-less length/filter endings, and non-stream
fidelity judges before building the snapshot so truncated tools reach
tool_truncated. Projections honour the reasoning alias, dialect warnings
are bounded, and responses carry finish_reason and stream_end.

Red: 39 of 46 tests in tests/unit/test_completion_transport.py failed
before this change (e.g. eof_after_finish raised 保真响应缺 [DONE];
reasoning-only length raised empty_completion; reasoning-only stream hit
the TTFT watchdog, re-confirmed by disabling alias liveness).
2026-10-14 23:31:54 -04:00
iomgaa 16743ca11d fix: merge unknown and null stream fields losslessly in completion accumulator
Null is treated as absent at every layer; unknown delta, tool and
function fields merge by OpenAI streaming conventions (strings concat,
label keys idempotent, indexed arrays by index) and conflicts drop the
key and record its path instead of failing the call. The accumulator
now tracks finish and usage-after-finish in both modes, exposes the
reasoning alias, and non-stream parsing splits shape checks from
snapshot construction.

Red: 20 of 47 tests in tests/unit/test_openai_completion.py failed
before this change (e.g. test_null_known_and_unknown_fields_are_absent
raised TransientError 未知 delta 字段; finish_seen/raw_message missing).
2026-10-14 23:21:05 -04:00
iomgaa e5ad67408a feat: add kernel completion verdict functions and response fields
Pure functions in types.py classify finish reasons, judge stream
completeness and outcome, and decide cacheability; TransportResult and
LLMResponse gain finish_reason and stream_end; snapshots accept
tool_calls null.

Red: tests/unit/test_completion_verdict.py failed at collection
(ImportError: _classify_finish et al. undefined) before this change.
2026-10-14 23:12:00 -04:00
iomgaa ab0e924849 docs: add implementation plan for unified completion verdict 2026-10-14 23:04:05 -04:00
iomgaa 607523ef5c docs: fold round-2 review fixes into completion verdict design 2026-10-14 22:46:56 -04:00
iomgaa 95104af2a5 docs: add unified completion verdict design for issues 30 and 31 2026-10-14 22:39:47 -04:00
iomgaa 5d2ad40336 chore: gate complexity only on functions touched by the change
Whole-tree radon blocking let 16 legacy C+ functions block every commit,
including docs-only ones. Touched functions still block; legacy debt is
reported as a warning.
2026-10-14 22:32:52 -04:00
iomgaa 22609c90d6 chore: merge approved 1.3.9 release preparation v1.3.9 2026-10-01 23:16:18 -04:00
iomgaa a0cf8546dc chore: prepare approved 1.3.9 release version 2026-10-01 23:08:37 -04:00
iomgaa ce10881eb0 docs: archive preserved wiki records and register hedge nodes 2026-10-01 23:03:51 -04:00
iomgaa bd82f16921 chore: merge 1.4.0 OpenAI message fidelity release 2026-10-01 14:48:47 -04:00
iomgaa 2c9c5a3aa7 test: forward response mode in transport helper 2026-10-01 14:48:29 -04:00
iomgaa 9185eab8c9 feat: preserve governed OpenAI tool messages in 1.4.0
Add faithful single-choice chat results, tool stream activity, error-frame retries, and isolated protocol caching.

Reject empty cached completions with the same value predicate as transport, add regression coverage, and adopt Apache-2.0.
2026-10-01 14:32:19 -04:00
iomgaa 0e29deac1a docs: record 1.3.8 release gate results v1.3.8 2026-09-14 03:36:06 -04:00
iomgaa b0232b7466 merge: release 1.3.8 net generation time and mid-stream stall hedging 2026-09-14 03:04:04 -04:00
iomgaa cf6e3fa008 chore: release 1.3.8 2026-09-14 03:03:39 -04:00
iomgaa a2a00c0ef2 test: sync PG telemetry integration helpers with 1.3.8 stall columns
_minimal_fields and the pre_135 acceptance dicts missed the two new
columns, KeyErroring against migrated 39-column physical tables
(caught by the pre-merge integration gate; production path is
signature-gated and unaffected). Verifier gaps P2-1/P2-2 closed:
full suite 1764 passed, PG 30 passed, lint green.
2026-09-14 03:01:40 -04:00
iomgaa 8489b8ea50 docs: resolve branch review note (final-state comment for content_event wiring) 2026-09-14 02:28:59 -04:00
iomgaa ca8743bf33 docs: document net generation time and mid-stream stall hedging 2026-09-14 02:13:55 -04:00
iomgaa 2ac05a20b6 feat: add opt-in mid-stream stall hedging for chat
HEDGE__STALL_AFTER_S triggers a cross-source hedge when the primary
leg stalls mid-stream (independent of HEDGE__AFTER_S); two-phase
hedge window with event recheck discipline; watchdog-killed primary
converges on the surviving hedge leg. STREAM__STALL_THRESHOLD_MS
(1000ms default) adjustable via env/settings/constructor. Assembly
guards: ValueError on never-opening windows, embedding/OCR scope
warning (B4). Batch D 14 tests red-to-green, 1688 unit+contracts.
2026-09-14 01:52:10 -04:00
iomgaa e0b0be09a7 feat: add stall_ms and stall_count telemetry columns
Third approved port change: TelemetryRecorder.record_llm_call gains
stall_ms/stall_count (assembly gate derives from this signature).
Schema five edit points (both DDLs, both backfill decls, COLUMNS)
with INTEGER nullable columns appended last; telemetry_schema_sql
regenerates from the same constants untouched. Emitter forwards the
pair from retry._emit on the success branch only (cancelled hedge
loser rows stay NULL by construction); cache-hit and terminal rows
pass explicit None. Both **fields recorders pick the columns up with
zero signature change.
2026-09-14 01:16:33 -04:00
iomgaa 53bcf43172 feat: redefine generation_ms as net generation time with stall attribution
CallStats gains stall_ms/stall_count (None = no stall observation);
winner sample triple (wall, stall_ms, stall_count) converted once in
_attempt success branch; net = max(0, wall - stall) converged into the
shared _record_winner_sample used by both the single-path guard and
hedge winner registration. Two-fail hedge rounds record nothing
(no winner to attribute). Design section 4.2; issues #27.
2026-09-14 00:56:54 -04:00
iomgaa 901a193514 feat: add a content event and stall accounting to the transport port
T1(计划 §4):观测原语与端口契约(issue #27/#28 底层)。

- Transport.complete 加必填 kw content_event(顺序在 first_token_event
  后,无默认值,同款约定):流式每增量 chunk 置位一次,非流式/对冲路
  恒不置位,None = 不观测
- TransportResult 增 stall_ms/stall_count(带默认 None):超阈值相邻
  增量 chunk 沉默总额与段数,chunk<2/非流式 → None,尾部不计
- SourceConfig 增 stall_threshold_ms(默认 1000,正整数拒 bool,
  _validate_watchdog 同款落点)
- _complete_stream 记增量 chunk 时间戳(空 chunk/usage 帧/keepalive
  不产生记录点)+ 模块级纯函数 _stall_from_chunk_times(严格大于
  阈值才减);max_inter_token_ms 原语义一字不动
- §2.2 同步清单全量:11 实现 + 11 调用点(重跑 grep 复核零遗漏)
- 批次 A 12 用例先红(TypeError/ImportError/AttributeError)后绿,
  证据 tests/outputs/138/t1/
2026-09-14 00:35:35 -04:00
iomgaa 6f3a620c73 docs: fix plan per independent review (B1 emitter fake sync, B2 guard return contract, N1-N5) 2026-09-14 00:10:37 -04:00
iomgaa 929d60e501 docs: add 1.3.8 implementation plan and B4 design errata
B4: assembly-time non-streaming hedge warning operationalized to
embedding/OCR scopes only (chat stream is per-call, no assembly
signal); AFTER_S same-gap backfill included. Plan T1-T5 with real
grep sync lists and fail-first test batches.
2026-09-13 23:46:34 -04:00
iomgaa 97de4104c6 docs: finalize streaming stall design with independent review errata
B1 chunk = any delta (content or reasoning), B2 telemetry plumbing
via explicit _emit pass, B3 orchestration entry gate for independent
stall hedging; N1-N9 advisory fixes merged. Human decisions recorded
in design section 9.
2026-09-13 23:20:52 -04:00
iomgaa 03cbf4c8db docs: add approved streaming stall measurement and mid-stream hedging design
Findings: industry paradigm research (watchdog-retry is the norm,
mid-stream hedging has no public precedent; pi-tps threshold-based
stall deduction; Gregg off-CPU paired reporting; vLLM exclusion
clauses). Design: generation_ms redefined as net generation time
(wall minus all inter-chunk stalls over threshold), CallStats gains
stall_ms/stall_count, HEDGE__STALL_AFTER_S mid-stream hedge
independent of HEDGE__AFTER_S. Issues #27 #28.
2026-09-13 22:53:00 -04:00
iomgaa a28d94451e docs: record 1.3.7 release gate results v1.3.7 2026-09-10 15:19:42 -04:00
iomgaa a04d87e8d7 merge: release 1.3.7 hedged requests and bare generation time 2026-09-10 14:52:08 -04:00