Then there’s the state Capitol, a community of several thousand politicians, staff members and lobbyists inside – but largely isolated from – a larger city.

The Capitol is infused with rituals, some engraved in rules and law, but many just traditions. One of them is that the end of any legislative session must be a marathon, running into the wee hours in which odd things happen.

Never miss a local story.

Sign up today for unlimited digital access to our website, apps, the digital newspaper and more.

New bills pop up, old ones thought dead are resurrected and some magically acquire amendments of uncertain origin.

How could one rationally explain to an ordinary Californian, for instance, why a bill dealing with the training of painters made its first appearance at 2 a.m. Saturday, just minutes before the Legislature was to finally adjourn?

One cannot rationally explain it, or why the session’s final night stretched that late when the legal deadline for passing bills was still 48 hours away, and when legislators just sat around, or engaged in flowery paeans to departing members, for many hours earlier in the day.

In part, the ritual is purposeful. Having hundreds of bills, close to half of the Legislature’s annual output, handled on one final day creates confusion and thus an opportunity for bills that might not survive the normal process to make it to the governor’s desk.

It’s also a pressure cooker. When it’s do-or-die time, interest groups that may have battled for months or even years to a stalemate become willing to deal.

The most famous – or infamous – end-of-session deal was cooked up in Frank Fat’s restaurant near the Capitol in 1987. Willie Brown, then the speaker of the Assembly, and lobbyists for medical providers, personal injury attorneys, the tobacco industry and business interests agreed on a wide-ranging tort law overhaul whose provisions were jotted onto a napkin.

The “napkin deal” was quickly passed the next day with only a brief pro forma “hearing.”

There’s also the fatigue factor. At some point, legislators are willing to vote for almost anything to escape from the Capitol and get some sleep.

However, it cannot be denied that for some strange reason, many of the Capitol’s denizens look forward to the hectic final night. They groove on the once-a-year ambiance, the sense of belonging, of being someone on the inside of things.

It’s an irrational, undemocratic and sometimes hurtful way to make policy for 38 million Californians.

But it’s a hoary ritual that is unlikely to end, because those in the Capitol like it.