#2641

ci: run the Python tests' Postgres on tmpfs with fsync off

Openac-pplxwants to merge intofrom

Summary

ci/scripts/run-python-tests.sh starts the Python tests' Postgres with its data directory on the container's disk and default durability (fsync, synchronous_commit and full_page_writes on). pytest-xdist runs one worker per CPU against it. The firewall rules schema tests (scripts/tests/firewall_rules_postgres.py::fresh_database() and its three callers) create a database per test and replay every earlier migration into it, each file in its own committed transaction. When the disk is busy, that replay slows down enough for a migration's own SET LOCAL statement_timeout = '5s' to cancel it (psycopg QueryCanceled), which fails the Python tests job for changes that touch none of this.

This change starts the server with space_start_test_postgres from ci/scripts/lib/test-deps.sh, the helper that already starts the Rust tests' shared server (ci/scripts/setup-nextest-postgres.sh). That helper:

  • keeps the data directory on a tmpfs (--env PGDATA=/var/lib/postgresql/data --tmpfs /var/lib/postgresql/data), so an image supplied through TESTCONTAINERS_POSTGRES_IMAGE keeps its data on the mount too;
  • runs the server with -c fsync=off -c synchronous_commit=off -c full_page_writes=off -c max_connections=200.

The server lives for one run and is deleted with its data, so crash durability buys nothing. The container name, the published port, space_wait_for_test_postgres and the cleanup trap are unchanged. Every path through the script that starts Postgres reaches the same start_postgres.

Size. The data directory's peak during a full run, sampled every 50 ms inside the container, was 80 MiB with 4 workers, which is what -n auto gives on the job's 4-vCPU ubuntu-24.04 runner, and 107 MiB with 32 workers. The helper sets no size limit, so the tmpfs gets the kernel default of half the host's memory, far above that peak. Pages count against memory only as they are written.

Validation

Local Linux host, 32 CPUs, Docker data on an NVMe ext4 disk. Tests ran with pytest -n 32 against a server started as before, or with the same tmpfs and settings as after. Those runs used an earlier revision of this change that set the flags inline, with a 512 MiB size limit; this head calls the shared helper, which sets the same flags, no size limit and max_connections=200. CI on this head runs the suite through the helper.

The fresh_database tests: the 7 tests in test_runtime_environment_states_memory_retired.py, test_firewall_rules_pending_round_bound.py and test_firewall_rules_pending_round_generation.py, which use the helper in firewall_rules_postgres.py. Each cell is 20 runs on one server. "Load" means four containers looping dd if=/dev/zero of=<file in the container> bs=1M count=256 conv=fsync on the Docker data disk. --dist loadfile is what CI uses; --dist load spreads the 7 tests over 7 workers.

ServerLoad--distpytest time per run (min–max)QueryCanceled
beforenoneloadfile8.1–9.6 s0/20
beforenoneload5.2–6.2 s0/20
beforeddloadfile249–303 s0/20
beforeddload88–121 s0/20
afternoneloadfile4.1–4.2 s0/20
afternoneload3.6–3.8 s0/20
afterddloadfile4.0–4.2 s0/20
afterddload3.6–3.7 s0/20

QueryCanceled did not reproduce here, before or after. Under load, the before runs' backends sat in IO:DataFileImmediateSync in the first, initial-schema migration, whose own statement_timeout is 5 minutes, not the 5 s most later migrations set. Under that load, single tests took up to 120 s. With fsync=off that sync does nothing, and the files run in the same ~4 s with or without the load.

The whole suite, ci/scripts/run-python-tests.sh as CI runs it (CI=true, so uv --locked). 3 runs each:

ServerWorkersWall timeResult
before32 (auto)51.8–51.9 s2167 passed, 1 skipped
before458.6–58.8 s2167 passed, 1 skipped
after32 (auto)51.5–51.9 s2167 passed, 1 skipped
after458.5–59.3 s2167 passed, 1 skipped

On an idle disk the suite's wall time is unchanged, because the Postgres tests are not its critical path. The gain is in how the suite behaves on a busy disk.

A server started with these settings reports fsync=off, synchronous_commit=off, full_page_writes=off and data_directory=/var/lib/postgresql/data on a tmpfs, and its container is removed on exit.

Not validated: the GitHub Actions job itself (CI on this head covers it), Docker Desktop on macOS, and a real 4-CPU runner. The 4-worker numbers ran with pytest -n 4 on the 32-CPU host.

Severity and risk

Severity: low to medium. This is a CI flake that fails unrelated pull requests in the merge queue. It does not affect shipped code.

Risk: the tests' Postgres holds its data in the runner's memory, about 100 MiB at today's peak. No Python test checks crash recovery or depends on where the data lives, and the Rust tests' shared server already runs this way. Rollback: revert the commit.

Rollout

This is test infrastructure only: no schema, protocol, persisted state or deployed component changes. Old and new versions of the script never share a server, because each run starts and deletes its own. Rollback is reverting the commit.

Not covered

On a newly started server, two workers' first migrations can race on CREATE ROLE (roles are cluster-wide, so pg_authid_rolname_index raises UniqueViolation). That happens before and after this change: here, a run of the four files on a fresh server hit it on 15 of 20 servers before and 11 of 20 after. It did not occur in any of the 18 full-suite runs here. It is a separate issue in the test helper or the migration, left for a separate change.

Local review: round 1 (Codex + Claude), READY AFTER FIXES; the fixes (reuse the shared helper, wording) checked directly, READY.

AI assistance: Claude Code (Claude Opus 5.5) wrote the script change, ran the measurements and drafted this description.

Activity

5
coderabbitai[bot]16h ago

No actionable comments were generated in the recent review.

Walkthrough

The test script documents the PostgreSQL test server’s temporary storage and reduced durability settings. Its startup function now pulls the PostgreSQL image through a shared helper and starts the container through another shared helper. This replaces the direct Docker invocation and removes its explicit authentication, pull, and detached-mode options.

Possibly related PRs

  • perplexityai/SPACE#1475: Adds the pytest-xdist worker setup that the new comments and data-use figures reference.
Merge Risk: Minimal · up to 63699

This change moves the Python tests' Postgres onto tmpfs with durability settings off, which speeds up migration replay in CI. It does not touch production code. Merge risk is minimal.

Architecture risk: Low · up to 63699

The change affects 1 source area.

For test PostgreSQL startup, the runner now provides the selected image to the pull helper and the image, container name, and port mapping to the startup helper, which owns the Docker pull and launch settings.

Changed areas: ci

Review details

Systems and components

  • observed — 1 changed file mapped to ci.
Pre-merge checks: 7

Check nameStatusExplanation
Title checkThe title uses the prefix "ci:" followed by a lowercase summary ("run the Python tests' Postgres on tmpfs with fsync off"), which matches the required lowercase area-and-colon format. It has no traili…
Description Follows The Pr TemplateThe PR description (PR #2641, perplexityai/SPACE) contains all four required items, each with real content: 1. "## Summary": present. It states that the change starts the Python tests' Postgres wi…
Bug Fixes Name A Regression TestThe check applies only when a pull request fixes an application behavior defect under crates/, shim/, or ui/. PR #2641 (ac-pplx, head ac/python-tests-pg-tmpfs) changes one file: ci/scripts/run-python-…
Weakened Safeguards Are JustifiedThe reviewed range changes one file, ci/scripts/run-python-tests.sh, in a single hunk. No test, assertion, lint, CI check, allowlist, baseline, exception list, or guideline file changes. The hunk ch…
Agent Tooling Runs No New CommandsThe check covers agent plugin manifests (plugin.json, plugin.yaml), SKILL.md files, and guideline files. The pull request changes exactly one file: ci/scripts/run-python-tests.sh, a CI shell script.…
External Code Sources Need A PersonThe check fails only when the diff adds or changes where external code comes from: Cargo dependency sources, container image references, downloaded binary URLs/checksums, or Helm chart dependencies. T…
Public-Safe ContentThe public-safe check passes. The diff changes only ci/scripts/run-python-tests.sh. A pattern scan of the added lines found no credentials, tokens, private keys, internal hostnames or URLs, cloud ac…
Full details: Title check

Explanation

The title uses the prefix "ci:" followed by a lowercase summary ("run the Python tests' Postgres on tmpfs with fsync off"), which matches the required lowercase area-and-colon format. It has no trailing period, no ticket ID, and no internal link. The title describes the main change: the Python test Postgres now runs on tmpfs with fsync disabled via the shared helper.

Full details: Description Follows The Pr Template

Explanation

The PR description (PR #2641, perplexityai/SPACE) contains all four required items, each with real content: 1. "## Summary": present. It states that the change starts the Python tests' Postgres with space_start_test_postgres, which puts PGDATA on tmpfs and disables fsync, synchronous_commit and full_page_writes. 2. "## Validation": present. It lists the local runs (fresh_database tests under load, full-suite wall times, pass counts) and the CI scope ("CI on this head covers it" for the GitHub Actions job). 3. "## Severity and risk": present. It states "Severity: low to medium" and gives a "Risk:" paragraph with rollback. 4. "AI assistance:" line: present. It reads "AI assistance: Claude Code (Claude Opus 5.5) wrote the script change, ran the measurements and drafted this description." The description has no empty sections and no placeholder HTML comments. Per the check, presence is judged, not quality or length. No code evidence was needed for this check.

Full details: Bug Fixes Name A Regression Test

Explanation

The check applies only when a pull request fixes an application behavior defect under crates/, shim/, or ui/. PR #2641 (ac-pplx, head ac/python-tests-pg-tmpfs) changes one file: ci/scripts/run-python-tests.sh. The changed-file inventory from the review range shows no paths under crates/, shim/, or ui/. The PR also describes itself as CI test infrastructure. It changes how the Python tests start their Postgres server to avoid a timeout under disk load. It does not fix application behavior. The check does not apply, so it passes without requiring a regression test.

Full details: Weakened Safeguards Are Justified

Explanation

The reviewed range changes one file, ci/scripts/run-python-tests.sh, in a single hunk. No test, assertion, lint, CI check, allowlist, baseline, exception list, or guideline file changes. The hunk changes how the test Postgres server starts. The old docker run call now goes through space_start_test_postgres from ci/scripts/lib/test-deps.sh. That helper keeps the same --detach, --pull=never and POSTGRES_HOST_AUTH_METHOD=trust settings. It also adds a tmpfs data directory and the fsync, synchronous_commit and full_page_writes off settings. These settings change server durability, not test coverage or a CI guard. The description says so and gives a reason. The container cleanup trap, the wait step and the test invocation are unchanged. No || true, set +e, continue-on-error, skip marker or SPACE_TEST_DEPS_OPTIONAL setting was added. The check does not treat tuning test infrastructure as weakening a safeguard, so it passes.

Full details: Agent Tooling Runs No New Commands

Explanation

The check covers agent plugin manifests (plugin.json, plugin.yaml), SKILL.md files, and guideline files. The pull request changes exactly one file: ci/scripts/run-python-tests.sh, a CI shell script. The diff does not touch any plugin manifest, skill, command, or AGENTS.md/CLAUDE.md file, so none of the listed failure conditions (hooks, MCP/LSP entries, non-name/description SKILL.md frontmatter keys, !-backtick shell substitutions) can apply. The script change replaces a direct docker run with the existing space_start_test_postgres helper. That starts a server in CI, not in an agent tool or on a developer machine through an agent manifest, so it falls outside this check's scope.

Full details: External Code Sources Need A Person

Explanation

The check fails only when the diff adds or changes where external code comes from: Cargo dependency sources, container image references, downloaded binary URLs/checksums, or Helm chart dependencies. The PR (perplexityai/SPACE#2641, author ac-pplx, head ac/python-tests-pg-tmpfs into main) changes one file, ci/scripts/run-python-tests.sh. Diff evidence (refs/coderabbit/pre-merge-check/base..head): - start_postgres no longer calls docker run directly. It now calls space_start_test_postgres with the same container name, --publish 127.0.0.1::5432, and output redirection. - The image is still resolved by space_test_dependency_postgres_image, which is unchanged. It defaults to public.ecr.aws/docker/library/postgres:16-alpine or honors TESTCONTAINERS_POSTGRES_IMAGE. The PR does not add, change, or pin a different image, tag, or digest. - space_start_test_postgres (in ci/scripts/lib/test-deps.sh) is not modified by this PR. It already existed and is used by other scripts. It adds only --tmpfs, PGDATA, and -c flags, and sources no new external code. No Cargo.toml, Dockerfile, Chart.yaml/Chart.lock, or download URL/checksum changes appear in the diff. The check does not apply, so it passes.

Full details: Public-Safe Content

Explanation

The public-safe check passes. The diff changes only ci/scripts/run-python-tests.sh. A pattern scan of the added lines found no credentials, tokens, private keys, internal hostnames or URLs, cloud account IDs, ARNs, or personal workstation paths. The title and description contain none of the listed sensitive categories either: - The paths they mention (/var/lib/postgresql/data, ci/scripts/...) are container and repository paths, not personal workstation paths. - The measurements are local test-run timings on a 32-CPU host, not production measurements or production logs. - The QueryCanceled and CREATE ROLE race notes describe a test flake, not an incident or an unfixed security vulnerability. - The AI-assistance line credits "Claude Code (Claude Opus 5.5)" with no link or internal value, so it does not trigger the failure condition. No finding applies.

Recent review info

Automatic approval policy

Commit: 63699e5ff92b.

SettingEffective valueSource
Automatic approvalsEnabledGlobal configuration
Merge riskModerateGlobal configuration
Security riskNot setGlobal configuration

No overrides matched. The global limits apply.

Not set means no limit was configured after inheritance. Use @coderabbitai configuration to inspect the resolved settings and their sources.

Run configuration

  • Source mode: Auto
  • Repository: perplexityai/SPACE
  • Branch: main
  • File: .coderabbit.yaml
  • Commit: adb4faf
  • Layers: Repository YAML; Enforced overrides: Organization
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 89bbd0ea-7151-48ba-a0c1-0f7e8dfe1979
Commits

Reviewing files that changed from the base of the PR and between adb4faf209803598d142e04e1b31fa8c859a58ef and 63699e5ff92be47737b051c1681ee6fde60273fc.

Files selected for processing: 1

  • ci/scripts/run-python-tests.sh

Included review availability: This review used your included allowance. 6 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 10 reviews per hour.

github-actions[bot]16h ago

Thanks for opening this pull request! A SPACE maintainer will take a look.

CONTRIBUTING.md explains how we review outside contributions.

coderabbitai[bot]approved changes16h ago
NancyKwongPerplexityapproved changes16h ago