Skip to content

fix(admin): scope session timeline metrics by tenant#231

Merged
smaramwbc merged 1 commit into
smaramwbc:mainfrom
skarL007:codex/fix-admin-session-timeline-tenant-metrics
Jun 7, 2026
Merged

fix(admin): scope session timeline metrics by tenant#231
smaramwbc merged 1 commit into
smaramwbc:mainfrom
skarL007:codex/fix-admin-session-timeline-tenant-metrics

Conversation

@skarL007

@skarL007 skarL007 commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Scope /admin/subjects/{subject_id}/sessions/{session_id}/timeline episode_count to the same base query used for tenant-filtered episode rows.
  • Scope per-episode citing_memory_count to tenant_id when the timeline request is tenant-filtered.
  • Add an integration regression covering two tenants sharing the same subject/session ids, including a cross-tenant memory reference to prove the metric does not leak.

Test plan

  • python -m ruff check server\api\admin.py tests\integration\test_admin_session_timeline_tenant_scope.py
  • python -m ruff format --check server\api\admin.py tests\integration\test_admin_session_timeline_tenant_scope.py
  • python -m py_compile server\api\admin.py tests\integration\test_admin_session_timeline_tenant_scope.py
  • python -m pytest tests\test_tenant_scoping_invariant.py tests\test_route_limits_invariant.py tests\test_admin_dashboard.py -q
  • STATEWAVE_EMBEDDING_PROVIDER=stub STATEWAVE_COMPILER_TYPE=heuristic PYTHONUTF8=1 python -m pytest tests -q --ignore=tests/integration --ignore=tests/smoke --ignore=tests/test_admin_subjects.py --ignore=tests/test_admin_clone.py --ignore=tests/test_memory_templates.py --ignore=tests/test_usage.py

Local integration note

  • python -m pytest tests\integration\test_admin_session_timeline_tenant_scope.py -q was attempted, but this Windows environment has no running statewave_test Postgres on localhost:5432.
  • docker compose up -d db was also attempted, but Docker Desktop's Linux daemon is not available on this machine.

Signed-off-by: skarL007 <marcelomachuca2023@gmail.com>

@smaramwbc smaramwbc left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exhaustively reviewed (correctness + security + test-quality, plus an adversarial verification pass that empirically tested pre/post against Postgres) — clean to merge.

  • Correct & complete. episode_count now derives from the tenant-filtered base query instead of a tenant-ignoring subquery, and per-episode citing_memory_count adds if tenant_id: ...where(MemoryRow.tenant_id == tenant_id) — closing the cross-tenant metric leak on a shared subject/session id. No fan-out (episode/memory ids are global UUID PKs).
  • Operator-global view preserved. Both new clauses are gated behind if tenant_id:, so the no-filter operator path is byte-identical pre/post (verified empirically). No over-scoping regression.
  • Security pass clean. admin.py + integration test only; single authored commit; no exec/network/secret/obfuscation; no info leak. The third hunk is cosmetic ReceiptRow reformatting.

One non-blocking nit: the test asserts only the tenant-a filtered view — adding the operator-global and tenant-b assertions (as the #229 sibling test does) would guard against a future over-scoping regression. Happy to follow up. Thanks for another tight isolation fix.

— Statewave team

@smaramwbc smaramwbc merged commit 379d598 into smaramwbc:main Jun 7, 2026
5 checks passed
smaramwbc added a commit that referenced this pull request Jun 7, 2026
… test

Follow-up to #231. The session-timeline tenant-scope test asserted only the
tenant-a filtered view. Add the operator-global assertion (episode_count==3
and the tenant-a episode cited by both tenants' memories == 2) and the
tenant-b filtered view (episode_count==2, citing counts == 0). The global
assertion guards against a future over-scoping regression where a tenant
filter leaks into the operator path — the behavior #231 preserves. Mirrors
the stronger both-tenants pattern in #229's test. Test-only.
smaramwbc added a commit that referenced this pull request Jun 7, 2026
… test

Follow-up to #231. The session-timeline tenant-scope test asserted only the
tenant-a filtered view. Add the operator-global assertion (episode_count==3
and the tenant-a episode cited by both tenants' memories == 2) and the
tenant-b filtered view (episode_count==2, citing counts == 0). The global
assertion guards against a future over-scoping regression where a tenant
filter leaks into the operator path — the behavior #231 preserves. Mirrors
the stronger both-tenants pattern in #229's test. Test-only.
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.

2 participants