Skip to content

A ClickStack namespace erasure no longer deletes other orgs' Loom metric points - #231

Merged
zlareb1 merged 10 commits into
mainfrom
fix/clickstack-namespace-erasure-org-scope
Nov 3, 2026
Merged

zlareb1 merged 10 commits into
mainfrom
fix/clickstack-namespace-erasure-org-scope

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Critical Bug Fix (data loss, cross-tenant read, auth bypass)

Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):

A ClickStack namespace erasure no longer deletes another org's Loom metric points for a namespace with the same name, or every Loom row when the erased namespace is named loom.

Why

Failing case: org acme erases namespace default. On the metrics tables the predicate was (Attributes['service.namespace'] = 'default' OR Attributes['loom.namespace'] = 'default') AND Attributes['loom.org'] IN ('acme', ''). Loom's own metric points carry loom.namespace and no loom.org (server/observability/metrics.py, kept org-free for label cardinality), so loom.org reads '' and org globex's points for its own default namespace matched and were deleted. A second case of the same kind: erasing a namespace named loom matched ResourceAttributes['service.namespace'] = 'loom', the constant Loom's exporter stamps on every span and log, so every Loom row without a loom.org tag (worker spans, log lines) in every org matched.

Pattern: the org guard read "no loom.org" as "a foreign emitter", but Loom itself emits rows with no org tag.

Fix: the two keys get their own org rule. A row matched by loom.namespace must carry the erasing org's loom.org exactly. A row matched by service.namespace keeps the untagged allowance (another emitter may hold the subject), but the value loom never matches. The user-scope predicate is unchanged.

Scope and risk

ClickStackBackend._namespace_where, plus the service.namespace resource value moved into one constant, SERVICE_NAMESPACE in server/observability/otel.py, which the exporter's resource and the backend both use (same value, no behaviour change).

Loom's op and domain metrics, counters and histograms (record_op, loom.request.duration, the server/observability/metrics.py instruments and the loom.code.* counters in server/code/app/common.py), carry loom.namespace and no loom.org, so a namespace erasure no longer removes them: by name alone they cannot be told apart from another org's. They hold no memory content, but their loom.namespace label is the namespace name, and a personal namespace's name is derived from the user's email local part. That label stays until the collector table's own TTL, if it has one, removes it; the docs page says so. Closing that residue means stamping loom.org on those metrics, which reverses a documented cardinality decision in metrics.py and touches every metric call site, so it is left to its own change. The state gauges in otel_probes.py and Loom's request spans carry loom.org and are still erased. The step's fail-closed behaviour (a precount or delete failure records failed) is unchanged. A foreign emitter whose service.namespace is literally loom can no longer be erased by namespace.

Compatibility, rollout and rollback

  • Wire: none.
  • Operator steps: none.
  • Rollback: reverting restores the cross-org match; nothing is stored.

Tests

  • tests/unit/test_clickstack_namespace_erasure.py::test_namespace_erasure_matches_only_this_orgs_rows runs the built predicate on clickhouse-local over Loom untagged, other-org and own-org points, Loom deployment rows and foreign emitter rows (untagged, own org, other org), for metrics, traces and sessions, one and many namespaces, and namespaces default and loom. It fails on the old predicate (untagged Loom points matched; loom matched every deployment row) and passes now.
  • test_clickstack_user_erasure_never_matches_another_org now runs the user-scope predicate of every default table on clickhouse-local instead of checking its string shape; that predicate is unchanged.
  • Locally: make format lint typecheck; tests/unit/test_clickstack_namespace_erasure.py, test_otel_erasure_lightweight.py, test_package_contracts.py, test_public_copy.py, test_doc_links.py. The full unit suite runs in CI.

AI assistance in the code (leave one; writing this description with AI is fine):

  • AI-generated (an agent wrote most of the diff): Claude Code. The failing case was checked against the metric attribute code and reproduced on clickhouse-local.

  • I can explain every line of this diff and how it interacts with the rest of Loom.

Checklist

  • make format-check, make lint and make typecheck pass locally; make test-unit and the integration suite run in CI.
  • Generated files are regenerated in this PR, not by hand: none apply.
  • A new migration is additive and numbered after the latest on main; no merged migration is edited.
  • A behaviour change to any file a plugin ships bumps both plugin manifests' version: none apply.
  • The frontend builds, if frontend/ changed: not changed.
  • Docs under docs/ describe the system as it now is, and this description names any operator steps and wire changes.
  • Repository text has no dates, people, host names, internal namespaces, ticket or decision numbers.
  • Commits are signed off (git commit -s), as CONTRIBUTING.md asks.

🤖 Generated with Claude Code

zlareb1 and others added 10 commits November 3, 2026 22:13
…ric points

Loom's own metric points carry `loom.namespace` and no `loom.org`, and the
org guard let untagged rows through, so erasing namespace `default` in one
org deleted every other org's points for its own `default`. A row keyed by
`loom.namespace` now matches only when it carries the erasing org's
`loom.org`; the untagged allowance stays for another emitter's
`service.namespace`, which no longer matches Loom's deployment constant
`loom`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…rs a tenant namespace named loom

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…ves and their label

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…g-free histograms

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…ves; the SQL test covers sessions and an own-org foreign row

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…t by string shape

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
@zlareb1
zlareb1 force-pushed the fix/clickstack-namespace-erasure-org-scope branch from c5171e0 to fe1c51e Compare November 3, 2026 22:14
@zlareb1
zlareb1 merged commit ee7c0e3 into main Nov 3, 2026
22 checks passed
@zlareb1
zlareb1 deleted the fix/clickstack-namespace-erasure-org-scope branch November 3, 2026 23:38
@pufit pufit mentioned this pull request Nov 4, 2026
9 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant