{"record":{"id":"ee2d0a3d68ae32ff","repo":"nautechsystems/nautilus_trader","slug":"timer-name-next-event-time-would-be-in-the","errorCode":null,"errorMessage":"Timer '{name}' next event time {} would be in the past (current time is {ts_now})","messagePattern":"Timer '(.+?)' next event time (.+?) would be in the past \\(current time is (.+?)\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/common/src/clock.rs","lineNumber":862,"sourceCode":"\n    let name = Ustr::from(name);\n    let allow_past = allow_past.unwrap_or(true);\n    let fire_immediately = fire_immediately.unwrap_or(false);\n\n    let start_time_ns = start_time_ns\n        .filter(|start_time_ns| *start_time_ns != 0)\n        .unwrap_or(ts_now);\n\n    let next_event_time = if fire_immediately {\n        start_time_ns\n    } else {\n        start_time_ns.checked_add(interval_ns).ok_or_else(|| {\n            anyhow::anyhow!(\"Timer '{name}' first event time exceeds UnixNanos range\")\n        })?\n    };\n\n    if !allow_past && next_event_time < ts_now {\n        anyhow::bail!(\n            \"Timer '{name}' next event time {} would be in the past (current time is {ts_now})\",\n            next_event_time.to_rfc3339(),\n        );\n    }\n\n    if let Some(stop_time) = stop_time_ns {\n        if stop_time <= start_time_ns {\n            anyhow::bail!(\n                \"Timer '{name}' stop time {} must be after start time {}\",\n                stop_time.to_rfc3339(),\n                start_time_ns.to_rfc3339(),\n            );\n        }\n\n        if !allow_past && stop_time <= ts_now {\n            anyhow::bail!(\n                \"Timer '{name}' stop time {} is in the past (current time is {ts_now})\",\n                stop_time.to_rfc3339(),","sourceCodeStart":844,"sourceCodeEnd":880,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/common/src/clock.rs#L844-L880","documentation":"validate_and_prepare_timer checks that the computed first event time (start_time_ns + interval_ns) is not in the past. When it is and allow-past handling is disabled, the timer would never fire at the requested time, so set_timer_ns rejects the request instead of silently registering a dead timer.","triggerScenarios":"Calling set_timer_ns with start_time_ns (plus interval_ns) earlier than clock.timestamp_ns() while allow_past is false — typically on a LiveClock.","commonSituations":"Reusing a saved timer spec across sessions; backtest-generated start times replayed live; slow startup so the process reaches timer registration after the intended start time; clock skew between machines.","solutions":["Set start_time_ns to the current time (clock.timestamp_ns()) or a future instant before calling set_timer_ns.","Enable the allow-past option if immediate firing of missed intervals is acceptable in your setup.","Recompute the schedule relative to 'now' each time the strategy starts rather than persisting absolute start times.","Catch the error and fall back to registering the timer with a now-based start time."],"exampleFix":"// before\nclock.set_timer_ns(\"my_timer\", interval_ns, saved_start_time_ns);\n// after\nlet now = clock.timestamp_ns();\nlet start = if saved_start_time_ns <= now { now } else { saved_start_time_ns };\nclock.set_timer_ns(\"my_timer\", interval_ns, start);","handlingStrategy":"validation","validationCode":"fn ensure_valid_timer_start(clock: &dyn Clock, start_time_ns: u64, interval_ns: u64) -> anyhow::Result<u64> {\n    let next = start_time_ns.checked_add(interval_ns)\n        .ok_or_else(|| anyhow::anyhow!(\"timer first event overflows UnixNanos\"))?;\n    if next <= clock.timestamp_ns() {\n        anyhow::bail!(\"timer first event {next} would be in the past\");\n    }\n    Ok(start_time_ns)\n}","typeGuard":null,"tryCatchPattern":"match clock.set_timer_ns(name, interval_ns, start, stop, None, false, false) {\n    Ok(()) => {},\n    Err(e) if e.to_string().contains(\"would be in the past\") => {\n        log::warn!(\"restarting timer at now: {e}\");\n        clock.set_timer_ns(name, interval_ns, clock.timestamp_ns(), stop, None, false, false)?;\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Compute start times relative to current clock time at registration, not persisted absolutes","Check for u64 overflow when adding interval to start time","Use allow_past deliberately when immediate catch-up firing is acceptable","Verify all times are Unix nanoseconds, not seconds or milliseconds"],"tags":["timer","clock","validation","time"],"backgroundTag":"invalid-argument-value","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}