Repository navigation
Close P2 claim gaps for leadership, Modbus faults, and audit retention - #8
Conversation
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>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 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".
| let patch = serde_json::json!({ "data": { DATA_KEY: updated } }); | ||
| match api | ||
| .patch(&name, &PatchParams::default(), &Patch::Merge(&patch)) |
There was a problem hiding this comment.
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 👍 / 👎.
| .get(plc_name) | ||
| .and_then(|history| history.last().cloned()) | ||
| { | ||
| if existing.action_taken == "Deleted" { | ||
| return Ok(existing); |
There was a problem hiding this comment.
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))); |
There was a problem hiding this comment.
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 👍 / 👎.
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>
There was a problem hiding this comment.
💡 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".
| ) | ||
| .map_err(|err| Error::Audit(err.to_string()))?; |
There was a problem hiding this comment.
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 👍 / 👎.
| let mut file = OpenOptions::new().create(true).append(true).open(path)?; | ||
| writeln!(file, "{}", serde_json::to_string(block)?)?; | ||
| file.sync_all()?; |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
💡 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))); |
There was a problem hiding this comment.
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 👍 / 👎.
| if !log.records.iter().any(|stored| stored.hash == record.hash) { | ||
| log.records.push(record.clone()); | ||
| } | ||
| serde_json::to_string_pretty(&log) |
There was a problem hiding this comment.
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 👍 / 👎.
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.
POD_NAME.make helm-install-proofscales the chart to two replicas and deletes the holder pod.AUDIT_LEDGER_DIRand upserted into thesetpoint-audit-ledgerConfigMap before the finalizer is removed. The same deletion hash is not stored twice, and a tampered block fails to load.kubeVersionand kind nodev1.28.15) and Rust 1.88 (workspacerust-versionand themsrvCI job). Seedocs/SUPPORT.md.Verification
cargo test --workspace --all-targetspassed on Rust 1.88.0 withRUSTFLAGS=-D warnings, and again on stable 1.100.1.cargo clippy --workspace --all-targets -- -D warningspassed on stable.helm lint charts/setpointpassed. The render includesPOD_NAME,AUDIT_LEDGER_DIR, and the audit ConfigMap Role./and/consoleshow the Halt disclaimer, the simulator Halt action, and the simulated proof label.make helm-install-proofwas not executed here..github/workflows/helm-install.ymlruns that proof on a clean kind 1.28 cluster.