Skip to content

fix: redact PII on manual Verify artifact edits in anonymised projects - #1437

Merged
ussaama merged 3 commits into
mainfrom
fix/verify-manual-edit-pii-redaction
Dec 2, 2026
Merged

ussaama merged 3 commits into
mainfrom
fix/verify-manual-edit-pii-redaction

Conversation

@JorimTheuns

@JorimTheuns JorimTheuns commented Nov 30, 2026 •

Copy link
Copy Markdown
Member

Summary

Manual edits to Verify artifacts (PUT /api/verify/artifact/:artifact_id with content) previously bypassed PII redaction even when the project had anonymize_transcripts enabled. This change runs deterministic PII redaction synchronously on manual edits for anonymised projects before storing and returning the artifact.

Changes

  • Added @dembrane/transcription as a workspace dependency of @dembrane/verify (namespace -> capability) and updated dembrane/platform/PACKAGES.md and dembrane/platform/bun.lock.
  • Updated updateArtifact in dembrane/platform/packages/verify/src/service.ts to pass body.content through regexRedactPii when project.anonymize_transcripts === true, leaving non-anonymised projects (false or null) untouched.
  • Added unit/service tests in dembrane/platform/packages/verify/test/manual-edit-redaction.test.ts and database-backed route tests in dembrane/platform/packages/verify/test/prompt-privacy.integration.test.ts verifying both anonymised and non-anonymised projects.

Verification

  • bun test packages/verify (34 pass, 0 fail; 35 Postgres-backed integration tests skipped locally without TEST_DATABASE_ADMIN_URL)
  • bun run packages check
  • bun run typecheck
  • bunx biome ci .
  • bun install --frozen-lockfile

Review fixes (supersede the Changes above where they differ)

  • Regex alone missed names, so a hand edit to an anonymised project's artifact now runs regex redaction and then a fast model call (text_fast, no thinking) that only lists PII spans. Code does the replacing, so the markdown and the typed text stay intact.
  • Each listed name also redacts its parts on their own (3+ letters, capitalised, not a particle like van/de/del/bin), with Unicode word boundaries.
  • Only changed, non-blank content is redacted. Re-saving the model's draft makes no call.
  • Fails closed: if the model fails twice, the save returns verify.generation_failed and nothing is stored.
  • Rate limit verify.edit_redaction: 20 per conversation per 10 minutes.
  • content is capped at 20,000 characters (422 above that).
  • Tests: 18 unit tests (casing, particles in several languages, retry, rate limit, failures), plus integration tests for privacy and the size cap.
  • Checked on the local stack: an edit with a name, email and phone is stored redacted, and the formatting is kept.

Known limits

  • A name the model never lists is not caught.
  • A name part that is also an ordinary capitalised word gets redacted everywhere in the edit.
  • The regex can read "2026 EU" as a postcode.
  • Approve waits on the model call (about 1 to 3 seconds).

@JorimTheuns
JorimTheuns force-pushed the fix/verify-manual-edit-pii-redaction branch from 98ffb51 to 7c2d14e Compare December 1, 2026 22:29
The regex pass alone let names through. After it, a fast model call names the
personal details left and code replaces exactly those spans (any casing, whole
words, capitalised name parts too, never a joining word like van/los/des
alone), so the markdown and the rest of the text stay as typed.

- Only edited text is checked; approving the unedited draft makes no call.
- A failed or non-JSON answer (after one retry) saves nothing:
  verify.generation_failed.
- content is capped at 20,000 characters and the check is rate limited per
  conversation (20 per 10 minutes), since it runs outside the AI allowance.
…t-pii-redaction

# Conflicts:
#	dembrane/platform/PACKAGES.md
@ussaama
ussaama merged commit 72e0b6f into main Dec 2, 2026
18 checks passed
@ussaama
ussaama deleted the fix/verify-manual-edit-pii-redaction branch December 2, 2026 13:35
@ussaama
ussaama deployed to pr-preview December 2, 2026 13:36 — with GitHub Actions Active
@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Now on staging, deployed 2026-12-02 13:44 UTC.

ussaama added a commit that referenced this pull request Dec 2, 2026
…st (#1438)

## Summary

Adds the expand-only conversation landscape gate schema, gate helpers,
room producer wiring across all six producer sites, and a canary
integration test. Existing non-deleted rows have `landscape_status IS
NULL` and behave unchanged in room producers; home search transcript
lookup also now excludes soft-deleted conversations (`c.deleted_at is
null`) so rejected conversations cannot leak in private reads.

### Schema and migration
- Adds 8 nullable columns (`landscape_status`, `landscape_review`,
`landscape_text`, `landscape_text_hash`, `landscape_consent_version`,
`landscape_decided_at`, `landscape_moderation`, `landscape_entered_at`)
and 3 check constraints (`conversation_landscape_status`,
`conversation_landscape_review`, `conversation_landscape_entry`) to
`conversation` in `dembrane/platform/packages/db/src/schema/index.ts`.
- Adds `0064_expand_conversation_landscape.sql` (with matching Drizzle
snapshot and journal entry): combines all 8 `ADD COLUMN IF NOT EXISTS`
clauses into one `ALTER TABLE "conversation"` statement and adds all 3
constraints `NOT VALID` inside idempotent `DO` blocks so the
`conversation` table is not scanned under lock and migration re-runs
remain safe.

### Gate helpers and producer sites
- Exports `inLandscapeRoom`, `inRoomSql`, and `usesAcceptedText` from
`dembrane/platform/packages/db/src/landscape.ts` (re-exported from
`@dembrane/db`), with a pure cross-product unit test in
`dembrane/platform/packages/db/test/landscape.test.ts`.
- `dembrane/platform/packages/analysis/src/recipes/services.ts`: gates
`loadTranscripts` and `countConversationsWithTranscripts` with
`inRoomSql`; gated rows read `landscape_text` and use the neutral
`Conversation n` label. `isoTimestamp` in
`dembrane/platform/packages/legacy-shape/src/directus.ts` also handles
`Date` instances returned by raw `postgres.js` clients.
- `dembrane/platform/packages/popcorn/src/storage.ts`: gates
`transcripts()` and `waitingConversations()` with `deleted_at IS NULL`
and `inRoomSql`, joins `conversation` when fetching chunks, and emits
`landscape_text` (with neutral label) for gated rows.
- `dembrane/platform/packages/conversations/src/v1/storage.ts` and
`reply.ts`: gates `adjacent`, `adjacentContent`, and
`adjacentConversations` with `inRoomSql` and substitutes
`landscape_text` for both `conversation.summary` and
`conversation_chunk.transcript` on gated rows.
- `dembrane/platform/packages/canvas/src/storage.ts`: gates
`gatherConversations` and `gatherChunks` with `deleted_at IS NULL` and
`inRoomSql`, masks `participant_name`, and returns `landscape_text` for
gated rows.
- `dembrane/platform/packages/conversations/src/search/storage.ts`: adds
`c.deleted_at is null` in `reachableConversations` (behavior fix for
soft-deleted conversations, matching `searchStorage.conversations()` and
required so rejected conversation chunks cannot appear in home search).

### Canary test
- Adds
`dembrane/platform/apps/api/test/landscape-canary.integration.test.ts`,
seeding a legacy conversation plus gated conversations in `pending`,
`accepted` (review null), `held`, `host_rejected`, `rejected`
(`deleted_at` set), and entered (`landscape_entered_at` set). Verifies
all six room producer sites (Map/analysis, Popcorn, Explore, and
Canvas), DB check constraints (wrapping `postgres.js` lazy queries in
native Promises so Bun `expect().rejects` exits promptly), and private
reads (Ask retrieval, report input, and home search).

## Verification
- `bunx drizzle-kit generate < /dev/null`: reports `No schema changes,
nothing to migrate`.
- `bun run lint`: 0 errors.
- `bun run typecheck`: passes.
- `bun run packages check`: passes.
- `bun test packages/db/test/landscape.test.ts
packages/analysis/test/load-transcripts.test.ts
apps/api/test/landscape-canary.integration.test.ts`: 12 pass, 0 fail
(canary 7 tests). Touched packages: 520 pass; the only failures are a
DBOS "already registered" error when several conversations suites share
one process, which fails the same way on the base branch.

## Review fixes

- Merged the updated #1439, which now includes current main.
- The migration was renumbered from 0060 to **0064** with a fresh
journal timestamp, because main's support migrations took 0060 to 0063
and an older `when` would make Drizzle skip it. The SQL is the same
hand-written idempotent expand with NOT VALID checks.
- Policy is written down in `landscape.ts` and pinned by a canary: room
producers (Map, Popcorn, Canvas, Explore) are gated, while host-private
reads (search, Ask, reports) only drop soft-deleted rows. The new canary
test checks that host search still finds pending, held and host-rejected
conversations.
- Gates: typecheck, biome, packages check, canary 7/7. The landscape,
popcorn, canvas, conversations and verify suites all pass. Some pipeline
files fail only when run together in one process (DBOS registry); each
passes on its own.

Merge order: #1437, then #1439, then #1438.

---------

Co-authored-by: Usama <reach.usamazafar@gmail.com>
Co-authored-by: Usama <59267656+ussaama@users.noreply.github.com>

This branch was successfully deployed

1 active deployment
pr-preview — 16d9a4c4 Deployed Dec 2, 2026 by ussaama via 51-teardown-pr-preview #1624
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants