Skip to content
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
e36af18
test(longitudinal): require durable observation persistence
seonghobae Aug 17, 2026
223c402
feat(longitudinal): add immutable observation schema
seonghobae Aug 17, 2026
96d9fd5
feat(longitudinal): persist immutable observation evidence
seonghobae Aug 17, 2026
219ad3f
feat(longitudinal): expose observation persistence adapter
seonghobae Aug 17, 2026
2bbe2ab
test(longitudinal): require tenant-bound persistence
seonghobae Aug 17, 2026
8b2b04a
feat(longitudinal): isolate observation evidence by tenant
seonghobae Aug 17, 2026
4e83c0d
feat(longitudinal): bind persisted observations to tenant
seonghobae Aug 17, 2026
263494e
test(longitudinal): require tenant-scoped restart recovery
seonghobae Aug 17, 2026
3891688
fix(longitudinal): restore durable observations after restart
seonghobae Aug 17, 2026
cf66f3d
fix(longitudinal): preserve checked membership sequence loading
seonghobae Aug 17, 2026
561f999
fix(longitudinal): satisfy strict rustdoc lint
seonghobae Aug 17, 2026
c0ad5d8
Merge branch 'main' into feat/longitudinal-observation-persistence-20…
github-actions[bot] Aug 17, 2026
bf8351d
test(longitudinal): reject membership-less persisted observations
seonghobae Aug 17, 2026
5fb0985
fix(longitudinal): reject observations without memberships
seonghobae Aug 17, 2026
b1ab98b
test(longitudinal): preserve corrupt-restore loader coverage
seonghobae Aug 17, 2026
3b24bce
fix(longitudinal): satisfy doc-markdown gate
seonghobae Aug 17, 2026
456cf12
test(longitudinal): cover immutable replay classification boundaries
seonghobae Aug 17, 2026
bc1ad6c
test(longitudinal): keep replay coverage formatted
seonghobae Aug 17, 2026
65bca82
test(longitudinal): avoid client helper shadowing
seonghobae Aug 17, 2026
7d69fc5
test(longitudinal): structure replay matrix for clippy
seonghobae Aug 17, 2026
27ee781
fix(longitudinal): clarify persistence reference errors
seonghobae Aug 17, 2026
bf4b3ce
test(longitudinal): reject numeric references and clock-code mismatch
seonghobae Aug 17, 2026
a514b66
fix(longitudinal): enforce opaque refs and clock anomaly integrity
seonghobae Aug 17, 2026
052cd95
fix(longitudinal): preserve corruption probes with insert-time clock …
seonghobae Aug 17, 2026
b4b6505
Merge branch 'main' into feat/longitudinal-observation-persistence-20…
opencode-agent[bot] Aug 18, 2026
78892b2
Merge branch 'main' into feat/longitudinal-observation-persistence-20…
opencode-agent[bot] Aug 18, 2026
46816e4
fix(longitudinal): isolate schema integrity tests and rustfmt
cursoragent Aug 18, 2026
73dadc6
fix(longitudinal): cover persist query errors and rustdoc clippy
cursoragent Aug 18, 2026
a436b5a
test(session-http): tolerate peer close during invalid framing
cursoragent Aug 18, 2026
dad81fc
test(longitudinal): reject Unicode numeric separators in DB refs
seonghobae Aug 19, 2026
1f86a81
fix(longitudinal): align DB numeric separator guard
seonghobae Aug 19, 2026
46bf001
test(longitudinal): reject control characters in DB refs
seonghobae Aug 19, 2026
6483b72
fix(longitudinal): reject unsafe DB reference controls
seonghobae Aug 19, 2026
8b0fbe1
test(longitudinal): require anomaly CHECK defense
seonghobae Aug 19, 2026
fb5e161
fix(longitudinal): enforce clock anomaly relation in CHECK
seonghobae Aug 19, 2026
9a080b7
test(longitudinal): preserve corrupt-history recovery probe
seonghobae Aug 19, 2026
b3cb2ea
fix(longitudinal): keep hyphen literal in reference regex
seonghobae Aug 20, 2026
441cea8
test(longitudinal): pin digit-bearing opaque reference contract
seonghobae Aug 20, 2026
b472cea
style(longitudinal): restore schema test trailing newline
seonghobae Aug 20, 2026
377777e
Merge protected main into longitudinal observation reconciliation
seonghobae Aug 20, 2026
8b34b24
test(longitudinal): require Unicode numeric parity in PostgreSQL
seonghobae Aug 20, 2026
c6b0583
fix(longitudinal): align PostgreSQL numeric refs with Rust
seonghobae Aug 20, 2026
dfb18f4
merge(main): reconcile longitudinal persistence with scoring adapter
seonghobae Aug 21, 2026
b9e7b8d
docs(longitudinal): distinguish active persistence from shipped flow
seonghobae Aug 21, 2026
2a2b85d
docs(longitudinal): map active PostgreSQL observation schema
seonghobae Aug 21, 2026
10394d6
docs(longitudinal): record active durable observation slice
seonghobae Aug 21, 2026
b5b1a36
docs(longitudinal): record tenant-scoped source identity
seonghobae Aug 21, 2026
75e4d0a
chore(longitudinal): reconcile observation persistence with current main
seonghobae Aug 21, 2026
ccb0b4b
Merge branch 'main' into feat/longitudinal-observation-persistence-20…
opencode-agent[bot] Aug 24, 2026
49a4b23
Merge branch 'main' into feat/longitudinal-observation-persistence-20…
seonghobae Aug 26, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 125 additions & 0 deletions migrations/0031_longitudinal_observation.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
-- Durable, immutable normalized longitudinal observation evidence.
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

CREATE TABLE IF NOT EXISTS longitudinal_observation (
observation_record_ref text PRIMARY KEY,
tenant_ref text NOT NULL,
enrollment_ref text NOT NULL,
source_system_ref text NOT NULL,
source_observation_ref text NOT NULL,
construct_ref text NOT NULL,
measure_ref text NOT NULL,
validity_start_at_unix_ms bigint NOT NULL,
validity_end_at_unix_ms bigint NOT NULL,
recorded_at_unix_ms bigint NOT NULL,
received_at_unix_ms bigint NOT NULL,
ingested_at_unix_ms bigint NOT NULL,
timezone_name text NOT NULL,
utc_offset_minutes smallint NOT NULL,
clock_anomaly_code text,
CONSTRAINT longitudinal_observation_source_identity_unique
UNIQUE (tenant_ref, enrollment_ref, source_system_ref, source_observation_ref),
CONSTRAINT longitudinal_observation_reference_check CHECK (
observation_record_ref = btrim(observation_record_ref) AND observation_record_ref <> '' AND observation_record_ref !~ '^[0-9]+$'
AND tenant_ref = btrim(tenant_ref) AND tenant_ref <> '' AND tenant_ref !~ '^[0-9]+$'
AND enrollment_ref = btrim(enrollment_ref) AND enrollment_ref <> '' AND enrollment_ref !~ '^[0-9]+$'
AND source_system_ref = btrim(source_system_ref) AND source_system_ref <> '' AND source_system_ref !~ '^[0-9]+$'
AND source_observation_ref = btrim(source_observation_ref) AND source_observation_ref <> '' AND source_observation_ref !~ '^[0-9]+$'
AND construct_ref = btrim(construct_ref) AND construct_ref <> '' AND construct_ref !~ '^[0-9]+$'
AND measure_ref = btrim(measure_ref) AND measure_ref <> '' AND measure_ref !~ '^[0-9]+$'
),
CONSTRAINT longitudinal_observation_time_check CHECK (
validity_start_at_unix_ms > 0 AND validity_end_at_unix_ms >= validity_start_at_unix_ms
AND recorded_at_unix_ms > 0 AND received_at_unix_ms > 0 AND ingested_at_unix_ms >= received_at_unix_ms
),
CONSTRAINT longitudinal_observation_timezone_check CHECK (
timezone_name = btrim(timezone_name) AND timezone_name <> '' AND timezone_name !~ '^[0-9]+$'
AND utc_offset_minutes BETWEEN -720 AND 840
),
CONSTRAINT longitudinal_observation_anomaly_check CHECK (
clock_anomaly_code IS NULL OR clock_anomaly_code = 'recorded_after_received'
)
Comment on lines +94 to +100

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📝 Info: Anomaly-code mapping stays consistent with domain flagging and CHECK constraint

The domain sets clock_anomaly = RecordedAfterReceived iff recorded_at > received_at (src/longitudinal_observation.rs:374-375), clock_anomaly_code maps that one-to-one (postgres_longitudinal_observation.rs), and the SQL longitudinal_observation_anomaly_check enforces exactly (code IS NULL AND recorded <= received) OR (code='recorded_after_received' AND recorded > received). These three definitions agree for the boundary case recorded == received (no anomaly), so persisted records never violate the constraint and require_clock_anomaly_code on load stays consistent. No defect found.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

);

CREATE TABLE IF NOT EXISTS longitudinal_membership_share (
observation_record_ref text NOT NULL
REFERENCES longitudinal_observation(observation_record_ref) ON DELETE RESTRICT,
membership_sequence bigint NOT NULL,
membership_context_ref text NOT NULL,
weight_parts_per_10_000 integer NOT NULL,
PRIMARY KEY (observation_record_ref, membership_sequence),
CONSTRAINT longitudinal_membership_context_unique
UNIQUE (observation_record_ref, membership_context_ref),
CONSTRAINT longitudinal_membership_sequence_check CHECK (membership_sequence > 0),
CONSTRAINT longitudinal_membership_reference_check CHECK (
membership_context_ref = btrim(membership_context_ref)
AND membership_context_ref <> ''
AND membership_context_ref !~ '^[0-9]+$'
),
CONSTRAINT longitudinal_membership_weight_check CHECK (
weight_parts_per_10_000 BETWEEN 1 AND 10000
)
);

CREATE OR REPLACE FUNCTION reject_longitudinal_mutation()
RETURNS trigger
LANGUAGE plpgsql
AS $$
BEGIN
RAISE EXCEPTION 'longitudinal observation evidence is immutable'
USING ERRCODE = '55000';
END;
$$;

DROP TRIGGER IF EXISTS longitudinal_observation_immutable_update ON longitudinal_observation;
CREATE TRIGGER longitudinal_observation_immutable_update
BEFORE UPDATE OR DELETE ON longitudinal_observation
FOR EACH ROW EXECUTE FUNCTION reject_longitudinal_mutation();

DROP TRIGGER IF EXISTS longitudinal_observation_immutable_truncate ON longitudinal_observation;
CREATE TRIGGER longitudinal_observation_immutable_truncate
BEFORE TRUNCATE ON longitudinal_observation
FOR EACH STATEMENT EXECUTE FUNCTION reject_longitudinal_mutation();

DROP TRIGGER IF EXISTS longitudinal_membership_immutable_update ON longitudinal_membership_share;
CREATE TRIGGER longitudinal_membership_immutable_update
BEFORE UPDATE OR DELETE ON longitudinal_membership_share
FOR EACH ROW EXECUTE FUNCTION reject_longitudinal_mutation();

DROP TRIGGER IF EXISTS longitudinal_membership_immutable_truncate ON longitudinal_membership_share;
CREATE TRIGGER longitudinal_membership_immutable_truncate
BEFORE TRUNCATE ON longitudinal_membership_share
FOR EACH STATEMENT EXECUTE FUNCTION reject_longitudinal_mutation();

CREATE OR REPLACE FUNCTION enforce_longitudinal_membership_total()
RETURNS trigger
LANGUAGE plpgsql
AS $$
DECLARE
total_weight bigint;
BEGIN
SELECT COALESCE(SUM(weight_parts_per_10_000), 0)
INTO total_weight
FROM longitudinal_membership_share
WHERE observation_record_ref = NEW.observation_record_ref;
IF total_weight <> 10000 THEN
RAISE EXCEPTION 'longitudinal membership shares must sum to 10000'
USING ERRCODE = '23514';
END IF;
RETURN NULL;
END;
$$;

-- A membership-only trigger cannot observe an observation whose membership vector is empty,
-- because no child INSERT exists to fire it. Defer the same invariant from the parent INSERT so
-- the complete vector can be inserted in the transaction while a header-only commit still fails.
DROP TRIGGER IF EXISTS longitudinal_observation_membership_total_check ON longitudinal_observation;
CREATE CONSTRAINT TRIGGER longitudinal_observation_membership_total_check
AFTER INSERT ON longitudinal_observation
DEFERRABLE INITIALLY DEFERRED
FOR EACH ROW EXECUTE FUNCTION enforce_longitudinal_membership_total();

DROP TRIGGER IF EXISTS longitudinal_membership_total_check ON longitudinal_membership_share;
CREATE CONSTRAINT TRIGGER longitudinal_membership_total_check
AFTER INSERT ON longitudinal_membership_share
DEFERRABLE INITIALLY DEFERRED
FOR EACH ROW EXECUTE FUNCTION enforce_longitudinal_membership_total();
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub mod postgres_inbox_consumption;
pub mod postgres_instrument_release;
pub mod postgres_integration;
pub mod postgres_item_delivery;
pub mod postgres_longitudinal_observation;
Comment thread
devin-ai-integration[bot] marked this conversation as resolved.
Resolved
pub mod postgres_response_snapshot;
pub mod postgres_result_snapshot;
pub mod postgres_scoring_job;
Expand Down
Loading
Loading