Skip to content

Tear down workflows when archiving documents#1481

Open
gearnode wants to merge 5 commits into
mainfrom
cursor/archive-workflow-teardown-d66e
Open

Tear down workflows when archiving documents#1481
gearnode wants to merge 5 commits into
mainfrom
cursor/archive-workflow-teardown-d66e

Conversation

@gearnode

@gearnode gearnode commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

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.

  • Archive / bulk archive: void open approval quorums (version → DRAFT), delete all REQUESTED signatures with cancelled webhooks, then run existing archive side effects
  • Unarchive / bulk unarchive: void any remaining PENDING_APPROVAL quorum before restoring ACTIVE
  • Migration: backfill archived documents that still have pending quorums, decisions, PENDING_APPROVAL versions, or REQUESTED signatures

CI fix

LoadRequestedByDocumentID used a JOIN that made the scoped tenant_id = @tenant_id fragment ambiguous in PostgreSQL, causing archive mutations to return internal server errors in e2e.

Test plan

  • TestDocumentVersion_ArchiveVoidsPendingQuorum
  • TestDocumentVersion_ArchiveCancelsPendingSignatures
  • TestDocumentVersion_UnarchiveRestoresEditableDraft
  • Updated TestDocumentVersion_SignArchivedDocumentFails (signature row removed, not just sign-blocked)
  • go test ./pkg/coredata/...
Open in Web Open in Cursor 

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 -9

  • Added e2e cases for archive teardown and unarchive recovery.
  • Verified quorum is voided and requested signatures are removed.
  • Updated archived-signing test to assert no signature rows remain.

Coredata +152 -0

  • Added LoadRequestedByDocumentID/DeleteRequestedByDocumentID for REQUESTED signatures and fixed the ambiguous tenant filter with an IN-subquery.
  • Migration backfills archived docs: voids pending decisions/quorums, converts PENDING_APPROVAL versions to DRAFT with next minor, and deletes REQUESTED signatures.

Service +207 -39

  • Archive/bulk archive: teardownDocumentWorkflowsInTx voids latest-version pending approvals and cancels requested signatures, emitting DocumentVersionSignatureCancelled webhooks, then freezes the doc.
  • Unarchive/bulk unarchive: ensureDraftReadyOnUnarchiveInTx voids any leftover pending approval before restoring ACTIVE, ensuring the latest version is DRAFT.
  • Refactor/perf: extracted voidApprovalInTx and voidPendingApprovalForLatestVersionInTx; grouped archive orchestration beside Archive/Unarchive; batch-loaded versions when cancelling signature requests.

Written for commit 9cc62e4. Summary will update on new commits.

Review in cubic

cursoragent and others added 3 commits July 11, 2026 09:53
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>
@gearnode gearnode marked this pull request as ready for review July 13, 2026 12:31
@gearnode gearnode requested a review from a team July 13, 2026 12:31

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 5 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread pkg/probo/document_service.go
cursoragent and others added 2 commits July 13, 2026 13:21
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>
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.

3 participants