跪拜 Guibai
← All articles
JavaScript · TypeScript · Frontend

The Loneliest Bug Fix: When No One Knows It Was Ever Broken

By 柯克七七 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

The most dangerous technical debt is the kind that never surfaces in dashboards or ticket queues. A module with a perfect track record can be a liability precisely because its failures are too rare and too self-healing to trigger an alert, leaving teams to mistake luck for engineering quality.

Summary

A core order module had passed every test and logged zero P0 incidents for three years, but its stability was an illusion. A `setTimeout` delay from 2019, a `__magic_flag` global variable, and a race condition that only triggered under a precise combination of network jitter and fast user clicks had been buried in the codebase for half a decade. Customer service had papered over the roughly 12 annual failures by telling users to refresh.

The fix replaced the timer with a Promise chain, swapped the global flag for a proper state machine, and added 47 unit tests simulating frantic user behavior. The code review treated it as a routine refactor. Weeks later, the QA team held the module up as a model of "innate stability" and asked to study its best practices.

The only record of the landmine ever existing is a single commit message and a private 3,000-word archaeology document. The invisible fix became the module's origin story, erasing its own necessity.

Takeaways
— A race condition survived five years because it only triggered under a rare combination of network jitter, fast user clicks, and a specific browser version.
— Customer service resolved the roughly 12 annual failures by telling users to refresh, so no bug report was ever filed and no incident was ever declared.
— The original `setTimeout` delay was a 2019 workaround for a slow API; after the API was fixed, the timer remained and later code grew dependent on it.
— A global `__magic_flag` variable meant to prevent duplicate fixes would skip the repair logic entirely if a user switched pages before the flag reset.
— Replacing the timer with a Promise chain and the global flag with a state machine eliminated the race condition without altering external behavior.
— 47 new unit tests covered network timeouts, rapid page switching, malformed API responses, and disconnection-reconnection cycles.
— The QA team later identified the module as an example of 'innate stability' and requested its test cases for a best-practices document, unaware any bugs had ever existed.
Conclusions

A bug's visibility and its danger are often inversely proportional: modules that constantly break get fixed, while silently unstable modules accumulate debt under a reputation for reliability.

Self-healing failures—where a refresh clears the symptom—are organizational blind spots because they remove the pain that would normally force a diagnosis.

The labor of removing invisible risk is structurally thankless; the better the fix, the less anyone believes there was ever a problem, and the work is recorded only as a refactor.

QA teams can inadvertently canonize luck as engineering excellence when their evaluation criteria rely on absence of reported issues rather than presence of deliberate resilience.

Concepts & terms
Race condition
A flaw where the behavior of a system depends on the sequence or timing of uncontrollable events, such as a slow API response arriving after a user has already navigated away.
State machine
A model that defines a finite set of states and explicit transitions between them, preventing a component from entering impossible or dirty states during rapid user interactions.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗