Skip to content

Scalability engine foundation: local-first core, JobRunner, FastAPI/SQLAlchemy discovery, scale CLI (Phases 0-2) - #69

Merged
kadireren7 merged 8 commits into
mainfrom
feat/scalability-foundation
Nov 23, 2026
Merged

kadireren7 merged 8 commits into
mainfrom
feat/scalability-foundation

Conversation

@kadireren7

@kadireren7 kadireren7 commented Nov 23, 2026 •

Copy link
Copy Markdown
Owner

Draft, not for merging without owner approval. It was opened to run CI (the workflow runs on pull_request). CI is green; results below.

Summary

This PR adds the foundation of the new scalability engine product line (Phases 0–2 in docs/ROADMAP.md): a local-first core that needs no services, an in-process job runner, static FastAPI and SQLAlchemy/SQLModel application discovery, and a first user-facing CLI, python -m patchfrog scale. It contains no detection rules, scores or MCP tools yet; those come in Phase 3 and later.

The existing review and compatibility lines are maintenance-only (ADR-001). Their only changes here are the S1 OpenAI quota fix, a lazy-import change in the CLI, and the code-graph move with a same-object re-export.

Commits

  1. docs: architecture, roadmap and governance: CLAUDE.md, docs/PROGRESS.md, docs/ROADMAP.md, docs/architecture/*, ADR-001..018, and the Apache-2.0 audit (license unchanged).
  2. fix(openai): structured insufficient_quota classification (S1).
  3. feat(config): CoreSettings/ServerSettings split and lazy apps.worker imports, so every --help and every DB-free command starts with an empty environment. Also scripts/safe_pytest.py.
  4. refactor(codegraph): neutral patchfrog.codegraph with deprecated same-object re-exports from patchfrog.upstream.code_graph.
  5. feat(scalability): architecture boundary tests and the public API contract, patchfrog.app (revision, store, jobs, discovery), patchfrog.scalability.project (FastAPI + SQLAlchemy/SQLModel discovery, JSON Schema), the scale CLI, corpora and tests.
  6. fix(deps): kombu>=5.3.4,<5.7 (S8, see CI result).
  7. docs: the CI validation record.

Architecture

  • Layering: domain ← engine ← application services ← adapters. The CLI is a thin adapter (patchfrog/cli_scale.py).
  • Boundary rule R1: new core roots patchfrog.app and patchfrog.scalability import only approved core modules and the stdlib. They import no persistence, server settings, Celery, Redis, GitHub, web framework or LLM SDK. Enforced by tests/architecture/.
  • Dependency cycles: the historical SCC is unchanged (29 units, 156 edges). The baseline did not grow.
  • Untrusted code: analysed repositories are parsed, never imported or executed. Git is used only to list files (no filters, hooks or fsmonitor), symlinks are never followed, and every analysed byte is verified against the captured revision.

Local-first core

  • RepositoryRevision: a content identity of the analysed working tree (Git or a plain directory).
  • LocalRunStore: content-addressed, crash-safe run artifacts. Liveness uses flock, runs survive a SIGKILL (recovered as interrupted), and prune and verify are available.
  • No PostgreSQL, Redis, Celery, GitHub App or AI provider is needed.

JobRunner

  • Idempotency key over the revision, config, engine version and ruleset version.
  • Cooperative cancellation and explicit budgets: wall time, artifact count and bytes.
  • A closed set of failure classes, a job-report artifact for every run, and single execution of identical requests across threads and processes.

Discovery

  • Frameworks: evidence comes from manifests and lockfiles. A version is never invented from a range or a pin.
  • FastAPI: apps and routers (also from factories), include_router prefix composition, aliases and imports (src/ and monorepo layouts), sync/async endpoints, and the effective Depends graph.
  • SQLAlchemy/SQLModel: declarative bases, models, columns and primary keys, relationships with lazy provenance, inheritance, engines, session factories, session providers and route → session links. Only the scheme of a literal URL is kept, never the credentials.
  • Uncertainty is explicit: unresolved and unsupported constructs are typed Unresolved/DbUnresolved entries, never guessed. coverage.complete is honest.

CLI

python -m patchfrog scale analyze [PATH], scale show RUN_ID and scale schema provide text, --details and --json output with documented exit codes (docs/scale-cli.md). The store defaults to user-level locations; it is never configured from a repository's .env. python -m patchfrog skips the eagerly importing full CLI: 0.15 s of startup instead of 3.5 s (measured).

Public API and schema

  • Public Engine API: 0.6.0, with 62 names (18 stable, 41 provisional, 3 deprecated). Everything added is provisional and additive.
  • ApplicationModel: schema 2. Version-1 artifacts still load. The JSON Schema is generated from the typed model (docs/schemas/application-model.v2.schema.json) and the loader is strict in the same way.
  • Additive store/discovery errors: RunNotFoundError, DiscoveryArtifactError.

Compatibility

  • The server environment contract is unchanged (pinned by tests/unit/test_core_settings.py).
  • The Celery task count is unchanged (9, checked by CI).
  • patchfrog.upstream.code_graph names remain as same-object aliases.
  • There is no runtime dependency change. pyproject.toml only excludes the new fixture tree from pytest collection, ruff and mypy.
  • There is no database schema change.
  • No private-consumer data is in the tree; /private/ is git-ignored.

Test evidence (local, before push)

  • ruff check . and mypy . --strict pass (874 files).
  • Targeted run: 334 passed. It covered architecture and public API, all discovery and corpus tests, JobRunner, store and revision, the CLI end-to-end tests, the CLI startup tests and S1.
  • Corpora (fixture agreement only, not real-world accuracy):
    • FastAPI: routes 36/36 and dependencies 12/12, P = R = 1.00.
    • SQLAlchemy/SQLModel: P = R = 1.00 in all 7 categories.
    • The evaluators detect 7/7 and 10/10 engine mutations.
  • Last complete local full suite (on the 2.3 tree): 3,292 collected = 3,233 passed + 54 skipped + 5 failed. The 5 failures are the known Redis-dependent test_ops_doctor.py tests, which fail only without a local Redis.
  • Not yet run: the full suite on the 2.4 and 2.5 changes (blockers B-2.4-REG and B-2.5-REG). This CI run is that verification.

CI result

Run 1 (45090246711, eff9149): ruff, mypy and migrations passed. pytest failed: 3,353 passed, 6 skipped, 18 errors.

  • Errors: all 18 were verifier worker subprocess did not become ready in time.
  • Root cause: kombu 5.7.0, released after the last green main CI, raises VersionMismatch at worker start with redis-py < 6.1, while redis is capped <6.0 here and by celery[redis] 5.4.
  • Pre-existing: the failure reproduces identically with main's own code (9b9de85), so it is not caused by this branch.
  • Fix: kombu>=5.3.4,<5.7 (S8). No assertion was changed.

Run 2 (45092267919, 3f00299): success. Job test: install, ruff, static analyzers, mypy --strict, migrations and head check, pytest (3,371 passed, 6 skipped, 0 failed, 0 errors; Postgres 16 + Redis 7, PATCHFROG_REQUIRE_POSTGRES=1), benchmark sanity, Docker builds (api, worker) and the Celery task registration check (9 tasks).

  • All collected tests ran: 3,371 + 6 equals the 3,377 collected locally for the same tree.
  • The 6 skips are by design: 5 migration-corpus cases with nothing to materialize, and 1 opt-in real-GitHub e2e test that is never enabled in CI.
  • Infrastructure tests ran: the PostgreSQL-backed and Redis-backed tests (test_ops_doctor.py and the verifier-worker corpora) ran and passed.

Blockers B-2.4-REG and B-2.5-REG are closed by this run.

Remaining limitations

  • No detection rules, findings or MCP scalability tools yet.
  • Discovery is static: dynamic registrations, computed values and some mapping styles are reported as unresolved (docs/architecture/DISCOVERY.md §4 and §9.3).
  • A patchfrog console script is ADR-018, still Proposed (recommended for Phase 6 packaging).
  • The full CLI still imports everything eagerly (S3). Only scale has the fast path.

🤖 Generated with Claude Code

https://claude.ai/code/session_01FmAjAsRVojgn2Ujwjtny4u

kadireren7 and others added 8 commits November 23, 2026 03:38
Adds the documentation set for the new scalability product line:
CLAUDE.md (project rules), docs/PROGRESS.md and docs/ROADMAP.md (status
and plan), and docs/architecture/* (overview, current state, decisions
ADR-001..018, boundaries, public API, local store, discovery, detection
rules, verification, MCP, test strategy, migration plan), plus the
Apache-2.0 migration audit (license unchanged).

The previous roadmap moves to docs/history/ and docs/architecture.md
becomes docs/compatibility-pipeline.md (no content loss). .gitignore
excludes the local /private/ directory so private-consumer material can
never be committed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FmAjAsRVojgn2Ujwjtny4u
The OpenAI adapter treated an exhausted quota as a transient rate limit,
so reviews retried instead of failing with an actionable error. It now
reads the structured code (exc.code / exc.type / exc.body, also when the
SDK error is still wrapped) with exact matching, keeping the message
fallback. Anthropic and Gemini are unchanged.

Seven regression tests through the real SDK error mapping; four fail on
the previous adapter.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FmAjAsRVojgn2Ujwjtny4u
… lazy worker imports (Phase 1.1)

- patchfrog.config.core.CoreSettings: settings every process may read,
  none required. Settings (ServerSettings) subclasses it; the server
  environment contract (aliases, required fields, defaults, order) is
  unchanged and pinned by tests/unit/test_core_settings.py (ADR-011).
- patchfrog/cli.py imports apps.worker lazily, so every --help path and
  the DB-free commands start with an empty environment (ADR-011);
  tests/unit/test_cli_local_startup.py checks this in fresh interpreters.
- scripts/safe_pytest.py: a resource-guarded, batched local runner with
  per-node-id accounting for memory-constrained hosts (CI unchanged).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FmAjAsRVojgn2Ujwjtny4u
…ted re-export (Phase 1.3, M4)

The DB-free local code graph moves from patchfrog/upstream/code_graph.py
to patchfrog/codegraph/ (implementation byte-identical below the module
docstring). patchfrog.upstream.code_graph re-exports the same objects as
deprecated aliases, so every existing import keeps working; upstream's
workspace and blast-radius modules import the new path. The historical
dependency SCC is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FmAjAsRVojgn2Ujwjtny4u
…ery and `scale` CLI (Phases 1.2-2.5)

Architecture boundaries (1.2/1.3): tests/architecture enforces R1 (core
closure purity), R2/R3 (no dependency-cycle growth, shrink-only baseline)
and R4 (adapter direction), plus the Public Engine API contract
(PUBLIC_API.md <-> public_api.py, import-time side-effect probe; API 0.6.0).

Local application layer (patchfrog.app, all stdlib, no services):
- revision: RepositoryRevision, a content identity of the analysed
  working-tree snapshot; git used for listing only (no filters, hooks or
  fsmonitor), symlinks never followed; read_revision_file verifies bytes.
- store: LocalRunStore, crash-safe content-addressed run artifacts
  (atomic publish, flock liveness, SIGKILL recovery, dedup, prune, verify).
- jobs: in-process JobRunner (idempotency key over revision + config +
  engine/ruleset version, cooperative cancellation, budgets, typed
  failure classes, single execution of identical requests).
- discovery: run_discovery, application discovery as a JobRunner job.

Scalability engine (patchfrog.scalability.project, parse-only stdlib ast):
- framework evidence from manifests/lockfiles (never invents a version);
- FastAPI apps, routers, include_router prefix composition, aliases and
  imports, sync/async endpoints, Depends graphs;
- SQLAlchemy/SQLModel bases, models, columns, relationships with lazy
  provenance, inheritance, engines, session factories, session providers
  and route -> session links;
- explicit Unresolved/Limitation entries instead of guesses; bounded by
  DiscoveryLimits; ApplicationModel schema 2 with a generated JSON Schema
  (docs/schemas/) and a strict loader.

CLI: `python -m patchfrog scale analyze|show|schema` (patchfrog/cli_scale.py,
a thin adapter; patchfrog/__main__.py dispatches it without importing the
full CLI). Also registered in `python -m patchfrog.cli`.

Tests: unit, process and end-to-end CLI tests; two hand-written fixture
corpora (FastAPI 14 cases, SQLAlchemy/SQLModel 13 cases) with
precision/recall evaluators. pyproject.toml only excludes the new fixture
tree from pytest collection, ruff and mypy, like the existing fixtures.
No runtime dependency is added.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FmAjAsRVojgn2Ujwjtny4u
kombu 5.7.0, released after the last green main CI, refuses redis-py
< 6.1 when the Redis transport starts (VersionMismatch), while redis is
capped below 6.0 here and by celery[redis] 5.4. pip installs the
combination without complaint, so every test that starts a real verifier
worker errored in CI (18 errors in test_fix_verification_corpus.py and
test_production_execution_corpus.py). Reproduced locally with main's own
code (9b9de85), so this is environmental dependency drift, not a change
on this branch.

Declares kombu>=5.3.4,<5.7 (5.6.x accepts redis 5.x; the floor matches
celery's). It narrows resolution back to the previously working family
and adds no dependency. Moving to redis-py 6 is a separate upgrade.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FmAjAsRVojgn2Ujwjtny4u
CI run 45092267919 (commit 3f00299, job `test`): ruff, mypy --strict,
migrations, pytest with real Postgres 16 and Redis 7 (3,371 passed,
6 by-design skips, 0 failed, 0 errors; equal to the 3,377 collected
locally), benchmark sanity, Docker builds and the Celery task check all
succeeded. Records the S8 root cause and ADR-015 impact assessment, the
commit scope and the hygiene checks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FmAjAsRVojgn2Ujwjtny4u
…admap note

- config/core.py: the import-boundary test lives in tests/architecture/
  (rule R1, CORE_ROOTS), not tests/unit/.
- history/roadmap-2026: state that the only edit is the renamed
  docs/architecture.md reference, instead of "kept unchanged".

Documentation only; no behaviour change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kadireren7
kadireren7 marked this pull request as ready for review November 23, 2026 10:21
@kadireren7
kadireren7 merged commit d27aae6 into main Nov 23, 2026
1 check 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.

1 participant