Skip to content

Hardening: make lifecycle and architecture claims match reality - #1

Open
SShogun wants to merge 2 commits into
masterfrom
hardening/lifecycle-ci-claims
Open

SShogun wants to merge 2 commits into
masterfrom
hardening/lifecycle-ci-claims

Conversation

@SShogun

@SShogun SShogun commented Sep 20, 2026 •

Copy link
Copy Markdown
Owner

Summary

This is the first ControlPlane P0 hardening pass after RedisForge.

1. Lifecycle correctness

  • replace the blocking ListenAndServe-only startup path with a testable graceful server lifecycle
  • handle SIGINT and SIGTERM
  • use a bounded 10-second HTTP shutdown window
  • close the PostgreSQL pool through normal deferred cleanup
  • surface listen/shutdown failures instead of silently treating them as success
  • add regression tests for cancellation-driven shutdown, listen failure, and shutdown failure

2. Verification and claim parity

  • strengthen CI to use the Go version declared in go.mod
  • keep the real PostgreSQL service + checked-in migrations
  • add gofmt, go vet, race-enabled tests, build, and golangci-lint gates
  • document the as-built architecture and explicit non-goals in ARCHITECTURE_STATUS.md
  • remove the unsupported README claim that the backend is "fully hardened for production use"
  • correct stale README details including the default branch/CI behavior, Application ownership, migration list, route surface, tests, and transaction signatures
  • rename Phase 5 from "Production Hardening" to the narrower "Repository Hardening"

Audit findings

The repository already had CI and the latest master run was green, but the README described a stale main-only workflow. More importantly, it marked graceful shutdown as complete even though main.go had no signal handling or Server.Shutdown.

The repository name can also suggest a distributed/Kubernetes-style control plane. The new as-built status document makes the current boundary explicit: this is a single-process server-rendered Go/PostgreSQL governance application, not a Kubernetes controller or split control-plane/data-plane system.

Verification

The branch was squashed to one commit. CI will run again on the exact PR SHA with:

PostgreSQL 16 + migrations
gofmt
go vet ./...
go test -race -count=1 ./...
go build ./...
golangci-lint

Scope

This PR does not add Phase 6 features such as metrics, tracing, Docker/Kubernetes deployment, health/readiness probes, or distributed rate limiting. The purpose is to make the existing portfolio project correct, verifiable, and honest before moving on.

Summary by Sourcery

Harden the application lifecycle and bring its CI verification and documentation in line with the repository’s actual architecture and capabilities.

New Features:

  • Add graceful HTTP server shutdown on SIGINT and SIGTERM with bounded cleanup and PostgreSQL pool closure.

Bug Fixes:

  • Surface server listen and shutdown failures instead of silently treating them as successful exits.

Enhancements:

  • Document the implemented architecture, runtime semantics, verification boundary, and explicit non-goals.
  • Align the README with the current lifecycle behavior, architecture, routes, migrations, tests, CI configuration, and repository-hardening scope.

CI:

  • Make CI use the Go version declared in go.mod and add formatting, vet, race-enabled tests, build, and lint gates against PostgreSQL migrations.

Documentation:

  • Replace unsupported production-readiness claims with an as-built architecture status and narrower repository-hardening documentation.

Tests:

  • Add lifecycle regression tests covering cancellation-driven shutdown, listen failures, and shutdown failures.

Copilot AI lite review requested due to automatic review settings September 20, 2026 18:36

@sourcery-ai sourcery-ai 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.

Sorry @SShogun, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 1 day and 12 hours by commenting @sourcery-ai review. Upgrade to get a review now.

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@sourcery-ai

sourcery-ai Bot commented Sep 20, 2026

Copy link
Copy Markdown

Reviewer's Guide

This hardening pass makes the HTTP and database lifecycle correct and testable, strengthens CI verification, and updates project documentation to accurately describe the current single-process Go/PostgreSQL architecture and its explicit non-goals.

Sequence diagram for graceful HTTP server shutdown

sequenceDiagram
    participant OS as OS
    participant Run as run()
    participant Server as HTTPServer
    participant Pool as PostgreSQLPool

    Run->>OS: signal.NotifyContext(SIGINT, SIGTERM)
    Run->>Server: serve(serverCtx, 10s)
    Server->>Server: ListenAndServe()
    OS-->>Run: cancellation
    Run->>Server: Shutdown(timeout context)
    Server-->>Run: shutdown result
    Run->>Pool: Close()
    Run-->>OS: return error or success
Loading

File-Level Changes

Change Details Files
Reworked server startup into a testable, signal-aware graceful lifecycle with bounded shutdown and explicit error propagation.
  • Added a serve abstraction around ListenAndServe and Shutdown.
  • Handled SIGINT/SIGTERM with a 10-second shutdown timeout.
  • Deferred PostgreSQL pool cleanup and converted fatal startup paths into returned errors.
  • Added regression coverage for cancellation, listen failure, and shutdown failure.
cmd/web/main.go
cmd/web/main_test.go
Aligned CI verification with the declared toolchain and expanded quality gates against a real PostgreSQL instance.
  • Read the Go version from go.mod and enabled module caching/downloads.
  • Retained PostgreSQL 16 migration setup.
  • Added formatting, vet, race-enabled tests, build, lint, permissions, and job timeout checks.
.github/workflows/go.yml
Documented the implemented architecture and narrowed project claims to the repository’s actual capabilities.
  • Added an as-built architecture document describing the single-process Go/PostgreSQL application, runtime semantics, and non-goals.
  • Removed production-readiness claims and renamed Phase 5 to Repository Hardening.
  • Corrected README details for branch/CI behavior, ownership, migrations, routes, tests, and transaction APIs.
ARCHITECTURE_STATUS.md
README.md

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai 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.

Sourcery assessment

Approved.

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