Repository navigation
Conversation
The `info` column of `test_results.tsv` is the diagnostic text investigators
read out of CIDB for `Stress test` / `Upgrade check` failures. Its escape codec
was not injective, so that text was silently wrong whenever the payload held a
literal backslash or a single quote.
Root cause: the escape character was never itself escaped. `escape_tsv_info`
encoded `\0 \t \r \n` but not `\`, so an on-disk `\n` meant either an encoded LF
or the payload's own two characters, and the reader (three chained `str.replace`
calls) always resolved it to the former. A fuzzer query `SELECT '\n'` was shown
as a real line break, and `C:\new\table` as `C:<LF>ew<TAB>able`. A sequential
replace chain cannot be made injective at all, because it re-scans its own
output.
The shell producers broke on the same ambiguity from the other side. `escaped()`
emits ClickHouse's `Escaped` rule (which does escape `\`) with a literal
four-character row terminator, and the nine call sites appended the result with
`echo -e`, which collapses one escape level. That collapse was simultaneously
load-bearing, since it turned the four-character terminator into a real
separator and is the only reason multi-line rows read correctly, and
destructive, since it also destroyed every payload backslash, left the
two-character `\'` leaking into the displayed text, and turned an encoded `\t`
back into a real TAB that split the cell. Measured over 30 days, that is 500
rows across three sites carrying a visible `\'`, against a control site whose
`info` does not pass through `escaped()` at 0.
Rather than decode the symptom, remove the second escape layer so there is
nothing to disambiguate:
- `escape_tsv_info` escapes `\` first, before the separators;
- `escaped()` emits a single-level row terminator and its nine call sites
append with `printf "...%s\n"`, so the escaped payload reaches disk
verbatim. `printf` still interprets escapes in its format string, so `$OK`
and `$FAIL` keep producing real tabs, while `%s` passes the payload
through untouched;
- the reader becomes `unescape_tsv_info`, a single-pass exact inverse of the
`Escaped` rule over the alphabet that rule emits (`0 b f n r t \ '`), with
an unrecognised `\X` kept verbatim rather than swallowed.
The reader also stops letting `csv` treat the double quote as structural. That
quote layer was a second undeclared codec on top of the one above: the double
quote is an ordinary character in the `Escaped` rule, so neither producer
escapes it, yet Python's `csv` reads a field-initial `"` as an opening quote.
`"quoted"` arrived as `quoted`, and an unterminated `"` made the reader consume
the two following result rows into that cell while reporting no malformed row
at all, so the `Corrupt test_results.tsv` surfacing could not fire and a real
`Hung check failed` row simply vanished from the report. `quoting=csv.QUOTE_NONE`
leaves the single escape layer as the only one.
After this there is one convention on disk, produced identically by both
producers, and one decoder that inverts it. A real TAB now survives where it
previously split the cell. A real NUL now survives too, and reaches
`Result.info` where the old chain could not produce one: that is safe because
`info` is only displayed and stored, never re-parsed, and none of the failure
patterns matched against it contains a backslash or a quote.
All nine `escaped`-family sites must convert together: a site left on `echo -e`
would keep producing the old ambiguous encoding that the new decoder misreads,
and the resulting failure would be a plausible-looking but wrong diagnostic
string. The 16 sites that keep `echo -e` do so deliberately; their `info` is
constant and they rely on the format-string escapes.
Two regression tests. The first round-trips through the real writer and the real
reader over the shapes that were lost, the shapes that already worked, the
double-quote shapes, and a real shell-produced on-disk cell; it also pins the
row swallow with a three-row fixture. It could not have been added before this
change, since it would have had to encode the lossy behaviour to pass. The
second is a static contract assertion over the two shell files, because no
Python assertion can observe the shell layer: reverting the row terminator, or
returning a single append site to `echo -e`, leaves every other assertion green
while corrupting every shell-produced row.
One transitional window is inherent to any codec change here: a file written by
an old image and read by a new job, or the reverse, decodes under the other
convention for one release. The blast radius is a diagnostic string, never a
verdict.
The shell contract test guarded `format_custom_row_after_delimiter` with a loop over the regex matches, which executes zero times when the setting is absent. It therefore pinned the setting's value but never its existence: deleting the ` settings ...` clause from `escaped()`, or renaming the setting, left every assertion in the file green. That is not hypothetical. `format_custom_row_after_delimiter` defaults to a real newline, so without the explicit two-character literal the helper emits real line feeds, command substitution preserves them, and `printf` writes several physical lines. Measured end-to-end against a real `clickhouse local` with the append statement from `stress_tests.lib`, on a two-line payload: with the setting the row occupies one physical line and both lines survive in `info`; without it the row occupies two, `info` is truncated to the first, and the remainder resurfaces as a malformed row. Half the diagnostic is lost. Count the setting across both shell files and assert the total once. A per-file assertion would be wrong: only `escaped()` sets it, so the count is one in `stress_tests.lib` and zero in `upgrade_runner.sh`. Co-Authored-By: Claude Opus 5 <[email protected]>
The shell contract test banned `echo -e` and required the substring `printf `, but `printf` preserves the escaped payload only because that payload is a `%s` argument. Two degradations keep the substring, keep the site count at nine and keep the row terminator single level, while reintroducing the escape-collapsing layer this branch removes: moving the substitution into the format string, and using `%b` instead of `%s`. Both were measured end to end against a real `clickhouse local`, sourcing `escaped()` from the tree and executing the append statement verbatim. Each turns a one-row, well-formed append into three physical lines with a malformed row, truncates `info` to its first line, and destroys every payload backslash. Neither reddened any committed assertion. So require the shape rather than forbidding the old spelling: each site must carry a double-quoted `printf` format, that format must not itself contain the `escaped`/`head_escaped`/`trim_server_logs` substitution, and it must contain a `%s` conversion. The order matters, because inlining the substitution also removes `%s`; checking for the substitution first is what lets the two degradations report distinct reasons. The existing `echo -e` and `printf ` assertions stay, so a site returned to `echo -e` still fails with its own message. The rule is clean on all nine converted sites and flags all nine on the parent of this branch.
The shell-producer test asserts, per site, that the escaped output is not
appended with `echo -e`, that a double-quoted `printf` format is used, that
the substitution is not inside that format, and that the format carries a
`%s`. Three spellings satisfy every one of those and still corrupt the row,
measured with real bash against the payload shape `escaped()` actually emits:
- dropping the quotes around the substitution splits the payload into words
and writes five rows, each holding one word of what should be one `info`;
- adding a `%b` beside the `%s` writes three physical lines, of which the
parser keeps one with `info` truncated to the first line and reports one
malformed;
- an extra operand makes `printf` reuse the format and write two rows, the
second carrying the operand as its `info`.
Nothing else in the repository would catch them: there is no shellcheck run,
`upgrade_runner.sh` disables SC2086 globally, and the two files already carry
four unquoted command substitutions, so the first spelling is native to them.
A rule over spellings cannot enumerate the corrupting forms, so assert the
outcome instead. The new test extracts each of the nine real append statements
from the scripts, joining backslash continuations and normalising a leading
`&&`/`||` and an enclosing subshell's trailing `)`, runs it under bash with the
three producer helpers stubbed to `printf '%s'` and the output redirected to a
temporary file, then requires exactly one physical line, one parsed row, no
malformed rows, and an `info` equal to the payload with its terminators decoded
to real line feeds. The site count is asserted so the scan cannot silently
cover fewer. The stub keeps this independent of a `clickhouse` binary, a server
and the network, which is verified rather than assumed.
The static test is kept byte for byte: it is what gives the terminator value, a
deleted `settings` clause and a renamed setting their own failure messages, and
the stub bypasses `escaped()` so the new test is blind to all three. The two are
complementary. `ci/tests/test_upgrade_runner_download_boundary.py` guards the
same shell file the same way and is the precedent followed here.
Internal second-model reviewEach finding below was adjudicated against the code, with the measurement that settled it.
Verified with no finding, independently of the author's evidence. The decoder's alphabet is One interaction with an open sibling, surfaced rather than left to CI. #113428 adds |
Pre-PR validation gate (click to expand)
Eight mutation arms each revert exactly one part of the fix and each reddens for its own reason.
Session id: cron:clickhouse-impl-slot-40:20260807-151200 |
|
cc @maxknv @alexey-milovidov, could you review this? The |
`Stress test (*)` and `Upgrade check (*)` never redirected the stress script's output, so it reached only the job console and `test_results.tsv` recorded the exit status alone. In the 30 days to 2026-08-09 all 152 `Test script failed` rows carried a byte-identical ` script exit code: 1`, so the family could not be triaged from the CI database; reading three of those job logs gave two unrelated causes. The script is now redirected to a capture outside `/test_output`, which is uploaded wholesale, and mirrored to the console with `tail --pid`. It is not piped: `prepare_for_hung_check` drops databases with a fire-and-forget `Popen(..., shell=True)` that inherits the wrapper's stdout, and a pipe reader waits for those clients long after the script exits, which timed the job out at 10800 s. The exit code is `$?` after `wait`, and the tail of the capture goes into the `info` cell of the row the wrapper already emitted. Those clients can also append after the script exits while the mirror ends with it, so the wrapper waits for the capture to stop growing and then prints the bytes the mirror missed. The wait is a bounded size poll rather than a wait on the descriptor, since that is what deadlocked the pipe form, and the flush offset is the mirror's own byte count because the file size afterwards can already include unmirrored bytes. `escaped()` pre-compensates its row terminator for `echo -e`, which collapses one escape level, so a `printf '%s'` caller would get a backslash before every decoded newline. `escaped_tail()` is its single-level sibling and `escaped()` is untouched. The reader decodes `\t`, `\r` and `\n` only, so a byte the `Escaped` rule encodes but it does not keeps a visible backslash; ClickHouse#113857 makes the codec reversible. This fixes visibility, not the trigger. Related: ClickHouse#113857 Co-Authored-By: Claude Fable 5 <[email protected]>
|
Workflow [PR], commit [bde3aee] Summary: ❌
AI ReviewSummaryThis PR makes the Findings
Final VerdictChanges requested until the codec contract has runnable regression coverage again. |
CI finish ledger - 25dd035Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task whose
I am not merging master to pick the fix up on this branch. Session id: cron:our-pr-ci-monitor:20260827-233000 |
The only conflict was a modify/delete on ci/tests/test_stress_job.py: this branch added three tests to it, and ClickHouse#115650 removed the whole ci/tests suite together with the CI Tests job that ran it (ci/jobs/ci_tests_job.py, JobConfigs.ci_tests, JobNames.CI_TESTS and the pull_request.py entry). The file, the suite and the runner are all gone on master, so the deletion is taken as-is rather than relocating the tests to a new home: that would be re-adding coverage a maintainer had just removed on the stated grounds that it pins CI-script internals instead of observable behaviour. The production fix is unchanged. Verified rather than assumed: the added-line and removed-line sets of the four production files are byte-identical before and after the merge (61 added, 22 removed), the merged tree leaves zero echo -e sites that append a command-substituted escaped payload, and master added no new site of that kind (its three new echo -e sites in upgrade_runner.sh write a constant info). No submodule pin moves relative to master.
|
Merged master. The only conflict was a modify/delete on The fix itself is untouched, and I checked that rather than assuming it: the added-line and removed-line sets of the four production files are byte-identical before and after the merge (61 and 22), no |
| } | ||
|
|
||
|
|
||
| def unescape_tsv_info(text: str) -> str: |
There was a problem hiding this comment.
This PR changes a three-part codec contract: escape_tsv_info, the escaped()/head_escaped() shell producers, and read_test_results(). After ci/tests/test_stress_job.py was deleted, there is no executable coverage left in the tree that exercises that round trip end to end. That is risky here because regressions do not reliably fail closed: a drift in one producer can still leave the first TSV fields parseable and quietly corrupt only info, which is exactly the failure mode this patch is trying to eliminate. Please move at least the focused round-trip cases into a suite that still runs before merging the production change alone.
There was a problem hiding this comment.
You are right about the mechanism: a drift in one producer corrupts only info while the first three fields stay parseable, so the job still passes. That asymmetry is what this change removes, and I am not claiming CI would fail closed on a regression of it.
The move itself is not available, which the description already records. On master 88f51c8dbe08 the directory holds 0 files and its runner went with it: ci_tests_job, JobConfigs.ci_tests, JobNames.CI_TESTS and the ci/workflows/pull_request.py entry all resolve to 0 references, against a control of stress_job at 10 files. That was #115650 (merged 2026-08-30T00:35:29Z) and #117138 (merged 2026-08-30T12:22:02Z), both by @ alexey-milovidov, on the stated grounds that the suite pinned "the internals of CI scripts rather than their observable behavior" and that AI bots had re-added the tests in previous attempts. No other in-tree home runs either: tests/ci/ has 0 test files, and the test_*.py files left under ci/ are job entrypoints or __main__ scripts with 0 def test_ and no invoker. Moving the same internals-pinning cases to a new path is that suite again under a different filename, so where such coverage should live is a maintainer's call rather than mine.
The round trip does run end to end in the job that owns it: ci/jobs/stress_job.py:198 runs stress_runner.sh, which sources stress_tests.lib, and the same job reads the file back at :239 through unescape_tsv_info. Nine Stress test jobs are in flight on this head.
Before taking the deletion I validated the codec out of tree: a 15-payload corpus (13 lost data before the change and none after, with 6 rows previously swallowed whole), a 21-case escape-alphabet matrix, and a five-arm mutation matrix in which reverting the writer, the reader, the escaped terminator, one echo -e append site, or the quote entry each reddens.
CI finish ledger - 6dadc6cEvery failure below has an owner: a fixing PR (ours or external), or a full-effort fix task whose
Nothing here touches this PR's change. The evidence that it is a trunk condition rather than this Session id: cron:our-pr-ci-monitor:20260830-160000 |
|
Fixing PR for the Not caused by this PR. The failure has hit every |
CI finish ledger - bde3aeeEvery failure below has an owner: a fixing PR, or a full-effort fix task whose fixing-PR link is
Session id: cron:our-pr-ci-monitor:20260831-040000 |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Description
The
infocolumn oftest_results.tsvis the diagnostic text investigators read out of CIDB forStress test/Upgrade checkfailures. Its escape codec was not reversible, so that text wassilently wrong whenever the payload held a backslash.
Root cause: the escape character was never itself escaped.
escape_tsv_infoencoded\0 \t \r \nbut not\, so an on-disk\nmeant either an encoded LF or the payload's own two characters,and the reader always chose the former.
C:\new\tablewas shown asC:<LF>ew<TAB>able.The shell producers broke on the same ambiguity:
escaped()emits a literal four-character rowterminator, and its nine call sites appended it with
echo -e, which collapses one escape level.That destroyed every payload backslash and left
\'leaking, on 500 rows over 30 days.The change removes the second escape layer rather than decoding its symptoms.
escape_tsv_infoescapes
\first;escaped()emits a single-level terminator and its nine call sites append withprintf "...%s\n"; the reader becomes a single-pass exact inverse of theEscapedrule, and stopsletting
csvtreat"as structural. A real TAB now survives, and\0\b\fdecode to realbytes instead of staying two characters, which is safe because
infois only displayed, neverre-parsed. The
echo -esites left untouched all write a constantinfo.Validation. A three-test regression case over 15 payloads: on master 13 lose data and 6 rows
vanish entirely; after the fix, none. Encoding growth on a real 309 KB
hung_check.logis +2characters.
Those tests lived in
ci/tests/test_stress_job.py, which #115650 removed along with the rest ofci/tests/and theCI Testsjob that ran it. I took that deletion rather than relocating them,which would re-add coverage that PR deliberately removed, so this ships the production change alone.
Workflow [PR]
Sync PR [sync-upstream/pr/113857]