Skip to content

fix(reliability): fail closed on artifact ledger persistence errors - #357

Open
seonghobae wants to merge 10 commits into
mainfrom
fix/artifact-ledger-fail-closed-main-20260811
Open

fix(reliability): fail closed on artifact ledger persistence errors#357
seonghobae wants to merge 10 commits into
mainfrom
fix/artifact-ledger-fail-closed-main-20260811

Conversation

@seonghobae

@seonghobae seonghobae commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

Objective

Prevent configured durable artifact-link/audit persistence failures from publishing contradictory process-local state. Protected main mutates the in-memory issued-link/revocation/read-event structures before appending to the configured ledger, so a failed disk append can throw to the caller while the same process still observes authority/audit state that cannot survive restart.

Test-first state

This Draft starts intentionally RED at exact test-only head eea4685ab5d7f454f00c3bdbfbef435753b6dc0e. Focused tests make the configured ledger path unwritable after construction and require failed issue, revoke, and read appends to leave the corresponding in-memory state unchanged. Protected main mutates memory first and therefore violates all three invariants.

Scope

ArtifactLinkLedger ordering plus focused regression tests only. This does not modify token parsing/signature behavior owned by active PR #276, artifact delivery controllers, credential/OIDC work, filesystem artifact storage, deletion receipts, or canonical documentation. It preserves the optional in-memory-only profile when no ledger path is configured.

Acceptance

Observe exact-head RED -> persist-before-publish ordering -> exact-head mvn -B --no-transfer-progress verify, 100% owned production coverage/public Javadocs -> CI/Security Scan/SAST/fuzz -> current reviews/threads/live-base refetch. Keep Draft until exact-head GREEN evidence exists. Independent write-authorized approval remains a separate protected-merge gate.

Summary by CodeRabbit

  • 버그 수정

    • 토큰 식별자의 권한 재바인딩을 방지하고 기존 기록을 보호합니다.
    • 이미 폐기된 토큰의 상태가 중복 변경되지 않습니다.
    • 감사 및 상태 기록이 영속 저장에 성공한 경우에만 반영됩니다.
    • 저장 실패 시 부분적으로 반영되지 않고 안전하게 오류를 반환합니다.
  • 테스트

    • 권한 변조, 원장 무결성, 발행·폐기·읽기 기록 실패 상황에 대한 검증을 강화했습니다.

@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@seonghobae, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 47 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 44173d87-6a4e-4391-b81e-1bfa56ade2d3

📥 Commits

Reviewing files that changed from the base of the PR and between 823b994 and 548f29f.

📒 Files selected for processing (2)
  • src/main/java/com/clearfolio/viewer/artifact/ArtifactLinkLedger.java
  • src/test/java/com/clearfolio/viewer/artifact/ArtifactLinkLedgerDurabilityTest.java
📝 Walkthrough

Walkthrough

ArtifactLinkLedger는 영속 로그 기록 후 메모리 상태를 갱신합니다. 중복 토큰 권한 재바인딩을 거부합니다. 영속화 실패와 원장 변조 처리 동작을 테스트로 검증합니다.

Changes

ArtifactLinkLedger 무결성

Layer / File(s) Summary
영속화 후 상태 갱신
src/main/java/com/clearfolio/viewer/artifact/ArtifactLinkLedger.java, src/test/java/com/clearfolio/viewer/artifact/ArtifactLinkLedgerFailClosedTest.java
발급된 토큰 식별자의 중복을 거부합니다. 발급, 폐기, 읽기 이벤트는 영속 로그 기록 후 메모리에 반영됩니다. 영속화 실패 시 예외를 발생시키고 메모리 상태를 유지합니다.
권한 재바인딩 및 원장 검증
src/test/java/com/clearfolio/viewer/artifact/ArtifactLinkLedgerAuthorityRebindingTest.java, src/test/java/com/clearfolio/viewer/artifact/ArtifactLinkServiceTest.java
기존 토큰 식별자에 다른 권한 정보를 기록하거나 재생하는 동작을 거부하는 테스트를 추가합니다. 변조 레코드는 별도 검증용 원장에서 처리합니다.

Estimated code review effort: 3 (Moderate) | ~20 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 제목은 원장 영속화 오류 발생 시 fail-closed 동작을 구현하는 변경 사항을 정확하고 간결하게 설명합니다.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/artifact-ledger-fail-closed-main-20260811

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@seonghobae
seonghobae marked this pull request as ready for review August 10, 2026 20:33
@seonghobae
seonghobae enabled auto-merge (squash) August 10, 2026 20:40

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 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 `@src/main/java/com/clearfolio/viewer/artifact/ArtifactLinkLedger.java`:
- Around line 78-79: Update ArtifactLinkLedger.appendLine to explicitly force
the file contents to physical storage with FileChannel.force(true) before
returning. Ensure this synchronization completes before in-memory publication at
src/main/java/com/clearfolio/viewer/artifact/ArtifactLinkLedger.java lines 78-79
(issued record), 114-115 (revocation record), and 125-126 (read audit event);
all three sites require no separate direct change if they already publish only
after appendLine returns.
🪄 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: ed8a2f12-b7df-493c-8b08-bd265e0f7643

📥 Commits

Reviewing files that changed from the base of the PR and between 55d7ae8 and 823b994.

📒 Files selected for processing (4)
  • src/main/java/com/clearfolio/viewer/artifact/ArtifactLinkLedger.java
  • src/test/java/com/clearfolio/viewer/artifact/ArtifactLinkLedgerAuthorityRebindingTest.java
  • src/test/java/com/clearfolio/viewer/artifact/ArtifactLinkLedgerFailClosedTest.java
  • src/test/java/com/clearfolio/viewer/artifact/ArtifactLinkServiceTest.java

@opencode-agent
opencode-agent Bot disabled auto-merge August 11, 2026 04:12
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.

1 participant