Plan: Implement repository contracts and Alembic migrations (2.6.2) - #142
Draft
leynos wants to merge 2 commits into
Draft
Plan: Implement repository contracts and Alembic migrations (2.6.2)#142leynos wants to merge 2 commits into
leynos wants to merge 2 commits into
Conversation
Contributor
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
leynos
force-pushed
the
2-6-2-repository-contracts-and-alembic-migrations
branch
from
June 15, 2026 20:23
44c0ff3 to
83ad969
Compare
…rations This plan defines the scope, stages, and validation criteria for implementing repository contracts and Alembic migrations for generation-run aggregates. The plan covers: - Verification of domain model from 2.6.1 - Definition of GenerationRunRepository and GenerationEventRepository protocols - Alembic migration for generation_runs and generation_events tables - SQLAlchemy ORM models and repository implementations - Integration tests validating event ordering and persistence semantics - Validation that all gates pass (check-fmt, typecheck, lint, test) The plan is structured as 8 stages with explicit go/no-go validation points. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
leynos
force-pushed
the
2-6-2-repository-contracts-and-alembic-migrations
branch
from
June 15, 2026 20:26
83ad969 to
ec1cfc1
Compare
Replace the initial generation-run persistence execplan, which was drafted without inspecting the codebase, with a version grounded in the actual 2.6.1 contracts, prior art, and a community-of-experts design review. Corrections over the previous draft: - Target the real ports in `episodic/canonical/generation_run_ports.py` (`create_run`, `get_run`, `list_runs`, `update_run_status`, `append_event`, `list_events`, and the checkpoint methods) rather than inventing `GenerationRunRepository.add`/`by_id` in a non-existent `episodic/generation/ports.py`. The ports already exist; this slice implements a PostgreSQL adapter for them. - Chain the migration off the true head `20260601_000009`, not the stale `20260508_000008`, and note the single linear head despite two `000009` files. - Mirror established storage patterns: `Base` declarative models, the history-table `UNIQUE(parent_id, seq)` + `CHECK (seq >= 1)` sequence pattern, `_RepositoryBase`, per-feature mappers, and `SqlAlchemyUnitOfWork` wiring. Design decisions added after the Logisphere panel (proceed-with-conditions): - Allocate per-run event `seq` as `MAX(seq)+1` under a unique constraint with a bounded retry inside a savepoint and a conflict metric, instead of escalating on first conflict; reject a global sequence (gaps) and a counter column (pattern divergence). - Widen `seq` to `BIGINT`; add `(episode_id, created_at)` and `(episode_id, status, created_at)` indexes; specify deterministic `list_runs` ordering and FK `ON DELETE` semantics; add an `updated_at` trigger. - Qualify behavioural equivalence to the single-writer case and document the py-pglite single-connection limitation; force the idempotency conflict branch in tests. Status remains DRAFT pending approval before implementation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This is a planning PR. It carries the execution plan for roadmap item
2.6.2 — Implement repository contracts and Alembic migrations and is
intended for review of the plan before any implementation begins. The plan is
in
DRAFTstatus and must be approved before code is written.The execplan lives at
docs/execplans/2-6-2-repository-contracts-and-alembic-migrations.md.It supersedes the initial draft on this branch, which was written without
inspecting the codebase (it invented port signatures and a module path that do
not exist, and cited a stale base migration revision). The replacement is
grounded in the real 2.6.1 contracts, prior art, and a community-of-experts
design review.
What the slice will deliver
2.6.1 already defined the generation-run domain model and the composite
GenerationRunPort(inepisodic/canonical/generation_run_ports.py) with anin-memory reference adapter. This slice adds the durable layer behind that port:
SqlAlchemyGenerationRunStoreimplementing the existingcomposite port, wired into
SqlAlchemyUnitOfWorkasuow.generation_runs.generation_runs,generation_events, andgeneration_checkpoints, chained off the current head20260601_000009.tests run against both the in-memory and PostgreSQL adapters.
Key design decisions (see the execplan Decision Log)
seqallocated asMAX(seq)+1underUNIQUE(generation_run_id, seq)with a bounded retry inside a savepoint and aconflict metric — mirroring the established history-table
revisionpattern;a global Postgres sequence is rejected (gap/visibility problems).
seqstored asBIGINT; composite indexes forlist_runs; explicit FKON DELETEsemantics (events/checkpointsCASCADE, episodeRESTRICT); anupdated_attrigger matching theworkflow_checkpointsprecedent.create_runidempotency via a uniqueidempotency_keycolumn (first-write-wins).single-writer-per-run assumption; the py-pglite single-connection limitation
and a follow-up real-PostgreSQL concurrency test are documented.
Testing approach
Red-Green-Refactor with pytest unit tests, py-pglite integration tests for event
ordering, and bounded Hypothesis property coverage for the sequence invariant.
vidai-mockis out of scope: this slice performs no inference. All gates(
make check-fmt,make typecheck,make lint,make test,make check-migrations,make markdownlint) must pass, followed by acoderabbit review --agentpass, at each milestone.References
docs/roadmap.md.docs/execplans/2-6-2-repository-contracts-and-alembic-migrations.md.