Skip to content

Review skill: check the lifetime of what jobs on other threads use - #128365

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:review-skill-jobs-on-other-threads
Nov 1, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:review-skill-jobs-on-other-threads

Conversation

@groeneai

@groeneai groeneai commented Oct 31, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #127911
Related: #126625
Related: #95818

Changelog category (leave one):

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

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Not required: changes only the agent instructions in .claude/.

Description

Asked for in #127911 (comment).

  • The review skill gets a triggered check for jobs on other threads: everything a job uses, including a lambda it calls, must outlive the join on every exit, including a later schedule that throws.
  • A re-review covers the code changed since the previous review, fixes included, not only whether earlier findings are resolved.
  • .claude/CLAUDE.md gets the same lifetime rule for authors.

Why: the last round of #126625 moved the job body into a closure declared after the pool and called by the jobs through [&], so a later schedule that threw destroyed it before the pool joined them (ASan stack-use-after-scope, fixed by #127911). The AI review approved that round with "the prior findings are addressed"; the Stress tests, which rarely inject thread creation failures, were green.

Validation: applied literally, the check flags the code of #126625 and passes the #127911 fix and two sites fixed by #95818. It also flags S3TablesCatalog::getTables, which declares tables and mutex after the runner whose jobs capture them by reference (RestCatalog::getTables declares them before); I did not change it in this PR.


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

Version info

  • Merged into: 26.11.1.995-master (included in 26.11 and later)

Add three rules to the agent instructions:

- `.claude/skills/review/SKILL.md`, triggered expansion "Jobs on other
  threads": list everything a scheduled job uses, including a lambda or
  `std::function` it calls, and check that each outlives the join on
  every exit after the first schedule (a later schedule throws, the
  scheduling thread throws while doing its own share, an early return).
  The joiner is declared after everything the jobs use, and a closure
  that refers to the pool is captured by value.
- Same file, "A fix is new code": a re-review covers the code changed
  since the previous review, including the fixes for earlier findings,
  with the same gates as the first review.
- `.claude/CLAUDE.md`: the same lifetime rule for authors.

The last round of ClickHouse#126625 moved the job body of
`loadStatisticsOfPartsInParallel` into a closure declared after the
pool, called by the jobs through `[&]`. A later schedule that threw
destroyed the closure before the pool joined the jobs (fixed by
ClickHouse#127911). The AI review approved that round with "the prior findings
are addressed", and Stress tests, the only ones that inject thread
creation failures broadly, were green on the final head.

Asked for in
ClickHouse#127911 (comment)

The reply there listed "`wait` rethrows" as an exit; it is not in the
rule because `ThreadPool::wait` and
`waitForAllToFinishAndRethrowFirstError` join all jobs before
rethrowing.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 0 findings) plus my own review (3 nits, not blocking).

# Sev Finding Verdict Evidence / action
1 💡 The trigger list does not name threadPoolCallbackRunnerUnsafe AGREE, noted Covered by the trigger's general clause ("schedules work that runs on another thread and is joined later"); not changed
2 💡 "reached mostly through rare thread-creation fault injection" is exact for a failing schedule, looser for the other two exits AGREE, noted Thread-creation fault injection is installed only by ci/jobs/scripts/stress/stress.py; not changed
3 💡 .claude/CLAUDE.md says "a later scheduling throws", the skill says "a later schedule throws" AGREE, noted Wording only; not changed

Severity: ❌ blocker / ⚠️ major / 💡 nit.

Session id: cron:clickhouse-review-slot-9:20261031-112200

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? N/A as a runtime repro (agent instructions only). The deterministic check: the new rule, applied literally to loadStatisticsOfPartsInParallel at the final head of #126625, flags load_parts (declared after pool, called by the jobs through [&]).
b Root cause explained? The author declared the pool after the data the jobs use but not after the closure they call, and [&] hid it. The re-review of that round checked the earlier findings only. The exit is reached only under rare thread creation fault injection in Stress tests.
c Fix matches root cause? Yes: the reviewer rule goes in .claude/skills/review/SKILL.md, which the CI review job and local reviews follow; the author rule goes in .claude/CLAUDE.md.
d Test intent preserved / new tests added? No test: agent-instruction change, validated locally (no tests for test infrastructure, #119766).
e Both directions demonstrated? Desk check: flags #126625's code and S3TablesCatalog::getTables; passes the #127911 fix, two sites fixed by #95818, and RestCatalog::getTables.
f Fix is general across code paths? Covers ThreadPool (all three schedule calls), ThreadPoolCallbackRunnerLocal, ThreadFromGlobalPool, scope guards as joiners, locals and members, and closures or std::function a job calls.
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A (no runtime inputs).
h Backward compatible? (maintainer-approved exception only) Yes: text only, no build, setting, format or CI behaviour change.
i Invariants and contracts preserved? Insertions only; existing rules, headers and order unchanged.

Session id: cron:clickhouse-impl-slot-4:20261031-110300

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @Algunenano, could you review this and add the can be tested label so CI runs? It adds a triggered review-skill check that everything a job on another thread uses, including a lambda it calls through [&], outlives the join on every exit (the #126625 bug class, also fixed by #95818), and makes a re-review cover the fixes made since the previous round.

@clickhouse-gh

clickhouse-gh Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [7cb8f1c]

Summary: ✅


AI Review

Summary

PR #128365, reviewed at 7cb8f1cafeb1b391e062a672e64ed96e4b4ee98c, adds guidance to check asynchronous job lifetimes on exceptional exits and to review fixes as new code. No actionable findings in this instructions-only change.

Final Verdict

Status: ✅ Approve.

@clickhouse-gh clickhouse-gh Bot added pr-ci comp-documentation Documentation (docs, examples, READMEs). labels Oct 31, 2026
@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Oct 31, 2026

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sounds good!

@alexey-milovidov alexey-milovidov self-assigned this Oct 31, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 31, 2026
Merged via the queue into ClickHouse:master with commit f760cbb Nov 1, 2026
529 of 531 checks passed
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 1, 2026
@clickhouse-gh clickhouse-gh Bot added comp-ai-tooling Tooling of AI coding agents in the repository: skills, hooks, permission settings, instructions a... and removed comp-documentation Documentation (docs, examples, READMEs). labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-ai-tooling Tooling of AI coding agents in the repository: skills, hooks, permission settings, instructions a... 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.

3 participants