Skip to content

fix(server): fix SQLite enum serialization causing failing test_schedule_lifecycle - #1

Merged
shivros merged 1 commit into
mainfrom
runner/fix-storage-enum-serialization
Jul 24, 2026
Merged

fix(server): fix SQLite enum serialization causing failing test_schedule_lifecycle#1
shivros merged 1 commit into
mainfrom
runner/fix-storage-enum-serialization

Conversation

@shivros

@shivros shivros commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes a failing test on main: test_schedule_lifecycle expected 1 pending schedule but got 0.

Root cause: SqliteStorage used serde_json::to_string() to serialize enum values into SQLite string columns. serde_json wraps enum variants in quotes (e.g. "pending" becomes "\\"pending\\"" in the DB), but SQL queries use bare string comparisons (WHERE status = 'pending'). Writes succeeded but filtered reads returned nothing.

Changes

  1. enum_to_str() / str_to_enum() helpers — strip/re-add JSON quotes for SQLite string columns. Applied to unit-variant enum columns: format, workflow_state, schedule status.

  2. Platform::to_db_key() / from_db_key() — Platform has a data-carrying Other(String) variant that breaks the generic helpers (serde_json serializes it as {"other":"x"}). Platform gets dedicated DB methods with an "other:<name>" format that round-trips correctly for all variants.

  3. cargo fmt — applied to fix pre-existing formatting violations in main.rs and api.rs that would fail CI's cargo fmt --check.

Verification

cargo test          → 8 passed, 0 failed (3 domain + 5 storage)
cargo clippy -D warnings → clean
cargo fmt --check   → clean

New tests added:

  • test_enum_round_trip — verifies unit-variant enum serialization
  • test_platform_db_key_round_trip — verifies all Platform variants round-trip, including Other("mastodon") and Other("custom:with:colons")

Review Panel

Both reviewers (GPT-5.5, Gemini 3 Flash) initially caught a critical bug: Platform::Other(String) was corrupted by the generic enum_to_str helper. Fixed by adding dedicated Platform::to_db_key/from_db_key methods.

🤖 Generated by Project Runner

…cycle failure

serde_json::to_string() wraps enum variants in quotes (e.g. '"pending"'),
but SQL queries use bare string comparisons (WHERE status = 'pending').
This mismatch caused save_schedule to succeed but list_pending_schedules
to return 0 rows.

Added enum_to_str/str_to_enum helpers that strip/re-add quotes for
SQLite string columns. Applied to unit-variant enum columns: format,
workflow_state, schedule status.

Platform has a data-carrying Other(String) variant that breaks the
generic helpers (serde_json serializes it as {"other":"x"}), so
Platform gets dedicated to_db_key/from_db_key methods that handle
all variants correctly including Other.

Also applied cargo fmt to fix pre-existing formatting violations in
main.rs and api.rs that would fail CI.

Co-authored-by: Archon <archon@purelymail.com>
@shivros

shivros commented Jul 24, 2026

Copy link
Copy Markdown
Contributor Author

🤖 Automated Review Panel

GPT-5.5 (openai/gpt-5.5)

Goal alignment: ✅ The fix correctly addresses the root cause — serde_json::to_string() wrapped enum variants in quotes but SQL queries used bare string comparisons. The enum_to_str/str_to_enum helpers resolve this for unit-variant enums.

Correctness bug found: 🔴 Platform::Other(String) is corrupted by enum_to_str because serde_json serializes Other("foo") as {"other":"foo"}, not "other". trim_matches('"') produces garbage.

Fix applied: Added dedicated Platform::to_db_key()/from_db_key() methods that handle all variants correctly, including Other with an "other:<name>" format. Added test_platform_db_key_round_trip test covering Other("mastodon") and edge cases.

Verdict after fix: ✅ Approve. All variants round-trip correctly.


Gemini 3 Flash (google/gemini-3-flash-preview)

Goal alignment: ✅ Primary fix is correct and the failing test now passes.

Critical issue found: 🔴 Same Platform::Other(String) corruption bug. The generic helpers break on data-carrying enum variants. Both reviewers independently caught this.

Fix applied: Platform now uses dedicated DB serialization methods. The generic enum_to_str/str_to_enum are only used for pure unit-variant enums (ScheduleStatus, ContentFormat, WorkflowState).

Additional note: The save_content workflow_state column still uses serde_json::to_string for tags — this is correct because tags is a Vec<String>, not an enum.

Verdict after fix: ✅ Approve. All 8 tests pass, CI gates green.


Both reviewers initially flagged the same critical bug (Platform::Other corruption). Fixed in commit c78f94c before PR was opened.

@shivros
shivros marked this pull request as ready for review July 24, 2026 05:42
@shivros

shivros commented Jul 24, 2026

Copy link
Copy Markdown
Contributor Author

Auto-Merge Gate — Approved

Confidence: 0.93

Rationale: This PR fixes a clear, well-understood bug: serde_json::to_string() wrapped enum variants in JSON quotes ("\"pending\"") but SQL queries used bare string comparisons (WHERE status = 'pending'). The fix introduces targeted enum_to_str/str_to_enum helpers for unit-variant enums and dedicated Platform::to_db_key/from_db_key methods for data-carrying variants.

Both reviewers (GPT-5.5, Gemini 3 Flash) independently caught a critical Platform::Other(String) corruption bug in the initial approach, which was fixed before PR creation. The fix adds two new round-trip tests covering all Platform variants including edge cases (Other("custom:with:colons")).

Checks observed: ✅ Formatting, ✅ Clippy, ✅ Tests (8 passed), ✅ Build, ✅ Secret Scanning — all green.
Scope: +109/-26, 4 files (platform.rs, storage.rs, api.rs, main.rs). Small, focused fix.
Goal: Fixes test_schedule_lifecycle failing on main. Verified by the new test suite.
No unresolved blocking comments. No "do not merge" markers in Linear or PR body.

Scope limits: This PR fixes the build only — COD-366 (content pipeline implementation) remains pending.

Auto-Merge Gate (squash)

@shivros
shivros merged commit 39e27f3 into main Jul 24, 2026
5 checks passed
@shivros
shivros deleted the runner/fix-storage-enum-serialization branch July 24, 2026 05:43
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