Repository navigation
Studio: skip the startup manifest migration scan when nothing changed since a clean pass - #16270
Conversation
… since the last clean pass
…arker check fails
|
@codex review |
1 similar comment
|
@codex review |
|
@codex review |
1 similar comment
|
@codex review |
|
@codex review |
1 similar comment
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 334d8bf73f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| # Any ordinary v2 record makes the pass unclean, migrated or not. | ||
| clean = False |
There was a problem hiding this comment.
Avoid recording a clean pass after manifest read failures
If an ordinary v2 manifest temporarily cannot be opened, _read_migration_payload() catches the OSError and returns None, so the scan continues without setting clean = False. Once the directories are old enough, this records a clean marker despite leaving that manifest unmigrated. Restoring read access (for example, with chmod) does not change the containing directory's mtime, so subsequent startups skip migration indefinitely until another manifest write invalidates the marker. Distinguish read failures from non-v2 payloads and prevent marker creation after a failed read.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 9338e57: OSError now propagates from the payload reader, so the per-file handler marks the pass unclean and no marker is written; regression test added.
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9338e576a1
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if clean: | ||
| try: | ||
| _record_clean_migration(parent, before, started_ns) |
There was a problem hiding this comment.
Prevent clean markers after directory enumeration failures
If an existing cache-* scope temporarily lacks directory-listing permission, _migration_manifest_paths() silently yields no files from it because Path.glob() suppresses the permission error. The fingerprint can still stat that directory, so an otherwise settled pass writes a clean marker despite leaving its v2 manifests unmigrated. Restoring permissions does not change the directory mtime, and subsequent startups therefore skip migration indefinitely. The file-read fix does not cover this path: the directory enumeration fails before _read_migration_payload() is called. Use enumeration that propagates failures, or explicitly verify each scope was successfully enumerated before recording the pass.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 16bf40b: enumeration now uses os.scandir per directory, a cache scope that cannot be listed is recorded and blocks the marker while the other scopes still migrate; regression tests added (monkeypatched and real chmod).
…ope cannot be listed [skip ci]
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Delightful! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
pre-commit.ci run |
# Conflicts: # studio/backend/hub/utils/download_manifest.py
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Nice work! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
…scan reads (unslothai#16556) ## What changes Follow-up to unslothai#16270. The downgrade migration scan (`_migration_manifest_paths`) matches `cache-*` scope folders on the case-folded name on Windows, as pathlib's glob does. The fingerprint that decides whether a later start can skip that scan (`_migration_fingerprint`) matched `cache-` case-sensitively. A scope folder whose on-disk name is spelled differently (for example `Cache-...`) was therefore scanned but never fingerprinted: a v2 manifest written into it after a clean pass moved no recorded mtime, and later starts skipped it. The fingerprint now uses the same name match as the scan (one `_folded` helper shared by `_listed` and the fingerprint), and the `os.scandir` it uses is closed with a `with` block. On Linux and macOS nothing changes (no folding there, same as the scan). Studio itself only creates lowercase `cache-<digest>` folders, so this only matters for a folder created or renamed outside Studio. ## Tests - New `test_scope_matched_only_when_folded_is_fingerprinted` (folding forced on so it runs on every OS): after a clean pass with a `Cache-Hand` scope, the marker records `Cache-Hand`, and a manifest written into it later is read by the next start. It fails on main (`'Cache-Hand' not in` the recorded dirs) and passes here. - `tests/test_manifest_migration_marker.py`: 21 passed. - Every backend test file importing `download_manifest`: 1929 passed, 1 skipped, and the same single failure as main (`test_cached_gguf_routes.py::test_pipeline_class_guard_passes_every_shipped_family`, unrelated). ## Not covered - Not run on a real Windows host; folding is simulated by patching `_folded`. The scan side already folds on Windows on main.
Studio: skip the startup manifest downgrade scan when nothing changed since the last clean pass
What changes
Every backend start runs
migrate_ordinary_v2_manifests_for_downgrade()inside the lifespan, before the server answers anything. It globs every Hub download manifest, stats each one and reads a 256 byte prefix to find ordinary v2 records to rewrite as v1. On a home with thousands of manifests that is the largest single lifespan step, and it competes for the GIL with the hardware detection thread, so it costs far more in the server than in isolation (about 65 us per file in the server vs 12 us standalone).The scan now records a clean pass and skips itself on the next start when nothing it depends on has changed:
hub-state/manifest_migration.jsonwith the mtime ofmanifests/and of eachcache-*scope dir, the active hub cache (canonical and raw), the manifest versions and a migration id.tmp + os.replace, so any added or replaced manifest moves the mtime of the dir holding it. A new scope dir moves the parent's. So any download, any manifest written by another Studio version, a cache setting change or a bump of_MANIFEST_MIGRATION_ID/_MANIFEST_VERSIONre-runs the full scan.cache-*scope that cannot be listed), stopped at the 10,000 file cap, or saw an ordinary v2 record it left alone. It is also skipped when the dirs changed in the last 2 s, so a write landing in the same mtime tick as the scan cannot be missed. In that case the next start scans as before.manifests/, not inside it, so writing it does not move the mtimes it records.The migration still runs synchronously in the same place in the lifespan, before any download can start, so no write moves into a window where it could race a download.
Results, base vs head
run.py --api-onlyon a scratch Studio home with 5000 manifests (10% v2 on first start), 1000 chat threads, 4000 messages and 200 research runs, CPU only, empty scratch HF cache. Interleaved base/head, separate home copy per arm. Medians [range], ms.Every warm head run is faster than the fastest warm base run. The first start does the full scan on both sides, as expected.
The 44 ms head run at 500 is the first start after a start that migrated 50 manifests. That pass is not recorded, so the next one scans again and then writes the marker.
Other startup maintenance measured on the same home and left alone: studio.db schema check plus research claim backfill (
open_wal_keeper) 11-14 ms warm, orphan reconciliation under 7 ms.Tests
tests/test_manifest_migration_marker.py, 18 tests (one POSIX-only, skipped on Windows). Head passes 18/18 on Linux and macOS, 17 + 1 skipped on Windows.test_cached_gguf_routes,test_export_offline_window,test_hub_download_http_size_ceilingandtest_mtp_drafter_companion, and they predate this change.#- A marker that cannot be read (including deeply nested JSON that raises
RecursionError) or any unexpected error in the marker check falls back to the full scan and writes no marker, so a bad marker can never block the migration.tmp+os.replace, which moves the folder mtime.Not covered
Follow-ups in this PR
os.scandirper directory instead ofPath.glob, which silently returns nothing for a directory it cannot read. Acache-*scope that cannot be listed blocks the marker while the other scopes still migrate. Matching stays case-insensitive on Windows, as glob was.