Background

Lately, I've been frequently approached with questions that are both fascinating and deeply mysterious. By "mysterious," I mean situations where something clearly works under normal conditions, yet suddenly fails for unknown reasons.

These issues are often tied to numerous unpredictable factors (such as the environment). For example: Why can't I check a file into git?

Resolving most of these mysterious problems often requires me to perform extensive operations and environmental analysis directly on the user's machine to identify what is impacting the program. Alternatively, it may require dozens of back-and-forth messages to accurately pinpoint the root cause. Moreover, since these issues function normally under standard conditions, they are notoriously difficult to resolve using Google or Stack Overflow.

This led me to think: instead of spending significant time troubleshooting for others every time, I should develop a universal methodology that allows most people to resolve these issues independently.

The Squeeze Debugging Method was born from this insight.

Squeeze Debugging Method

The Squeeze Debugging Method refers to constraining the problem from two directions simultaneously, thereby narrowing the possible scope of the root cause to minimal condition changes.

The Squeeze Debugging Method is suitable for resolving:

Errors that function normally under regular or ideal conditions, but consistently fail to operate correctly in certain environments.

Execution Method

The execution method for the Squeeze Debugging technique is as follows:

First, you have identified an environment E1 where program P exhibits an abnormal behavior A.

At this point, you need to construct an ideal environment E2. An ideal environment is defined as one that satisfies all conditions required for program P to run without exhibiting the abnormal behavior.

After constructing environment E2, run P in E2.

If P exhibits the abnormal behavior A, this proves that P itself has a design flaw.

If P does not exhibit the abnormal behavior A, this proves that the differences between environment E1 and environment E2 caused A.

At this point, we need to investigate which specific differences between E1 and E2 led to A.

Compare the configuration and operation processes performed in environment E1 with those in environment E2. This yields a set of differences C = { D1, D2, D3 ... Dn }, where C is not an empty set.

Apply each difference D in C to E1, making E1 progressively closer to E2.

After applying each difference D, re-run P in E1.

If P now begins to exhibit the abnormal behavior A, this indicates that D may be the cause of A.

If P still does not exhibit the abnormal behavior A, this indicates that D is likely unrelated to A.

Roll back the difference D.

Apply each difference D in C to E2, making E2 progressively closer to E1.

After applying each difference D, re-run P in E2.

If P still exhibits the abnormal behavior A, this indicates that D is likely unrelated to A.

If P no longer exhibits the abnormal behavior A, this indicates that D may be the cause of A.

Roll back the difference D.

At this point, we have identified which potential factors may cause A to occur.

Human Language Representation

For a bug that has occurred, we can construct an ideal environment where this bug does not occur. Then, list the differences between the environment where the bug appears and the ideal environment.

Change these differences one by one to bring the ideal environment and the faulty environment closer together.

Observe which specific difference ultimately causes the failure.

Notes

The Squeeze Debugging Method can only identify "possible conditions," not "necessary," "sufficient," or "necessary and sufficient" ones.

This is because combinations of conditions may affect the outcome. Therefore, the Squeeze Debugging Method is only applicable in situations where you need to quickly pinpoint potential causes.

Example 1

I know that my computer cannot run Spotify properly. Why is that?

First, construct an ideal environment. Use the latest version of Windows 10 Pro, installed fresh on a brand-new computer released this year. Then complete all system updates to ensure international network connectivity is stable. Download and install Spotify from the official Spotify website, then launch Spotify.

In this scenario, Spotify will most likely work correctly. At this point, we begin comparing the differences between the faulty environment and the ideal environment:

  • The faulty environment uses a Chinese operating system, while the ideal environment uses an English operating system
  • The faulty environment is connected to the Chinese network, while the ideal environment uses the international network
  • The faulty environment does not have the latest system updates installed, while the ideal environment has system updates installed
  • The faulty environment uses Windows 10 N, while the ideal environment uses Windows 10 Pro
  • The faulty environment downloaded Spotify from a pirated third-party website, while the ideal environment downloaded Spotify from the official Spotify website
  • The faulty environment has over 300 additional software packages installed, with only 3% of C drive space remaining. The ideal environment has no other software installed, with 95% of C drive space remaining

Then we begin binary search debugging. Start by moving the faulty environment closer to the ideal environment.

  • Switch the faulty environment to the international network. Observation: It still does not run properly.
  • Switch the faulty environment to an English operating system. Observation: It still does not run properly.
  • Install the latest system updates on the faulty environment. Observation: It still does not run properly.
  • Download Spotify from the official Spotify website on the faulty environment. Observation: It still does not run properly.

At this point, continuing to move the faulty environment closer to the ideal environment becomes difficult. We switch to moving the ideal environment closer to the faulty environment:

  • Install the over 300 additional software packages from the faulty environment onto the ideal environment. Observation: The ideal environment still runs properly.
  • Downgrade the ideal environment from Windows 10 Pro to Windows 10 N. Observation: The ideal environment no longer runs properly. At this point, whether Windows is using the N version is a possible cause.

Then we go back to the faulty environment to verify this cause:

  • Switch the faulty environment to Windows 10 Pro. Observation: The issue is resolved.

In summary, we have determined: Whether Windows is the N version may affect the operation of Spotify.

Example 2

It is known that an airplane's cockpit has 10 switches and one start button. Each switch has two positions: ON and OFF.

Previously, we set all 10 switches to the ON position, and when we pressed the start button, the airplane's engine started successfully.

However, today, we attempted to start the airplane, but it failed to start. It is known that all 10 switches are currently in the OFF position. You need to quickly determine why the airplane cannot start.

Perform binary search debugging.

First, set all 10 switches to ON and verify that the airplane can indeed start.

Then, try turning off each switch one by one. If the airplane fails to start, this indicates that the switch in question may be necessary for the airplane to start.

If the above method encounters obstacles, is too costly, or is too slow, then:

Set all 10 switches to OFF. Verify that the airplane indeed cannot start.

Then, try turning on each switch one by one. If the airplane starts, this indicates that the switch in question may be necessary for the airplane to start.