Skip to content

encryption: add the §5.4 rewrite-job decision layer (Stage 9C-6) - #1235

Merged
bootjp merged 1 commit into
mainfrom
design/encryption-9c6-rewrite-decisions
Oct 22, 2026
Merged

bootjp merged 1 commit into
mainfrom
design/encryption-9c6-rewrite-decisions

Conversation

@bootjp

@bootjp bootjp commented Sep 10, 2026 •

Copy link
Copy Markdown
Owner

Adds the Stage 9C-6 decision layer for re-encrypting retained MVCC history during DEK rotation, plus an inter-batch rewrite rate budget.

Behavior

  • Classify every physically retained (user_key, version_ts), including the retained anchor below or at the retention floor. Tombstones are skipped; cleartext is rewritten only during an explicit migration sweep.
  • Report different_dek for encrypted versions outside the targeted retiring DEK, including intermediate old keys.
  • Advance a virtual deadline from max(previousDeadline, now) for each batch, preventing idle time from becoming burst credit. Preserve byte accounting in unthrottled mode and clamp unrepresentable delays.
  • Keep the execution half separate: these APIs have no production callers yet and do not change stored data or issue timestamps.
  • Merge current main and preserve its encrypted Jepsen milestone in the design table.

Validation

  • go test ./internal/encryption/... -race -count=1: all three packages passed.
  • go vet ./internal/encryption/...: passed.
  • git diff --check: passed.
  • Caller audit with rg: classifier and throttle callers are confined to their tests.
  • Linux CI go test -race ./..., including required kernel FUSE tests: passed.
  • Full CI lint: passed.
  • Jepsen acceptance workloads with encryption off and on: both passed.
  • Local full tests encountered the existing macOS FUSE syscall.Statfs_t.Namelen compile failure; the local lint binary was built with Go 1.26 and could not parse Go 1.27 source. The successful Linux CI checks cover both validations.

Risk

Additive, unwired API contract only. Tests cover retained history, retention anchors, explicit cleartext migration, third-key classification, post-idle bursts, cumulative byte accounting, and duration overflow. The merge commit bypassed the hook because of the known unrelated macOS FUSE compile failure.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 10, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-22T13:19:49.154382Z 9f8b749 Manual request
🔒 Security Review ✅ Completed 2026-10-22T13:19:23.533656Z 9f8b749 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Sep 10, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

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

Next included review available in 54 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: cf3bd627-b7b7-4d5d-b900-82259aaef1c2
📥 Commits

Reviewing files that changed from the base of the PR and between 429f5ee and 9f8b749.

📒 Files selected for processing: 3
  • docs/design/2026_04_29_partial_data_at_rest_encryption.md
  • internal/encryption/rewrite_plan.go
  • internal/encryption/rewrite_plan_test.go
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cbb6e954f9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread internal/encryption/rewrite_plan.go Outdated
Comment thread internal/encryption/rewrite_plan.go Outdated
Comment thread internal/encryption/rewrite_plan.go Outdated
Comment thread internal/encryption/rewrite_plan.go Outdated
@bootjp

bootjp commented Sep 12, 2026

Copy link
Copy Markdown
Owner Author

Correction to my earlier doc-row commit on this PR.

That commit said the §9.2 metrics needed naming in the open row because elastickv_encryption_writes_per_dek{key_id} was not exported anywhere. main has since merged #1221 (Stage 9C-1), which exports it from the storage-envelope path (monitoring/encryption.go:58), so that justification no longer holds for that metric.

Fixed while merging main to clear the conflict: the table now carries main's 9C-1 row, and the open 9C+ row names only the metrics that are genuinely still unexported (active_dek_id, last_proposed_index_per_raft_dek, kek_unwrap_seconds, sidecar_raft_index).

The 9C-6 decision layer and its tests are unchanged.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cff9662207

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread internal/encryption/rewrite_plan.go Outdated
Copilot AI balanced review requested due to automatic review settings October 11, 2026 10:43

Copilot AI 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.

🟡 Changes recommended

The retention boundary, anti-burst throttling, and DEK reason classification contracts are currently incorrect.

3 open findings
What changed in this PR

Adds the unwired Stage 9C-6 decision layer for MVCC encryption rewrites and rate throttling.

Changes:

  • Adds per-version rewrite classification.
  • Adds rewrite throughput throttling.
  • Documents the shipped decision layer with unit tests.
File Description
internal/​encryption/​rewrite_plan.go Implements rewrite decisions and throttling.
internal/​encryption/​rewrite_plan_test.go Tests classification and rate behavior.
docs/​design/​2026_04_29_partial_data_at_rest_encryption.md Records Stage 9C-6 status.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread internal/encryption/rewrite_plan.go Outdated
Comment on lines +93 to +97
if version.CommitTS <= minRetainedTS {
// Below the retention floor: no reader can reach it, and the
// retirement criterion (§5.4 item 4) is stated against
// minRetainedTS for exactly this reason.
return RewriteDecision{Verdict: RewriteSkip, Reason: RewriteReasonUnretained}

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Verified in current HEAD: ClassifyMVCCRewrite processes all physically retained versions without a timestamp-only exclusion. Tests cover both an exact-floor version and an anchor below the floor, so a cold key remains rewritable. All callers were audited with rg; only tests call this unwired API. The encryption package race tests pass.

Comment thread internal/encryption/rewrite_plan.go Outdated
Comment on lines +105 to +108
if version.KeyID == retiringKeyID {
return RewriteDecision{Verdict: RewriteReencrypt, Reason: RewriteReasonRetiringDEK}
}
return RewriteDecision{Verdict: RewriteSkip, Reason: RewriteReasonAlreadyFresh}

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Verified in current HEAD: the reason is now different_dek, without asserting that an untargeted DEK is active. The table-driven test separately covers the active key and another old key. All callers were audited; only tests consume this unwired contract. Race tests pass.

Comment thread internal/encryption/rewrite_plan.go Outdated
Comment on lines +153 to +158
required := time.Duration(float64(t.written) / t.bytesPerSecond * float64(time.Second))
elapsed := now.Sub(t.started)
if elapsed >= required {
return 0
}
return required - elapsed

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Verified in current HEAD: Record advances the virtual deadline from max(previousDeadline, now) for every positive batch. TestRewriteThrottleDoesNotBankIdleTime covers a minute-long stall followed by back-to-back batches; the debt grows by one second per MiB at 1 MiB/s. The design row and PR description now describe the virtual-deadline rule. Race tests pass.

@bootjp

bootjp commented Oct 22, 2026

Copy link
Copy Markdown
Owner Author

Updated HEAD: 4316e56.

Merged current main and resolved the design-table conflict while preserving the encrypted Jepsen milestone. Rechecked all eight historical inline findings against the current implementation and replied with their regression coverage. Current-head root findings before this push: zero.

Validation: encryption package race tests (all three packages), go vet, caller audit, and git diff --check passed. Full local testing is limited by the existing macOS FUSE Statfs_t.Namelen compile failure; local lint is limited by its Go 1.26-built binary encountering Go 1.27 source. Full Linux tests and lint will be checked in CI. Commit signature verified locally; Author and Committer are bootjp contact@bootjp.me.

@codex review

@bootjp
bootjp force-pushed the design/encryption-9c6-rewrite-decisions branch from 4316e56 to 9f8b749 Compare October 22, 2026 13:17
@bootjp

bootjp commented Oct 22, 2026

Copy link
Copy Markdown
Owner Author

Updated HEAD: 9f8b749.

Replaced historical commits containing session attribution with one signed commit by bootjp contact@bootjp.me, based on current main. The complete Git tree is byte-identical to the previously tested 4316e56 commit (verified with git diff --exit-code). All inline replies and test results remain applicable. No implementation change was introduced by this history cleanup.

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: 9f8b749c41

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: 9f8b749c41

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@bootjp
bootjp merged commit 3ed7e32 into main Oct 22, 2026
10 checks passed
@bootjp
bootjp deleted the design/encryption-9c6-rewrite-decisions branch October 22, 2026 17:25
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.

2 participants