Repository navigation
Update material metadata without losing source provenance #9432
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
huangruiteng
merged 4 commits into
loopx-project:main
from
steven-kid:roadmap-auto/20261125-material-metadata-update
Nov 26, 2026
+393
−21
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
8eb8a84
Add provenance-preserving material metadata updates
steven-kid ab42bb0
Report rejected material summary sync and preserve sync-only recovery
steven-kid 050391a
Guard material metadata updates against source-session registries
steven-kid 771f0c0
Merge remote-tracking branch 'origin/main' into HEAD
huangruiteng File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| """Explicit metadata patches over the existing project material registration owner.""" | ||
| from __future__ import annotations | ||
|
|
||
| import copy | ||
| from pathlib import Path | ||
| from typing import cast | ||
|
|
||
| from ..authority import ( | ||
| Payload, _apply_authority_entry, _dict_view, find_goal_index, | ||
| normalize_project_materials, now_local, public_safe_optional, validate_authority_source_id, | ||
| ) | ||
| from ..control_plane.projects.registry_codec import ( | ||
| load_project_registry, mutate_project_registry, require_runtime_compatible_project_registry, | ||
| ) | ||
|
|
||
|
|
||
| def update_authority_source( | ||
| *, registry_path: Path, goal_id: str, source_id: str, | ||
| freshness: str | None = None, owner_status: str | None = None, | ||
| gate_status: str | None = None, revision: str | None = None, | ||
| conflict_rule: str | None = None, dry_run: bool = False, | ||
| ) -> Payload: | ||
| """Patch recorded metadata under the registry lock; never reopen the source.""" | ||
| registry_path = registry_path.expanduser() | ||
| source_id = validate_authority_source_id(source_id) | ||
| changes: Payload = {} | ||
| for name, value in (("freshness", freshness), ("owner_status", owner_status), | ||
| ("gate_status", gate_status), ("revision", revision), | ||
| ("conflict_rule", conflict_rule)): | ||
| if value is not None: | ||
| cleaned = public_safe_optional(name, value) | ||
| if not cleaned: | ||
| raise ValueError(f"{name} must not be empty") | ||
| changes[name] = cleaned | ||
| if not changes: | ||
| raise ValueError("specify at least one metadata field to update") | ||
|
|
||
| def reduce(registry: Payload) -> tuple[Payload, Payload]: | ||
| require_runtime_compatible_project_registry(registry, operation="authority metadata update") | ||
| index = find_goal_index(registry, goal_id) | ||
| goal = cast(list[Payload], registry["goals"])[index] | ||
| authority = _dict_view(goal.get("authority_registry")) | ||
| materials = normalize_project_materials(authority.get("project_materials")) | ||
| if source_id not in materials: | ||
| raise ValueError("source_id is not registered in this authoritative project registry; " | ||
| "select the project registry or register the source first") | ||
| entry = dict(materials[source_id]) | ||
| entry.update(changes) | ||
| entry["id"] = source_id | ||
| summary, _previous = _apply_authority_entry( | ||
| registry, goal_id=goal_id, entry=entry, registered_at=now_local(), | ||
| ) | ||
| return entry, summary | ||
|
|
||
| if dry_run: | ||
| registry = load_project_registry(registry_path) | ||
| entry, summary = reduce(copy.deepcopy(registry)) | ||
| else: | ||
| entry, summary = mutate_project_registry( | ||
| registry_path, operation="update_authority_source", reducer=reduce, | ||
| ) | ||
| return { | ||
| "ok": True, "operation": "update", "dry_run": dry_run, "written": not dry_run, | ||
| "registry": str(registry_path), "goal_id": goal_id, "source_id": source_id, | ||
| "entry": entry, "updated_fields": sorted(changes), | ||
| "authority_registry_path": "authority_registry.project_materials", | ||
| "authority_registry_summary": summary, "raw_source_ref_stored": False, | ||
| "write_effect": "updated recorded metadata only; omitted fields, reference provenance and topics preserved; " | ||
| "no source access or permission change" if not dry_run else | ||
| "would update recorded metadata only; no registry writes or source access", | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.