Skip to content

progress_dashboard: publish text through a unique temp file - #4492

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
bobcatchris:fix/dashboard-unique-temp
Nov 23, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
bobcatchris:fix/dashboard-unique-temp

Conversation

@bobcatchris

Copy link
Copy Markdown
Contributor

Self-found CPU-only BUILD item, claimed narrowly on the coordination board (comment). This is not BUILD-1283 (D3D item counts) or the treemap-palette item; it changes only save_text().

What was wrong

tools/progress_dashboard.py::save_text() wrote through the fixed name path + ".tmp". If a stale directory or a concurrent dashboard run held that name, open(..., "w") raised PermissionError and an otherwise valid progress.html/JSON could not be refreshed.

What changed

  • Publish from tempfile.mkstemp in the output directory, keeping atomic os.replace().
  • Preserve the published mode with file_mode.published_mode().
  • Restore 0600 in the failure path before unlinking, so a read-only destination cannot strand a temp file on Windows.
  • Add a synthetic regression that plants a directory at the old fixed name.

Tested

Windows, Python 3.12, no GPU/game data:

  • python -I tests/test_progress_dashboard.py: 27/27 OK (26/27 before the tool change; only the new case failed with PermissionError).
  • python -I -m compileall -q on both changed files: exit 0.

AI-assisted. No game files, keys or decryption.

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

Ran this at a59a9baf on Windows 11: python -I tests/test_progress_dashboard.py -> 27 tests, OK; git diff --check clean.

The dashboard's text output is published through a unique temp file and rename; the existing tests pass. No blocking issue.

@mrbean56

Copy link
Copy Markdown

Tested a59a9baf81 on Linux (Debian 13), Python 3.13.5: pass.

  • pytest tests/test_progress_dashboard.py -q: 27 passed, 6 subtests passed.
  • Negative control: with main's tools/progress_dashboard.py and this test file, test_save_text_refreshes_when_fixed_temp_name_is_a_directory fails, so the test pins it.
  • Independently: a file created 0640 keeps 0640 after save_text (an existing file's bits are reused), a new file gets the directory's umask-derived 0664, mkstemp leaves no .tmp after success, and when os.replace fails (destination is a directory) the temp file is gone and the exception propagates. tools/file_mode.py is already on main, so this has no hidden PR dependency.
  • The unique temp name in the same directory is what keeps os.replace atomic; two concurrent writers now resolve last-wins instead of fighting over one .tmp name.

No GPU, no game data. AI-assisted.

@Atomic258

Copy link
Copy Markdown
Contributor

Tested a59a9baf on Linux, Python 3.10, CPU only, synthetic fixtures, no game files: pass.

  • python -I tests/test_progress_dashboard.py → 27/27 pass.
  • Negative control: on main the new test fails with IsADirectoryError on report.json.tmp — exactly the blocked-refresh case.
  • Read: mkstemp in the destination directory keeps os.replace atomic, published_mode restores visibility, and the cleanup path unlinks the temp after forcing it writable for Windows. git diff --check and check_no_game_data.py clean.

AI-assisted (Devin).

@kapitche

Copy link
Copy Markdown
Contributor

Tested a59a9ba merged with main 03b09a0 on Linux (WSL2), Python 3.12.16: pass. tests/test_progress_dashboard.py 27 tests OK; tests/test_text_write_line_endings.py OK. Negative control: tools/progress_dashboard.py restored from main with the PR test kept -> FAILED (errors=1, the new stale-.tmp-directory test). Also by hand (umask 022): a new file gets 0644, and overwriting a 0640 file keeps 0640, with only the destination left in the directory. Diff read: mkstemp in the destination directory, mode copied via file_mode.published_mode, the temp is removed on any failure; the file_mode import goes through the same sys.path.insert pattern other tools use. No concerns.

@ItsNotRexed
ItsNotRexed merged commit 2758d7d into ItsNotRexed:main Nov 23, 2026
2 checks passed
@memorypressure

Copy link
Copy Markdown

Merges cleanly into main 3faac55. All 27 tests pass under python -I and pytest, and your new case is a genuine regression test — dropped into a clean main worktree it fails with IsADirectoryError on the fixed .tmp name, green with your per-PID fix (re-run both sides). The write pins encoding and newline, published_mode is the existing helper, and nothing else consumes the old fixed tmp name. One nit: the cleanup does chmod then unlink inside a single except OSError, so a chmod failure skips the unlink and leaks the staging file — the same shape flagged in #4516, and main's tools/saves.py cleanup has it too (confirmed in main's source), so a repo-wide split into separate try/except blocks would be the tidy fix. Checks were still queued. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run).

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants