Graph-Native Infrastructure for Context and Accountable AI Systems
Python agent-memoryaiai-governanceai-infrastructureartificial-intelligencecontext-engineeringcontext-graphsdata-engineeringdecision-intelligencedeveloper-toolsexplainable-aigenerative-aigraph-ragknowledge-graphllmontologyprovenancepythonreasoningsemantic-search
fix(provenance): address review nits and add CHANGELOG entry
KaifAhmad17045d7b94e74
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 1a7464b7..2a25095a 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -9,6 +9,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0## [Unreleased]+### Added++- **Global default persistent storage for `ProvenanceManager`, plus a working `provenance` CLI** (#795, #802) by @Sameer6305 and @KaifAhmad1+ - Every ingestion/processing module (`kg_provenance.py`, `pipeline_provenance.py`, and 20+ other call sites) instantiated its own `ProvenanceManager()` with no `storage_path`, so all of them silently fell back to `InMemoryStorage` and the SQLite audit trail was never actually written. `ProvenanceManager.set_default_storage_path(path)` now sets a class-level default that every no-arg instantiation picks up, and `Semantica.__init__` wires `config.provenance.storage_path` into it automatically during orchestrator init+ - Added the thread-safe `default_storage_path(path)` context manager (`semantica.provenance.default_storage_path`) for test isolation — it stacks nested overrides and guarantees restoration of the previous default on exit, even on exception, so tests can't leak global state into each other+ - Fixed `ProvenanceManager.__init__` raising `TypeError` on the CLI's `config=` kwarg, and implemented the four methods the CLI already called but that didn't exist on the class: `lineage()`, `audit_log()`, `export_prov()` (W3C PROV-O turtle/ntriples/jsonld via `rdflib`), and `check()` — unblocking `semantica provenance lineage|audit|export|check` end-to-end+ - Follow-up review fixes: `track_entity` no longer aliases a caller-supplied `used_entities` list (it copied the reference and later mutated it in place via `.append()`, which could corrupt a list the caller still held); removed dead fallback branches in `orchestrator.py`/`manager.py` left over from not realizing `Config.get()` already resolves dotted paths; added a `--dry-run` option to `provenance audit` to match `provenance export` (previously only the global `--dry-run` flag worked, not a local one); and `provenance check --strict` no longer prints a green "✓" success line immediately before failing — a failing check now renders as a warning before the `ClickException` is raised+### Fixed- **`react-hooks/set-state-in-effect` cascading renders across 12 Explorer workspace files** (#769, #796) by @Sameer6305 and @KaifAhmad1diff --git a/semantica/cli.py b/semantica/cli.pyindex 2523e2e2..56d8e9a0 100644--- a/semantica/cli.py+++ b/semantica/cli.py@@ -2523,9 +2523,11 @@ def provenance_lineage(cli_ctx: CLIContext, entity_id: str, depth: int, local_jsdefault="table", show_default=True)@click.option("--output", default=None, type=click.Path())@click.option("--json", "local_json", is_flag=True, default=False)[email protected]("--dry-run", "local_dry", is_flag=True, default=False)@click.pass_objdef provenance_audit(cli_ctx: CLIContext, since: Optional[str], fmt: str,- output: Optional[str], local_json: bool) -> None:+ output: Optional[str], local_json: bool,+ local_dry: bool) -> None:"""Export the audit log.\b@@ -2535,7 +2537,7 @@ def provenance_audit(cli_ctx: CLIContext, since: Optional[str], fmt: str,cli_ctx = _require_ctx(cli_ctx)def _action() -> None:- if _is_dry(cli_ctx, False):+ if _is_dry(cli_ctx, local_dry):_dry(cli_ctx, "export audit log", since=since, format=fmt, output=output)returntry:@@ -2604,11 +2606,14 @@ def provenance_check(cli_ctx: CLIContext, strict: bool, local_json: bool) -> Nonresult = pm.check(strict=strict)except ImportError as exc:raise click.ClickException(f"Provenance module not available: {exc}") from exc+ is_valid = not isinstance(result, dict) or result.get("valid", True)if _is_json(cli_ctx, local_json):_jecho(result if isinstance(result, dict) else {"valid": bool(result)})- else:+ elif is_valid:_ok(cli_ctx, f"Provenance check: {result}")- if strict and isinstance(result, dict) and not result.get("valid", True):+ else:+ _warn(cli_ctx, f"Provenance check: {result}")+ if strict and not is_valid:raise click.ClickException(f"Provenance integrity check failed: {result.get('errors')} error(s)")diff --git a/semantica/core/orchestrator.py b/semantica/core/orchestrator.pyindex f0c8cfb2..2d1ead68 100644--- a/semantica/core/orchestrator.py+++ b/semantica/core/orchestrator.py@@ -92,9 +92,10 @@ class Semantica:# Configure global provenance storage path if specifiedtry:+ # Config.get() already resolves dotted paths against nested dicts+ # (see get_nested_value), so this single lookup covers both+ # top-level and config.provenance={"storage_path": ...} shapes.prov_storage_path = self.config.get("provenance.storage_path")- if not prov_storage_path and isinstance(self.config.get("provenance"), dict):- prov_storage_path = self.config.get("provenance", {}).get("storage_path")if prov_storage_path:from ..provenance import ProvenanceManagerProvenanceManager.set_default_storage_path(prov_storage_path)diff --git a/semantica/provenance/manager.py b/semantica/provenance/manager.pyindex 1f99123b..ab0abb26 100644--- a/semantica/provenance/manager.py+++ b/semantica/provenance/manager.py@@ -115,10 +115,10 @@ class ProvenanceManager:returnif not storage_path and config:- if isinstance(config, Mapping) or isinstance(config, dict):+ if isinstance(config, Mapping):prov_config = config.get("provenance", {})prov_has_path = (- isinstance(prov_config, (Mapping, dict))+ isinstance(prov_config, Mapping)and "storage_path" in prov_config)if prov_has_path:@@ -239,7 +239,7 @@ class ProvenanceManager:first_seen=existing.first_seen if existing else datetime.utcnow().isoformat(),last_updated=datetime.utcnow().isoformat(),parent_entity_id=parent_id, # Link to history or explicit parent- used_entities=kwargs.get("used_entities", []),+ used_entities=list(kwargs.get("used_entities", [])),)# Make the archived history entry discoverable via trace_lineage()'s