mirror of
https://github.com/headroomlabs-ai/headroom.git
synced 2026-11-22 13:29:19 +08:00
> Replaces #4864: same change as one commit, because a commit message there failed commitlint and fixing it would need a force-push. ## Description `sql/create_proxy_telemetry_v2.sql` created an `anon_select` policy and `GRANT SELECT ... TO anon` on the raw telemetry table. The anon key is meant to be public, so anyone holding it could read every raw row. The Supabase beacon was removed in #1526, so the script is now marked legacy and keeps only the INSERT path that older releases still use. The SELECT policy and grant are gone. The script now runs `DROP POLICY IF EXISTS "anon_select"` and `REVOKE SELECT ... FROM anon`, and drops `anon_insert` before creating it, so re-running the whole script on a project created with the old version removes the read access. `run-all-plugins.sh` (dev launcher) silently exported `HEADROOM_LICENSE_DEV=1`, turning off licence verification, whenever `~/.headroom/plugins.env` was missing. It now keeps a `HEADROOM_LICENSE` already in the environment and otherwise exits with a message. Closes # ## Type of Change - [x] Bug fix (non-breaking change that fixes an issue) - [ ] New feature (non-breaking change that adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Documentation update - [ ] Performance improvement - [ ] Code refactoring (no functional changes) ## Changes Made - `sql/create_proxy_telemetry_v2.sql`: legacy header; anon INSERT only; idempotent policy section that drops the old read policy and revokes SELECT. - `run-all-plugins.sh`: no `HEADROOM_LICENSE_DEV` fallback. - `tests/test_sql_anon_access.py`: static checks (there is no SQL harness in the repo) that no policy or grant gives anon SELECT/ALL on the raw table, INSERT is still granted, the DROP POLICY / REVOKE run as live statements, and the dev script does not export `HEADROOM_LICENSE_DEV`. ## Testing - [x] Unit tests pass (`pytest`) - [x] Linting passes (`ruff check .`) - [x] Type checking passes (`mypy headroom`) - [x] New tests added for new functionality - [ ] Manual testing performed ### Test Output ```text $ pytest -q tests/test_sql_anon_access.py 2 passed # same tests against origin/main files 2 failed ``` ## Real Behavior Proof - Not run against Postgres: a local Postgres container run was attempted but Docker was unavailable on the test machine. Not run against the live Supabase project; if it still exists, someone with access needs to re-run this script (or the DROP POLICY / REVOKE pair) once. This PR does not change any deployed database. ## Runtime Rollout Safety - Rollout-managed feature(s): none - Minimum rollout channel: n/a - Stable/default behavior changed: no runtime change; setup SQL and a dev script only. - Kill switch / disable path: n/a - Unsafe override required: no - Qualification impact: none - Rollback path: revert this commit. ## Review Readiness - [x] I have performed a self-review - [x] This PR is ready for human review ## Checklist - [x] My code follows the project's style guidelines - [x] I have performed a self-review of my code - [x] I have commented my code, particularly in hard-to-understand areas - [x] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [x] I did **not** edit `CHANGELOG.md` — it is generated by release-please from my Conventional Commit PR title (a CI guard enforces this) 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- devin-review-badge-begin --> --- <a href="https://app.devin.ai/review/headroomlabs-ai/headroom/pull/4867" target="_blank"><picture><source media="(prefers-color-scheme: dark)" srcset="https://static.devin.ai/assets/gh-devin-review-dark.svg?v=4"><img src="https://static.devin.ai/assets/gh-devin-review-light.svg?v=4" alt="Devin Review"></picture></a> <!-- devin-review-badge-end --> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
81 lines
2.5 KiB
SQL
81 lines
2.5 KiB
SQL
-- Supabase SQL: Create proxy_telemetry_v2 table
|
|
-- LEGACY: current releases no longer send to Supabase (removed in #1526); only
|
|
-- older releases still insert rows here. Kept for reference and for the
|
|
-- dashboard_summary refresh in create_dashboard_summary.sql.
|
|
-- Run this in the Supabase SQL Editor (https://supabase.com/dashboard → SQL Editor)
|
|
|
|
CREATE TABLE IF NOT EXISTS proxy_telemetry_v2 (
|
|
id uuid DEFAULT gen_random_uuid() PRIMARY KEY,
|
|
created_at timestamptz DEFAULT now() NOT NULL,
|
|
|
|
-- Core identity (always present)
|
|
session_id text NOT NULL,
|
|
instance_id text,
|
|
headroom_version text,
|
|
python_version text,
|
|
os text,
|
|
sdk text,
|
|
backend text,
|
|
session_minutes integer,
|
|
headroom_stack text,
|
|
install_mode text,
|
|
requests_by_stack jsonb,
|
|
|
|
-- Effectiveness metrics
|
|
tokens_saved bigint,
|
|
requests integer,
|
|
compression_percent real,
|
|
cache_hit_rate real,
|
|
cost_saved_usd real,
|
|
cache_saved_usd real,
|
|
models_used jsonb,
|
|
|
|
-- Performance overhead
|
|
overhead_avg_ms real,
|
|
overhead_max_ms real,
|
|
|
|
-- TTFB
|
|
ttfb_avg_ms real,
|
|
|
|
-- Pipeline timing (JSONB: {transform_name: avg_ms})
|
|
pipeline_timing jsonb,
|
|
|
|
-- Request patterns
|
|
avg_tokens_before integer,
|
|
avg_tokens_after integer,
|
|
|
|
-- Compression cache
|
|
compression_cache jsonb,
|
|
|
|
-- CCR usage
|
|
ccr jsonb,
|
|
|
|
-- Waste signals
|
|
waste_signals jsonb
|
|
);
|
|
|
|
-- Index for querying by session and time
|
|
CREATE INDEX IF NOT EXISTS idx_ptv2_session_id ON proxy_telemetry_v2(session_id);
|
|
CREATE INDEX IF NOT EXISTS idx_ptv2_created_at ON proxy_telemetry_v2(created_at DESC);
|
|
CREATE INDEX IF NOT EXISTS idx_ptv2_version ON proxy_telemetry_v2(headroom_version);
|
|
|
|
-- Enable Row Level Security
|
|
ALTER TABLE proxy_telemetry_v2 ENABLE ROW LEVEL SECURITY;
|
|
|
|
-- RLS policy: anon can INSERT only (the beacon of older releases). anon has no
|
|
-- SELECT: read raw rows with the service role. The public dashboard reads the
|
|
-- aggregated dashboard_summary table (create_dashboard_summary.sql).
|
|
--
|
|
-- Safe to re-run on an existing project, and re-running is how a project set
|
|
-- up with an earlier version of this script (which also let anon read every
|
|
-- row) is fixed: the old read policy and grant are removed here.
|
|
DROP POLICY IF EXISTS "anon_select" ON proxy_telemetry_v2;
|
|
REVOKE SELECT ON proxy_telemetry_v2 FROM anon;
|
|
|
|
DROP POLICY IF EXISTS "anon_insert" ON proxy_telemetry_v2;
|
|
CREATE POLICY "anon_insert" ON proxy_telemetry_v2
|
|
FOR INSERT TO anon
|
|
WITH CHECK (true);
|
|
|
|
GRANT INSERT ON proxy_telemetry_v2 TO anon;
|