feat(lifecycle): add dependency-free durable cleanup worker - #279
feat(lifecycle): add dependency-free durable cleanup worker#279seonghobae wants to merge 20 commits into
Conversation
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthrough내구성 있는 삭제 영수증과 lifecycle lock을 추가했습니다. 삭제는 tombstone, checksum 검증, artifact 정리 순서로 실행됩니다. 실패한 삭제는 bounded recovery로 재시도합니다. 삭제 후 저장을 차단하고, tenant별 idempotency와 서비스 위임을 적용했습니다. Changes내구성 있는 artifact 삭제
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant DurableDocumentDeletionService
participant ArtifactDeletionCoordinator
participant ConversionJobRepository
participant ArtifactDeletionReceiptStore
participant ArtifactStore
DurableDocumentDeletionService->>ArtifactDeletionCoordinator: deleteForTenant(jobId, tenantId)
ArtifactDeletionCoordinator->>ConversionJobRepository: metadata tombstone 적용
ArtifactDeletionCoordinator->>ArtifactDeletionReceiptStore: 삭제 receipt 저장
ArtifactDeletionCoordinator->>ArtifactStore: artifact 조회 및 checksum 검증
ArtifactDeletionCoordinator->>ArtifactStore: artifact 삭제
ArtifactDeletionCoordinator->>ArtifactDeletionReceiptStore: 완료 또는 retryable failure 기록
Possibly related issues
🚥 Pre-merge checks | ✅ 2 | ❌ 3❌ Failed checks (3 warnings)
✅ Passed checks (2 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
|
@coderabbitai review @opencode-agent @cwl-noema-review Please independently review exact current head |
|
✅ Action performedReview finished.
|
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (6)
src/test/java/com/clearfolio/viewer/lifecycle/ArtifactDeletionCoordinatorTest.java (2)
250-250: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value
assertArrayEquals를 사용하세요.
assertTrue(Arrays.equals(...))는 실패 시 기대값과 실제값을 보고하지 않습니다.assertArrayEquals(REPLACEMENT_ARTIFACT, mismatchStore.getPdf(JOB_ID).orElseThrow())로 바꾸면 실패 진단이 쉬워집니다.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/test/java/com/clearfolio/viewer/lifecycle/ArtifactDeletionCoordinatorTest.java` at line 250, In ArtifactDeletionCoordinatorTest, replace the assertTrue(Arrays.equals(...)) assertion with assertArrayEquals using REPLACEMENT_ARTIFACT and mismatchStore.getPdf(JOB_ID).orElseThrow() so failures report expected and actual byte arrays.
298-327: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win배치 상한이 실제로 검증되지 않습니다.
이 테스트는 대기 영수증 2개와
maxReceiptsPerRun=2를 사용합니다. 두 값이 같으므로Math.min(maxReceiptsPerRun, pending.size())의 상한 동작이 확인되지 않습니다. 상한을 제거해도 이 테스트는 통과합니다.대기 영수증 수가
maxReceiptsPerRun보다 큰 경우를 추가하세요. 예: 대기 3개, 상한 2개일 때 반환값이 2이고 세 번째 영수증에는findByJobId상호작용이 없음을 검증하세요.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/test/java/com/clearfolio/viewer/lifecycle/ArtifactDeletionCoordinatorTest.java` around lines 298 - 327, Update recoveryBatchIsBoundedIsolatesFailuresAndUsesScheduledEntryPoint to provide three pending receipts while retaining maxReceiptsPerRun as 2, and configure the first two for the existing failure/success paths. Assert retryPendingWork() returns 2 and verify the third receipt has no findByJobId interaction, preserving the scheduled-entry-point assertions.src/main/java/com/clearfolio/viewer/lifecycle/ArtifactDeletionCoordinator.java (2)
159-171: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win복구 실패 로그에 예외 종류를 포함하세요.
현재 로그는 예외 정보를 전혀 남기지 않습니다. 운영자는 실패 원인을 구분할 수 없습니다. 개인정보 보호를 유지하려면 예외 클래스 이름만 기록하세요. 메시지와 식별자는 제외하세요.
♻️ 제안 리팩터
} catch (RuntimeException exception) { metrics.recordFailed(); - log.warn("Artifact deletion recovery retained an incomplete receipt."); + log.warn( + "Artifact deletion recovery retained an incomplete receipt. cause={}", + exception.getClass().getSimpleName() + ); }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/main/java/com/clearfolio/viewer/lifecycle/ArtifactDeletionCoordinator.java` around lines 159 - 171, Update the catch block in retryPendingWork to include only exception.getClass().getName() in the recovery warning log, preserving the existing message while excluding the exception message and identifiers.
207-225: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick win
deleteGloballyLocked에서resumeReceiptLocked를 사용하세요.동일한 tenant와 checksum의 기존 영수증은 상태와 관계없이 반환됩니다. 현재 코드는 메타데이터를 먼저 삭제한 뒤
markMetadataTombstoned를 호출합니다. 이 메서드는DELETION_REQUESTED만 허용하므로ARTIFACT_CLEANUP_FAILED또는ARTIFACT_CLEANUP_COMPLETED상태에서 예외가 발생합니다. 메타데이터 삭제 후 예외가 발생하는 순서도 피해야 합니다.deleteForTenantLocked와 같이resumeReceiptLocked(receipt)를 호출하여 실패 상태는 재시도하고 완료 상태는 no-op으로 처리하세요.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/main/java/com/clearfolio/viewer/lifecycle/ArtifactDeletionCoordinator.java` around lines 207 - 225, Update deleteGloballyLocked to call resumeReceiptLocked(receipt) instead of markMetadataTombstoned after obtaining the receipt, matching deleteForTenantLocked so failed cleanup is retried and completed cleanup is a no-op. Ensure receipt resumption occurs before repository.deleteById(jobId), preventing metadata deletion when resumption rejects the receipt state.src/main/java/com/clearfolio/viewer/ClearfolioViewerApplication.java (1)
13-13: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win스케줄러 스레드 풀 구성을 검토하세요.
Spring Boot의 기본
TaskScheduler풀 크기는 1입니다.ArtifactDeletionCoordinator.retryPendingAfterDelay는 최대 100개의 영수증에 대해 블로킹 artifact I/O를 수행합니다. 복구 배치가 길어지면 같은 스레드를 사용하는 다른 스케줄 작업이 지연됩니다.
spring.task.scheduling.pool.size를 늘리거나 정리 작업 전용TaskScheduler빈을 정의하세요. 복구 실행 시간에 대한 지표도 함께 추가하면 지연을 관측할 수 있습니다.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/main/java/com/clearfolio/viewer/ClearfolioViewerApplication.java` at line 13, Update the scheduling configuration used by `@EnableScheduling` so retryPendingAfterDelay does not run on Spring Boot’s single default scheduler thread; either set spring.task.scheduling.pool.size to an appropriate value or define a dedicated TaskScheduler bean for artifact cleanup, and add execution-duration metrics for the recovery batch.src/test/java/com/clearfolio/viewer/lifecycle/ArtifactDeletionCoordinatorCoverageTest.java (1)
142-156: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value중복 테스트 헬퍼와 범위를 벗어난 단언을 정리하세요.
두 가지 사항이 있습니다.
- 라인 155의
new ArtifactDeletionMetrics(null)단언은 테스트 이름aggregateMetricsExposeOnlyCountsAndCurrentPendingWork의 범위를 벗어납니다. 같은 단언이ArtifactDeletionCoordinatorTest의 라인 410에도 있습니다. 여기서는 제거하세요.- 라인 192-200의
sha256헬퍼는ArtifactDeletionCoordinatorTest의 라인 581-588과 동일합니다. 공용 테스트 지원 클래스로 옮기세요.com.clearfolio.viewer.testsupport패키지가 이미 존재합니다.Also applies to: 192-200
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/test/java/com/clearfolio/viewer/lifecycle/ArtifactDeletionCoordinatorCoverageTest.java` around lines 142 - 156, The aggregateMetricsExposeOnlyCountsAndCurrentPendingWork test should only verify metric counts and current pending receipts, so remove the ArtifactDeletionMetrics(null) assertion. Move the duplicated sha256 test helper into a shared support class under com.clearfolio.viewer.testsupport, then update both ArtifactDeletionCoordinatorCoverageTest and ArtifactDeletionCoordinatorTest to reuse it and remove their local helper implementations.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@CHANGELOG.md`:
- Around line 71-72: CHANGELOG의 관리자 작업 조회 API 설명이 전체 시스템 작업을 반환하는 것으로 잘못 표현되어
있습니다. “시스템 내 전체 작업 내역”을 요청된 tenant 또는 관리자의 권한 범위에 해당하는 작업만 조회한다는 내용으로 수정하십시오.
In
`@src/main/java/com/clearfolio/viewer/lifecycle/ArtifactDeletionCoordinator.java`:
- Around line 127-183: Remove the instance-level synchronized serialization from
deleteForTenant, deleteGlobally, and retryPendingWork, relying on lifecycleLocks
for per-job coordination. Move blocking deletion and receipt-recovery work,
including DurableDocumentDeletionService.deleteJob request-path execution, onto
a boundedElastic scheduler so WebFlux event-loop threads are not blocked;
preserve the existing per-job locking and recovery behavior.
In
`@src/test/java/com/clearfolio/viewer/lifecycle/ArtifactLifecycleLockRegistryTest.java`:
- Around line 39-45: Ensure both concurrency tests wait until the competing task
has actually started before asserting it is blocked: in
src/test/java/com/clearfolio/viewer/lifecycle/ArtifactLifecycleLockRegistryTest.java
lines 39-45, add a secondStarted latch countdown immediately before withJobLock
and await it before checking secondEntered; in
src/test/java/com/clearfolio/viewer/lifecycle/ArtifactLifecycleSerializationTest.java
lines 70-77, add deletionStarted immediately before coordinator.deleteForTenant
and await it before checking deletion.isDone().
---
Nitpick comments:
In `@src/main/java/com/clearfolio/viewer/ClearfolioViewerApplication.java`:
- Line 13: Update the scheduling configuration used by `@EnableScheduling` so
retryPendingAfterDelay does not run on Spring Boot’s single default scheduler
thread; either set spring.task.scheduling.pool.size to an appropriate value or
define a dedicated TaskScheduler bean for artifact cleanup, and add
execution-duration metrics for the recovery batch.
In
`@src/main/java/com/clearfolio/viewer/lifecycle/ArtifactDeletionCoordinator.java`:
- Around line 159-171: Update the catch block in retryPendingWork to include
only exception.getClass().getName() in the recovery warning log, preserving the
existing message while excluding the exception message and identifiers.
- Around line 207-225: Update deleteGloballyLocked to call
resumeReceiptLocked(receipt) instead of markMetadataTombstoned after obtaining
the receipt, matching deleteForTenantLocked so failed cleanup is retried and
completed cleanup is a no-op. Ensure receipt resumption occurs before
repository.deleteById(jobId), preventing metadata deletion when resumption
rejects the receipt state.
In
`@src/test/java/com/clearfolio/viewer/lifecycle/ArtifactDeletionCoordinatorCoverageTest.java`:
- Around line 142-156: The aggregateMetricsExposeOnlyCountsAndCurrentPendingWork
test should only verify metric counts and current pending receipts, so remove
the ArtifactDeletionMetrics(null) assertion. Move the duplicated sha256 test
helper into a shared support class under com.clearfolio.viewer.testsupport, then
update both ArtifactDeletionCoordinatorCoverageTest and
ArtifactDeletionCoordinatorTest to reuse it and remove their local helper
implementations.
In
`@src/test/java/com/clearfolio/viewer/lifecycle/ArtifactDeletionCoordinatorTest.java`:
- Line 250: In ArtifactDeletionCoordinatorTest, replace the
assertTrue(Arrays.equals(...)) assertion with assertArrayEquals using
REPLACEMENT_ARTIFACT and mismatchStore.getPdf(JOB_ID).orElseThrow() so failures
report expected and actual byte arrays.
- Around line 298-327: Update
recoveryBatchIsBoundedIsolatesFailuresAndUsesScheduledEntryPoint to provide
three pending receipts while retaining maxReceiptsPerRun as 2, and configure the
first two for the existing failure/success paths. Assert retryPendingWork()
returns 2 and verify the third receipt has no findByJobId interaction,
preserving the scheduled-entry-point assertions.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 142b8e08-8bc4-40a8-90c0-199d2e828bc4
📒 Files selected for processing (19)
CHANGELOG.mddocs/security/2026-08-06-durable-artifact-deletion-receipts.mddocs/superpowers/plans/2026-08-06-durable-artifact-cleanup.mddocs/superpowers/specs/2026-08-06-durable-artifact-cleanup-design.mdsrc/main/java/com/clearfolio/viewer/ClearfolioViewerApplication.javasrc/main/java/com/clearfolio/viewer/artifact/LifecycleFencedArtifactStore.javasrc/main/java/com/clearfolio/viewer/config/ArtifactStoreConfig.javasrc/main/java/com/clearfolio/viewer/lifecycle/ArtifactDeletionCoordinator.javasrc/main/java/com/clearfolio/viewer/lifecycle/ArtifactDeletionMetrics.javasrc/main/java/com/clearfolio/viewer/lifecycle/ArtifactLifecycleLockRegistry.javasrc/main/java/com/clearfolio/viewer/service/DurableDocumentDeletionService.javasrc/main/resources/application.ymlsrc/test/java/com/clearfolio/viewer/artifact/LifecycleFencedArtifactStoreTest.javasrc/test/java/com/clearfolio/viewer/config/ArtifactStoreConfigTest.javasrc/test/java/com/clearfolio/viewer/lifecycle/ArtifactDeletionCoordinatorCoverageTest.javasrc/test/java/com/clearfolio/viewer/lifecycle/ArtifactDeletionCoordinatorTest.javasrc/test/java/com/clearfolio/viewer/lifecycle/ArtifactLifecycleLockRegistryTest.javasrc/test/java/com/clearfolio/viewer/lifecycle/ArtifactLifecycleSerializationTest.javasrc/test/java/com/clearfolio/viewer/service/DurableDocumentDeletionServiceTest.java
|
@coderabbitai review Please review exact current head |
|
|
|
@coderabbitai review Review exact current head |
|
I will include the final bounded-batch regression. I will treat fuzz run
|
|
@opencode-agent review Please independently review exact current head |
|
Superseded by #283. Exact final worker blobs from |
|
Closing as superseded by clean-stack PR #283. #283 is based on receipt foundation v2, preserves the reviewed cleanup-worker implementation, carries the strict replay RED/GREEN hardening, and includes the operator cleanup runbook at exact head |
Objective
Implement issue #263 Slice C on the immutable receipt-ledger foundation. This Draft connects authorized deletion to receipt-first metadata tombstoning, exact-digest artifact cleanup, restart and scheduled recovery, repeat-request idempotency, and a conversion/deletion generation fence. Slice D truthful HTTP status, signed-link revocation, and accessible viewer state remain out of scope.
Exact current stack
Exact current head is
bd60961fd03f1396bcd3d6695604ae0483a6a376on immutable base branchstack/durable-deletion-receipt-ledger-v1exact head8448fdd98d4a6c58f4e5407fcfcce903785abaa8.Fresh comparison reports:
pom.xml, workflow, SBOM, attribution, release, version, or existingDefaultDocumentConversionServicechange.Bounded implementation
ArtifactDeletionCoordinatorpersists intent before metadata tombstoning, validates exact SHA-256 or the documented absence sentinel, records controlled read/delete/mismatch failures, and replays bounded incomplete work at startup and fixed delay.LifecycleFencedArtifactStorerejects everyputPdfafter a durable receipt exists. An in-flight publication that wins first is snapshotted and deleted; a later publication fails closed.Test-first review fixes
All three exact predecessor-head actionable CodeRabbit threads were addressed and resolved only after the corresponding source or deterministic regression changed. Fresh exact-head CodeRabbit and OpenCode/Noema review requests were submitted; predecessor-head comments and statuses are not reused.
Acceptance state
31101322544completed successfully across all three targets;Keep this PR Draft. Parent order remains #270 → #268 → #280 receipt foundation → this Slice C. Do not resolve #268's incomplete-cleanup finding or claim product-level deletion completion until this exact slice and later Slice D pass every protection. Do not bypass protections, infer approval from advisory status, or publish a release.