Skip to content

Fix the NightlyChangelog job running out of its GitHub token - #116138

Merged
alexey-milovidov merged 3 commits into
masterfrom
fix-nightly-changelog-token-expiry
Aug 25, 2026
Merged

alexey-milovidov merged 3 commits into
masterfrom
fix-nightly-changelog-token-expiry

Conversation

@alexey-milovidov

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

Copy link
Copy Markdown
Member

The NightlyChangelog job has not updated #111720 since 2026-08-13. Every run since then ends with

RuntimeError: Failed to push auto/changelog-26.8

preceded by HTTP 401: Bad credentials from every gh call in the second half of the run (run of 2026-08-24).

The token expires mid-run. The GitHub App installation token is valid for an hour; the runs take 1h12m to 1h43m. The job does try to refresh it before each editing attempt and before creating the pull request, but GHAuth.auth mints at most once per process unless force is set, so those calls have always been no-ops - and there was no refresh before the push at all. On 2026-08-24 the token was minted at 02:50:30, the first Bad credentials appeared at 03:47:57, and the push failed at 04:32:17. This change mints a fresh token in every step that talks to GitHub (changelog.py, each editing attempt, the revert resolution of the edit verification, the push, the pull request lookup, the per-version processing) through a refresh_gh_token helper.

What pushed the runs past the hour is prepare repository: the CI checkout is shallow, and git fetch --unshallow origin used the default refspec, pulling every branch of the repository along with the history - 30 to 36 minutes of every run. It now fetches only the master refspec.

Fetching just the commit graph (--filter=tree:0) would make this 12 seconds instead, and I tried that first, but it is not safe: it leaves the checkout a partial clone, and tests/ci/changelog.py runs its own bare git fetch --tags inside the style-test container with stderr discarded, which then never returns. A manually dispatched run of this branch (32747225427) confirmed both halves: prepare repository finished in 16 seconds, and the job then sat in Fetching all tags from 15:53 to 20:52 until praktika's 5-hour job timeout killed it, pushing nothing. So the filter is out, and the token refresh - not a faster fetch - is what makes the job survive.

That run also showed that an unbounded docker run turns a hung git operation into a five-hour job that pushes nothing, so the generation now has a 40-minute timeout: the step fails, the job proceeds to the push, and the raw entries still land.

Once the push works again, the raw entries land on the branch and the Changelog-generated-up-to: trailer advances, which also ends the loop where each night regenerated a bigger block than the night before (579 entries on 2026-08-24 instead of the usual ~50) and therefore took even longer.

Master has since deleted the ci/tests/*.py suite (3a69545dc04, "we don't have automated CI tests"), so this branch merges master and drops the tests it had added; the changed steps were verified with a throwaway script instead — both fetches restricted to the master refspec with no filter, no --unshallow on a complete repository, the push minting a fresh token while "nothing to push" mints none, and the container run carrying the 40-minute timeout.

Not fixed here: the editing step has been failing its own fail-closed verification since 2026-08-12 (Entries disappeared in the edit without a matching revert). That is a separate problem - the run of 2026-08-12 finished inside the hour with a valid token and still failed. This change makes the raw entries reach the pull request again while that is investigated.

Related: #111720
Related: #111255
Related: #111220

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

Workflow [PR]
Sync PR [sync-upstream/pr/116138]

Version info

  • Merged into: 26.9.1.58 (included in 26.9 and later)

The `NightlyChangelog` job has not updated
#111720 since 2026-08-13: every
run since then fails with

    RuntimeError: Failed to push auto/changelog-26.8

preceded by `HTTP 401: Bad credentials` from every `gh` call in the second
half of the run.

The GitHub App installation token is valid for an hour, and a run is much
longer than that (1h12m to 1h43m in the last ten days). The job does try to
refresh it before the editing attempts and before creating the pull request,
but `GHAuth.auth` mints a token at most once per process unless `force` is
set, so those calls have always been no-ops, and there was no refresh before
the push at all. In the run of 2026-08-24 the token was minted at 02:50:30,
the first `Bad credentials` appeared at 03:47:57, and the push failed at
04:32:17.

Mint a fresh token in every step that talks to GitHub - `changelog.py`, each
editing attempt, the revert resolution of the edit verification, the push,
the pull request lookup, and the per-version processing - through a
`refresh_gh_token` helper that passes `force=True`.

What made the runs cross the one-hour mark is `prepare repository`: the CI
checkout is shallow, and `git fetch --unshallow origin` pulled the trees and
blobs of the entire history plus every branch, which took 30 to 36 minutes of
each run. The job only walks the commit graph (the range from the cycle start
tag to master), so fetch the commits without contents: `--filter=tree:0`
against the master refspec only, the same way praktika unshallows the
repository for its own jobs. The few old file versions the job does read are
fetched lazily from the promisor remote.

With the push working again, the raw entries land on the branch and the
`Changelog-generated-up-to:` trailer advances, which also ends the loop where
each night regenerated a bigger block than the night before (579 entries on
2026-08-24 instead of the usual ~50) and so took even longer.

The editing step itself has been failing its own fail-closed verification
since 2026-08-12 (`Entries disappeared in the edit without a matching
revert`), which is a separate problem: that run finished inside the hour with
a valid token. This change makes the raw entries reach the pull request again
while that is investigated.

Related: #111255
Related: #111220
The dispatched run
https://github.com/ClickHouse/ClickHouse/actions/runs/32747225427 showed both
sides of the fetch change. `git fetch --unshallow --filter=tree:0` took 12
seconds instead of 30 minutes, and `prepare repository` went from ~38 minutes
to 16 seconds - but it leaves the checkout a partial clone
(`remote.origin.promisor=true`), and `tests/ci/changelog.py` runs its own
bare `git fetch --tags` inside the style-test container, with `stderr`
discarded. That fetch never returned: the job sat in `Fetching all tags` from
15:53 to 20:52, when praktika's 5-hour job timeout killed it, and nothing was
pushed.

Fetch the history with its contents again, but keep the restriction to the
master refspec (the default refspec pulled every branch of the repository as
well). The token refresh is what fixes the failure this branch is about; the
fetch no longer has to fit into the lifetime of a token.

Bound the generation, too: an unbounded `docker run` turned a hung git
operation into a five-hour job that pushed nothing. With a timeout the step
fails, the job goes on to the push, and the raw entries still land.
…og-token-expiry

# Conflicts:
#	ci/tests/test_changelog_nightly.py
@clickhouse-gh

clickhouse-gh Bot commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [4c5232a]

Summary: ✅


AI Review

Summary

This PR refreshes the NightlyChangelog GitHub App token before each GitHub-facing step, narrows prepare_repo fetches to the master refspec, and adds a timeout around the changelog.py container run. The token-refresh path looks reasonable, but the new timeout does not implement the behavior promised in the PR description: a timed-out generation still skips push_branch, so the job still publishes nothing in that failure mode.

Missing context / blind spots
  • ⚠️ At review time the only concrete CI evidence on PR #116138 was Config Workflow and Style check; the generated CI Tests and Code Review reports were still pending or skipped, so the changed control flow is being validated here by code inspection rather than an exercised CI path.
Findings
  • ⚠️ Majors
    • [ci/jobs/changelog_nightly.py:546] The new generation timeout only shortens a hung changelog.py run; it does not make the raw entries "still land". When Shell.check(...) returns False here, generate_raw_entries raises, _step(...) makes ok = False, and the if ok: guards in process_version skip both the edit and push steps. The exact failure the PR describes therefore still ends with "push nothing", just after about 40 minutes instead of at the 5-hour job timeout.
Tests
  • ⚠️ There is no focused check for the timeout path through process_version. A small unit-style test that forces generate_raw_entries to fail and then asserts the intended push_branch decision would prove the contract and would have caught this mismatch.
Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required actions: either implement the promised behavior for a timed-out generation, or change the code comments and PR description so they no longer claim that raw entries still get pushed in that case. If the behavior is kept, add the smallest focused check that drives the timeout/failure path through process_version and proves the intended push decision.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Aug 25, 2026
f"-e GH_TOKEN --network=host --volume=$(pwd):/wd --workdir=/wd "
f"{STYLE_TEST_IMAGE} sh -c {shlex.quote(cmd)}",
verbose=True,
timeout=GENERATE_TIMEOUT_SEC,

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.

This timeout does not actually implement the behavior described in the PR text/comments. When Shell.check(...) returns False here, generate_raw_entries raises, _step(...) in process_version sets ok = False, and the later if ok: guards skip both the edit and push paths. In other words, a hung changelog.py still ends with "push nothing"; the only change is that it fails after about 40 minutes instead of the 5-hour job timeout.

If the intent is to keep the raw commit visible when long follow-up work fails, the timeout needs to apply after the generate commit exists. If the intent is only to cap wall-clock time, the code comments and PR description should stop claiming that the raw entries "still land" on a generation timeout.

@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.

LGTM

@alexey-milovidov alexey-milovidov self-assigned this Aug 25, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Aug 25, 2026
Merged via the queue into master with commit d557eeb Aug 25, 2026
180 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-nightly-changelog-token-expiry branch August 25, 2026 02:01
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 25, 2026
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-ci 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.

2 participants