Commit 6265149
authored
Block recovery on invalid OAuth credentials (#16)
## Summary
- classify refresh-token `invalid_grant`, HTTP 401, and unusable token
files as explicit OAuth authorization conditions
- keep OAuth client/config failures fatal even when returned with HTTP
401
- serialize token refresh across encoder, helper, authorization, and
optional telemetry processes
- refresh and replay an exact buffered YouTube API request once after
HTTP 401
- preserve refresh-token rotation returned by the OAuth token endpoint
- pause API recovery without ambiguous backoff until the private token
file changes
- preserve an already-public FFmpeg stream under its local watchdog and
revalidate exact lifecycle state after reauthorization
- limit child-specific signal handling to visible test-pattern runs so
device authorization terminates normally
- document the blocked lifecycle, shared local lock, recovery command,
and automatic resume behavior
## Root Cause
The API helper correctly reported a rejected refresh token as a
permanent failure, but the supervisor accepted only retryable classes
and converted `fatal` to `ambiguous`. That produced an endless retry
cycle instead of an actionable authorization block. A cached access
token that remained locally unexpired could also be rejected by YouTube
with HTTP 401; that path bypassed refresh-token `invalid_grant`
handling. The API CLI additionally installed test-pattern signal
handlers for every subcommand, causing `authorize` to swallow
termination signals when no child existed.
## Safety
- no OAuth, stream, camera, host, or deployment values are included
- OAuth-blocked waits perform no YouTube API request or lifecycle-state
mutation
- HTTP 401 receives at most one token refresh and one exact replay; 403,
5xx, timeouts, and other failures are never replayed
- `invalid_client`, `invalid_scope`, and `unauthorized_client` remain
fatal and never trigger token refresh or token-file wait
- token refresh is single-flight through one mode-`0600`
local-filesystem advisory lock
- a rotated refresh token returned by Google is retained; an omitted or
empty replacement preserves the existing token
- a failed post-refresh replay waits on the post-refresh token
fingerprint and cannot busy-loop on its own token write
- existing mutation locks, exact-ID reconciliation, and write-ahead
create intent remain unchanged
- token fingerprints are bounded, local-only, and never logged or
persisted
- transient API and quota retry behavior is unchanged
## Rollback
Revert PR #16 after merge and redeploy the two prior runtime scripts. No
state migration or credential change is required.
## Validation
- `.venv/bin/ruff check bin tests`
- `.venv/bin/python -m py_compile bin/youtube-autoencoder
bin/youtube-autoencoder-api`
- `.venv/bin/pytest -q` -> 244 passed
- `git diff --check`
- real concurrent expired-token callers -> one refresh request, shared
result
- rotated refresh-token response -> replacement retained on disk
- HTTP 400/401 client/config failures -> fatal with no token refresh
- distinct-family adversarial plan review -> Antigravity APPROVE and
Claude APPROVE
## Public-Safety Checklist
- [x] No OAuth client files, refresh tokens, stream keys, camera
credentials, or generated runtime state were committed.
- [x] Documentation was updated for user-facing behavior changes.
- [x] Local tests or relevant manual validation were run.1 parent abf5d2d commit 6265149
9 files changed
Lines changed: 944 additions & 59 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
5 | 15 | | |
6 | 16 | | |
7 | 17 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
| 64 | + | |
64 | 65 | | |
65 | 66 | | |
66 | 67 | | |
| |||
131 | 132 | | |
132 | 133 | | |
133 | 134 | | |
134 | | - | |
| 135 | + | |
| 136 | + | |
135 | 137 | | |
136 | 138 | | |
137 | 139 | | |
| |||
143 | 145 | | |
144 | 146 | | |
145 | 147 | | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
146 | 152 | | |
147 | 153 | | |
148 | 154 | | |
| |||
399 | 405 | | |
400 | 406 | | |
401 | 407 | | |
| 408 | + | |
402 | 409 | | |
403 | 410 | | |
404 | 411 | | |
| |||
521 | 528 | | |
522 | 529 | | |
523 | 530 | | |
524 | | - | |
| 531 | + | |
525 | 532 | | |
526 | | - | |
527 | | - | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
528 | 537 | | |
529 | 538 | | |
530 | 539 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
33 | 34 | | |
34 | 35 | | |
35 | 36 | | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
36 | 42 | | |
37 | 43 | | |
38 | 44 | | |
| |||
83 | 89 | | |
84 | 90 | | |
85 | 91 | | |
| 92 | + | |
86 | 93 | | |
87 | 94 | | |
88 | 95 | | |
| |||
199 | 206 | | |
200 | 207 | | |
201 | 208 | | |
| 209 | + | |
| 210 | + | |
202 | 211 | | |
203 | 212 | | |
204 | 213 | | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
205 | 268 | | |
206 | 269 | | |
207 | 270 | | |
| |||
906 | 969 | | |
907 | 970 | | |
908 | 971 | | |
909 | | - | |
910 | | - | |
911 | | - | |
912 | | - | |
913 | | - | |
914 | | - | |
915 | | - | |
916 | | - | |
917 | | - | |
918 | | - | |
| 972 | + | |
| 973 | + | |
919 | 974 | | |
920 | | - | |
921 | | - | |
922 | | - | |
923 | | - | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
924 | 1008 | | |
925 | | - | |
926 | | - | |
927 | | - | |
928 | | - | |
929 | | - | |
930 | | - | |
931 | | - | |
932 | | - | |
933 | | - | |
934 | | - | |
| 1009 | + | |
935 | 1010 | | |
936 | 1011 | | |
937 | 1012 | | |
| |||
1082 | 1157 | | |
1083 | 1158 | | |
1084 | 1159 | | |
| 1160 | + | |
1085 | 1161 | | |
1086 | 1162 | | |
1087 | 1163 | | |
1088 | 1164 | | |
1089 | 1165 | | |
1090 | 1166 | | |
1091 | 1167 | | |
| 1168 | + | |
| 1169 | + | |
| 1170 | + | |
| 1171 | + | |
| 1172 | + | |
| 1173 | + | |
| 1174 | + | |
| 1175 | + | |
1092 | 1176 | | |
1093 | 1177 | | |
1094 | 1178 | | |
| |||
0 commit comments