Skip to content

fix: preserve streamed capture and bound long-running resource costs - #216

Open
QvQQ wants to merge 7 commits into
Netis:mainfrom
QvQQ:fix/capture-stream-durability
Open

QvQQ wants to merge 7 commits into
Netis:mainfrom
QvQQ:fix/capture-stream-durability

Conversation

@QvQQ

@QvQQ QvQQ commented Dec 4, 2026 •

Copy link
Copy Markdown

Problem and resulting behavior

Stream boundaries, TCP reordering and shutdown could discard captured output or leave ownership alive. Large body indexing and repeated turn/pairing scans also increased resource costs during long runs.

This update preserves the original capture and durable-ingestion fixes and adds the long-running resource repairs:

  • Preserve UTF-8 SSE frames, partial Chat/Responses output and provider errors through reordering, half-close, EOF and drain. Show empty and incomplete output accurately.
  • Add opt-in durable payload journaling before asynchronous DuckDB indexing, deduplicate stored bodies, propagate durability errors and coordinate shutdown/checkpoints.
  • Tie active snapshots to pending partitions, preserve visible IDs across reordered boundaries and maintain ordered turn rollups instead of repeatedly scanning all pending calls.
  • Persist the exact token-estimation summary so summarized ClickHouse list pages omit response bodies. Backfill legacy unknowns with paced physical-key pages; stream topology projections and endpoint batches while preserving cross-batch multiplicities and enforcing an explicit aggregation budget.
  • Discover pairing candidates through a versioned time-ordered index, retain complete clusters across pages and persist original repair intent before batched metadata updates. Replay fresh authoritative rows after partial failure/restart, preserve monotonic versions, and rebuild the index when its table or MV is replaced on Atomic or Ordinary databases.

Validation

  • Fresh final-tree full workspace: 1,450 passed, zero failed, 4 existing ignored, using live ClickHouse 24.8 and dynamic DuckDB v1.5.3 (cargo test --workspace --no-default-features -j1 -- --test-threads=1). All 65 ClickHouse tests passed. The only compiler warning is the preexisting unused MODELS_USED import in the Aglake backend.
  • Fresh focused storage run: 149 passed (84 shared storage + 65 ClickHouse), zero failures/ignored. All live ClickHouse cases ran; the new Ordinary regression was observed failing before the fix and passing after it, and persistent comments survived an actual server restart.
  • Final static checks: 34 scenarios / 83 tags, coverage-policy checks, constructor scoping and tracked-content leakage checks passed; quality-checker self-tests 35/35 and leakage self-tests 3/3 passed.
  • Previously verified unchanged surfaces: DuckDB fault-feature tests 106 passed (1 ignored documentation example); four new-binary PCAP control/reordering replay cases passed; console tests 224 passed and TypeScript/Vite build passed. Those surfaces were not rerun for this ClickHouse-only compatibility follow-up.

The live summary-maintenance regression observes acknowledged mutation batches and post-completion pacing from query logs. An initial final-workspace run exposed an overly tight six-second test deadline; the test now uses a bounded eventual-progress watchdog while retaining exact batch, pacing and historical-wrap assertions. Production timing and cursor behavior are unchanged.

The performance regressions use deterministic work counters and actual ClickHouse query logs. With 1,000/2,000/4,000 ordered calls, snapshot visits fall from 500,500/2,001,000/8,002,000 to 1,000/2,000/4,000. With 100 recent candidates and 0/100,000/500,000 historical rows, the measured warmed whole sweep reads 813/813/813 rows instead of 100/100,100/500,100. These are fixture measurements, not universal physical-row or RSS guarantees.

Review notes

The four already-published capture/journal commits remain unchanged; the follow-up work is grouped into three logical turn/query/pairing commits. Existing design documentation and the scenario registry are updated with the code.

Full detail bodies and existing pairing classification semantics are retained. Initialization/recovery can scan retained history; ClickHouse granules/part mutations and a single large decoded row can exceed soft per-batch targets. Long-SSE buffering, count-bounded queues and failed remote-batch delivery policy remain outside these repairs.

  • Behavioral regression tests and registered scenarios.
  • Public content checked for internal infrastructure details.
  • Instrumented changed-code coverage / no-decrease ratchet.

QvQQ added 7 commits December 4, 2026 19:40
Keep UTF-8 SSE frames and partial Responses output across TCP reordering, half-close and EOF. Release consumed capture buffers and full-call ownership, and coordinate storage checkpoints with graceful shutdown.

Expose DuckDB resource controls and optional dynamic linking while preserving bundled defaults.
Append and sync deduplicated payloads before acknowledging ingestion. Commit replay cursors with metadata, hydrate detail reads on demand, and propagate durability and drain failures.
Preserve provider errors alongside partial text, reasoning and tools. Distinguish empty and unfinished output in the console, and request a bounded libpcap burst buffer.
Map stream integrity, TCP lifecycle, turn ownership, durable replay and shutdown failures to existing regression tests. Scope the journal read fixture under the test-only constructor allowlist.
Retire only snapshots owned by drained or discarded partitions and preserve visible IDs across late eligibility and reordered boundaries. Maintain ordered rollups and event indexes instead of rebuilding or scanning all pending calls.

Add reference-field, lifecycle, drain and deterministic linear-work regressions.
Persist the exact token-estimation summary, hydrate only legacy unknown bodies, and backfill summaries with paced physical-key pages. Stream minimal topology projections, resolve endpoints in time-pruned batches, and retain cross-batch multiplicities under an explicit aggregation budget.

Cover compatibility, restart, query-log transfer costs and budget failures.
Use an all-version time-ordered candidate index, complete cross-page clusters and a durable original-patch plan. Replay fresh authoritative rows in batches with checked versions, fixed backfill coverage and retention coordination.

Detect index and materialized-view replacement on Atomic and Ordinary databases. Cover partial writes, restarts, object recreation, late data and warmed whole-sweep scan costs. Document maintenance costs and register regression contracts.
@QvQQ QvQQ changed the title fix: preserve streamed capture and durable payload ingestion fix: preserve streamed capture and bound long-running resource costs Dec 5, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant