Tear down workflows when archiving documents#1481
Open
gearnode wants to merge 5 commits into
Open
Conversation
Archive and bulk archive now void pending approval quorums and cancel requested signatures before freezing the document. Unarchive reverts any leftover pending approval to draft. A migration backfills archived documents that still carry in-flight workflow rows. Signed-off-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Bryan FRIMIN <bryan@frimin.fr>
LoadRequestedByDocumentID joined document_versions while applying the unqualified tenant_id scope fragment, which PostgreSQL rejects. Use the same IN-subquery shape as DeleteRequestedByDocumentID. Signed-off-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Bryan FRIMIN <bryan@frimin.fr>
Move approval void logic into voidPendingApprovalForLatestVersionInTx on DocumentApprovalService and group signature cancellation with the existing cancelPreviousMajorSignatureRequestsInTx helpers. Place archive-specific InTx orchestration beside Archive and Unarchive. Signed-off-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Bryan FRIMIN <bryan@frimin.fr>
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 5 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Archive teardown loaded each document version inside the signature cancellation loop. Collect version IDs and use LoadByIDs once instead. Signed-off-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Bryan FRIMIN <bryan@frimin.fr>
The test-e2e, scan, and Analyze (go) jobs failed during action download with Service Unavailable, not due to code regressions. Signed-off-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Bryan FRIMIN <bryan@frimin.fr>
SachaProbo
approved these changes
Jul 16, 2026
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
Archiving a document now tears down in-flight workflow state before the document is frozen. Unarchiving defensively reverts any leftover pending approval back to draft.
DRAFT), delete allREQUESTEDsignatures with cancelled webhooks, then run existing archive side effectsPENDING_APPROVALquorum before restoringACTIVEPENDING_APPROVALversions, orREQUESTEDsignaturesCI fix
LoadRequestedByDocumentIDused a JOIN that made the scopedtenant_id = @tenant_idfragment ambiguous in PostgreSQL, causing archive mutations to return internal server errors in e2e.Test plan
TestDocumentVersion_ArchiveVoidsPendingQuorumTestDocumentVersion_ArchiveCancelsPendingSignaturesTestDocumentVersion_UnarchiveRestoresEditableDraftTestDocumentVersion_SignArchivedDocumentFails(signature row removed, not just sign-blocked)go test ./pkg/coredata/...Summary by cubic
Archiving now tears down in-flight workflows by voiding pending approvals and deleting requested signatures before the doc is frozen. Unarchiving voids any leftover pending approval and restores a draft; signature cancellation now batch-loads versions to reduce queries.
Tests
+223-9Coredata
+152-0LoadRequestedByDocumentID/DeleteRequestedByDocumentIDforREQUESTEDsignatures and fixed the ambiguous tenant filter with an IN-subquery.PENDING_APPROVALversions toDRAFTwith next minor, and deletesREQUESTEDsignatures.Service
+207-39teardownDocumentWorkflowsInTxvoids latest-version pending approvals and cancels requested signatures, emittingDocumentVersionSignatureCancelledwebhooks, then freezes the doc.ensureDraftReadyOnUnarchiveInTxvoids any leftover pending approval before restoringACTIVE, ensuring the latest version isDRAFT.voidApprovalInTxandvoidPendingApprovalForLatestVersionInTx; grouped archive orchestration besideArchive/Unarchive; batch-loaded versions when cancelling signature requests.Written for commit 9cc62e4. Summary will update on new commits.