Skip to content

Prove the release gate blocks a disposable container deploy - #6

Merged
AngelP17 merged 7 commits into
mainfrom
cursor/gated-deploy-proof-a52d
Dec 4, 2026
Merged

AngelP17 merged 7 commits into
mainfrom
cursor/gated-deploy-proof-a52d

Conversation

@AngelP17

@AngelP17 AngelP17 commented Dec 4, 2026

Copy link
Copy Markdown
Owner

Summary

The release gate already returned HTTP 200/423, but the example deploy workflow only printed a message. This change makes a real disposable deployment honor that decision, and closes the related audit, remediation, agent, and Go coverage gaps.

  • ReleaseDeployer deploys only when the gate is open. A locked gate leaves the running container untouched. Rollback restores the previous revision while the gate is still locked, and a later revision deploys after fresh healthy observations reopen the gate.
  • The target is a local container imported from /bin/busybox. No registry pull and no paid infrastructure. make deploy-proof and the Deploy workflow run that proof.
  • Privileged writes and their audit rows share a transaction. If the audit insert fails, the write rolls back and the API returns audit_unavailable (HTTP 503).
  • Each audit row is HMAC-signed and hash-chained per shard. A changed field, signature, or missing row fails AuditLog.chain_intact?. Optional CELLGUARD_AUDIT_HMAC_KEY (at least 32 bytes) overrides the key derived from SECRET_KEY_BASE.
  • Remediation client rejections and transport errors are recorded and do not report success. An audit outage refuses the call before the client runs.
  • AgentSchedulerJob plus AgentRunJob#perform runs budget_guard, chaos_orchestrator, incident_response, and healing.
  • Go tests cover classifier decision boundaries, the classify and health handlers, the decision counter, the agent-runner Rails client, each runner agent, and the scheduler tick. A non-200/423 gate response is now an error for budget guard.

Verification

  • RAILS_ENV=test bundle exec rails test — 50 runs, 198 assertions, 0 failures
  • make go-classifier-test and go build ./cmd/classifier
  • make go-agent-runner-test and go build ./cmd/runner
  • test/integration/gated_deploy_test.rb deployed rev-a and rev-b, refused rev-c while locked, rolled back to rev-a, then deployed rev-d after recovery

A caller that never uses ReleaseDeployer can still deploy elsewhere. Audit verification is local: there is no external write-once ledger, and a database superuser can delete rows, which breaks the chain check.

Open in Web Open in Cursor 

The example workflow only printed a message after the gate proof. Deployments now go through ReleaseDeployer, which refuses a locked gate, rolls a local container back, and deploys again after recovery. Audit rows are HMAC-chained, and a failed insert rolls the privileged write back.

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:40:00.098628Z 0d673c3 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.

Passing the archive through a Ruby string failed on CI when the locale was UTF-8. Docker now imports the tar file directly.

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: 2d728cf3c4

ℹ️ 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 +21 to +22
ActiveRecord::Base.transaction do
budget = BudgetEvaluator.new.evaluate!(shard: shard)

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 Acquire audit and budget locks in a consistent order

On PostgreSQL, concurrent evaluation and manual budget_guard requests for the same shard can deadlock. This transaction first obtains the error-budget row lock through BudgetEvaluator, then requests the audit advisory lock. Conversely, AgentsController#run uses with_audited_mutation to obtain the audit advisory lock before BudgetGuardAgent#execute updates that same budget row. Each request can therefore wait on the other's lock, causing PostgreSQL to abort one operation. Acquire these locks in a consistent order while preserving AGENTS.md's same-transaction audit/write requirement.

AGENTS.md reference: AGENTS.md:L81-L81

Useful? React with 👍 / 👎.

Comment thread app/models/audit_log.rb Outdated
Comment on lines +63 to +65
canonical_json(metadata)
].join("\n")
Digest::SHA256.hexdigest(payload)

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 Use unambiguous serialization for signed audit fields

When a signed string contains a newline, joining the fields with newline separators permits different field values to produce the same digest. For example, action incident_resolved with justification approved\nby ops hashes identically to action incident_resolved\napproved with justification by ops. A direct database edit can therefore change those fields without invalidating either the HMAC or chain_intact?, contrary to the stored-field tamper-detection invariant in AGENTS.md. Encode the complete payload as a canonical JSON array/object or another length-delimited representation before hashing.

AGENTS.md reference: AGENTS.md:L81-L81

Useful? React with 👍 / 👎.

Comment thread app/models/audit_log.rb Outdated
Comment on lines +55 to +56
def self.payload_digest(sequence:, shard_id:, actor:, action:, justification:, prev_digest:, metadata:)
payload = [

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 Include audit timestamps in the authenticated payload

A database writer can change an audit row's created_at while both authentic? and chain_intact? continue to return true, because the digest never includes that column. This affects operator-visible evidence: AuditLogsController#index orders and limits records by created_at, and returns that timestamp, so an undetected edit can reorder events or move a record outside the latest-50 feed. Seal and verify the persisted timestamp as part of the payload to satisfy AGENTS.md's stored-field tamper-detection invariant.

AGENTS.md reference: AGENTS.md:L81-L81

Useful? React with 👍 / 👎.

AngelP17 and others added 4 commits December 4, 2026 10:33
Evaluation and agent runs now lock the shard row, then the error-budget row, then the audit chain. Signatures use a canonical JSON payload that includes created_at, so a timestamp edit or a newline inside a field fails verification.

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: 74037fb865

ℹ️ 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 +105 to +107
with_audited_mutation(
action: "agent_toggle",
shard: Shard.find_by(name: "shard-default"),

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 Resolve a persisted audit shard for global agent operations

When the database contains only custom shards and has not loaded the demo seeds, Shard.find_by(name: "shard-default") returns nil. The new audit-first wrapper then raises AuditLog::PersistenceError in seal!, so an otherwise valid global agent toggle returns HTTP 503 without updating its configuration; both run_all branches have the same dependency. Previously these operations worked without the demo shard because the audit helper skipped nil shards. Resolve or create a persisted audit scope for these global operations while retaining the required transactional audit, rather than making them depend on optional demo seed data.

AGENTS.md reference: AGENTS.md:L81-L81

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: 0d673c3d32

ℹ️ 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 app/models/audit_log.rb
Comment on lines +32 to +34
configured = ENV["CELLGUARD_AUDIT_HMAC_KEY"].to_s
unless configured.empty?
raise PersistenceError, "audit signing key must be at least 32 bytes" if configured.bytesize < 32

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 Document the new audit signing key in README.md

The new CELLGUARD_AUDIT_HMAC_KEY setting is documented in docs/DEPLOYMENT.md and AGENTS.md, but is absent from README.md. This violates the root AGENTS.md requirement to document every new environment variable in both README and the deployment guide. Add the setting, its minimum 32-byte length, and the SECRET_KEY_BASE fallback to README so readers can discover how audit signing is configured.

AGENTS.md reference: AGENTS.md:L341-L341

Useful? React with 👍 / 👎.

@AngelP17
AngelP17 merged commit fd7dd57 into main Dec 4, 2026
4 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