{"record":{"id":"e1b6ff42c43c3fa4","repo":"gitbutlerapp/gitbutler","slug":"system-time-is-set-before-the-unix-epoch","errorCode":null,"errorMessage":"system time is set before the Unix epoch","messagePattern":"system time is set before the Unix epoch","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/gitbutler-git/src/context.rs","lineNumber":332,"sourceCode":"        .serialize(serializer)\n}\n\nfn remote_tracking_branch_parts(\n    repo: &gix::Repository,\n    branch: &gix::refs::FullNameRef,\n) -> Result<(String, String)> {\n    let (remote, short_name) = extract_remote_name_and_short_name(branch, &repo.remote_names())\n        .ok_or_else(|| anyhow!(\"failed to determine remote and branch name for `{branch}`\"))?;\n    let short_name = std::str::from_utf8(short_name.as_ref())\n        .context(format!(\"branch name for `{branch}` is not valid UTF-8\"))?\n        .to_owned();\n    Ok((remote, short_name))\n}\n\nfn now_ms() -> u128 {\n    UNIX_EPOCH\n        .elapsed()\n        .expect(\"system time is set before the Unix epoch\")\n        .as_millis()\n}\n\nasync fn handle_git_prompt_push(\n    prompt: String,\n    askpass: Option<Option<StackId>>,\n) -> Option<String> {\n    if let Some(branch_id) = askpass {\n        tracing::info!(\"received prompt for branch push {branch_id:?}: {prompt:?}\");\n        askpass::get_broker()\n            .expect(\"askpass broker must be initialized\")\n            .submit_prompt(prompt, askpass::Context::Push { branch_id })\n            .await\n    } else {\n        tracing::warn!(\"received askpass push prompt but no broker was supplied; returning None\");\n        None\n    }\n}","sourceCodeStart":314,"sourceCodeEnd":350,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/gitbutler-git/src/context.rs#L314-L350","documentation":"now_ms() measures UNIX_EPOCH.elapsed() to get the current time in milliseconds and expects success. `Instant`-style elapsed from the epoch fails if the system clock is set before 1970-01-01, in which case the expect panics. It guards against a host clock misconfiguration.","triggerScenarios":"Calling now_ms (used by askpass/git prompt handling) while the system clock is set to a time before the Unix epoch (negative elapsed time from UNIX_EPOCH).","commonSituations":"VMs or embedded systems with dead CMOS batteries booting at 1970 or earlier; manually mis-set system clocks; containers with incorrect clock sources.","solutions":["Fix the system clock: run NTP/time sync (`timedatectl set-ntp true`, `ntpdate`, or correct date manually)","Make now_ms fallible or clamp: use SystemTime::now().duration_since(UNIX_EPOCH).unwrap_or_default()","Log a warning when elapsed() fails instead of panicking, returning 0"],"exampleFix":"// before\nfn now_ms() -> u128 {\n    UNIX_EPOCH\n        .elapsed()\n        .expect(\"system time is set before the Unix epoch\")\n        .as_millis()\n}\n// after\nfn now_ms() -> u128 {\n    SystemTime::now()\n        .duration_since(UNIX_EPOCH)\n        .unwrap_or_default()\n        .as_millis()\n}","handlingStrategy":"fallback","validationCode":"// Rust: check clock sanity before epoch math\nfn clock_is_sane() -> bool {\n    std::time::SystemTime::now()\n        .duration_since(std::time::UNIX_EPOCH)\n        .is_ok()\n}","typeGuard":"fn system_time_ms() -> Option<u128> {\n    std::time::SystemTime::now()\n        .duration_since(std::time::UNIX_EPOCH)\n        .ok()\n        .map(|d| d.as_millis())\n}","tryCatchPattern":"match UNIX_EPOCH.elapsed() {\n    Ok(d) => d.as_millis(),\n    Err(_) => { tracing::warn!(\"system clock before Unix epoch\"); 0 }\n}","preventionTips":["Enable NTP time synchronization on hosts and VMs","Check system clock settings when timestamps look wrong or app panics at startup","Never assume the wall clock is post-1970; clamp or default elapsed time"],"tags":["rust","time","system-clock","panic","environment"],"backgroundTag":"invalid-date-format","analyzedSha":"58e5313667b857ef39a730e380af31816a7b1768","analyzedAt":"2026-09-18T06:50:32.052Z","contentChangedAt":"2026-09-18T06:50:32.052Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}