Skip to content

fix(security): invalidate metadata-derived caches on runtime metadata change - #2213

Merged
xuyushun441-sys merged 1 commit into
mainfrom
seam/cache-invalidation-on-metadata-change
Jun 22, 2026
Merged

fix(security): invalidate metadata-derived caches on runtime metadata change#2213
xuyushun441-sys merged 1 commit into
mainfrom
seam/cache-invalidation-on-metadata-change

Conversation

@xuyushun441-sys

Copy link
Copy Markdown
Contributor

Why

SecurityPluginfieldNamesCache / tenancyDisabledCache / cbpRelCache 从元数据惰性填充,但从不失效。"元数据在 kernel 生命周期内不变"的假设在运行时改元数据(Studio / AI Studio 在线建模)时被打破——schema/RLS 会读到旧值直到重启,单节点也如此

What

  • start() 订阅 metadata.watch('*'),元数据变更时清这三个缓存。
  • 通用开源机制(对可选的 watch API 做了 guard)。配合 cluster pub/sub 驱动时,metadata.changed 会跨节点传播 → 这也是 EE 多节点跨节点缓存失效的铺底(见 cloud ADR-0018)。
  • 新增针对性单测;本地验证全绿(plugin-security 123 passing)。

影响

  • 单节点:修了一个 latent 正确性 bug(运行时改元数据后缓存陈旧)。
  • 多节点:为 EE 的跨节点失效提供本地钩子(跨节点激活由 EE 的 cluster 驱动完成,不在本 PR)。

🤖 Generated with Claude Code

@vercel

vercelBot commented Jun 22, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

ProjectDeploymentActionsUpdated (UTC)
specReadyReadyPreview, CommentJun 22, 2026 2:50pm

Request Review

@github-actions

github-actionsBot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 1 package(s): @objectstack/plugin-security.

8 hand-written doc(s) reference the affected code and may need an implementation-accuracy re-verification:

  • content/docs/concepts/implementation-status.mdx(via @objectstack/plugin-security)
  • content/docs/concepts/packages.mdx(via @objectstack/plugin-security)
  • content/docs/getting-started/cli.mdx(via @objectstack/plugin-security)
  • content/docs/guides/cheatsheets/permissions-matrix.mdx(via packages/plugins/plugin-security)
  • content/docs/guides/metadata/dashboard.mdx(via @objectstack/plugin-security)
  • content/docs/guides/packages.mdx(via @objectstack/plugin-security)
  • content/docs/guides/plugins.mdx(via @objectstack/plugin-security)
  • content/docs/guides/security.mdx(via @objectstack/plugin-security)

Advisory only. To re-verify, run the docs-accuracy-audit workflow scoped to these files:
node scripts/docs-audit/affected-docs.mjs origin/main → pass the list as args.docs.

… change
SecurityPlugin's fieldNames/tenancy/controlled-by-parent caches were populated
lazily from metadata but never invalidated — so runtime metadata edits (Studio /
AI authoring) served stale schema/RLS until restart, even single-node. Subscribe
to metadata.watch('*') in start() and clear them on change.
Generic open-core mechanism (guarded on the optional watch API). With a cluster
pub/sub driver the metadata.changed event propagates cross-node, so this is also
the groundwork for cross-node cache invalidation in EE multi-node (cloud ADR-0018).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@xuyushun441-sys
xuyushun441-sysforce-pushed the seam/cache-invalidation-on-metadata-change branch from c27aebd to 895d9e5CompareJune 22, 2026 14:48
@xuyushun441-sys
xuyushun441-sys merged commit 8125c3d into mainJun 22, 2026
16 checks passed
@xuyushun441-sys
xuyushun441-sys deleted the seam/cache-invalidation-on-metadata-change branch June 22, 2026 14:53
xuyushun441-sys added a commit that referenced this pull request Jun 22, 2026
…rve` (#2226)
`os serve` constructed the Runtime without a cluster config, so it always used
the in-memory cluster driver — a multi-replica deployment could not coordinate
(and the split-brain guard blocked it). `os serve` now reads OS_CLUSTER_DRIVER
(+ OS_REDIS_URL), dynamically imports the matching remote driver package (so it
works in both config-boot and compiled-artifact mode), and forwards the cluster
config to the Runtime. Open-core ships only the in-memory driver; remote drivers
(e.g. @objectstack/service-cluster-redis) are provided by the EE distribution —
absent ⇒ graceful fallback to in-memory.
Verified via A/B boot (local redis): with OS_CLUSTER_DRIVER=redis + replicas=2
the server boots (guard passes = redis active); without it, replicas=2 trips the
split-brain guard (memory). Enables the EE multi-node activation (cloud ADR-0018)
of the cache-invalidation (#2213) and scheduler-leader-election (#2219) seams.
Co-authored-by: Jack Zhuang <277994282+os-zhuang@users.noreply.github.com>
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@xuyushun441-sys@os-zhuang