fix(cron): accept bare cron-expression string in Schedule deserializer#2868
fix(cron): accept bare cron-expression string in Schedule deserializer#2868graycyrus wants to merge 2 commits into
Conversation
|
Warning Review limit reached
More reviews will be available in 5 minutes and 18 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughSchedule deserialization now uses a custom Serde Visitor: JSON strings are coerced into Schedule::Cron (tz and active_hours set to None), and map/object inputs are deserialized via the existing internally-tagged representation. Tests cover both input forms. ChangesCron Schedule deserialization
Sequence DiagramsequenceDiagram
participant Input as JSON Input
participant Visitor as ScheduleVisitor
participant Cron as Schedule::Cron
participant Tagged as TaggedEnum
Input->>Visitor: "0 9 * * 1" (bare string)
Visitor->>Cron: coerce to Cron { expr, tz=None, active_hours=None }
Input->>Visitor: {"kind":"cron","expr":"0 9 * * 1"} (tagged object)
Visitor->>Tagged: deserialize tagged enum
Tagged->>Visitor: map to Schedule::Cron variant
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
|
Actionable comments posted: 0 |
|
Actionable comments posted: 0 |
M3gA-Mind
left a comment
There was a problem hiding this comment.
Clean fix. The Deserialize visitor approach is idiomatic — deserialize_any dispatches to visit_str/visit_string for bare strings and visit_map (delegating via MapAccessDeserializer to an inner tagged-enum derivation) for the full object form. Serialization is unchanged so no wire-format regression.
Tests hit all four cases: bare 5-field string, 6-field ( */5), CronJobPatch with bare string (exact CORE-RUST-FY payload), and regression guard for the structured object form.
One minor observation: visit_string duplicates the body of visit_str rather than forwarding (self.visit_str(value.as_str())), but both are functionally correct and the duplication is minimal.
Approving — waiting on CI green to merge.
8c5a573
|
The branch has I've opened #2874 with the two cron-fix commits cleanly rebased on current |
8c5a573 to
1cb015e
Compare
Fixes Sentry issue CORE-RUST-FY (closes tinyhumansai#2866). The `openhuman.cron_update` RPC deserializes the `schedule` field as an internally-tagged `Schedule` enum. Agents and some frontend callers were sending a bare string like `"0 9 * * 1"` instead of the structured object `{"kind":"cron","expr":"0 9 * * 1"}`, causing serde to reject with: "invalid type: string, expected internally tagged enum Schedule" Fix: add a custom `Deserialize` impl for `Schedule` that routes a bare string to `Schedule::Cron { expr, tz: None, active_hours: None }`, while still delegating the full object form to the existing tagged-enum logic. Serialization is unchanged (always emits the object form). New tests: - `schedule_deserializes_bare_cron_string` - `schedule_deserializes_bare_5_field_cron_string` - `cron_job_patch_accepts_bare_schedule_string` (the exact failing shape) - `cron_job_patch_still_accepts_structured_schedule_object` (regression)
1cb015e to
9f27d7d
Compare
Summary
openhuman.cron_updatedeserializes theschedulefield as an internally-taggedScheduleenum. Agents and some frontend callers send a bare string like"0 9 * * 1"instead of the structured form{"kind":"cron","expr":"0 9 * * 1"}. Serde rejected this with:invalid type: string, expected internally tagged enum Schedule.Deserializeimpl forScheduleinsrc/openhuman/cron/types.rs. A bare string is coerced toSchedule::Cron { expr, tz: None, active_hours: None }; the full object form still works as before. Serialization is unchanged.CronJobPatchwith bare string (exact failing shape), and regression guard for the structured object form. All 20cron::typestests pass.Test plan
cargo test --lib openhuman::cron::types— all 20 passcargo check— clean (no new errors){"method":"openhuman.cron_update","params":{"job_id":"<id>","patch":{"schedule":"0 9 * * 1"}}}— should succeed instead of returning deserialization errorSummary by CodeRabbit
New Features
Tests