Skip to content

Close P2 claim gaps for leadership, Modbus faults, and audit retention - #8

Merged
AngelP17 merged 4 commits into
mainfrom
cursor/p2-claim-proof-closure-89c5
Dec 4, 2026
Merged

AngelP17 merged 4 commits into
mainfrom
cursor/p2-claim-proof-closure-89c5

Conversation

@AngelP17

@AngelP17 AngelP17 commented Dec 4, 2026

Copy link
Copy Markdown
Owner

Summary

Closes the remaining P2 claim-to-proof gaps for Setpoint. Proofs stay on a simulated PLC. Halt is documented as an operator status, not a safety-certified emergency stop. Physical PLC validation is labeled pending.

  • Leader election is a shared decision function. Two holders elect one leader, a stale compare-and-swap loses, and the standby acquires the lease after expiry. Pod identity comes from POD_NAME. make helm-install-proof scales the chart to two replicas and deletes the holder pod.
  • Modbus calls use connect and I/O deadlines. A dropped peer fails that call, and the next call opens a new TCP connection.
  • Reconciliation reads cooldown and desired value from the resource. A follower does not reconcile. An auto write is skipped when the spec generation or desired value changes before the write.
  • A deletion audit block is fsynced under AUDIT_LEDGER_DIR and upserted into the setpoint-audit-ledger ConfigMap before the finalizer is removed. The same deletion hash is not stored twice, and a tampered block fails to load.
  • Minimum supported versions are Kubernetes 1.28 (kubeVersion and kind node v1.28.15) and Rust 1.88 (workspace rust-version and the msrv CI job). See docs/SUPPORT.md.

Verification

  • cargo test --workspace --all-targets passed on Rust 1.88.0 with RUSTFLAGS=-D warnings, and again on stable 1.100.1.
  • cargo clippy --workspace --all-targets -- -D warnings passed on stable.
  • helm lint charts/setpoint passed. The render includes POD_NAME, AUDIT_LEDGER_DIR, and the audit ConfigMap Role.
  • The landing pages at / and /console show the Halt disclaimer, the simulator Halt action, and the simulated proof label.
  • Docker and kind are not available in this environment, so make helm-install-proof was not executed here. .github/workflows/helm-install.yml runs that proof on a clean kind 1.28 cluster.
Open in Web Open in Cursor 

Prove multi-replica lease failover, Modbus disconnects, timeouts, and reconnection, and keep reconciliation from writing a stale desired value across restarts or concurrent spec changes. Deletion audit records are fsynced and stored in a ConfigMap before the finalizer is removed. Minimum versions are Kubernetes 1.28 and Rust 1.88. Halt remains an operator status, not a certified emergency stop, and physical PLC validation stays pending.

Co-authored-by: Angel L. Pinzon  <angelpinzon1706@gmail.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-04T15:39:42.535581Z 855146d New commits
ℹ️ 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.

@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: 303e261b9a

ℹ️ 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 crates/operator/src/audit_retention.rs Outdated
Comment on lines +115 to +117
let patch = serde_json::json!({ "data": { DATA_KEY: updated } });
match api
.patch(&name, &PatchParams::default(), &Patch::Merge(&patch))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Guard audit ConfigMap updates with a resource version

When two PLC deletions reconcile concurrently, both can read the same ConfigMap, append their respective records, and successfully patch deletions.json; the second patch then overwrites the first record. Neither patch includes a metadata.resourceVersion precondition, so the 409 retry branch does not prevent this lost update. Both reconciles can subsequently remove their finalizers, leaving one deletion absent from the retained ConfigMap. Use an optimistic-concurrency update and re-merge after conflicts.

Useful? React with 👍 / 👎.

Comment thread crates/operator/src/crypto.rs Outdated
Comment on lines +181 to +185
.get(plc_name)
.and_then(|history| history.last().cloned())
{
if existing.action_taken == "Deleted" {
return Ok(existing);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Scope deletion idempotency to the resource identity

If two resources named pump-1 in different namespaces are deleted without an intervening audit append for that name, the second deletion reuses the first resource's Deleted block because this lookup is keyed only by PLC name. merge_deletion_json then deduplicates by that reused hash, so the second namespace's deletion is never recorded even though its finalizer is removed. The same issue affects a recreated resource deleted before producing a normal audit block. Include namespace and resource UID in the deletion identity so retries are idempotent without conflating distinct resources.

Useful? React with 👍 / 👎.

"Spec for {}/{} changed during reconcile; skipping writes until the next pass",
namespace, name
);
return Ok(Action::requeue(Duration::from_secs(1)));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Persist completed corrections before returning on a stale spec

For a PLC with multiple Auto registers, an earlier register can be successfully corrected before a spec update causes a later register to return SpecChanged. This early return discards the accumulated status, including the earlier write's last_correction_at and recent_corrections, because update_status runs only after the loop. If that register drifts again, the next pass can write again without honoring the configured cooldown or correction limit. Persist completed correction bookkeeping before leaving the stale-spec path while still skipping further writes.

Useful? React with 👍 / 👎.

cursoragent and others added 2 commits December 4, 2026 15:32
Replace the audit ConfigMap with its resourceVersion and re-merge after a conflict so one deletion cannot overwrite another. Save status before a stale spec skips the rest of the registers, so an earlier correction still honors cooldown. Key deletion idempotency by namespace, name, and UID.

Co-authored-by: Angel L. Pinzon  <angelpinzon1706@gmail.com>

@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: 1e9a91e2da

ℹ️ 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 on lines +221 to +222
)
.map_err(|err| Error::Audit(err.to_string()))?;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Persist correction bookkeeping before propagating audit errors

If an Auto correction succeeds but the subsequent ledger append fails (for example, because the audit volume is full), this ? returns before update_status saves last_correction_at and recent_corrections. If the register drifts again, subsequent reconciles can write without honoring its cooldown or hourly correction limit. The stale-spec branch now saves this bookkeeping, but this separate audit-error branch still discards it. Persist completed correction bookkeeping even when generating the audit block fails.

Useful? React with 👍 / 👎.

Comment on lines +388 to +390
let mut file = OpenOptions::new().create(true).append(true).open(path)?;
writeln!(file, "{}", serde_json::to_string(block)?)?;
file.sync_all()?;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Recover incomplete ledger appends before accepting further writes

If this append writes only part of a record before an I/O error, or the process terminates during the write, the JSONL file retains an incomplete trailing record. There is no rollback or startup recovery: subsequent appends concatenate onto that fragment, and Ledger::open propagates the JSON parsing error on restart. Because main requires the ledger to open successfully, one interrupted append can leave the operator crash-looping until its audit files are manually repaired or discarded. Use recoverable framing or truncate an incomplete trailing append to the last verified record before resuming.

Useful? React with 👍 / 👎.

@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: 855146d307

ℹ️ 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".

"Leadership expired before an Auto write to {}/{}",
namespace, name
);
return Ok(Action::requeue(Duration::from_secs(1)));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Persist completed corrections before returning on leadership loss

For a PLC with multiple Auto registers, an earlier register can be successfully corrected before a later register reaches the write gate after leadership expires. This return discards the earlier correction's last_correction_at and recent_corrections, since status is persisted only after the loop. The next leader therefore evaluates cooldown and hourly limits without that successful correction and can write again when the register drifts. Persist completed correction bookkeeping on this exit path, as the adjacent SpecChanged branch already does.

Useful? React with 👍 / 👎.

Comment on lines +118 to +121
if !log.records.iter().any(|stored| stored.hash == record.hash) {
log.records.push(record.clone());
}
serde_json::to_string_pretty(&log)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Bound or shard the retained deletion document

In a long-running installation with repeated PLC creation and deletion, every deletion across all watched namespaces is appended to this single ConfigMap document indefinitely. Eventually the document exceeds Kubernetes' ConfigMap size limit, and retain_deletion_event returns an error for every subsequent deletion. Because the controller requires retention to succeed before removing its finalizer, those PLCs remain stuck terminating, and retries cannot recover. Shard or rotate the retained records before reaching the limit while preserving the required audit history.

Useful? React with 👍 / 👎.

@AngelP17
AngelP17 merged commit d10bcb6 into main Dec 4, 2026
11 checks passed
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