Repository navigation
Conversation
praktika's state files are per-directory: Settings.TEMP_DIR (./ci/tmp) holds job.log, environment.json and result_<job>.json, and nothing arbitrates access to them. A second run in the same checkout therefore overwrites the state of the one already running. On PR ClickHouse#116044 that happened for real. The Code Review job's review agent runs with -s workspace-write and elected to verify the PR by running a nested `python3 -m ci.praktika run "integration" ...` inside the live job's own checkout. Three things followed: - __main__.py opens RUN_LOG in "w" mode, truncating job.log while the outer writer still held a large offset, so the kernel zero-filled the hole. 82% of the uploaded job.log was NUL, which also made the failure hard to triage (the system grep classifies the file as binary and prints nothing). - generate_local_run_environment rewrote environment.json with JOB_NAME="integration" and an empty JOB_KV_DATA. _Environment.get() re-reads that file on every call and caches nothing, so the clobber was permanent. - The outer job then wrote its real, successful result under the wrong filename, because Result.create_from() falls back to the clobbered JOB_NAME. result_code_review.json stayed PENDING, so praktika truthfully reported "Job killed or terminated, no Result provided" for a job that had already posted its full review, and the resulting not-ok status opened the Slack-feed branch where the erased commit_authors raised TypeError: 'NoneType' object is not iterable. Take the temp directory as a non-blocking flock at the top of the run branch and hold it for the invocation. The placement is load-bearing: workflow discovery itself writes environment.json (_Environment.get() creates and dumps it when absent, on both fallback branches), so a lock taken just before the log open would leave a real window uncovered. It is also independent of --ci, since a nested --ci run truncates the log and rewrites JOB_NAME just the same. Scoping by resolved directory rather than by process ancestry is deliberate: an inherited marker would miss a concurrent run from an unrelated shell in the same checkout, would wrongly reject a safe run in a different checkout, and is set too late to cover pre_hooks. A kernel lock also releases on SIGKILL, which matters because praktika killpg's its own children on timeout. Only BlockingIOError is treated as contention; every other OSError propagates with its own errno, since Utils.exit_with_error discards the original exception and would otherwise turn an unsupported filesystem or a permission fault into a permanent and false "another run is using this directory". This mirrors StatusFile.cpp, which special-cases EWOULDBLOCK the same way and throws from errno otherwise. Validated with an A/B harness against a throwaway temp directory: without the change the outer log ends 96.8% NUL with its prefix broken, with the change 0% and byte-identical, and an arming assertion confirms the nested run reached the truncating open in the first arm and not in the second. Also measured: the three shared files are byte-identical after a refusal; an absent environment.json stays absent (an unlocked control does create it); a fresh checkout with the directory absent proceeds; --ci refuses too; an unrelated setsid holder is caught; a pre_hook-shaped child refuses while its parent proceeds; a different temp directory proceeds; a SIGKILLed holder leaves no stale lock; mode "a" does not truncate a pre-existing lock file; and the lock is visible across a docker bind mount, so run_in_docker jobs are covered as well. The unguarded iteration over commit_authors is deliberately left as is: with the clobber prevented, an absent key means malformed state and should keep failing loudly rather than being silently defaulted. The conditional store in native_jobs.py is not the cause either, since _Environment seeds that key unconditionally on both the Config-job and no-Config-job paths and the real job log shows it present and empty. No automated test accompanies this: an arm under ci/tests would be removed along with that directory.
Internal second-model review (click to expand)An independent cold review plus a second-model gate ran against this diff before it was
Additional checks the review made independently of the change's own evidence:
|
|
Workflow [PR], commit [ff791fe] Summary: ❌
AI ReviewSummaryThis PR prevents concurrent Tests
Final VerdictRequest changes: the implementation looks sound, but the missing regression test leaves an important CI-corruption fix unpinned. |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-40:20260824-121800 |
|
cc @maxknv, could you review this? A |
| # discovery below already writes environment.json, so the lock precedes it. | ||
| temp_dir = Path(Settings.TEMP_DIR).resolve() | ||
| os.makedirs(temp_dir, exist_ok=True) | ||
| lock_file = open(temp_dir / ".praktika.lock", "a") |
There was a problem hiding this comment.
The new refusal path is one of the rare praktika run fixes that is cheap to lock down with an automated test, because it fires before workflow discovery or any real job setup. A focused ci/tests case can hold .praktika.lock in a helper process, monkeypatch Settings.TEMP_DIR to a temporary directory, call ci.praktika.__main__.main(), and assert that it exits with this error instead of touching the workflow loader.
Right now the only proof of the guard lives in the PR description. Without a regression test here, a later refactor of the run prologue can silently re-open the job.log / environment.json clobber this PR is fixing.
There was a problem hiding this comment.
Agreed on the fact: this guard has no automated regression test, and a later refactor of the run prologue could re-open the clobber silently. That risk is real and correctly identified.
I am declining the remedy, because it names ci/tests. That directory is being removed: #115650 ("Remove ci/tests (attempt 2)") deletes it wholesale (68 files, -22,695 lines), including the CI Tests job wiring in ci/defs/job_configs.py, and the standing instruction from @ alexey-milovidov is "We don't use ci/tests, they will be removed." A cell added there would be deleted with the rest.
There is also no sanctioned alternative home for a praktika-level assertion today: 31 of the 32 pytest files in this repo that import praktika live in ci/tests, and the only other one is vendored (contrib/silk). So I am leaving the guard covered by the manual arms recorded in the PR description, and stating the coverage loss there rather than putting the assertion somewhere unsanctioned.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
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. Compile time of recompiled translation units6 translation units recompiled, 4 s compile time in total, 6 of them have a recent master baseline. |
|
fix is comming in ai review job. it must not allow it. |
CI finish ledger - ff791feEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Not caused by this PR: my diff is one file (
Session id: cron:our-pr-ci-monitor:20260824-160000 |
|
Understood, and I will not reopen or re-push. One scope note for the job-side fix: the clobber is not specific to the integration job the agent tried to run. |
|
This recurred on 2026-09-23. The Same mechanism as here. At 18:06:15Z the codex agent ran While looking for your job-side fix I found So I do not think the choice is mine, @maxknv. Which would you prefer?
I have option 2 planned and I will not push anything until you say which one you want. |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Description
On PR #116044 the
Code Reviewjob posted its full review, then went red anyway: praktikareported
Job killed or terminated, no Result provided, the step exited 1 withTypeError: 'NoneType' object is not iterable, and 82% of its ownjob.logwas NUL.The job's review agent runs with
-s workspace-writeand elected to verify the PR by runninga nested
python3 -m ci.praktika run "integration" ...inside the live job's own checkout.praktika's state files are per-directory (
Settings.TEMP_DIR, i.e../ci/tmp), so the nestedrun wrote over the outer job's files. It opens
RUN_LOGin"w"mode, truncatingjob.logwhile the outer writer still held a large offset, and the kernel zero-filled the hole - that
is the NUL log. It also rewrote
environment.jsonwith its ownJOB_NAMEand an emptyJOB_KV_DATA, and_Environment.get()re-reads that file on every call, so the clobber waspermanent: the outer job wrote its real result under the wrong filename,
result_code_review.jsonstayedPENDING, and praktika truthfully reported no result. Thatnot-ok result opened the Slack-feed branch, where the erased
commit_authorsraised theTypeError.This takes the temp directory as a non-blocking
flockat the top of therunbranch, heldfor the invocation, so a second run against the same directory refuses at once while a run in
any other checkout is unaffected. It sits before workflow discovery, which already writes
environment.json. OnlyBlockingIOErroris contention; any otherOSErrorpropagates,mirroring
StatusFile.cpp.A/B harness: without the change the outer log ends 96.8% NUL, with it 0% and byte-identical.
Refusal is independent of
--ci, coverspre_hooks, and survivesSIGKILL. Blast radius isbounded: each job step already runs
rm -rf ./ci/tmpbeforepraktika runandflockisper-inode, so a leaked lock cannot block the next job, and the empty lock file changes no
digest.
Validation matrix and deliberate omissions
open(RUN_LOG, "w")(arming assertion)environment.jsonstays absentFileNotFoundError--cisetsidsibling holderpre_hooksshape (child of the holder)SIGKILLed"a")BlockingIOError11 vs plainOSError9, uncaughtBUSY11; holder killed:ACQUIRED/,.., symlink)rm -rf ./ci/tmpTwo adjacent changes are deliberately not made. The unguarded
for commit_author in commit_authorsis left alone: with the clobber prevented, an absentcommit_authorsmeans malformed state and should keep failing loudly. The conditional storein
native_jobs.pyis not the cause -_Environmentseeds that key unconditionally on boththe Config-job and no-Config-job paths, and the real job log shows it present and empty.
No automated test is added: a
ci/tests/arm would be removed with that directory.Workflow [PR]
Sync PR [sync-upstream/pr/116121]