Skip to content

Revert "Fix propagation of settings in accurateCastOrDefault" - #114911

Merged
alexey-milovidov merged 1 commit into
masterfrom
revert-109946-respect-settings-accurate-cast-or-default
Aug 15, 2026
Merged

alexey-milovidov merged 1 commit into
masterfrom
revert-109946-respect-settings-accurate-cast-or-default

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Aug 15, 2026 •

Copy link
Copy Markdown
Member

Reverts #109946

Version info

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

@alexey-milovidov alexey-milovidov self-assigned this Aug 15, 2026
@alexey-milovidov
alexey-milovidov merged commit c8959f8 into master Aug 15, 2026
1 check failed
@alexey-milovidov
alexey-milovidov deleted the revert-109946-respect-settings-accurate-cast-or-default branch August 15, 2026 00:51
@clickhouse-gh

clickhouse-gh Bot commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [d960fbc]

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Aug 15, 2026
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 15, 2026
@clickgapai

Copy link
Copy Markdown
Contributor

The Context has expired LOGICAL_ERROR this PR reverts is still on the 26.7 branch (backport #114689) and has four open backports — flagging so the revert reaches them before the next patch releases.

Reproducer
CREATE TABLE t (s String, ip IPv6 MATERIALIZED toIPv6OrDefault(s)) ENGINE = MergeTree ORDER BY tuple();
INSERT INTO t (s) VALUES ('::1');
-- Code: 49. DB::Exception: Context has expired: while executing function toIPv6OrDefault

Any stored expression using to<Type>OrDefault / accurateCastOrDefault (MATERIALIZED default, MATERIALIZE COLUMN, ALTER … UPDATE) hits it: #109946 stored the CastOverloadResolver — which holds only a weak_ptr<const Context> — in FunctionCastOrDefault and calls build() at execute time, after the analyzing context is gone.

Affected versions (verified by running the reproducer on CI builds):

build result
master fb565a7d (last build before #109946) clean
master aef28dd2 (after #109946, before this revert) reproduces
master c8959f88 (this revert) clean
26.7 branch tip 8fbb09e3 (26.7.4.44, carries backport #114689) reproduces
released 26.7.3.19 / 26.6.2.160 / 26.5.6.113 / 26.3.17.110 / 25.8.29.51 clean (all predate the backport)

No published release carries the bug yet. The next 26.7 patch release will, and the open backports of #109946 (#114688 → 26.6, #114687 → 26.5, #114686 → 26.3, #114685 → 25.8) would ship it to the other maintained branches.

Next step: revert backport #114689 on the 26.7 branch (or backport this revert to it), and close #114685/#114686/#114687/#114688 unless #109946 is re-landed with a fix.

CC introducer author: @Avogar

Analysis metadata

comp-functions · Finding phase_d_pr114911

alexey-milovidov added a commit to groeneai/ClickHouse that referenced this pull request Aug 17, 2026
The `-- MATERIALIZED default whose cast overflows` arm took its expected
value from `toDateTimeOrDefault`, so it asserted that a `to<Type>OrDefault`
function honours `date_time_overflow_behavior`. That only holds while
ClickHouse#109946 is in the tree. It is reverted on master by ClickHouse#114911, where
`FunctionCastOrDefault` goes back to `castColumnAccurateOrNull` with a null
context and therefore always saturates. The arm passes on this pull
request's base, which predates the revert, and fails against master:

  2149-06-06  2013-04-29 17:31:44   expected, wrap-around
  2149-06-06  2106-02-06 00:00:00   actual, saturating

That is why the private sync reported this test as the only new failure,
in every stateless job it ran in, while the public checks stayed green.

Spelling the conversion as an explicit `CAST` pins the arm to
`CastOverloadResolverImpl`, which is what this change is about, and makes
it read the same before and after the revert. Verified against three
binaries - master `d59f2be34ed3` with the revert in effect, this pull
request's head, and the private sync build - all of which reproduce the
reference byte for byte. The reference file is unchanged.

Related: ClickHouse#109946
Related: ClickHouse#114911
Related: ClickHouse#114912

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
alexey-milovidov added a commit that referenced this pull request Aug 24, 2026
Edited following .claude/skills/edit-changelog/SKILL.md, by hand on a
workstation: the editing step of the NightlyChangelog job has been failing
its own verification since 2026-08-12, so three raw blocks had accumulated
(47 + 84 + 628 entries).

Of the 759 raw entries, 482 are integrated into the in-progress 26.8 section
and 277 are dropped:

- Section 3: the 300 `NOT FOR CHANGELOG / INSIGNIFICANT` entries are dropped,
  except 41 that describe a user-visible change and are promoted into a real
  category, among them a server abort on a corrupt `ORC` stripe footer
  (#114924), `EXPLAIN ANALYZE` for streaming queries (#112445), `SELECT` from
  `TimeSeries` (#115622), streaming watermarks (#106169), and the
  `clickhouse-local` CORS overrides (#115129).
- Section 2: every revert in the range cancels out inside it, so neither side
  appears. Two are re-applications: #114912 re-applies the
  `accurateCastOrDefault` fix, so #109946 keeps its entry with both links and
  the intervening revert #114911 is gone; #114409 re-applies the PromQL
  streaming plan, recorded on the #113656 entry.
- Section 4: `Build/Testing/Packaging Improvement` keeps the seven entries a
  user, packager or from-source builder notices (musl `getaddrinfo` and
  `sched_getcpu`, signed macOS artifacts, Debian packages for release builds
  only, zstd-compressed Docker layers, `unit_tests_dbms` without the full
  library set, vendored Rust built with optimizations locally) and drops the
  CI plumbing.
- Sections 5 and 6: bare pull request URLs converted to links, settings put
  in backticks, four entries rewritten from developer notes into user-visible
  descriptions, and three moved into `Performance Improvement`.

No entry of a strict-retention category was deleted: the job's own
`verify_edit` passes on this edit.

Not done here, because the release manager does it at release time: the full
significance sort, the aggressive merging of sibling pull requests, and the
`FIXME` release date and presentation links.
alexey-milovidov added a commit that referenced this pull request Aug 27, 2026
Address review: `resolve_reverted_originals` granted deletion credit to every
raw-block revert with a `Reverts owner/repo#N` marker, even when that revert
was itself reverted later in the same range — so an edit dropping `#109946`
(reverted by `#114911`, which `#114912` reverted in turn) still passed
verification while the fix ships in the release.

Now the resolved reverts are walked in descending PR-number order (a revert
always has a higher number than its target): an uncancelled revert cancels
the reverts it targets and only uncancelled reverts contribute deletion
credit. Because a revert of a revert made through the web UI can lack the
body marker (`#114912` has none), the target is also resolved from the
nested title — `Revert "Revert "X""` binds to the earlier range revert
titled `Revert "X"`.

PR: #116221

Co-Authored-By: Claude Fable 5 <[email protected]>
alexey-milovidov added a commit that referenced this pull request Aug 28, 2026
`verify_edit` was only net-effect aware inside one raw block, while the job
edits a release cycle in ~30 nightly increments and a revert chain routinely
spans them:

1. run N integrates `#109946`;
2. run N+1 sees `#114911` and deletes `#109946`;
3. run N+2 sees only raw `#114912`.

On run N+2 nothing disappears in the edit — `#109946` went away the previous
day — so verification passed with a shipped fix missing from `CHANGELOG.md`,
and the editing agent had no way to know the entry ever existed: it is gone
from the file, and the intervening revert is gone from the raw blocks.

The branch now carries that memory itself, in trailers on its own edit
commits, the same way `Changelog-generated-up-to:` carries the generation
point:

    Changelog-revert: <revert> <reverted> <title of the revert>
    Changelog-deleted-entry: <pull request> <its bullet as it was deleted>

`analyze_reverts` resolves each run's reverts against that ledger and reduces
the *cumulative* graph, so a chain spread over several runs behaves exactly
like one arriving in a single raw block, at any depth:

- the reduction is what decides deletion credit, so a cancelled revert
  licenses nothing;
- an entry recorded as deleted whose revert is no longer uncancelled has to
  be back in `CHANGELOG.md` — `verify_edit` fails the run while it is not,
  and the prompt asks for it by name, quoting the bullet from the ledger;
- the recorded titles also let a web-UI `Revert "Revert "X""` (which carries
  no `Reverts owner/repo#N` marker) bind to an earlier revert the job saw
  days ago.

A branch whose edit commits predate the trailers has an empty ledger and
keeps the previous behaviour.

`ci/tests/test_changelog_nightly_revert_ledger.py` pins the timelines: the
whole chain in one block, the revert alone, the revert of the revert arriving
after the deletion, a revert of the re-apply, an empty ledger, and an
unresolvable revert.
alexey-milovidov added a commit that referenced this pull request Aug 28, 2026
`reapplied_by` walked one level out from the direct remover, so it found the
revert that first put a change back and stopped there. With
`#109946` ← `#114911` ← `#114912` ← `#115500` ← `#116000` — out, back, out,
back, all inside one cycle — it reported only `#114912`, which the recorded
bullet already carried from the first restoration. The re-apply check was
therefore satisfied by the stale line and `#116000` was lost for good: a
revert of a revert has no bullet of its own, so the link on the entry is its
only trace in the release.

`revert_chain` now walks the whole chain above the entry, and the uncancelled
reverts of that chain are the ones that ship, so they are the ones that belong
on the bullet. `removed_by` is the complement — the cancelled ones — which also
makes the prompt name both removals of a repeated cycle instead of the first.
The three-pull-request case is unchanged: one remover, one re-applier.

The prompt asks for the links of every re-applier, noting that some may
already be on the recorded line from an earlier restoration.

`test_a_longer_chain_records_every_reapply` walks the five-pull-request
timeline and asserts `removed_by == ['114911', '115500']`,
`reapplied_by == ['114912', '116000']`, that replaying the recorded line is
rejected for missing `#116000`, and that appending it passes. It fails with
the one-level walk.
alexey-milovidov added a commit that referenced this pull request Aug 28, 2026
…llow them

Two fail-open paths, both from the verifier only ever checking one direction.

**`credits` allowed a deletion but never required it.** An uncancelled revert
made the disappearance of an entry acceptable; leaving the entry in place was
acceptable too, so a change that is out of the release could be published. The
`withheld` check now covers all of `credits`, not only the entries an earlier
run had already deleted: a revert arriving today licenses a deletion the agent
still has to make. With the fix and its revert in one raw block, keeping the
entry now fails with `Entries whose revert still stands are in the in-progress
section (['#109946 (reverted by #114911)'])`.

**The re-apply link was only required of entries being restored.** When the
whole chain arrives in one raw block the entry never left the section, so
`missing` is empty and the link went unchecked - the same loss as before, by a
different route. The requirement is now stated for every entry that ships and
was ever reverted, and checked wherever that entry sits. The prompt gets the
matching "Entries to amend" list, so it asks for exactly what the verifier
requires; the cancelled revert left visible next to such an entry is caught by
the first fix.

Two tests added, the ones the review asked for, plus the "cancelled revert
still visible" variant. `changelog()` in the tests now builds a raw block with
several `#### Category` sections, the shape the generator really emits, so the
same-range case can put the fix under a strict category and its revert under
`NO CL ENTRY`.
valerypetrov pushed a commit to valerypetrov/ClickHouse that referenced this pull request Aug 28, 2026
The editing step of the `NightlyChangelog` job has been failing its own
verification every night since 2026-08-12, always the same way:

    Entries disappeared in the edit without a matching revert (['103182', '109946'])

`verify_edit` requires that every raw entry of a strict-retention category
keeps its pull request link - an entry may be rewritten, merged or moved, but
not dropped, because the generation point has already moved past it and no
later run will offer it again. The prompt never said so, and the skill stated
the rule only implicitly, so the agent pruned entries it judged
insignificant: `ClickHouse#103182` (`Lightweight Updates v2`, a `Backward Incompatible
Change`) was deleted outright.

The second half of the same failure is the revert handling. `ClickHouse#109946` fixed
the propagation of settings in `accurateCastOrDefault`, `ClickHouse#114911` reverted
it, and `ClickHouse#114912` reverted that revert - all three in one range. The skill
covers this in section 2.5, but the agent reached the "landed and then
reverted, so delete both" rule first and lost a fix that ships.

So:

- The prompt now lists the strict-retention categories (from
  `STRICT_RETENTION_CATEGORIES`, so the two cannot drift apart), says which
  entries may be deleted and why deleting anything else is unrecoverable, and
  states the revert-of-revert rule.
- The skill gets a retention rule ahead of the individual edits, and the
  walk over `NO CL ENTRY` checks whether a revert is itself reverted before
  it concludes that a change was reverted. The `accurateCastOrDefault` chain
  is written out there as the worked example.
- A retry now tells the agent why the previous attempt was rejected. Without
  it, all three attempts of a run reproduced the same edit and the same
  rejection - visible in every run from 2026-08-12 on.

A hand edit that followed these rules passed `verify_edit` on the first try,
which is how the 26.8 backlog (759 raw entries) was cleared in
ClickHouse#111720.

Related: ClickHouse#111720
Related: ClickHouse#116138
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.

3 participants