Skip to content

[codex] Improve deploy migration logging - #1102

Merged
Asherlc merged 2 commits into
mainfrom
succulent-jumpsuit
May 8, 2026
Merged

Asherlc merged 2 commits into
mainfrom
succulent-jumpsuit

Conversation

@Asherlc

@Asherlc Asherlc commented May 8, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • stream detached migration container logs during deploy instead of waiting for exit or timeout
  • add explicit Postgres and ClickHouse migration phase/progress logs
  • record the production migration visibility incident in the incident baseline

Root Cause

The deploy workflow started the migration container in detached mode and only printed container logs after completion or timeout. During the production lock wait, Actions only showed repeated Migration still running... lines, hiding the migration phase and blocking statement.

Validation

  • pnpm lint
  • pnpm test src/db/migrate.test.ts src/db/clickhouse-migrations.test.ts src/db/run-migrate.test.ts
  • pnpm tsc --noEmit
  • cd packages/server && pnpm tsc --noEmit
  • cd packages/web && pnpm tsc --noEmit

pnpm test:changed was not run because local Docker could not start this worktree's Postgres dependency: another container (aloud-bike-db-1) is already bound to 127.0.0.1:5435.

Summary by CodeRabbit

  • New Features

    • Live-streaming of migration logs during deployment for better visibility.
    • More detailed migration progress logging (lock/acquire status, pending counts, per-phase completion).
  • Documentation

    • Added incident write-up documenting migration observability gap and mitigations.
  • Tests

    • Updated migration test assertions to match improved log wording.

@coderabbitai

coderabbitai Bot commented May 8, 2026 •

Copy link
Copy Markdown

Review Change Stack
No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d4571208-27fb-44ea-873b-e7556a050def

📥 Commits

Reviewing files that changed from the base of the PR and between 772057e and 9789370.

📒 Files selected for processing (2)
  • .github/workflows/deploy-web-stack.yml
  • docs/production-incident-baseline.md
✅ Files skipped from review due to trivial changes (1)
  • docs/production-incident-baseline.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/deploy-web-stack.yml

📝 Walkthrough

Walkthrough

This PR addresses a production incident where a detached migration container ran unobserved during deployment. The fix combines application-level structured logging throughout Postgres and ClickHouse migration phases with CI/CD live container log streaming via docker logs --follow, replacing blind-spot logging after completion/timeout.

Changes

Migration observability enhancement

Layer / File(s) Summary
Incident context
docs/production-incident-baseline.md
Post-mortem for 2026-05-08 incident documenting migration log blind spot, root cause (logs collected only after completion), and mitigations: live log streaming and structured phase logging.
Postgres migration logging
src/db/migrate.ts
Adds logger.info calls for Postgres connectivity, advisory-lock acquisition, migration file/applied count inventory, and pending-count before execution.
ClickHouse migration logging
src/db/clickhouse-migrations.ts
Adds logger import and structured logging: per-migration start/applied messages, backfill range inventory from Timescale chunks, per-range bounds (with index), and backfill completion. Backfill loop now uses .entries() for range indexing.
Migration orchestration
src/db/run-migrate.ts
Refactored main() to emit distinct start/complete log messages for Postgres and ClickHouse phases, each reporting applied-migration count. Aligns completion message format across both phases.
Test assertions
src/db/run-migrate.test.ts
Updated test expectation to match new ClickHouse completion log format: ClickHouse migrations complete — 1 migration(s) applied.
CI/CD live streaming
.github/workflows/deploy-web-stack.yml
Adds PID-based background docker logs --follow process management: helper function to stop/wait for log stream, start stream after container launch, coordinate shutdown during cleanup, and stop before final log capture.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • Asherlc/dofek#1099: Modifies ClickHouse migrations; related to ClickHouse migration logging and backfill changes.
  • Asherlc/dofek#1086: Modifies run-migrate flow and tests touching migration execution/logging paths.
  • Asherlc/dofek#1081: Modifies ClickHouse migrations and backfill code with related logging and test updates.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title '[codex] Improve deploy migration logging' directly and clearly summarizes the main objective of the pull request, which is to enhance logging during the deployment migration process.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch succulent-jumpsuit

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

github-actions Bot commented May 8, 2026 •

Copy link
Copy Markdown
Contributor

Storybook previews for 8478b068 are ready:

This comment updates automatically on each PR push.

@Asherlc
Asherlc marked this pull request as ready for review May 8, 2026 15:05
Copilot AI review requested due to automatic review settings May 8, 2026 15:05

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.

Pull request overview

This PR improves deploy-time migration observability by streaming migration container logs during GitHub Actions deploys and adding clearer phase/progress logging across Postgres and ClickHouse migration steps. It also documents the triggering production incident in the incident baseline to preserve operational context and mitigation guidance.

Changes:

  • Stream detached migration container logs live during the deploy workflow instead of only after exit/timeout.
  • Add explicit Postgres and ClickHouse phase/progress log lines (lock acquisition, pending counts, ClickHouse migration IDs, and metric_stream backfill ranges).
  • Record the “Production Migration Log Blind Spot” incident and mitigation steps in the production incident baseline.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
.github/workflows/deploy-web-stack.yml Starts docker logs --follow in the background to stream migration logs during deploy while still polling container status.
src/db/run-migrate.ts Adds high-level phase logs around Postgres and ClickHouse migration execution.
src/db/run-migrate.test.ts Updates log assertion to match the new ClickHouse completion log message.
src/db/migrate.ts Adds Postgres migration progress logs (connect, advisory lock wait/acquire, migration counts).
src/db/clickhouse-migrations.ts Adds ClickHouse migration progress logs, including per-migration and per-backfill-range visibility.
docs/production-incident-baseline.md Documents the 2026-05-08 deploy migration log visibility incident, root cause, and mitigation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@coderabbitai coderabbitai 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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/workflows/deploy-web-stack.yml:
- Around line 453-454: Replace the bare wait/clear lines with a call to the
existing stop_migration_log_stream helper to avoid an unbounded wait; locate the
block that references migration_log_pid (the two lines "wait
\"$migration_log_pid\" >/dev/null 2>&1 || true" and "migration_log_pid=\"\"")
and invoke stop_migration_log_stream which will kill the logs process and then
wait safely, ensuring migration_log_pid is cleared by that helper or cleared
immediately after the call.

In `@docs/production-incident-baseline.md`:
- Around line 3395-3435: Add a new "Follow-Up Work" subsection under the
"2026-05-08: Production Migration Log Blind Spot" entry that concisely lists
concrete next steps, owners, and target dates; include items to (1) update the
deploy workflow to stream logs and add the new migration-phase metrics (owner,
deadline), (2) schedule a postmortem action to review long-running queries and
implement DB migration runbook changes (owner, deadline), (3) add automated CI
checks or tests that exercise detached-container migration flow (owner,
deadline), and (4) record any documentation or training updates required; title
the subsection "Follow-Up Work" and keep it a short bulleted list referencing
the incident and the implemented fix.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b53ac477-7444-45a7-af27-0e789e258b9a

📥 Commits

Reviewing files that changed from the base of the PR and between dd5e7b6 and 772057e.

📒 Files selected for processing (6)
  • .github/workflows/deploy-web-stack.yml
  • docs/production-incident-baseline.md
  • src/db/clickhouse-migrations.ts
  • src/db/migrate.ts
  • src/db/run-migrate.test.ts
  • src/db/run-migrate.ts

Comment thread .github/workflows/deploy-web-stack.yml Outdated
Comment thread docs/production-incident-baseline.md
@github-actions

github-actions Bot commented May 8, 2026

Copy link
Copy Markdown
Contributor

Review app is ready:

This environment runs on a dedicated Hetzner server for PR #1102 and updates on each push.

@Asherlc
Asherlc enabled auto-merge (squash) May 8, 2026 15:17
@Asherlc
Asherlc merged commit d1ffaf1 into main May 8, 2026
63 checks passed
@Asherlc
Asherlc deleted the succulent-jumpsuit branch May 8, 2026 15:26
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