Root CauseWhat broke, why, and the fix.

transient vs permanent error handling sidelined a valid token and left uploads hanging

· debugging, OAuth, automation
ⓘ Operated by TechAthletes. Every post here is a bug we hit in our own work — symptom, root cause, fix. Nothing is sponsored and we are not paid to mention any tool.

Key points

  • Upload jobs hung for eight days while the Mac was offline, and no uploads completed. The OAuth token had not originally been broken. (Source: our own measurement, 2026-09-23)
  • A broad exception handler treated a network refresh failure as an unusable token and renamed the token file with a .revoked suffix. (Source: our own measurement, 2026-09-23)
  • Browser authorization then waited indefinitely in unattended jobs because the environment variable intended to prevent that behavior was never set. (Source: our own measurement, 2026-09-23)
  • Tests confirmed that transport failures preserved the token, invalid_grant triggered token retirement, and noninteractive authorization exited without hanging. (Source: our own measurement, 2026-09-23)

Uploads stopped, but the jobs did not finish

During the recorded incident, scheduled YouTube upload jobs hung for eight days while their Mac was offline. No uploads completed. Troubleshooting went as far as OAuth reauthorization, although the token had not originally been broken.

The failure was therefore more specific than an upload request that could not reach its destination. A network interruption changed how the application treated its stored credentials. That change sent unattended jobs into an authorization flow requiring browser consent, where they waited indefinitely.

Repeated scheduled runs added to the problem. Four jobs accumulated instead of completing with a failure status. The scheduler continued to start work, but the existing work did not reach an end.

The logs did not make that distinction visible. They contained start lines without corresponding completion lines. The incident record identifies that lack of completion evidence as the reason the hang went unnoticed for eight days: the available logging did not distinguish a hung run from work that had not executed.

There were two connected defects to repair. One incorrectly classified a refresh failure and altered the token file. The other allowed the resulting recovery path to wait for interaction in a process without a terminal. Fixing either boundary mattered, but the recorded correction addressed both.

A refresh exception became a verdict against the token

The credential-loading function called creds.refresh(). Its exception handling grouped failures under except Exception, described the stored token as unusable, and renamed the token file with a .revoked suffix.

The recorded error description was:

stored token unusable

That description was stronger than the evidence available during the outage. The refresh operation had raised TransportError: the application could not reach Google. It had not established that the refresh token was invalid.

A transient error in this incident is a network transport failure that prevents credential refresh without establishing that the stored refresh token is invalid.

The distinction mattered because the exception handler did more than report a failed operation. It changed persistent credential state. A valid refresh token was removed from its normal location because the network was unavailable.

The renamed token file supplied a useful piece of evidence. Its modification time was September 14 at 15:02, which the incident record identifies as the start of the offline period. That tied the token-file transition to the loss of connectivity. The token was not originally broken; the application’s response to the refresh exception made it unavailable to the normal loading path.

The corrected classification reserved retirement of the stored token for RefreshError containing invalid_grant. RFC 6749, Section 5.2 defines invalid_grant as meaning the provided grant or refresh token "is invalid, expired, revoked... or was issued to another client" — a specific statement about the credential itself, not about whether the network request reached the server. A transport failure did not meet that condition. Neither did an unknown exception.

This was the central mistake behind the incident: an inability to complete a check became a definitive judgment about the object being checked. Once that judgment reached the token-retirement branch, the application initiated recovery from a credential problem that the transport failure had not demonstrated.

(Source: our own measurement, 2026-09-23)

The recovery path required a person who was not there

After moving the token aside, the application fell through to InstalledAppFlow.run_local_server(). That introduced a second dependency: browser consent.

The scheduled processes ran through cron or launchd with piped standard input and no terminal. In that context, the consent flow waited indefinitely. What began as an unreachable network endpoint became a job waiting for interactive authorization.

A guard against browser authorization already existed. It depended on an environment variable, YT_NO_BROWSER_AUTH. The investigation found no place setting that variable. The code expressed the intended protection, but the actual execution environment never enabled it.

That difference explains why the existence of a guard was insufficient evidence that unattended runs were protected. Its behavior depended on configuration absent from every setting location found in the investigation.

The replacement used terminal availability directly:

sys.stdin.isatty() and sys.stdout.isatty()

Under the corrected behavior, browser consent required both standard input and standard output to be attached to terminals. The environment variable remained supplementary rather than carrying the entire protection.

A noninteractive process needing authorization now exited immediately with NEEDS_REAUTH. The interactive authorization script could still take the browser-consent path naturally.

This change made the recovery decision reflect the process that was actually running. An unattended upload job could report that authorization was needed without pretending it could complete a conversation with a person. An interactive invocation retained access to that conversation.

The original failure chain therefore had two separate assumptions: a refresh exception meant unusable credentials, and a process reaching authorization could wait for browser consent. Neither assumption held for the recorded offline, scheduled execution.

The fix preserved credentials and made runs finish visibly

The revised exception handling left the token completely untouched for TransportError and unknown exceptions. Those paths exited with a nonzero status and NETWORK_DOWN. Moving the token to .revoked was restricted to RefreshError with invalid_grant.

The treatment of unknown exceptions is a meaningful boundary in this implementation. They shared the nondestructive exit path; they did not receive permission to retire the token merely because refresh had failed.

Verification used temporary copies and did not touch the real token. Three tests exercised the branches responsible for the incident:

  • Injecting TransportError left every byte of the token unchanged and produced a nonzero exit.
  • Injecting invalid_grant moved the token to .revoked.
  • Running with stdin=/dev/null produced an immediate NEEDS_REAUTH instead of a hang.

All three passed. These checks verified both the classification decision and its consequence: whether the file changed, whether the process failed, and whether an unattended invocation returned.

The operational changes addressed overlapping runs and missing completion evidence. Each upload job received a mkdir lock to prevent concurrent execution, with stale-lock release after two hours. A runtime limit used this recorded command:

perl -e 'alarm shift; exec @ARGV' 1800

The jobs also gained an END line carrying the exit code.

Those changes covered different parts of the observed failure. The lock addressed repeated starts while an earlier run remained active. The runtime limit bounded execution. The completion line supplied the evidence missing from the previous start-only logs.

The corrected credential handling prevented the network failure from sidelining a valid token. The terminal check prevented unattended browser consent. The operational controls made execution state more explicit when investigating a run.

(Source: our own measurement, 2026-09-23)

The lesson: test what uncertainty is allowed to change

The useful lesson from this incident is a concrete question: when a check cannot finish, what does the application change?

Here, a failed refresh attempt changed the token file. That was the wrong consequence for a transport failure. The corrected behavior preserved the credentials and returned a failure status, leaving token retirement to the specific authorization error identified in the record.

A developer reviewing a similar flow can follow the same boundaries. Find the refresh call, inspect the exception branches, and trace every branch that renames or otherwise retires stored credentials. Then test a transport exception against a temporary token copy and compare the file before and after execution.

The next boundary is recovery. Inspect whether a scheduled process can enter browser authorization, and whether the protection depends on an environment variable that is actually set. The recorded noninteractive test used stdin=/dev/null; its expected result after the fix was an immediate authorization-needed exit.

Finally, inspect a completed run’s log. A start line records entry into the job. In this incident, the added END line and exit code provided the completion evidence that had been missing.

The same source record describes a related measurement mistake: reporting unavailable click data as zero. Its distinction between a measured value, a measured zero, and an unavailable measurement follows the same reasoning. Missing evidence needs its own representation before it reaches a consequential decision.

For the upload jobs, that decision was whether to retire credentials and request authorization. The repair made the distinction executable: transport failure preserved the token, the specified grant error retired it, and a process without a terminal returned instead of waiting for consent.

Root Cause is written while shipping small software products — you can see them at TechAthletes.

All posts →

Get new posts by email

We email you only when a new post goes up here. You can unsubscribe at any time.

Privacy policy