fix(discovery): stabilize first-open normalization before caching

This commit is contained in:
阿白叔 committed 2026-10-15 10:23:52 +08:00
1 parent 80f1cfd799
commit 260e270be8
2 files changed
+105 -6

No files matched your search

@@ -35,7 +35,10 @@ def project_fingerprint(project: Path, excluded_root: Path) -> tuple | None:
kept = []
for name in sorted(dirs):
path = current / name
if path.resolve() == excluded or name.casefold() == '.git':
relative = tuple(part.casefold() for part in path.relative_to(root).parts)
audit_directory = (len(relative) == 3 and relative[:2] == ('database', 'cdbsvr')
and relative[2] in {'log', 'plog', 'events'})
if path.resolve() == excluded or name.casefold() == '.git' or audit_directory:
continue
info = path.lstat()
if _unsafe(info):
@@ -106,11 +109,18 @@ class DiscoveryCache:
and (not collect_components or has_components)):
self._entries[key] = entry
return deepcopy(discovery)
discovery = loader()
after = project_fingerprint(project, self.data_root)
if before is not None and before != after:
# Native first-open may normalize an old database. Discard that
# discovery and reopen once; only a verified stable pass is usable.
for attempt in range(2):
if attempt:
before = project_fingerprint(project, self.data_root)
discovery = loader()
after = project_fingerprint(project, self.data_root)
if before is not None and before == after:
break
else:
raise TaskCenterError("quick_run_sheet_discovery",
"project contents changed during discovery; retry read-only discovery")
"project contents changed or could not be verified during discovery; retry read-only discovery")
# Refuse incomplete inventories and bound both projects and row count.
sheets = getattr(discovery, 'sheets', ())
matches = getattr(discovery, 'matched_old_parts', {})