bricksentry 0.1.32__tar.gz → 0.1.33__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. {bricksentry-0.1.32 → bricksentry-0.1.33}/CHANGELOG.md +10 -0
  2. {bricksentry-0.1.32 → bricksentry-0.1.33}/PKG-INFO +3 -2
  3. {bricksentry-0.1.32 → bricksentry-0.1.33}/README.md +2 -1
  4. bricksentry-0.1.33/deploy/databricks-app/requirements.txt +1 -0
  5. {bricksentry-0.1.32 → bricksentry-0.1.33}/pyproject.toml +1 -1
  6. {bricksentry-0.1.32 → bricksentry-0.1.33}/server.json +2 -2
  7. {bricksentry-0.1.32 → bricksentry-0.1.33}/src/bricksentry/__init__.py +1 -1
  8. {bricksentry-0.1.32 → bricksentry-0.1.33}/src/bricksentry/assess.py +19 -3
  9. {bricksentry-0.1.32 → bricksentry-0.1.33}/src/bricksentry/lineage.py +11 -0
  10. {bricksentry-0.1.32 → bricksentry-0.1.33}/templates/job-check/databricks_template_schema.json +2 -2
  11. {bricksentry-0.1.32 → bricksentry-0.1.33}/tests/test_0132.py +40 -0
  12. bricksentry-0.1.32/deploy/databricks-app/requirements.txt +0 -1
  13. {bricksentry-0.1.32 → bricksentry-0.1.33}/.gitignore +0 -0
  14. {bricksentry-0.1.32 → bricksentry-0.1.33}/CONTRIBUTING.md +0 -0
  15. {bricksentry-0.1.32 → bricksentry-0.1.33}/LICENSE +0 -0
  16. {bricksentry-0.1.32 → bricksentry-0.1.33}/SECURITY.md +0 -0
  17. {bricksentry-0.1.32 → bricksentry-0.1.33}/action.yml +0 -0
  18. {bricksentry-0.1.32 → bricksentry-0.1.33}/deploy/container/Dockerfile +0 -0
  19. {bricksentry-0.1.32 → bricksentry-0.1.33}/deploy/databricks-app/README.md +0 -0
  20. {bricksentry-0.1.32 → bricksentry-0.1.33}/deploy/databricks-app/app.yaml +0 -0
  21. {bricksentry-0.1.32 → bricksentry-0.1.33}/deploy/databricks-app/bricksentry.yml +0 -0
  22. {bricksentry-0.1.32 → bricksentry-0.1.33}/deploy/databricks-app/databricks.yml +0 -0
  23. {bricksentry-0.1.32 → bricksentry-0.1.33}/deploy/databricks-app/grants.sql +0 -0
  24. {bricksentry-0.1.32 → bricksentry-0.1.33}/examples/databricks/bricksentry.yml +0 -0
  25. {bricksentry-0.1.32 → bricksentry-0.1.33}/examples/databricks/bricksentry_check_my_table.ipynb +0 -0
  26. {bricksentry-0.1.32 → bricksentry-0.1.33}/examples/databricks/bricksentry_check_my_table.py +0 -0
  27. {bricksentry-0.1.32 → bricksentry-0.1.33}/examples/databricks/bricksentry_hr_walkthrough.ipynb +0 -0
  28. {bricksentry-0.1.32 → bricksentry-0.1.33}/examples/databricks/bricksentry_hr_walkthrough.py +0 -0
  29. {bricksentry-0.1.32 → bricksentry-0.1.33}/examples/databricks/bricksentry_quickstart.ipynb +0 -0
  30. {bricksentry-0.1.32 → bricksentry-0.1.33}/examples/databricks/bricksentry_quickstart.py +0 -0
  31. {bricksentry-0.1.32 → bricksentry-0.1.33}/examples/databricks/bricksentry_validation.ipynb +0 -0
  32. {bricksentry-0.1.32 → bricksentry-0.1.33}/examples/databricks/bricksentry_validation.py +0 -0
  33. {bricksentry-0.1.32 → bricksentry-0.1.33}/examples/databricks/github-workflow.yml +0 -0
  34. {bricksentry-0.1.32 → bricksentry-0.1.33}/examples/databricks/policy.yml +0 -0
  35. {bricksentry-0.1.32 → bricksentry-0.1.33}/examples/demo/agent_loop_demo.py +0 -0
  36. {bricksentry-0.1.32 → bricksentry-0.1.33}/scripts/build_notebook.py +0 -0
  37. {bricksentry-0.1.32 → bricksentry-0.1.33}/scripts/render_demo_image.py +0 -0
  38. {bricksentry-0.1.32 → bricksentry-0.1.33}/src/bricksentry/__main__.py +0 -0
  39. {bricksentry-0.1.32 → bricksentry-0.1.33}/src/bricksentry/agent_tools.py +0 -0
  40. {bricksentry-0.1.32 → bricksentry-0.1.33}/src/bricksentry/agent_view.py +0 -0
  41. {bricksentry-0.1.32 → bricksentry-0.1.33}/src/bricksentry/backends/__init__.py +0 -0
  42. {bricksentry-0.1.32 → bricksentry-0.1.33}/src/bricksentry/backends/base.py +0 -0
  43. {bricksentry-0.1.32 → bricksentry-0.1.33}/src/bricksentry/backends/databricks_backend.py +0 -0
  44. {bricksentry-0.1.32 → bricksentry-0.1.33}/src/bricksentry/backends/duckdb_backend.py +0 -0
  45. {bricksentry-0.1.32 → bricksentry-0.1.33}/src/bricksentry/changes.py +0 -0
  46. {bricksentry-0.1.32 → bricksentry-0.1.33}/src/bricksentry/cleanup.py +0 -0
  47. {bricksentry-0.1.32 → bricksentry-0.1.33}/src/bricksentry/cli.py +0 -0
  48. {bricksentry-0.1.32 → bricksentry-0.1.33}/src/bricksentry/config.py +0 -0
  49. {bricksentry-0.1.32 → bricksentry-0.1.33}/src/bricksentry/demo.py +0 -0
  50. {bricksentry-0.1.32 → bricksentry-0.1.33}/src/bricksentry/diff.py +0 -0
  51. {bricksentry-0.1.32 → bricksentry-0.1.33}/src/bricksentry/explain.py +0 -0
  52. {bricksentry-0.1.32 → bricksentry-0.1.33}/src/bricksentry/github.py +0 -0
  53. {bricksentry-0.1.32 → bricksentry-0.1.33}/src/bricksentry/governed.py +0 -0
  54. {bricksentry-0.1.32 → bricksentry-0.1.33}/src/bricksentry/history.py +0 -0
  55. {bricksentry-0.1.32 → bricksentry-0.1.33}/src/bricksentry/job.py +0 -0
  56. {bricksentry-0.1.32 → bricksentry-0.1.33}/src/bricksentry/job_demo.py +0 -0
  57. {bricksentry-0.1.32 → bricksentry-0.1.33}/src/bricksentry/mcp_server.py +0 -0
  58. {bricksentry-0.1.32 → bricksentry-0.1.33}/src/bricksentry/measures.py +0 -0
  59. {bricksentry-0.1.32 → bricksentry-0.1.33}/src/bricksentry/models.py +0 -0
  60. {bricksentry-0.1.32 → bricksentry-0.1.33}/src/bricksentry/netguard.py +0 -0
  61. {bricksentry-0.1.32 → bricksentry-0.1.33}/src/bricksentry/notify.py +0 -0
  62. {bricksentry-0.1.32 → bricksentry-0.1.33}/src/bricksentry/policy.py +0 -0
  63. {bricksentry-0.1.32 → bricksentry-0.1.33}/src/bricksentry/policy_templates.py +0 -0
  64. {bricksentry-0.1.32 → bricksentry-0.1.33}/src/bricksentry/preview.py +0 -0
  65. {bricksentry-0.1.32 → bricksentry-0.1.33}/src/bricksentry/py.typed +0 -0
  66. {bricksentry-0.1.32 → bricksentry-0.1.33}/src/bricksentry/report.py +0 -0
  67. {bricksentry-0.1.32 → bricksentry-0.1.33}/src/bricksentry/validation.py +0 -0
  68. {bricksentry-0.1.32 → bricksentry-0.1.33}/templates/job-check/README.md +0 -0
  69. {bricksentry-0.1.32 → bricksentry-0.1.33}/templates/job-check/template/{{.project_name}}/.gitignore +0 -0
  70. {bricksentry-0.1.32 → bricksentry-0.1.33}/templates/job-check/template/{{.project_name}}/README.md.tmpl +0 -0
  71. {bricksentry-0.1.32 → bricksentry-0.1.33}/templates/job-check/template/{{.project_name}}/databricks.yml.tmpl +0 -0
  72. {bricksentry-0.1.32 → bricksentry-0.1.33}/templates/job-check/template/{{.project_name}}/resources/bricksentry_check.job.yml.tmpl +0 -0
  73. {bricksentry-0.1.32 → bricksentry-0.1.33}/templates/job-check/template/{{.project_name}}/src/bricksentry_check.py +0 -0
  74. {bricksentry-0.1.32 → bricksentry-0.1.33}/templates/job-check/template/{{.project_name}}/src/bricksentry_demo.py +0 -0
  75. {bricksentry-0.1.32 → bricksentry-0.1.33}/tests/conftest.py +0 -0
  76. {bricksentry-0.1.32 → bricksentry-0.1.33}/tests/test_0110.py +0 -0
  77. {bricksentry-0.1.32 → bricksentry-0.1.33}/tests/test_0112.py +0 -0
  78. {bricksentry-0.1.32 → bricksentry-0.1.33}/tests/test_0114.py +0 -0
  79. {bricksentry-0.1.32 → bricksentry-0.1.33}/tests/test_0120.py +0 -0
  80. {bricksentry-0.1.32 → bricksentry-0.1.33}/tests/test_0121.py +0 -0
  81. {bricksentry-0.1.32 → bricksentry-0.1.33}/tests/test_0122.py +0 -0
  82. {bricksentry-0.1.32 → bricksentry-0.1.33}/tests/test_0123.py +0 -0
  83. {bricksentry-0.1.32 → bricksentry-0.1.33}/tests/test_0126.py +0 -0
  84. {bricksentry-0.1.32 → bricksentry-0.1.33}/tests/test_0127.py +0 -0
  85. {bricksentry-0.1.32 → bricksentry-0.1.33}/tests/test_0128.py +0 -0
  86. {bricksentry-0.1.32 → bricksentry-0.1.33}/tests/test_0129.py +0 -0
  87. {bricksentry-0.1.32 → bricksentry-0.1.33}/tests/test_0130.py +0 -0
  88. {bricksentry-0.1.32 → bricksentry-0.1.33}/tests/test_0131.py +0 -0
  89. {bricksentry-0.1.32 → bricksentry-0.1.33}/tests/test_018.py +0 -0
  90. {bricksentry-0.1.32 → bricksentry-0.1.33}/tests/test_019.py +0 -0
  91. {bricksentry-0.1.32 → bricksentry-0.1.33}/tests/test_assess_policy.py +0 -0
  92. {bricksentry-0.1.32 → bricksentry-0.1.33}/tests/test_check_notebook.py +0 -0
  93. {bricksentry-0.1.32 → bricksentry-0.1.33}/tests/test_databricks_and_uc.py +0 -0
  94. {bricksentry-0.1.32 → bricksentry-0.1.33}/tests/test_demo.py +0 -0
  95. {bricksentry-0.1.32 → bricksentry-0.1.33}/tests/test_diff.py +0 -0
  96. {bricksentry-0.1.32 → bricksentry-0.1.33}/tests/test_hr_notebook.py +0 -0
  97. {bricksentry-0.1.32 → bricksentry-0.1.33}/tests/test_notebook.py +0 -0
  98. {bricksentry-0.1.32 → bricksentry-0.1.33}/tests/test_notify_templates.py +0 -0
  99. {bricksentry-0.1.32 → bricksentry-0.1.33}/tests/test_preview_agents.py +0 -0
  100. {bricksentry-0.1.32 → bricksentry-0.1.33}/tests/test_sample_guard_and_store.py +0 -0
@@ -1,5 +1,15 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.33 (2026-11-23)
4
+
5
+ From a round of 15 previously untested areas on 0.1.32 on a Free Edition workspace. Thirteen were verified for the first time (NOT NULL and generated columns, empty tables, unicode names, INSERT OVERWRITE, duplicate and NULL keys in both directions, OPTIMIZE and RESTORE as the latest commit, bad job arguments, and the `wide-blast-radius` and `pii-table` rules firing on real Unity Catalog lineage and tags). It found one defect:
6
+
7
+ - **Tags and owners are read afresh for every check.** Unity Catalog lineage cached a table's owner and tags (and column tags) for the life of the process. A one-shot job run was unaffected, but in a long-running process, such as the MCP server agents use, a `pii` or `certified` tag added after the first check of a table was never seen, so those rules silently stopped applying to it. Every check (`assess`, `preview_write`, `check-last-change`, `impact`) now starts by forgetting cached governance metadata.
8
+ - A long-running process keeps at most the 500 most recent assessments in memory; older ones are still found in the assessment store when one is configured.
9
+ - README: Unity Catalog shows new tags within about a minute but new lineage can take 10–15 minutes, so a check right after a change may not see it yet.
10
+
11
+ Verified before release on Databricks Free Edition from the release branch: one long-running instance gave `warn` on an untagged table, then `needs_human` ("table is tagged pii") once the tag was added, and likewise `pii-column-changed` for a column tag, with `impact` showing the tag and the downstream column; a key-colliding MERGE still gives BLOCK with a correct Undo, and masked tables still get the clear message.
12
+
3
13
  ## 0.1.32 (2026-11-22)
4
14
 
5
15
  Fixes from a scale, adversarial and platform-feature round on 0.1.31 on a Free Edition workspace. It found no safety problem: previews took 20–33 s on 1 million rows and 27–29 s on 10 million with exact counts; 8 operations at once on the same tables finished cleanly with unique clones; partitioned, liquid-clustered, identity-column and CHECK-constraint tables previewed correctly; hostile column names, forbidden words in values and 300-clause SQL were handled.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: bricksentry
3
- Version: 0.1.32
3
+ Version: 0.1.33
4
4
  Summary: Change impact analysis and deployment guardrails for data changes on Databricks, for pipelines and the AI agents that edit them: data diffs, Unity Catalog blast radius, policy verdicts and rollback plans.
5
5
  Project-URL: Homepage, https://bricksentry.org
6
6
  Project-URL: Documentation, https://bricksentry.org/docs
@@ -495,7 +495,7 @@ Without lineage access bricksentry still diffs, and adds a `lineage-unavailable`
495
495
 
496
496
  ## What a check costs
497
497
 
498
- The work runs on your SQL warehouse as plain SQL; nothing large is copied out. One table diff runs about five queries (plus three or four cheap metadata queries to pin each table's Delta version): a duplicate-key count on each side, one full outer join on the key columns, and one profile (row count, nulls, totals) per side, plus up to ten small queries for example values. Each reads both versions of the table, so cost grows with table size: seconds for millions of rows, minutes and real warehouse cost for hundreds of millions. Measured on a Free Edition serverless warehouse with 0.1.31: a preview took 20–33 s on 1 million rows and 27–29 s on 10 million, `check-last-change` 27 s on 10 million. For big tables, set `sample_pct` (a fixed hash sample of keys, checked against a full-table checksum so a change outside the sample isn't missed), or check only the tables that matter. On serverless, sampling mainly lowers warehouse cost; the time is spent reading the tables either way. Lineage lookups are one query per depth level, bounded by `lookback_days`.
498
+ The work runs on your SQL warehouse as plain SQL; nothing large is copied out. One table diff runs about five queries (plus three or four cheap metadata queries to pin each table's Delta version): a duplicate-key count on each side, one full outer join on the key columns, and one profile (row count, nulls, totals) per side, plus up to ten small queries for example values. Each reads both versions of the table, so warehouse cost grows with table size. Measured on a Free Edition serverless warehouse: a preview took 20–33 s on 1 million rows, 27–29 s on 10 million, 37–61 s on 100 million (47 s even when every row changed), and under 5 minutes on 1 billion (287 s with every row changed), always with exact counts; `check-last-change` took 27 s on 10 million, 49 s on 100 million and 264 s on 1 billion. These were narrow synthetic tables that compress well; wide real tables take longer. For big tables, set `sample_pct` (a fixed hash sample of keys, checked against a full-table checksum so a change outside the sample isn't missed), or check only the tables that matter. Sampling lowers warehouse cost; it starts saving time on large tables (`sample_pct: 10` was 1.5× faster on 100 million rows and 2.8× faster on 1 billion, and estimated the changed share within 0.01 points). For tables above roughly 500 million rows, we suggest sampling 10%: pass `--sample-pct 10` when you check them (CLI or job task), or set `sample_pct: 10` in `bricksentry.yml` if every table you check is that large. Exact diffs stay the default. Lineage lookups are one query per depth level, bounded by `lookback_days`.
499
499
 
500
500
  ## Audit trail
501
501
 
@@ -530,6 +530,7 @@ bricksentry is in **public beta** (0.1.x). It has been tested hard but only by i
530
530
 
531
531
  ## Known limits (v0.1.x)
532
532
 
533
+ - **Lineage and tags arrive with a delay.** Unity Catalog shows new tags in its system tables within about a minute, but new lineage can take 10–15 minutes (measured on a Free Edition workspace). A check right after a change may not see it yet. bricksentry reads them afresh for every check, so the next check after they appear does.
533
534
  - **Lineage is recorded at runtime.** Brand-new tables have no downstream history yet. Unity Catalog doesn't capture RDD operations, and UDFs hide column-level mapping; column lineage records source-to-target derivations, so a column used only in a filter or join may not appear.
534
535
  - **Tables with column masks or row filters can't be checked.** Databricks refuses shallow clones and time travel on them, so `preview_write` and `check-last-change` stop with a message saying so. bricksentry won't copy governed data into the sandbox to get around it. Check the change on the table that feeds it, or on a dev copy without the mask or filter.
535
536
  - **Keys are required.** Tables without a stable key can't be diffed row by row yet (an aggregate-profile mode is planned).
@@ -447,7 +447,7 @@ Without lineage access bricksentry still diffs, and adds a `lineage-unavailable`
447
447
 
448
448
  ## What a check costs
449
449
 
450
- The work runs on your SQL warehouse as plain SQL; nothing large is copied out. One table diff runs about five queries (plus three or four cheap metadata queries to pin each table's Delta version): a duplicate-key count on each side, one full outer join on the key columns, and one profile (row count, nulls, totals) per side, plus up to ten small queries for example values. Each reads both versions of the table, so cost grows with table size: seconds for millions of rows, minutes and real warehouse cost for hundreds of millions. Measured on a Free Edition serverless warehouse with 0.1.31: a preview took 20–33 s on 1 million rows and 27–29 s on 10 million, `check-last-change` 27 s on 10 million. For big tables, set `sample_pct` (a fixed hash sample of keys, checked against a full-table checksum so a change outside the sample isn't missed), or check only the tables that matter. On serverless, sampling mainly lowers warehouse cost; the time is spent reading the tables either way. Lineage lookups are one query per depth level, bounded by `lookback_days`.
450
+ The work runs on your SQL warehouse as plain SQL; nothing large is copied out. One table diff runs about five queries (plus three or four cheap metadata queries to pin each table's Delta version): a duplicate-key count on each side, one full outer join on the key columns, and one profile (row count, nulls, totals) per side, plus up to ten small queries for example values. Each reads both versions of the table, so warehouse cost grows with table size. Measured on a Free Edition serverless warehouse: a preview took 20–33 s on 1 million rows, 27–29 s on 10 million, 37–61 s on 100 million (47 s even when every row changed), and under 5 minutes on 1 billion (287 s with every row changed), always with exact counts; `check-last-change` took 27 s on 10 million, 49 s on 100 million and 264 s on 1 billion. These were narrow synthetic tables that compress well; wide real tables take longer. For big tables, set `sample_pct` (a fixed hash sample of keys, checked against a full-table checksum so a change outside the sample isn't missed), or check only the tables that matter. Sampling lowers warehouse cost; it starts saving time on large tables (`sample_pct: 10` was 1.5× faster on 100 million rows and 2.8× faster on 1 billion, and estimated the changed share within 0.01 points). For tables above roughly 500 million rows, we suggest sampling 10%: pass `--sample-pct 10` when you check them (CLI or job task), or set `sample_pct: 10` in `bricksentry.yml` if every table you check is that large. Exact diffs stay the default. Lineage lookups are one query per depth level, bounded by `lookback_days`.
451
451
 
452
452
  ## Audit trail
453
453
 
@@ -482,6 +482,7 @@ bricksentry is in **public beta** (0.1.x). It has been tested hard but only by i
482
482
 
483
483
  ## Known limits (v0.1.x)
484
484
 
485
+ - **Lineage and tags arrive with a delay.** Unity Catalog shows new tags in its system tables within about a minute, but new lineage can take 10–15 minutes (measured on a Free Edition workspace). A check right after a change may not see it yet. bricksentry reads them afresh for every check, so the next check after they appear does.
485
486
  - **Lineage is recorded at runtime.** Brand-new tables have no downstream history yet. Unity Catalog doesn't capture RDD operations, and UDFs hide column-level mapping; column lineage records source-to-target derivations, so a column used only in a filter or join may not appear.
486
487
  - **Tables with column masks or row filters can't be checked.** Databricks refuses shallow clones and time travel on them, so `preview_write` and `check-last-change` stop with a message saying so. bricksentry won't copy governed data into the sandbox to get around it. Check the change on the table that feeds it, or on a dev copy without the mask or filter.
487
488
  - **Keys are required.** Tables without a stable key can't be diffed row by row yet (an aggregate-profile mode is planned).
@@ -0,0 +1 @@
1
+ bricksentry[databricks,mcp]==0.1.33
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "bricksentry"
7
- version = "0.1.32"
7
+ version = "0.1.33"
8
8
  description = "Change impact analysis and deployment guardrails for data changes on Databricks, for pipelines and the AI agents that edit them: data diffs, Unity Catalog blast radius, policy verdicts and rollback plans."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -8,12 +8,12 @@
8
8
  "source": "github"
9
9
  },
10
10
  "websiteUrl": "https://bricksentry.org",
11
- "version": "0.1.32",
11
+ "version": "0.1.33",
12
12
  "packages": [
13
13
  {
14
14
  "registryType": "pypi",
15
15
  "identifier": "bricksentry-mcp",
16
- "version": "0.1.32",
16
+ "version": "0.1.33",
17
17
  "runtimeHint": "uvx",
18
18
  "transport": {
19
19
  "type": "stdio"
@@ -23,4 +23,4 @@ __all__ = [
23
23
  "TableDiff",
24
24
  "Verdict",
25
25
  ]
26
- __version__ = "0.1.32"
26
+ __version__ = "0.1.33"
@@ -61,6 +61,11 @@ class Sentry:
61
61
  return d
62
62
 
63
63
  def downstream(self, table: str, depth: int | None = None) -> list[ImpactNode]:
64
+ """Downstream lineage with owners and tags read afresh (see ``LineageProvider.refresh``)."""
65
+ self.lineage.refresh()
66
+ return self._downstream(table, depth)
67
+
68
+ def _downstream(self, table: str, depth: int | None = None) -> list[ImpactNode]:
64
69
  return self.lineage.downstream(table, depth or int(self.config.lineage.get("depth", 3)))
65
70
 
66
71
  def rollback_plan(self, table: str) -> str:
@@ -87,6 +92,9 @@ class Sentry:
87
92
  """
88
93
  candidates = candidates or {}
89
94
  diffs = diffs or {}
95
+ # Governance metadata (tags, owners) is read afresh for every check, never reused from an
96
+ # earlier one: in a long-lived process a tag added since would otherwise be missed.
97
+ self.lineage.refresh()
90
98
  results: list[TableAssessment] = []
91
99
  notify: set[str] = set()
92
100
  for table in tables:
@@ -102,7 +110,7 @@ class Sentry:
102
110
  err = str(e)
103
111
  lineage_err: str | None = None
104
112
  try:
105
- nodes = self.downstream(table)
113
+ nodes = self._downstream(table)
106
114
  except Exception as e: # e.g. no SELECT on system.access.table_lineage
107
115
  nodes = []
108
116
  lineage_err = _first_line(e)
@@ -147,7 +155,7 @@ class Sentry:
147
155
  policy_sha256=self.policy.sha256,
148
156
  triggered_by=_actor(),
149
157
  )
150
- self._assessments[a.id] = a
158
+ self._remember(a)
151
159
  self._save(a)
152
160
  return a
153
161
 
@@ -194,7 +202,7 @@ class Sentry:
194
202
  a = Assessment.from_dict(json.loads(f.read_text()))
195
203
  except (OSError, ValueError, KeyError, TypeError):
196
204
  return None
197
- self._assessments[a.id] = a
205
+ self._remember(a)
198
206
  return a
199
207
 
200
208
  def preview_write(
@@ -290,6 +298,14 @@ class Sentry:
290
298
  return [f"notify: bad config ({e})"]
291
299
  return send(assessment, settings, pr=pr, force=force)
292
300
 
301
+ _MAX_IN_MEMORY = 500 # a long-lived server shouldn't grow forever; older ones reload from the store
302
+
303
+ def _remember(self, a: Assessment) -> None:
304
+ self._assessments.pop(a.id, None)
305
+ self._assessments[a.id] = a
306
+ while len(self._assessments) > self._MAX_IN_MEMORY:
307
+ self._assessments.pop(next(iter(self._assessments)))
308
+
293
309
  # --- lookups for agents -------------------------------------------------
294
310
  def get_assessment(self, assessment_id: str) -> Assessment | None:
295
311
  return self._assessments.get(assessment_id) or self._load(assessment_id)
@@ -45,6 +45,12 @@ class LineageProvider(ABC):
45
45
  """Downstream columns fed by ``columns`` of ``table``, with their tags."""
46
46
  return []
47
47
 
48
+ def refresh(self) -> None:
49
+ """Forget anything cached, so the next check reads owners and tags afresh.
50
+ Called at the start of every check: a long-lived process (the MCP server)
51
+ must see a pii or certified tag added after its first check."""
52
+ return None # nothing cached by default
53
+
48
54
 
49
55
  class StaticLineage(LineageProvider):
50
56
  """Lineage from config::
@@ -179,6 +185,11 @@ class UnityCatalogLineage(LineageProvider):
179
185
  self._meta_cache: dict[str, tuple[str | None, dict[str, str]]] = {}
180
186
  self._exists: dict[str, bool] = {} # True / False when information_schema answered; absent if unknown
181
187
 
188
+ def refresh(self) -> None:
189
+ self._col_tag_cache.clear()
190
+ self._meta_cache.clear()
191
+ self._exists.clear()
192
+
182
193
  def _excluded(self, name: str) -> bool:
183
194
  n = name.lower()
184
195
  return any(fnmatch.fnmatch(n, p) for p in self.exclude_patterns)
@@ -86,10 +86,10 @@
86
86
  },
87
87
  "bricksentry_version": {
88
88
  "type": "string",
89
- "default": "0.1.32",
89
+ "default": "0.1.33",
90
90
  "description": "bricksentry version to install in the job (pinned; change it and redeploy to upgrade)",
91
91
  "pattern": "^\\d+\\.\\d+\\.\\d+$",
92
- "pattern_match_failure_message": "Use a version like 0.1.32.",
92
+ "pattern_match_failure_message": "Use a version like 0.1.33.",
93
93
  "order": 10
94
94
  }
95
95
  },
@@ -116,3 +116,43 @@ def test_cli_and_job_report_it_cleanly(monkeypatch, tmp_path):
116
116
  lines: list[str] = []
117
117
  code = job.run(["--tables", "sales.orders", "--scratch-schema", "scratch"], backend=db, out=lines.append)
118
118
  assert code == 2 and "has a column mask" in "\n".join(lines)
119
+
120
+
121
+ # --- governance metadata is read afresh for every check (0.1.33) ----------------------
122
+ def _uc(backend):
123
+ from bricksentry.lineage import UnityCatalogLineage
124
+
125
+ backend.execute("CREATE SCHEMA IF NOT EXISTS sys3")
126
+ backend.execute("CREATE OR REPLACE TABLE sys3.table_lineage AS SELECT * FROM (VALUES "
127
+ "('sales.orders', 'sales.daily', 'JOB', '1', current_date)) "
128
+ "t(source_table_full_name, target_table_full_name, entity_type, entity_id, event_date)")
129
+ backend.execute("CREATE OR REPLACE TABLE sys3.tables AS SELECT * FROM (VALUES "
130
+ "(NULL, 'sales', 'orders', 'data-team'), (NULL, 'sales', 'daily', 'bi')) "
131
+ "t(table_catalog, table_schema, table_name, table_owner)")
132
+ backend.execute("CREATE OR REPLACE TABLE sys3.table_tags AS SELECT * FROM (VALUES "
133
+ "('x', 'x', 'x', 'x', NULL)) t(catalog_name, schema_name, table_name, tag_name, tag_value)")
134
+ return UnityCatalogLineage(backend, lineage_table="sys3.table_lineage", tables_table="sys3.tables",
135
+ tags_table="sys3.table_tags")
136
+
137
+
138
+ def test_tag_added_after_first_check_is_seen(sentry):
139
+ b = sentry.backend
140
+ lin = _uc(b)
141
+ s = Sentry(sentry.config, backend=b, lineage=lin)
142
+ first = s.preview_write("UPDATE {{target}} SET status = 'x' WHERE order_id = 1", "sales.orders")
143
+ assert "pii" not in str(first)
144
+ # A long-lived process (the MCP server): the tag is added after the first check.
145
+ b.execute("INSERT INTO sys3.table_tags VALUES (NULL, 'sales', 'orders', 'pii', NULL), "
146
+ "(NULL, 'sales', 'daily', 'certified', NULL)")
147
+ second = s.preview_write("UPDATE {{target}} SET status = 'y' WHERE order_id = 1", "sales.orders")
148
+ t = second["tables"][0]
149
+ assert "pii" in t["tags"], t
150
+ nodes = s.downstream("sales.orders")
151
+ assert any("certified" in n.tags for n in nodes)
152
+
153
+
154
+ def test_in_memory_assessments_are_capped(sentry, monkeypatch):
155
+ monkeypatch.setattr(type(sentry), "_MAX_IN_MEMORY", 3)
156
+ ids = [sentry.preview_write(f"UPDATE {{{{target}}}} SET status = 's{i}' WHERE order_id = 1",
157
+ "sales.orders")["id"] for i in range(5)]
158
+ assert list(sentry._assessments) == ids[-3:]
@@ -1 +0,0 @@
1
- bricksentry[databricks,mcp]==0.1.32
File without changes
File without changes
File without changes
File without changes