Skip to content

Disambiguate processors in the ExecutingGraph::addEdge exception - #112745

Merged
alexey-milovidov merged 12 commits into
masterfrom
addedge-exception-uniq-id
Aug 9, 2026
Merged

alexey-milovidov merged 12 commits into
masterfrom
addedge-exception-uniq-id

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Jul 31, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

Description

When ExecutingGraph::addEdge finds a connected peer that is missing from the list of processors, the thrown LOGICAL_ERROR ("Processor {} was found as {} for processor {}, but not found in list of processors") named both endpoints of the broken edge via getName, which is ambiguous when several processors share a name. Identify each endpoint by getUniqID (the name plus the per-thread processor index) and its address instead. Both processors are alive at this point — the missing peer was merely never added to the collection — so the dereference is safe.

The address is what makes the diagnostic unconditional: getUniqID disambiguates only while CurrentThread is initialized, and IProcessor otherwise assigns processor_index = 0 to every processor, so outside a query thread the message would degrade back to ambiguous Foo_0 identifiers. The address also lets the reader match the endpoints against the pipeline dump that the PipelineExecutor constructor appends to the exception: printPipeline gained an opt-in with_addresses flag, enabled only on this diagnostic path, that labels every node with the same {uniqID} at {address} format. It is off by default, so user-facing output such as EXPLAIN PIPELINE keeps stable labels.

This is the follow-up promised in the review of #110955, which removed the rendering of out-of-collection peers from printPipeline (that rendering dereferenced a potentially dangling peer). For the malformed-graph path in the PipelineExecutor constructor, the numeric suffix that the removed rendering used to provide is now carried by the exception message itself.

A gtest covers the message contract in the degraded, no-CurrentThread context:

Processor NullSink_0 at 0xe910b9170018 was found as output for processor SourceFromSingleChunk_0 at 0xe910cb890198, but not found in list of processors

Related: #110955

Version info

  • Merged into: 26.8.1.1060 (included in 26.8 and later)

When `ExecutingGraph::addEdge` finds a connected peer that is missing from
the list of processors, the thrown `LOGICAL_ERROR` named both endpoints of
the broken edge via `getName`, which is ambiguous when several processors
share a name. Use `getUniqID` (the name plus the per-thread processor
index) for both endpoints instead; both processors are alive at this
point, so the call is safe. This recovers the disambiguation previously
provided by the out-of-set node rendering that was removed from
`printPipeline` in #110955.

Related: #110955

Co-Authored-By: Claude Fable 5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [0190155]

Summary: ✅


AI Review

Summary

This PR makes the malformed-pipeline diagnostic from ExecutingGraph::addEdge actionable again by identifying endpoints as {uniqID} at {address} and by using the same labels in the appended printPipeline dump. On the current head, the previously raised review concerns are addressed, the added regression test covers the no-CurrentThread path that motivated the fix, and I did not find any remaining correctness, compatibility, or evidence gaps in the touched code.

Final Verdict
  • Status: ✅ Approve

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.60% 86.60% +0.00%
Functions 91.90% 91.90% +0.00%
Branches 78.80% 78.80% +0.00%

Changed lines: Changed C/C++ lines covered: 57/57 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Jul 31, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 80.90% 86.50% +5.60%
Functions 91.40% 91.90% +0.50%
Branches 72.90% 78.60% +5.70%

Changed lines: Changed C/C++ lines covered: 2/7 (28.57%) · Uncovered code

Full report · Diff report

…sage

The review of #112745 asked for focused coverage of the only observable
contract of the change: when `ExecutingGraph::addEdge` finds a connected
peer that is missing from the list of processors, the thrown
`LOGICAL_ERROR` must name both endpoints via `getUniqID` (distinct
per-thread `_N` suffixes), not the ambiguous `getName`. The test builds a
source connected to a sink that is deliberately omitted from the list of
processors and asserts the exception message contains both `getUniqID`
values. In debug and sanitizer builds, where a logical error aborts at the
throw site, the same contract is pinned through a death test matching the
abort message.

Co-Authored-By: Claude Fable 5 <[email protected]>
`getUniqID` distinguishes repeated processor classes only while `CurrentThread`
is initialized. Outside a query thread `IProcessor` assigns `processor_index = 0`
to every processor, so the malformed-graph diagnostic degraded back to ambiguous
`Foo_0` identifiers. Print the processor address alongside `getUniqID`, which
keeps the two endpoints of the broken edge distinguishable in every context and
lets the reader match them against a pipeline dump.

The regression test no longer manufactures a `ThreadStatus`: it now runs in
exactly the degraded context and still observes two distinct identifiers. That
also fixes the interference the manufactured status caused in the shared unit
test binary - the local `ThreadStatus` reset `current_thread` to null on
destruction, which broke every later test on the main thread that expects an
initialized status (`LimitByTransform.ClearsOutputSlicesWhenTransformThrows` and
`LimitBySortedStreamTransform.ClearsOutputSlicesWhenTransformThrows` failed with
`Thread #N status was not initialized`).

The death test matches the shape of the message rather than the parent process's
exact addresses, because the `threadsafe` style re-executes the test binary.
`Unit tests (asan_ubsan)`, `(tsan)` and `(msan)` failed with `Syntax error at
index 19 in simple regular expression ...: '[' is unsupported` — ClickHouse
builds googletest with `GTEST_HAS_POSIX_RE=0`, so `EXPECT_DEATH` patterns are
matched by gtest's own simple engine, which supports neither character classes
nor `\d`.

Use only `.` and `*`, which both engines accept. Verified against the simple
engine directly (`testing::internal::RE::PartialMatch` compiled with
`GTEST_HAS_POSIX_RE=0`): the observed message matches, and a message naming the
same processor for both endpoints does not.
@clickhouse-gh

clickhouse-gh Bot commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 019015563 with master c8cea90a1 (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 2999ffda7; compile times per translation unit against the most recent warmup build that recompiled it).

⚠️ Significant changes: compile time of recompiled translation units.

Binary sizes
Binary Master PR Δ
programs/clickhouse-stripped 690.38 MiB 687.39 MiB -2.99 MiB (-0.43%)

Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction.

Object file sizes

509 object files changed (+306.95 KiB total), 1 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Processors/Formats/Impl/HiveTextRowOutputFormat.cpp.o new 148.12 KiB +148.12 KiB
src/CMakeFiles/dbms.dir/DataTypes/Serializations/SerializationMap.cpp.o 2.16 MiB 2.18 MiB +21.09 KiB (+0.96%)
src/CMakeFiles/dbms.dir/DataTypes/Serializations/SerializationArray.cpp.o 228.85 KiB 249.85 KiB +21.00 KiB (+9.18%)
src/CMakeFiles/dbms.dir/DataTypes/Serializations/SerializationTuple.cpp.o 271.66 KiB 292.33 KiB +20.66 KiB (+7.61%)

737 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units ⚠️

565 translation units recompiled, 629 s compile time in total, 15 of them have a recent master baseline.

Translation units without a recent master baseline:

  • contrib/llvm-project-cmake/__/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp: 26.0 s
  • contrib/llvm-project-cmake/__/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp: 10.7 s
  • contrib/vectorscan-cmake/__/vectorscan/src/nfagraph/ng_violet.cpp: 6.6 s
  • contrib/llvm-project-cmake/__/llvm-project/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp: 6.3 s
  • contrib/wasmedge-cmake/__/wasmedge/lib/executor/instantiate/component/component.cpp: 5.9 s
  • contrib/llvm-project-cmake/__/llvm-project/llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp: 5.9 s
  • contrib/ai-sdk-cpp-cmake/__/ai-sdk-cpp/src/providers/openai/openai_factory.cpp: 5.8 s
  • contrib/s2geometry-cmake/__/s2geometry/src/s2/s2builder.cc: 5.7 s
  • contrib/llvm-project-cmake/__/llvm-project/llvm/utils/TableGen/GlobalISelEmitter.cpp: 5.6 s
  • contrib/wasmedge-cmake/__/wasmedge/lib/executor/engine/threadInstr.cpp: 5.4 s
  • contrib/wasmedge-cmake/__/wasmedge/lib/executor/instantiate/table.cpp: 5.3 s
  • contrib/vectorscan-cmake/__/vectorscan/src/rose/rose_build_program.cpp: 5.1 s

Job report

alexey-milovidov and others added 2 commits August 4, 2026 03:43
…esses

The exception from `ExecutingGraph::addEdge` names both endpoints as
`{uniqID} at {address}`, but the pipeline dump that `PipelineExecutor`
appends to it labelled nodes with `getUniqID` only. When `CurrentThread`
is not initialized, `getUniqID` degrades to the `_0` suffix for every
processor, so repeated processor classes in the dump could not be matched
against the endpoints named by the exception.

Add an opt-in `with_addresses` flag to `printPipeline`, enabled only on
this diagnostic path, so the dump uses the same `{uniqID} at {address}`
labels. It stays off by default because addresses are unstable noise in
user-facing output such as `EXPLAIN PIPELINE`. The gtest now also asserts
that the source description reappears verbatim in the appended dump.

Co-Authored-By: Claude Fable 5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=112745&sha=026079509fe2ed66e663d9fe1e30621e34b67f3a&name_0=PR&name_1=AST%20fuzzer%20%28arm_asan_ubsan%29 and provide a fix in a separate PR. If the fix is already in progress, link it here.

The failure is the logical error Reading from materialized CTE 't' before its materialization completed - DelayedPortsProcessor gate is missing in the query plan on a twice-referenced materialized CTE — tracked by the open issue #113184, which has no fix PR yet. It is unrelated to this PR (the diff only changes the ExecutingGraph::addEdge exception message and the malformed-pipeline dump labels).

For the record, the other two reds on this head are the known ColumnBLOB should be converted to a regular column before usage logical error, tracked by #113165 with the open fix #111997, and Fast test (arm_darwin) was cancelled by runner infrastructure with zero test failures.

@groeneai

groeneai commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

Investigated. It is the shape tracked by #113184, and that issue still has no fix PR, so I am authoring one and will link it here.

Identity. The abort site is MemorySource::generate at src/Processors/QueryPlan/ReadFromMemoryStorageStep.cpp:87, the fail-fast invariant that #108924 itself introduced and retained. Same message, same STID 2467-2c2d.

#113184 is live. Its reproducer aborts deterministically for me on a debug build of current master (91687a7d610e6ee), on a single server with test_shard_localhost:

Logical error: 'Reading from materialized CTE 'ct' before its materialization completed -
DelayedPortsProcessor gate is missing in the query plan'.

One thing worth adding to #113184. Its "required ingredients" list says the twice-referenced materialized CTE must appear twice in the join tree. The carrier here does not: t is referenced twice from two IN-set subqueries (x GLOBAL NOT IN (SELECT ... FROM t) and x IN (SELECT c FROM t)), with no join-tree duplication and no explicit Distributed table in the query text. I ran nine reduction arms around that text (plain MergeTree, merge('^t1$'), merge('.*'), a Distributed table read directly, and the CTE itself reading Distributed, each with and without GLOBAL) and none of them trip the gate, so the Distributed ingredient is most likely supplied by whatever merge('.*') resolved to in the fuzzer's own database rather than being absent. That means the gate-missing channel is reachable without the join-tree double reference, which is a slightly wider precondition than the issue currently records, and it is what my fix has to cover.

It is unrelated to this PR, as you say: no frame in the stack is below ExecutingGraph::addEdge or the pipeline dump.

On the other two, nothing to add beyond a status note: #111997 is mine and still open awaiting review.

@groeneai

groeneai commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

The fix PR promised above is #113489. It targets the shape #113184 tracks: a materialized CTE that reads a Distributed table and is filtered by IN (another materialized CTE), referenced more than once.

Root cause is a build-order interaction rather than a missing check. addBuildSubqueriesForMaterializedCTEsIfNeeded built the CTEs' plans in forward dependency-level order, so a containing CTE's body was planned while its deeper dependency still had no plan. Planning that body recursively builds nested plans (the shard-local plan for the Distributed read, the IN-set source), and their own collectMaterializedCTEs only collects a subquery-less, name-resolved reference once the CTE is plan-backed (CollectMaterializedCTE.cpp:44, the rule #108924 added), so those plans got no DelayedMaterializingCTEsStep. buildOrderedSetInplace then ran such a plan as a standalone pipeline, where no gate from any other plan can apply, so the reader ran before the writer and the fail-fast check fired. The PR builds the plans deepest level first, which makes that existing predicate true in time instead of weakening it. CollectMaterializedCTE.cpp and the fail-fast throw are untouched.

One thing to be explicit about, since I raised the carrier here: #113489 does not fix the failure on this PR. I re-ran your carrier on both binaries, against a schema whose merge('.*') expansion includes a Distributed table, and it returns the same correct value either way, so it does not reproduce for me at all and the fix cannot be credited with it. Its CTE body has no nested CTE, so it is a different shape inside the same STID. The PR body states that rather than implying family-wide coverage.

That also caps what I can say about the precondition I flagged earlier. Every shape I can reproduce duplicates the outer CTE in the join tree or in a UNION ALL; my nine reduction arms around your query text reproduced nothing. So the observation that your carrier lacks join-tree duplication still stands on the CI occurrence itself, not on anything I could reproduce locally, and I have no measurement that widens #113184's ingredient list. I am not asking for that issue to be edited on my account.

This PR remains unrelated to the failure, as you said.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 @groeneai, investigate two unrelated CI failures seen on the previous head (0b82dcb6) of this PR and provide fixes in separate PRs. If a fix is already in progress, link it here.

  1. AST fuzzer (amd_debug, targeted): logical error Invalid number of columns in chunk pushed to OutputPort. Expected 0, found 1 (STID: 2270-3258) on SELECT DISTINCT cume_dist() IGNORE NULLS OVER (RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) FROM remote(..., view(...)) SETTINGS max_block_size = 1. The CI database shows this STID hitting ~12 unrelated PRs since 2026-08-03, and there is no tracking issue for this STID (the existing issues Logical error: Invalid number of columns in chunk pushed to OutputPort. Expected A, found B (STID: 2270-3452) #96656 and Logical error: Invalid number of columns in chunk pushed to OutputPort. Expected A, found B (STID: 2270-32ca) #103695 are the same message family but different STIDs).

  2. Stress test (arm_debug): logical error Not-ready Set is passed as the second argument for function 'in' (STID: 0250-4e52). The exact-STID auto-issue Logical error: Not-ready Set is passed as the second argument for function 'A (STID: 0250-4e52) #102803 was closed on 2026-07-12, but the failure has been recurring on master and unrelated PRs since 2026-08-01 (per the CI database), so the shape is live again and currently unowned — please check whether the open Fix materialized CTE gate missing for a reused CTE over Distributed #113489 covers it, and if not, reopen or re-file the tracking issue.

The third red on that head, 02122_join_group_by_timeout, is a transient timing flake (all 9 reruns passed) — no action needed there. This PR's diff only touches the ExecutingGraph::addEdge diagnostics and printPipeline labelling, so none of these are caused here.

@groeneai

groeneai commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

Investigated both. Confirming your reading of the artifacts on each, with one correction on item 2.

1. STID 2270-3258 — fixed by an open PR of mine, #113469

No new PR needed. #113469 ("Fix lost rows and LOGICAL_ERROR for a window function over a distributed table with no referenced column") fixes your carrier.

cume_dist() references no column of the table expression, so prepareBuildQueryPlanForTableExpression reads one synthetic column purely to learn the row count (src/Planner/PlannerJoinTree.cpp:686). The window function is deferred to the initiator along with the projection that would have consumed that column, so it is pruned. The view(...) produces a constant, so the shard keeps one column while the initiator expects none, and RemoteSource::prepare raises the error — hence your empty Header: against Chunk: Nullable(size = 1, Nothing(size = 1), UInt8(size = 1)).

Measured on a real two-shard server, your exact query with only the port rewritten. Fix arm is #113469's head f477b0013b5050b, build id asserted against SELECT lower(buildId()); its marker symbol is present there and absent in the master snapshot, with the error string present in both.

carrier pristine master #113469
your cume_dist() query abort; message, Chunk: line and frames identical to your report, including RemoteSource.cpp:102 returns 1, 0 fatals
#113510 DENSE_RANK, #113266 row_number, #112930 cluster()+rank, #113469's own fuzzer hit abort clean

Five of six carriers I tried discriminate. The sixth (#112871) did not reproduce for me, but that is my paraphrase of the fuzzed query losing the shape, not evidence about coverage.

Breadth over 40 days on the exact STID: 15 rows, 14 PRs, 0 master — close to your ~12 since 2026-08-03, and every row is the analyzer shape. One limit I am not claiming past: the same message is also reachable through the old interpreter, and #113469's locus is analyzer-only, so that shape is deliberately out of scope there.

No tracking issue: confirmed. 2270-3258 returns nothing, and #96656 is 2270-3452 while #103695 is 2270-32ca — same message family, different STIDs, as you say. I would rather not open one while the fix is in review; say the word if you want it filed anyway and I will attach the measurements above.

2. STID 0250-4e52 — #113489 does not cover it; the live shape is already tracked by open #107619

(a) #113489 does not cover it. It is the materialized-CTE build-order fix, whose symptom is Reading from materialized CTE ... DelayedPortsProcessor gate is missing. Your stack carries no CTE frame: in.cpp:116 -> IFunction -> ExpressionActions.cpp:693/837 -> FilterTransform -> plain pipeline executor. Across all 95 rows of this STID in 40 days, rows with a materialized-CTE frame: 0; with FunctionIn::executeImpl: 95.

(b) I suggest not reopening #102803, on two measurements:

  • antaljanosbenjamin's repro from that issue (null_in_subquery, i GLOBAL NOT IN (...), his settings) now returns the asserted 66668 on pristine master with no logical error. The closure was correct for the shape it was filed for; what recurs is a different producer sharing the STID.
  • The STID identifies an architecture, not a defect. Over 40 days 0250-4e52 is 97 arm rows and 0 amd; 0250-41a5 is 161 amd / 39 arm; 0250-3e49 is 37 arm. No check_name produces both 4e52 and 41a5, and the function name does not split them either (each carries in, nullIn, globalIn, notNullIn alike). Logical error: Not-ready Set is passed as the second argument for function 'A (STID: 0250-41a5) #107619's stack, STID 0250-41a5 and open, is the same chain frame for frame with only line drift — and it is the larger half at 197 rows / 158 PRs / 12 master, against 95 / 87 / 7 here.

Your "live again" reading is right: 36 rows after #102803 closed, 18 since 2026-08-01, 7 master hits, most recently 7ca487f2 on 2026-08-03. The latest occurrence anywhere is 2026-08-06 07:13Z, nine minutes before your comment.

So my preference is to record this arm_debug occurrence and the arch measurement on #107619 rather than reopen. If you would rather have one tracker per architecture, say so and I will file it — creating or reopening issues is the one thing I hold for your confirmation.

On the fix side, the residual after your merged #107924 is the GLOBAL IN / GLOBAL JOIN external-table branch it excludes by design (the !set_and_key->external_table guard in PreparedSets.cpp). Your open draft #102308 deletes that exclusion, and I posted my analysis there on 2026-08-01 rather than open a competing PR on the identical hunk. That branch accounts for 2 of the 7 master hits (globalIn, globalNotIn); the other 5 are the local in / nullIn path, tracked under #107619.

Agreed on 02122_join_group_by_timeout, and that none of the three is caused by this PR's diff.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Both CI failures on the current head (48f96667) are unrelated to this PR (the diff only touches the ExecutingGraph::addEdge exception message, the printPipeline dump labels, and two gtests) and both already have open fixes:

  1. Stress test (arm_tsan) — Logical error in IColumn::assertTypeEquality via HashJoin buildAdditionalFilter (STID 2508-30f6). A chronic master flake spiking since 08-04 (25–55 failures/day across dozens of unrelated PRs and master itself, per the CIDB checks table). Owner: open PR Fix a mixed JOIN ON condition evaluated over mismatched column types for a dictionary #113534 (mixed JOIN ON condition evaluated over mismatched column types).
  2. AST fuzzer (amd_tsan) — Logical error: Shard number is greater than shard count (STID 5066-457d) from a parallel-replicas viewExplain fuzz query. Also hits master and unrelated PRs daily since at least 08-03. Owner: open PR Bind the parallel replicas shard scope to the cluster that produced it #113589 (bind the parallel replicas shard scope to the cluster that produced it).

Neither fix has landed on master yet, so there is nothing to pull in by re-merging. Review state is clean: zero unresolved threads and the AI verdict on this head is ✅ No new findings.

@alexey-milovidov alexey-milovidov left a comment •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds fishy. I don't like it. Merging only because the EXPLAIN ANALYZE feature is new and I don't like having bugs.

@alexey-milovidov alexey-milovidov self-assigned this Aug 9, 2026
@alexey-milovidov
alexey-milovidov requested a review from Fgrtue August 9, 2026 22:36
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Aug 9, 2026
Merged via the queue into master with commit f6850db Aug 9, 2026
180 checks passed
@alexey-milovidov
alexey-milovidov deleted the addedge-exception-uniq-id branch August 9, 2026 23:20
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 10, 2026

@Fgrtue Fgrtue left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should have used the id that we store in the node of the graph. Because the id that we store in the node is actually the same number that we use when dumping the processors when calling get_proc_id.

If we would like to, we could also print a message like this Processor n{ProcId} AggregatingTransform_X has output port 2 (might be useful for debugging) connected to o0 NullSink, which is not in the list of processors. See n17 and o0 in the pipeline dump below. And after that in principal we could also have printed the additional edge in the dump in DOT format, showing where exactly there should have been the edge.

This probably would make the UI much more friendly for debugging, and also would allow not to have the problems with tracking the address of the processor, which is very tedious in the bulk of text.

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

Labels

pr-not-for-changelog This PR should not be mentioned in the changelog pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants