Commit Graph

473 Commits

Author SHA1 Message Date
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
iomgaa c60011b034 chore: release 1.3.7 2026-09-10 14:51:53 -04:00
iomgaa 9f7d407120 fix: skip hedge dispatch when primary finishes during admission
Address branch review findings 1-4 on feature/1.3.7-hedged-requests:

- src/polygateway/middleware/retry.py: recheck primary.done() after
  hedge admission in _attempt_hedged; release the hedge permit via
  settle_and_release(permit, 0) (release_probe for probe entries) and
  adjudicate the primary directly instead of firing a billable HTTP
  request that would be cancelled immediately
- src/polygateway/config.py: check_hedge_assembly raises a hedge-located
  ValueError for empty sources instead of a bare min() error
- tests/unit/test_hedge.py: pin that an injected FakeClock jump of 10^6
  seconds does not trigger hedging (design section 8); pin pick(exclude)
  counting no gate_rejections and leaving reasons untouched; pin silent
  hedge abandonment when the candidate circuit is open; deterministic
  regression for the admission-window race (BlockingLimiter harness)
- tests/unit/test_config.py: assert the empty-sources guard message
  locates the hedge key

Red-to-green evidence in tests/outputs/137/review-fixes/
2026-09-10 14:47:40 -04:00
iomgaa 0572611af7 docs: document hedged requests and bare generation time 2026-09-10 14:12:30 -04:00
iomgaa fe616cf91d docs: add approved hedged requests design and implementation plan 2026-09-10 14:04:31 -04:00
iomgaa adc069447a feat: add opt-in cross-source hedged requests for chat 2026-09-10 14:03:25 -04:00
iomgaa 463eca380d feat: expose bare generation time and hedge flags in CallStats
CallStats gains hedges/generation_ms/hedge_won (all defaulted, appended
after total_latency_ms); _CallContext counts them via record_generation
(overwrite for chat/OCR, accumulate for embedding batches) and
register_hedge, and snapshot carries them out. All three _attempt
implementations time only the transport call itself on the same injected
clock as total_latency_ms; the chat sink is recorded by the orchestrator
so hedge winner attribution stays with T3. Hedge counters stay 0/False
until the T3 orchestration lands.

Red-green evidence: tests/outputs/137/t2/ (10 new tests AttributeError
red, then green; full unit+contracts 1621 passed).
2026-09-10 13:28:51 -04:00
iomgaa 0a6d6225db feat: add a required first-token event to the transport port
Transport.complete gains the keyword-only first_token_event (no default,
per the port convention): streaming sets it on the first delta, the
non-streaming path accepts it but never sets it, None means the caller
does not observe the first token. All fake/wrapping transports and the
three direct call sites follow the signature; the e2e wrapper forwards.

Red-green evidence: tests/outputs/137/t1/ (batch A TypeError red, then
147 file tests + 1550 unit tests green).
2026-09-10 13:16:38 -04:00
iomgaa 166b2865d0 docs: record 1.3.6 release gate results and matrix exemption v1.3.6 2026-09-10 11:31:27 -04:00
iomgaa b0ab39edbf docs: scope the slow release gate by diff intersection 2026-09-10 11:30:40 -04:00
iomgaa a07a6b096b merge: release 1.3.6 call deadline and cancellation settlement 2026-09-10 05:22:35 -04:00
iomgaa 53d2f089e1 chore: release 1.3.6 2026-09-10 05:22:24 -04:00
iomgaa 5e2c35a812 test: pin the expiry window and close settlement review gaps 2026-09-10 05:20:56 -04:00