From cdd1ae5d21cbf51e51d602ff57127dce6bc02c43 Mon Sep 17 00:00:00 2001 From: Kresna Sucandra Date: Tue, 28 Jul 2026 04:14:35 +0000 Subject: [PATCH 1/4] fix: remove redundant __init__ from CodeArchive model MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The custom __init__ manually set defaults (id, created_at, updated_at, version, tags, visibility, is_archived, dependencies, metadata) that are already declared via Pydantic Field(default_factory=...) on the class attributes. This created two sources of truth — a drift hazard where changing one set of defaults without the other silently produces inconsistent behavior. Removing the custom __init__ lets Pydantic handle all default generation through its standard machinery, eliminating the duplication. Addresses TODO.md P3 item: 'models/code_archive.py:127-149 __init__ manually re-implements every default already provided by Field(default_factory=...)' --- TODO.md | 6 +++--- evoseal/models/code_archive.py | 24 ------------------------ 2 files changed, 3 insertions(+), 27 deletions(-) diff --git a/TODO.md b/TODO.md index e7edb696..55ba35e9 100644 --- a/TODO.md +++ b/TODO.md @@ -262,7 +262,7 @@ - [ ] **`providers/local_models.py:103-119`** — `_query_installed_models` is `lru_cache`d indefinitely with no TTL; a newly pulled/removed Ollama model isn't picked up until something explicitly calls `clear_model_cache()` - [ ] **`model_fine_tuner.py:122-137`** — `_check_gpu_availability()` is defined but never called; despite the module docstring claiming "Requires a CUDA GPU," `initialize_model()` silently proceeds on CPU instead of failing fast - [ ] **`model_fine_tuner.py:220,240`** — `example['instruction']`/`example['output']` direct dict access with no `.get()`; a malformed training example raises `KeyError` surfaced only as a generic error string instead of a clear validation message -- [ ] **`models/code_archive.py:127-149`** — `__init__` manually re-implements every default already provided by `Field(default_factory=...)`, a drift hazard (two sources of truth for the same defaults) +- [x] **`models/code_archive.py:127-149`** — `__init__` manually re-implements every default already provided by `Field(default_factory=...)`, a drift hazard (two sources of truth for the same defaults) - [x] **`evoseal/agents/agentic_system_example.py:7`** — `from evoseal.agentic_system import ...` is the wrong module path (actual: `evoseal.agents.agentic_system`); the example fails immediately with `ModuleNotFoundError` ### Documentation Polish @@ -306,8 +306,8 @@ | 🔴 P0 | 11 | 11 | Original 5 complete; all 6 critical bugs from 2026-07-22 whole-repo review fixed (PRs #74, #76-#79) | | 🟠 P1 | 24 | 14 | Original safety/integration items done; +12 high-priority bugs from 2026-07-22 review; signal-handler init fix; safety.yaml created | | 🟡 P2 | 30 | 16 | Co-evolution loop gaps (7 items, 7 done) + existing P2 + 13 medium bugs from 2026-07-22 review + 4 latent collect->train bugs found closing the loop (1 fixed, 1 new HF-format gap logged) | -| 🟢 P3 | 24 | 12 | Makefile, pre-commit, Docker, ADRs, ADR refresh, CHANGELOG complete; +10 hygiene items from 2026-07-22 review | -| **Total** | **89** | **53** | +| 🟢 P3 | 24 | 13 | Makefile, pre-commit, Docker, ADRs, ADR refresh, CHANGELOG complete; +11 hygiene items from 2026-07-22 review | +| **Total** | **89** | **54** | > Update this table as you complete items. Recommended flow: P0 → P1 → P2 → P3. > diff --git a/evoseal/models/code_archive.py b/evoseal/models/code_archive.py index 557bfe97..12980963 100644 --- a/evoseal/models/code_archive.py +++ b/evoseal/models/code_archive.py @@ -124,30 +124,6 @@ class CodeArchive(BaseModel): validate_assignment=True, ) - def __init__(self, **data: Any) -> None: - """Initialize the code archive with default values.""" - # Set default values - if "id" not in data: - data["id"] = str(uuid4()) - if "created_at" not in data: - data["created_at"] = datetime.now(UTC) - if "updated_at" not in data: - data["updated_at"] = data["created_at"] - if "version" not in data: - data["version"] = "1.0.0" - if "tags" not in data: - data["tags"] = [] - if "visibility" not in data: - data["visibility"] = CodeVisibility.PRIVATE - if "is_archived" not in data: - data["is_archived"] = False - if "dependencies" not in data: - data["dependencies"] = [] - if "metadata" not in data: - data["metadata"] = {} - - super().__init__(**data) - @field_validator("content") @classmethod def validate_content_not_empty(cls: type[ModelT], v: str) -> str: From ea03f3b742c5c1d8f133b8685994132a87ea6982 Mon Sep 17 00:00:00 2001 From: Kresna Sucandra Date: Tue, 28 Jul 2026 04:48:08 +0000 Subject: [PATCH 2/4] fix(models): ensure updated_at equals created_at on construction Add model_post_init to restore the guarantee that updated_at mirrors created_at when a CodeArchive is first created. Without this, the two independent Field(default_factory=lambda: datetime.now(UTC)) calls introduce microsecond drift, silently breaking the invariant the old custom __init__ maintained. Addresses reviewer feedback on PR #103. --- evoseal/models/code_archive.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/evoseal/models/code_archive.py b/evoseal/models/code_archive.py index 12980963..c354ba20 100644 --- a/evoseal/models/code_archive.py +++ b/evoseal/models/code_archive.py @@ -124,6 +124,16 @@ class CodeArchive(BaseModel): validate_assignment=True, ) + def model_post_init(self, __context: Any) -> None: + """Ensure updated_at mirrors created_at on first construction. + + The old custom __init__ set ``updated_at = created_at`` when not + explicitly provided. With plain field defaults each factory calls + ``datetime.now(UTC)`` independently, introducing a microsecond + drift. This hook restores the original guarantee. + """ + self.updated_at = self.created_at + @field_validator("content") @classmethod def validate_content_not_empty(cls: type[ModelT], v: str) -> str: From e91c0675f43735092e746e87276d86a2097ed6a8 Mon Sep 17 00:00:00 2001 From: Kresna Sucandra Date: Tue, 28 Jul 2026 05:17:35 +0000 Subject: [PATCH 3/4] fix(models): preserve explicit updated_at in model_post_init model_post_init unconditionally set self.updated_at = self.created_at, silently discarding any real updated_at value on deserialization (model_validate / model_validate_json). This broke round-tripping and lost edit history. Now only overwrites when updated_at was not explicitly provided. Ref: PR #103 review feedback --- evoseal/models/code_archive.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/evoseal/models/code_archive.py b/evoseal/models/code_archive.py index c354ba20..bf1e2eb6 100644 --- a/evoseal/models/code_archive.py +++ b/evoseal/models/code_archive.py @@ -130,9 +130,11 @@ def model_post_init(self, __context: Any) -> None: The old custom __init__ set ``updated_at = created_at`` when not explicitly provided. With plain field defaults each factory calls ``datetime.now(UTC)`` independently, introducing a microsecond - drift. This hook restores the original guarantee. + drift. This hook restores the original guarantee — but only when + ``updated_at`` was not explicitly set (e.g. on deserialization). """ - self.updated_at = self.created_at + if "updated_at" not in self.model_fields_set: + self.updated_at = self.created_at @field_validator("content") @classmethod From 4a5dc4951cb2e7102c995edfebfe6f059d3f7462 Mon Sep 17 00:00:00 2001 From: Kresna Sucandra Date: Tue, 28 Jul 2026 05:48:31 +0000 Subject: [PATCH 4/4] fix: correct model_post_init docstring and fix TODO.md table row MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fix misleading parenthetical in model_post_init docstring: deserialization supplies updated_at explicitly, so the branch is skipped, not triggered. The example now correctly references fresh programmatic construction. - Add missing fourth cell to Total row in TODO.md summary table (MD056). Reviewer point on missing field defaults is already handled — all seven fields (id, version, tags, visibility, is_archived, dependencies, metadata) have Field(default_factory=...) or plain defaults. No change needed. Reviewer point on wasted datetime.now() is noted but negligible; the alternatives (Optional type, sentinel) add complexity for no real gain. --- TODO.md | 2 +- evoseal/models/code_archive.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/TODO.md b/TODO.md index 55ba35e9..9f8d6693 100644 --- a/TODO.md +++ b/TODO.md @@ -307,7 +307,7 @@ | 🟠 P1 | 24 | 14 | Original safety/integration items done; +12 high-priority bugs from 2026-07-22 review; signal-handler init fix; safety.yaml created | | 🟡 P2 | 30 | 16 | Co-evolution loop gaps (7 items, 7 done) + existing P2 + 13 medium bugs from 2026-07-22 review + 4 latent collect->train bugs found closing the loop (1 fixed, 1 new HF-format gap logged) | | 🟢 P3 | 24 | 13 | Makefile, pre-commit, Docker, ADRs, ADR refresh, CHANGELOG complete; +11 hygiene items from 2026-07-22 review | -| **Total** | **89** | **54** | +| **Total** | **89** | **54** | | > Update this table as you complete items. Recommended flow: P0 → P1 → P2 → P3. > diff --git a/evoseal/models/code_archive.py b/evoseal/models/code_archive.py index bf1e2eb6..46f1c6d2 100644 --- a/evoseal/models/code_archive.py +++ b/evoseal/models/code_archive.py @@ -131,7 +131,8 @@ def model_post_init(self, __context: Any) -> None: explicitly provided. With plain field defaults each factory calls ``datetime.now(UTC)`` independently, introducing a microsecond drift. This hook restores the original guarantee — but only when - ``updated_at`` was not explicitly set (e.g. on deserialization). + ``updated_at`` was not explicitly set (e.g. on fresh programmatic + construction, not deserialization, which supplies the value). """ if "updated_at" not in self.model_fields_set: self.updated_at = self.created_at