feat: ephemeral-document cleanup (per-workflow blob + Temporal purge) - #203
Merged
Conversation
Opt-in, per-workflow ephemeral policy. When a workflow declares
metadata.ephemeral, documents it processes are purged once they reach a
terminal status — blob files and/or the Temporal execution record are
deleted per the policy — while the OCR result in Postgres is retained.
- metadata.ephemeral: true | { files, temporalRecord } for per-target control
- EphemeralDocumentCleanupService: @Cron(EVERY_MINUTE) janitor, gated solely
by workflow config (no global flag, no per-group setting)
- TemporalClientService.deleteWorkflowExecution (idempotent on NOT_FOUND)
- documents.purged_at marker + partial index documents_purge_scan_idx
(WHERE purged_at IS NULL) to keep the janitor scan cheap at high volume
- docs-md/ephemeral-document-cleanup.md
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
alex-struk
marked this pull request as ready for review
June 24, 2026 18:22
alex-struk
requested review from
NoorChasib,
antsand,
dbarkowsky and
kmandryk
as code owners
June 24, 2026 18:22
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds an opt-in, per-workflow ephemeral policy. When a workflow's config declares
metadata.ephemeral, documents it processes are purged once they reach a terminal status — blob files and/or the Temporal execution record are deleted per the policy — while the OCR result in Postgres is retained so clients can still poll it.Configured entirely on the workflow: no global flag, no per-group setting.
metadata.ephemeralvaluestrue{ "files": true, "temporalRecord": false }truefalse/ absentWhat's included
EphemeralDocumentCleanupService—@Cron(EVERY_MINUTE)janitor; per-document failures isolated; idempotent (safe to retry).TemporalClientService.deleteWorkflowExecution— idempotent onNOT_FOUND.documents.purged_atmarker (stops reprocessing; row +ocr_resultskept) + partial indexdocuments_purge_scan_idx (workflow_config_id, status) WHERE purged_at IS NULLso the scan stays cheap at high volume.docs-md/ephemeral-document-cleanup.md.Migrations
20260623000000_add_document_purged_at20260624000000_add_documents_purge_index(partial index — Prisma can't express it in schema; managed via raw SQL)Verification
ephemeral: true→ blobs and Temporal record deleted, OCR text retained.{ files: true, temporalRecord: false }→ blobs deleted, Temporal record kept, OCR text retained.🤖 Generated with Claude Code