Skip to content

fix(contracts,ci): prune per-stream storage on close and repair migration/CI pipeline - #1942

Open
Ayomikun2005 wants to merge 3 commits into
LabsCrypt:mainfrom
Ayomikun2005:chore/close-stream-cleanup-ci-fixes
Open

Ayomikun2005 wants to merge 3 commits into
LabsCrypt:mainfrom
Ayomikun2005:chore/close-stream-cleanup-ci-fixes

Conversation

@Ayomikun2005

Copy link
Copy Markdown

Four repo-hygiene fixes: one contract storage leak and three CI/script defects.

Closes #1863
Closes #1864
Closes #1865
Closes #1866

#1863 — close_stream now prunes everything keyed by the stream

close_stream removed only DataKey::Stream(stream_id), leaving the conditional-stream bookkeeping (ConditionalMilestones, AttestedIds, written into the shared instance entry for every conditional stream) and the position metadata (persistent, paying rent with no stream attached) behind forever.

New storage::remove_position_metadata and storage::remove_conditional_metadata are called from close_stream next to remove_stream, and the function docs no longer overclaim.

Test: test_close_stream_prunes_conditional_entry_and_positions asserts the milestone, attestation and position records exist before the close and are all gone afterwards.

Note for review: #1941 (still open) keys DataKey::StreamPosition by (stream_id, role). Whichever lands second needs remove_position_metadata to loop over both roles — a one-line change at the merge, flagged rather than pre-empted so the two PRs don't fight over the same file.

#1864 — test:integration:docker reports failures and runs the whole suite

The old script ended in docker compose stop postgres, so the npm script always exited 0, and it only ran stream-lifecycle.test.ts. It now runs vitest run tests/integration, captures its status, stops Postgres, and exits with that status; docker compose up -d --wait postgres gates on the compose healthcheck instead of racing startup.

Verified by running the exact chain against a deliberately failing spec: vitest returned 1 and the ; rc=$?; …; exit $rc sequence propagated it (chain exit 1).

#1865 — deploy-contracts uploads the WASM it actually builds

The build step writes contracts/target/wasm32-unknown-unknown/release/stream_contract.optimized.wasm, but the upload read …/optimized/*.wasm, a directory nothing creates, so if-no-files-found: error guaranteed a failed step. The upload now points at the release directory — the same path ci.yml uses — and a "Verify Optimized WASM Exists" step fails early with the directory listing if the file is missing.

#1866 — migration history repaired, no more db push --accept-data-loss

  • Destructive duplicate removed. 20260926000000_add_indexer_dead_letter_event used to DROP TABLE … CASCADE the table created by 20260830000000_add_indexer_dead_letter_event and recreate it with a different shape. It now evolves the table in place (RENAME COLUMN, ADD COLUMN + DROP DEFAULT, index swap), so replaying history can no longer destroy quarantined events.
  • Hidden drift captured. schema.prisma declared WebhookSubscription, WebhookDelivery, AlertHistory, PushSubscription, NotificationChannel, LinkCode, NotificationLog and several indexes that no migration ever created — the drift db push was masking. A new 20261121000000_add_notification_webhook_tables migration (generated with prisma migrate diff, not by hand) brings a freshly migrated database up to the model.
  • CI check added. New migrations job runs on backend/prisma/** changes against an empty Postgres service: prisma migrate deploy, then prisma migrate diff --from-config-datasource --to-schema … --exit-code so any future history/schema drift fails the build.
  • No data-loss fallbacks left. testnet-e2e.yml now runs prisma migrate deploy instead of db push --accept-data-loss; the dev:mock:seed script drops the flag too. No --accept-data-loss remains in any workflow or script.

Verification (real Postgres via embedded-postgres, no Docker daemon here)

  • fresh database, full history: prisma migrate deploy → 0
  • prisma migrate diff --from-config-datasource --to-schema prisma/schema.prisma --exit-code → 0 (migrations now match the model exactly)
  • replay with data: applied history through 20260830000000, inserted a dead-letter row, applied the rest → the row survived with the renamed columns (eventId, txHash, ledgerSequence, payload, errorMessage) intact

Checks run

  • cargo test -p stream_contract: 280 passed, 0 failed, 1 pre-existing ignored.
  • cargo clippy -p stream_contract --all-targets -- -D warnings and cargo fmt --all --check: clean.
  • yaml.safe_load on the three touched workflows and json.load on both package.json files: valid.
  • Migration replay/drift/data-preservation runs above.

Not run: GitHub Actions itself (no runner here), and the full backend integration suite (needs the compose stack, which is unavailable in this environment).

…igration pipeline

close_stream removed only the stream record, so conditional streams leaked
milestone/attestation entries into instance storage and position metadata
kept paying rent forever; both are now pruned. The contract-deploy workflow
uploaded from a directory it never wrote, and test:integration:docker always
exited 0 while running a single spec. The migration history no longer drops
the dead-letter table on replay, a missing notification/webhook migration was
generated to remove the drift db push was hiding, and CI now replays the
history on an empty database and fails on schema drift.
@Ayomikun2005
Ayomikun2005 force-pushed the chore/close-stream-cleanup-ci-fixes branch from 2d8fb7a to f060952 Compare November 24, 2026 14:46
Comment thread .github/workflows/ci.yml

steps:
- name: Checkout code
uses: actions/checkout@v4
Comment thread .github/workflows/ci.yml
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
DataKey::StreamPosition is keyed by (stream_id, PositionRole) since the
per-role position storage change, so the single-argument remove left the
recipient entry behind and did not compile.
@Ayomikun2005
Ayomikun2005 force-pushed the chore/close-stream-cleanup-ci-fixes branch from 33bc1b5 to aaab074 Compare November 24, 2026 16:12
Frontend CI failed on the CancelConfirmModal Escape-key assertion, which
passes on its own and does not touch anything in this branch.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants