Anton Morgunov| ischemist
HomeCVPublicationsProjectsWritingsLeadership
HomeCVPublicationsProjectsWritingsLeadership

© 2018-2026 Anton Morgunov

The ProtocolML ModelsGitHubLinkedIn
Back to all posts
Back to all posts

The 400-year software patch to a 10-day memory leak

January 11, 2026 · Anton Morgunov

If you were born in any of the former Soviet countries, you're probably familiar with the concept of "Old New Year""old new" - peak Russianism celebrated on Jan 13. There's also Christmas celebrated on Jan 7, which by analogy should be called "old Christmas", but no, it's the Christmas. If you ask for an explanation, you'd probably be told it has something to do with Gregorian and Julian calendars, and I never really bothered to figure out what it meant until this past Christmas.which we celebrated properly by buying a live tree, so I thought it was time to figure things out

Turns out it's a fascinating story about a fundamental bug in the leap year calculation in the Julian calendar, which was silent for 800 years, it took another 800 years for the issue ticket to be closed, 200-400 years to be deployed internationally (in the process, Sweden invented Feb 30th), and will have to be revisited in roughly 2700 years.and you thought you shipped slowly

So the story starts with the Roman Empire, in which apparently priests could arbitrarily add months to a year to extend the one-year terms of elected officials they likedyou can just do things, and the power was abused to an extent that end-of-summer harvest was happening in the spring. Julius Caesar went to Egypt, and learned about the formula "a year is 365 days, but every 4th add one more", which was a result of centuries worth of empirical observations of the rising of the star Sirius. So Caesar decides to adopt this rule, but to fix the debt of random addition of months, he had to make the year 46 BC last 445 days, terming it Ultimus annus confusionis (the last year of confusion).

The problem, however, is that in this system a year lasts 365.25 days, whereas the true astronomical year's duration is 365.24219 days. The difference is roughly 1 day every 128 yearsa creeping memory leak. Who could possibly notice this distinction?

Well, in year 325, during the First Council of Nicaea, it was decided that the date of Easter should be tied to some easily verifiable astronomical constant: the vernal equinox,the full formula is first Sunday after the first full moon after the equinox which in that year happened to be on Mar 21 in the Julian calendar. 400 years later, an English monk Bede whose job was to calculate the date of Easter notices that the actual equinox happens on Mar 18.opened a jira ticket 5 centuries later, Roger Bacon revisits the issue, calls Julian calendar "intolerable, horrible, and laughable", and proposes a bugfix: drop one day every 125 years.first PR opened.

It takes another 300 years (when the drift is already 10 days) before Aloysius Lilius writes a comprehensive proposal for the reform, proposing deleting Julian leap day on each of its ten occurences over 40 years.gradual rollout It takes 10 years before Pope Gregory XIII convenes a commission to finally resolve the drift, and invites Christopher Clavius, a leading mathematician of the time. Clavius reads the Lilius's proposal and convinces the Church that it's the best solution. The core suggestion is replacing the leap year calculation logic from:

def is_leap_year_julian(year: int) -> bool:
    return year % 4 == 0

to

def is_leap_year_gregorian(year:int) -> bool:
    """97 leap years per 400 years"""
    if year % 400 == 0:
        return True      # keep these
    if year % 100 == 0:
        return False     # remove these (3 per 400 years)
    return year % 4 == 0

Why? Well, the problem is simple, you overcount the leap years, roughly 3 extra per each 400 years. You need to get rid of 3 leap years every 400 years; the most elegant solution would be to remove memorable years that are equidistant. A 100th year mark is memorable enough, but by default it'd overcorrect, so we enforce every 400th year to be a leap year.

Pope Gregory issues a papal bull "Inter Gravissimas" (among the most serious) on February 24, 1582, and instructs that the day after Oct 4, 1582 will be October 15, 1582 (skip 10 days immediately, an implementation advocated by Clavius).

Here's where the fun starts. Protestants refused to accept this patch on principle, so Denmark & Norway accept it only in 1700 (118 years later) and Great Britain and colonies accept it in 1752 (170 years later, by which point they needed to skip 11 daysthere's a historical meme that there were 11 day riots because people demanded to give them 11 days back; unfortunately it doesn't seem to be historically correct, still funny though).

Sweden decided to implement an original gradual rollout proposal, transitioning over 40 years, skipping all 11 leap days from 1700-1740. In 1700 they successfully skipped the leap day; but in 1704 they forgot (distracted by Great Northern War?), and forgot again in 1708. As a result, they had a calendar 1 day ahead of Julian, 10 days behind Gregorian. In 1712, King Karl XII decides to git revert back to Julian, but because they were 1 day ahead of Julian, and 1712 was already a leap year, they added Feb 30. Yeah, Sweden is the only country in the history of the world to ever have a February 30th, it even has a name: tillökningsdagen (the add-on day). Eventually, they decided to skip 11 days in one go in 1753.

Russia, being Orthodox, never accepted the patch. Lenin, unburdened by what has been, decides to align Russia with "the rest of civilized people", so in 1918 Sovnarkom issues a Decree on the Introduction of the Western European Calendarnaming chosen to avoid any mentions of religion/pope, instituting a 13-day skip from Jan 31, 1918 to Feb 14, 1918. As an unfortunate but hilarious side effect, the holiest day in the Soviet lore, the day of the Great October revolution had to be now celebrated in November (Oct 25 Julian is Nov 7 Gregorian).

Within a few years, the patch has also been accepted by Turkey and Greece, concluding the 400-year deployment.the Russian Orthodox Church still doesn't recognize it and at this point probably never will

If you want another rabbit hole, here's a fun fact. The true tropical year in our current measurement is 365.24219 days. Lilius used Alfonsine tables to derive a value of 365.24255 days (quite close to the patched Gregorian 365.2425 definition), but those tables were derived using Ptolemaic theory. Had he used Prutenic tables, derived from the Copernican theory, he'd have to use the value of 365.24720 days, which is farther from the truth than the result of the ancient Ptolemaic theory. How come? During derivation of Prutenic tables, the tropical year was confused with sidereal year, so basically the Gregorian patch is based on the Geocentric theory even though Heliocentrism has already been proposed by that time.

You probably should stop reading at this point because another rabbit hole gets dark quickly.

I was curious why the Christmas tree is called New Year's tree in Russian. By 1929, Bolsheviks decide to institute a full scale crackdown on religion and effectively ban Christmas without ever doing so explicitly. Under the disguise of industrialization, they suggested replacing 7-day week with a continuous 5-day production week, with a random subset of workers having a rest day every 5 days. This solved two problems at once: there was no more Sunday to attend church, and you could easily designate Jan 7 a working day.

By 1935, there was an attempt to course-correct the lack of holidays during cold brutal winters, so a high-ranking communist Postyshev writes a letter to Pravda (the Truth), in which he effectively proposes to rebrand Christmas into a secular New Year. He argued that the ban on a "tree" was an incorrect "leftist deviation"a direct quote, you can't make this up by supporters of Trotsky. He framed the tree not as an inherently religious object, but as a source of joy that, in pre-revolutionary times, was enjoyed by the children of the bourgeoisie while the children of the proletariat could only watch in envy. So it'd be unwise to keep denying the children from this source of joy. Postyshev also was a staunch advocate of the Great Purge and 3 years later he'd confess to being a part of the Trotskyistcan't make this up right-wingyeah, don't worry about the apparent contradiction of political labels counter-revolutioni.e. accused of purging actually good / innocent people and was shot in 1939. Пылающей тропой мы идем к коммунизму.

So uh, happy Old New Year, I guess?

Featured Work

January 1, 2026

Vibe coding killed Cursor

Cursor is dying because cost-optimization forces models into tunnel vision. RAG agents fail because they only see what they search for. The superior workflow for 2026 is massive context windows (gemini 2.5 pro) and manual control. Stop letting agents hide code from the model.

opinionAI
December 14, 2025

RetroCast and SynthArena: building the infrastructure for the next breakthrough in chemistry

A breakdown of Procrustean Bed for AI-Driven Retrosynthesis: A Unified Framework for Reproducible Evaluation

a deep dive into how the metrics for ai chemical synthesis are broken, rewarding models for "solving" routes with impossible, hallucinatory chemistry. we present the data and the open-source tools to fix it.

researchMLretrosynthesisinfrastructureevals