Skip to content

pm-stack: define action/event schema contract (#6103) - #6183

Merged
developing-today[bot] merged 4 commits into
mainfrom
queue/9916-6103-action-event-schema
Nov 7, 2026
Merged

developing-today[bot] merged 4 commits into
mainfrom
queue/9916-6103-action-event-schema

Conversation

@dezren39

@dezren39 dezren39 commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Define the column, key, idempotency, timestamp, and provenance contracts for �[0mpublic.agg_actions�[0m and action outcomes in �[0mpublic.shared_events�[0m.
  • Add versioned up/down SQL with constraints and a rollback guard, plus a disposable PostgreSQL 16 test.
  • Record JSON fallback/rollback and the limited P1 / Move 1 status in the schema map and migration plan.

Scope

This is schema/documentation/test only. It does not migrate rows, change live readers or writers, apply DDL to Supabase �[0mmuse-dev2�[0m, or complete P1 / Move 1. #1744 acceptance criterion 3 remains unchecked.

Verification

  • �[0mbash pm-stack/shared-schema/test-migration.sh�[0m — pass (constraints and rollback on disposable PostgreSQL 16)
  • �[0mPM_AGG_FRESHNESS_PORT=47871 bun test test/actions.test.ts�[0m — 25 pass
  • �[0mbash -n pm-stack/shared-schema/test-migration.sh�[0m — pass
  • �[0mgit diff --check�[0m — pass

Fixes #6103


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

@dezren39
dezren39 requested a review from a team as a code owner November 5, 2026 09:32
@dezren39
dezren39 requested a balanced review from Copilot November 5, 2026 09:32
@coderabbitai

coderabbitai Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 29 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 544fe364-702a-430b-9395-411a0cccd8a0
Commits

Reviewing files that changed from the base of the PR and between e3626d1 and c9a41e7.

Files selected for processing: 6

  • pm-stack/SHARED-SCHEMA-MAP.md
  • pm-stack/SHARED-SCHEMA-MIGRATION-PLAN.md
  • pm-stack/shared-schema/README.md
  • pm-stack/shared-schema/migrations/20261105_0001_action_event_store.down.sql
  • pm-stack/shared-schema/migrations/20261105_0001_action_event_store.up.sql
  • pm-stack/shared-schema/test-migration.sh
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-07T03:12:10.738965Z c9a41e7 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e5a9417cff

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +70 to +71
AND jsonb_typeof(attribution->'asserted') = 'boolean'
AND (attribution->>'confidence' <> 'authenticated' OR attribution->'asserted' = 'true'::jsonb)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Reject attribution objects with a missing asserted flag

An attribution object such as {"confidence":"authenticated"} passes this constraint: the missing asserted field makes both relevant predicates SQL NULL, and PostgreSQL CHECK constraints accept NULL results. This permits authenticated provenance without the explicit assertion required by the new contract and by validateAuditExtras in aggregator/src/events.ts. Make the boolean-presence predicate reject NULL, for example by wrapping it in coalesce(..., false).

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in dccaccf: the boolean-presence predicate is now coalesce(jsonb_typeof(attribution->'asserted') = 'boolean', false), so a missing asserted flag makes the CHECK false instead of NULL. The test adds a rejection case for {"confidence":"authenticated"} with no asserted flag. — repo-worker-code-d (fallback mode, issue #6103)

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

7 open issues
What changed in this PR

Defines an initial, versioned schema contract for PM aggregator actions (public.agg_actions) and action outcomes (public.shared_events), with locally testable up/down SQL and supporting documentation/planning updates.

Changes:

  • Add up/down SQL migrations to create agg_actions + shared_events with constraints, indexes, RLS, and grants.
  • Add a disposable PostgreSQL 16 Docker-based migration verification script.
  • Document the contract and update the shared schema map/migration plan to reflect current status and rollback/fallback expectations.
File Description
pm-stack/​shared-schema/​test-migration.sh Adds a disposable Dockerized Postgres test that exercises constraints and down-migration guardrails.
pm-stack/​shared-schema/​migrations/​20261105_0001_action_event_store.up.sql Introduces the initial schema for actions and shared events with contracts enforced via constraints/indexes/RLS/grants.
pm-stack/​shared-schema/​migrations/​20261105_0001_action_event_store.down.sql Adds a rollback guard to prevent dropping non-empty tables, then drops the tables.
pm-stack/​shared-schema/​README.md Documents the schema contract, constraints, and migration/rollback strategy for Move 1 actions/outcomes.
pm-stack/​SHARED-SCHEMA-MIGRATION-PLAN.md Updates preconditions/move notes to reflect this slice’s new contract/DDLs and current status.
pm-stack/​SHARED-SCHEMA-MAP.md Adds a map entry pointing to the new action/event schema contract and local DDL/test artifacts.

Review effort: Lite

Comment thread pm-stack/shared-schema/README.md Outdated
| `payload` | `jsonb`, not null | `payload` | Must be a JSON object; verb-specific validation stays at the application boundary. |
| `author` | `jsonb`, not null | `author` | Must contain a supported `kind`, non-empty `id`, and non-empty `label`. This is self-asserted authorship, **not authenticated identity**. |
| `created_at` | `timestamptz`, not null | `createdAt` | Creation time; no `updated_at` field exists in the source contract. |
| `state` | `text`, not null, default `new` | `state` | Check-constrained to `new`, `applied`, `rejected`, `superseded`. A result timestamp is recorded in `applied_at` for both applied and rejected transitions. |

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in dccaccf: the documented contract is now DB-enforced — agg_actions_result_timestamp_check requires applied_at for applied/rejected and forbids it for new; the test rejects an applied action without a result timestamp. — repo-worker-code-d

Comment on lines +4 to +12
IF EXISTS (SELECT 1 FROM public.shared_events LIMIT 1)
OR EXISTS (SELECT 1 FROM public.agg_actions LIMIT 1) THEN
RAISE EXCEPTION 'refusing to drop non-empty action/event tables; export/replay rows first';
END IF;
END
$$;

DROP TABLE public.shared_events;
DROP TABLE public.agg_actions;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in dccaccf: the down migration's guard now uses to_regclass(...) IS NOT NULL existence checks and DROP TABLE IF EXISTS, so rollback works from a partially-applied state while still refusing to drop non-empty tables. — repo-worker-code-d

Comment on lines +3 to +12
BEGIN
IF EXISTS (SELECT 1 FROM public.shared_events LIMIT 1)
OR EXISTS (SELECT 1 FROM public.agg_actions LIMIT 1) THEN
RAISE EXCEPTION 'refusing to drop non-empty action/event tables; export/replay rows first';
END IF;
END
$$;

DROP TABLE public.shared_events;
DROP TABLE public.agg_actions;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in dccaccf (same change as the sibling comment): to_regclass-guarded existence checks plus DROP TABLE IF EXISTS in the down migration. — repo-worker-code-d

Comment on lines +47 to +48
psql_test -c 'CREATE ROLE service_role;'
psql_test < "$up"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in dccaccf: the test role is now created BYPASSRLS LOGIN (modeling Supabase's service_role) and the test proves the role can insert and read back a shared_events row under RLS, not just hold grants. — repo-worker-code-d

Codex P2: preserve original event timestamp strings (event_at_raw/ingested_at_raw) alongside normalized timestamptz so imported audit events stay hash-verifiable; reject attribution objects missing the asserted flag (coalesce the boolean-presence predicate so NULL no longer passes the CHECK).

Copilot: enforce the documented applied_at contract with a state/timestamp CHECK; reject empty idempotency keys; make the down migration tolerate partially-applied state (to_regclass guards + DROP TABLE IF EXISTS); model Supabase service_role with BYPASSRLS/LOGIN in the test and prove it can write/read under RLS.

Test: bash pm-stack/shared-schema/test-migration.sh — pass on disposable PostgreSQL 16 (20 ok checks, incl. new rejections and raw-timestamp round-trip).

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: dccaccf6d1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

))
),
CONSTRAINT agg_actions_result_timestamp_check CHECK (
(state IN ('applied', 'rejected') AND applied_at IS NOT NULL)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Allow rejected duplicate actions without a consumer timestamp

When mirroring or importing duplicate-answer records from the current action store, this constraint rejects valid existing rows. ActionsStore.add() in aggregator/src/actions.ts:734–754 creates duplicate attempts directly in state rejected, with duplicateOf and resultNote but without appliedAt; these records are persisted as audit history, and markResultTransition() leaves them unchanged because they are already terminal. Requiring applied_at for every rejected action therefore prevents lossless migration of these records. Allow the rejected-duplicate case without a consumer-result timestamp rather than requiring importers to invent one.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in c9a41e7: the result-timestamp CHECK now exempts rejected duplicates — state='rejected' requires applied_at only when duplicate_of_action_id is null, matching ActionsStore.add() (verified at aggregator/src/actions.ts:734–754: duplicates are created rejected with duplicateOf/resultNote and no appliedAt). Tests cover both directions: a rejected duplicate without a timestamp is accepted; a rejected non-duplicate without one is still rejected. — repo-worker-code-d (fallback mode, issue #6103)

…for #6103

Preserve verbatim attribution/source JSON serializations (attribution_raw/source_raw) alongside jsonb, since canonicalFields hashes JSON.stringify of the original objects and jsonb reorders keys. Relax the result-timestamp CHECK for rejected duplicates: ActionsStore.add() creates them already-rejected with duplicateOf/resultNote and no consumer timestamp, so they must import losslessly; rejected non-duplicates still require applied_at.

Test: bash pm-stack/shared-schema/test-migration.sh — pass on disposable PostgreSQL 16 (23 ok checks).
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.

PM stack #1744: define schema contract for the first shared action/event store

2 participants