Repository navigation
Support animated PNG in the PNG format - #112846
Conversation
A `t` column of integer type turns the result of a query into an animation (`APNG`). Records are grouped into frames by the value of `t`, which is the relative time offset of the frame. Every frame is an independent image: the canvas is empty at the start of each frame, and in the implicit coordinate mode the cursor restarts from the top-left corner. The unit of `t` is set by the new settings `output_format_image_time_multiplier_seconds` and `output_format_image_time_divisor_seconds`, which default to 1 and 60, so one unit of `t` is 1/60 of a second by default. A frame is displayed until the next one begins, and the last frame is displayed for as long as the frame before it. The new setting `output_format_image_streaming_animation` writes each frame out as soon as the next value of `t` is seen, instead of buffering all the frames in memory, so that a viewer can display them while the query is still running. The `acTL` chunk has to precede the first `IDAT` and declare the total number of frames, which a forward-only writer does not know, so the streaming mode declares an upper bound instead of the exact count. Browsers play such a file, but decoders that trust the declared count report an error after the last real frame, so the setting defaults to false and the default output is a specification-conforming `APNG`. Co-Authored-By: Claude Fable 5 <[email protected]>
|
Workflow [PR], commit [77543a0] Summary: ✅
AI ReviewSummaryThis PR adds Findings❌ Blockers
Final Verdict❌ Changes requested. The buffered animation support looks solid, but the raw streaming mode still returns invalid LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 393/437 (89.93%) · Uncovered code |
|
Preview deployment for your docs. Learn more about Mintlify Previews.
|
…maller issues `delayFromUnits` scaled an over-long delay down by `(num + MAX_DELAY_PART - 1) / MAX_DELAY_PART`. With `num` close to the maximum of `UInt64` - two frames at the two ends of the `t` domain with `output_format_image_time_divisor_seconds = 1` - that addition wraps around, the factor comes out as zero and the next division is undefined behavior. This is also what the `arm_tidy` build reported as `clang-analyzer-core.DivideZero`. The ceil-division is now written so that it cannot overflow, and the factor is clamped to at least one. The value of `t` was read through `getInt` and carried as `Int64`, so a `UInt64` `t` above the maximum of `Int64` wrapped negative, which reordered the frames in the buffered mode and made the streaming mode reject a monotonic sequence as decreasing. It is now mapped to an order-preserving `UInt64` key, which keeps the whole domain of both signed and unsigned `t`; a difference of two keys is still the difference of the two values, so the frame delays are unchanged. In the streaming mode `acTL` declared `MAX_DECLARED_FRAMES` even when the very first frame was handed over from `finalizeFrames`, i.e. when the whole result had already been read and the animation has exactly one frame - an empty result, or a result where every row has the same `t`. Such an output looked truncated to a decoder that trusts `acTL`; the exact count is now declared. `resetFormatterImpl` called `clear` on `animation_buffer`, which keeps the capacity. The buffer holds the whole encoded animation, so a large animated `iterm` or `kitty` payload pinned that memory for the lifetime of a reused formatter such as `MessageQueueSink`. It is now swapped with an empty one. Tests cover a one-frame and an empty animation in the streaming mode, `t` of `UInt64` above the maximum of `Int64` in both modes, and the widest possible gap over the `Int64` domain.
`IOutputFormat` flushes only after a whole chunk has been consumed, so a chunk holding many distinct values of `t` kept all of its completed frames in the output `WriteBuffer` until the chunk ended. The streaming mode is meant to let a viewer display the frames while the query is still running, so `writeFrame` now flushes after each frame when the datastream goes straight to the output. `flushImpl` rather than `flush`, because the writing mutex is already held by the caller of `consume`. With an inline terminal image protocol the datastream is a single payload that cannot be sent early anyway, so nothing is flushed there. Verified over HTTP with a query of four frames spaced by `sleepEachRow`: the first `fcTL` chunk reaches the client after 1.2 s of a 2.4 s query.
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 357/402 (88.81%) · Uncovered code |
The Kitty graphics protocol does have animation, but it is a separate flow of per-frame commands (`a=f` to transmit a frame, `a=a` to control playback), not an animated datastream. `writeImageKitty` transmits a single PNG payload with `f=100,a=T`, so an `APNG` would be decoded by Kitty as its default image only, silently turning the animation into a still image. Reject `kitty` for a result with a `t` column, the same way `sixel` is rejected, instead of advertising an animation that does not play.
When the delay numerator did not fit into the 16-bit part of `fcTL`, both parts of the fraction were floor-divided by the scaling factor, which distorts a ratio whose parts the factor does not divide: a gap of 65536 units with `output_format_image_time_divisor_seconds = 3` came out as 32768/1 instead of ~65536/3, half as long again. Now the largest denominator that brings the numerator into 16 bits is taken and the numerator is rounded to the nearest integer, so 65536/3 becomes 43691/2. https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=112846&sha=latest&name_0=PR #112846 Co-Authored-By: Claude Fable 5 <[email protected]>
The only conflict is `docs/en/interfaces/formats/PNG.md`, which `master` deleted along with the rest of the legacy Docusaurus tree in "Docs: remove legacy Docusaurus documentation" (9440ca7), while this branch documented the animation in it. The deletion is taken as is: the documentation of the `PNG` format now lives in the `Documentation` struct registered by `registerOutputFormatPNG` in `src/Processors/Formats/Impl/PNGOutputFormat.cpp`, from which `docs/reference/formats/PNG.mdx` is generated, and this branch already carries the same animation sections there. The deleted page was a duplicate of that source, so nothing is lost. #112846
|
🕵 Both stress-test failures on 90e1101 are unrelated to this PR:
All 7 |
The streaming mode declares `MAX_DECLARED_FRAMES` in `acTL` as an upper bound, but nothing stopped `emitFrame` from writing more frames than that, after which the declared count would not be even an upper bound and the APNG would be invalid. The buffered path likewise narrowed `buffered_frames.size()` to `UInt32` without a check. Now a frame past the 31-bit limit of `acTL` throws `TOO_MANY_ROWS` before it is written (or buffered). #112846
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=112846&sha=89a5889df1c52785320be8d2ed3f3f48a5d5d89c&name_0=PR&name_1=Integration%20tests%20%28amd_binary_excluded_from_llvm%29 and provide a fix in a separate PR. If the fix is already in progress, link it here. The failure is |
|
No fix is in flight for either. Both need a private-side change, which I cannot make: this account gets 404 on 1. 2. I did check whether the public twins need the same bump: 4 kills in 9463 and 9370 runs over 30 days, against the 16-in-7-days that justified the parallel split, so I am not splitting them. Growth is +31 and +24 s/day on p50, about seven weeks of p99 headroom. |
Parsing the first argument of the `remote`, `mysql`, and similar table
functions rebuilt the whole set of accumulated strings once per ordinary
character (`append` created `elem_to + elem_what` for a single-element
set), making the parsing quadratic in the description length. A fuzzed
1 MiB zero-padded `FixedString` address, such as
`mysql(toFixedString('127.0.0.1:9004', 1048575), ...)`, therefore hung
during query analysis for tens of minutes under TSan, where neither
`KILL QUERY` nor `max_execution_time` could interrupt it, and failed the
stress test hung check:
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=112846&sha=b6c24302410686f74109c91177b6585a898cb349&name_0=PR&name_1=Stress%20test%20%28amd_tsan%29
(found on ClickHouse#112846)
Now a single-element set is appended to each accumulated string in
place, which is linear. A 1.6 MiB address went from 25.6 s to 0.29 s in
a release build.
Co-Authored-By: Claude Fable 5 <[email protected]>
…e delay The settings 'output_format_image_time_multiplier_seconds' and 'output_format_image_time_divisor_seconds' define the time unit of 't' as a fraction, and only its reduced form ends up in the 'fcTL' frame delay, so validating each setting against 65535 separately rejected exactly representable scales such as 100000/60 = 5000/3. The fraction is now normalized by its greatest common divisor before validation, and only a reduced denominator over the 16-bit limit is rejected: the denominator is stored verbatim in 'delay_den', while an over-large numerator only means that delays past the longest expressible one are clamped, which 'delayFromUnits' does for long delays anyway. The test gained a positive case for the 100000/60 scale, and the negative case that hard-coded its rejection now uses the irreducible 1/100000. Co-Authored-By: Claude Fable 5 <[email protected]>
|
🕵 Triage of the CI on 598fd12's predecessor c688531:
|
…he bare unit `fcTL` stores the actual frame delay, not the base time unit, so a setting like `output_format_image_time_divisor_seconds = 100000` is valid whenever the observed gaps of `t` reduce it into the 16-bit delay parts: two frames at `t = 0` and `t = 2` give `2/100000 = 1/50000`, which is exactly representable, yet the constructor used to throw on the bare unit before reading any rows. The fit check moves to `delayFromUnits`, after the per-frame `gcd` reduction: a delay of `MAX_DELAY_PART` seconds or more is clamped as before, a sub-second delay whose reduced denominator is still over the limit throws `BAD_ARGUMENTS`, and an over-large numerator keeps the rounded rescaling. #112846
| /// covers an empty result and the common case of a single distinct value of `t`, which would otherwise | ||
| /// produce a spec-conforming file that looks truncated to a decoder that trusts `acTL`. | ||
| if (streaming_animation) | ||
| return (finalizing && emitted_frames == 0) ? 1 : PNGWriter::MAX_DECLARED_FRAMES; |
There was a problem hiding this comment.
output_format_image_streaming_animation is documented as a memory/latency tradeoff, but this path makes a successful direct-output query emit a non-conforming APNG whenever more than one frame is streamed. acTL.num_frames is required to equal the real frame count, and here it stays at 2147483647; the PR description already notes that validating decoders such as Pillow then treat the file as truncated. That means the opt-in setting does not just reduce compatibility, it turns FORMAT PNG into an incorrect file-format result.
Please keep the raw-output path spec-conforming, for example by buffering unless the transport can be patched later, or by rejecting/gating this unsafe path instead of exposing it as a normal PNG setting.
There was a problem hiding this comment.
It is on-purpose.
|
Test: |
|
🕵 Triage of the three stress reds on
The cause was removed from |
| const auto next_frame = std::next(it); | ||
| /// Every frame is displayed until the next one begins; the last one reuses the previous duration. | ||
| const UInt64 delay_units = next_frame != buffered_frames.end() | ||
| ? static_cast<UInt64>(next_frame->first) - static_cast<UInt64>(it->first) |
There was a problem hiding this comment.
t is documented as the frame's relative time offset, but both animation paths only use gaps between consecutive distinct values. A concrete trace is t = 10, 20: the first frame is emitted immediately for 10 units, so t = 0, 10 and t = 10, 20 produce the same animation. That silently discards the leading offset instead of preserving the advertised start times.
Please either reject a first t different from zero, document that the timeline is normalized so min(t) becomes zero, or synthesize an initial empty frame so non-zero starting offsets survive serialization.
There was a problem hiding this comment.
Which isn't a problem.
@ alexbakharew asked on both LeakCheck::SkipQuietly call sites why the comment does not state that the LeakSanitizer check is skipped. Each of the three comments now leads with the fact, then the invariant that requires it: which memory is still owned at that point (clickhouse-local, server) or that the leak check deadlocks in signal context under the allocator lock (client), and why the notice is quiet or reported there. Comments only; no behaviour change. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=112846&sha=2e6a38112ad4dacef62f5cc4cdb396cc297282eb&name_0=PR&name_1=Stress%20test%20%28arm_asan_ubsan%2C%20s3%29 Related: ClickHouse#112846
On ASan builds the server's forced-shutdown branch calls safeExit(0), which calls __lsan_do_leak_check(). That branch is taken precisely because connection handlers and refresh tasks missed the drain timeout, so LSan stops the world and classifies chunks those threads are still using. The reports are unattributable by construction. Two were reported on 2026-08-08 as a uniqExact hash-table "direct leak" (2 MiB on ClickHouse#112846, 4 MiB on ClickHouse#101264). Both are a single allocation with zero indirect leaks, and the two green asan_ubsan jobs on the same commit of ClickHouse#112846 also force-shutdown with connections live while reporting nothing, so neither is an aggregation bug. Since ClickHouse#113608 made previously unattributed sanitizer reports nameable, these compete with real leaks in every stress report. safeExit gets a defaulted run_leak_check parameter, so every existing caller keeps today's behavior, and the two force-exit branches reached while handler threads are still running pass false. A stderr line records that coverage was skipped rather than passed; its wording avoids "<Name>Sanitizer:" so that CI log parsing does not read it as a failure. Keeper's identical-looking branch is left alone on purpose: it calls server_pool.joinAll() first, so no handler is still running there and this report class cannot arise. The client's SIGINT/SIGQUIT handler keeps the default. Clean shutdowns never reach safeExit, so they keep full leak coverage through the ordinary at-exit check. Two mechanisms that look plausible were measured and rejected. __lsan_disable() does not suppress the check: it is an allocation-time per-thread flag, and a probe still reported the leak. Omitting the call does not re-arm the at-exit check either: that check is installed with Atexit(), which _exit() bypasses, so omission can only remove reports, never add any. Co-Authored-By: Claude Fable 5 <[email protected]>
|
The one-week re-census, as promised. #114053 merged 2026-08-13 08:40 UTC. Headline: the unattributable class is gone. No I am reporting the master-only arm, because a PR branch only contains the fix once it merges master, so the all-PR population is a mixture of fixed and unfixed builds. Every master build after the merge has it, so that arm has no dilution. Jobs matching
The middle window matters: the 145 and 150 row days on 08-10/08-11 were mostly the PromQL query-tree storm, which your revert #114326 removed on 08-12 01:14, before this fix. Comparing raw pre-merge days against now would credit that revert to this change, so the honest baseline is the post-revert window, and the effect being claimed here is 0.27% to 0.00%. With 0 in 1569 runs the rate is not "zero", it is at most about 0.19% (rule of three). The post-merge observation window is 2.3 days, so that bound is what limits the claim, not the count. The fix is verifiably live rather than merely correlated with quiet CI. On Controls: One measurement note in case it is useful elsewhere: |
04665 is claimed by two live open PRs (ClickHouse#112846, ClickHouse#112849). The collision is silent: the filenames differ so git reports no conflict, and check_gaps_in_tests_numbers only rejects gaps of 100 or more, never collisions. 04666, 04670, 04674 and 04675 are claimed too, by ClickHouse#112816, ClickHouse#112458 and unpublished branches respectively. Co-Authored-By: Claude Fable 5 <[email protected]>
Support animated PNG in the
PNGformat.If the result has a
tcolumn of an integer type, the format produces an animated PNG (APNG) instead of a still image. Records are grouped into frames by the value oft, which is the relative time offset of the frame. Every frame is an independent image: the canvas is empty at the start of each frame, and in the implicit coordinate mode the cursor restarts from the top-left corner. Thetcolumn can be combined with either coordinate mode.The unit of
tis set by the new settingsoutput_format_image_time_multiplier_seconds(default 1) andoutput_format_image_time_divisor_seconds(default 60), so one unit oftis 1/60 of a second by default. A frame is displayed until the next one begins, and the last frame is displayed for as long as the frame before it.The new setting
output_format_image_streaming_animation(defaultfalse) writes each frame out as soon as the next value oftis seen, instead of buffering all the frames in memory, so a viewer can display the frames while the query is still running. It requirestto be non-decreasing and throws otherwise.It defaults to
falsebecause of a constraint of the format itself: theacTLchunk must precede the firstIDATand must declare the total number of frames, which a forward-only writer does not know. This is why theAPNGmuxer offfmpegseeks back to patchacTLand warns when the output is not seekable; a ClickHouseWriteBuffercannot seek. The streaming mode therefore declares an upper bound rather than the exact count. Measured behaviour of real decoders on such a file:APNGpatch oflibpngemits a non-fatalpng_warning("Number of actual frames fewer than expected")atIEND.SkPngRustCodec::parseAdditionalFrameInfosmaps the frames that never arrive tokIncompleteInput.Pillowreports the declared count and then raisesOSError: Truncated File Readpast the last real frame.With the default
falsethe frame count is exact and the output conforms to the specification.The
sixelprotocol cannot represent an animation at all, and the Kitty graphics protocol animates only through a separate flow of per-frame commands, so both reject a result with atcolumn. Theitermprotocol carries the whole datastream as a single payload, so the frames cannot reach the terminal early there; since that payload is fully buffered before it is sent, the exact frame count is patched intoacTLand the payload conforms to the specification even in the streaming mode.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Support animated PNG in the
PNGoutput format. Atcolumn turns the result of a query into an animation, with the time scale oftset byoutput_format_image_time_multiplier_secondsandoutput_format_image_time_divisor_seconds, andoutput_format_image_streaming_animationto write the frames out as the query produces them instead of buffering them in memory.Version info
26.8.1.1267(included in26.8and later)