Skip to content

fix: run one Mobile pass per settings change and read tailscale commands at their exit - #2185

Merged
yansfil merged 9 commits into
mainfrom
fix/flaky-phone-link
Nov 7, 2026
Merged

yansfil merged 9 commits into
mainfrom
fix/flaky-phone-link

Conversation

@yansfil

@yansfil yansfil commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Closes with-hide/hide-private#435
Closes with-hide/hide-private#480
Closes with-hide/hide-private#524
Related: with-hide/hide-private#158 (이 PR로 닫지 않습니다. 아래 Summary)

Summary

휴대폰 연결(hided mobile) 시험이 가끔 실패하던 원인은 제품 쪽 둘과 시험 쪽 하나였습니다.

  • Assert the alternate-screen wheel contract on the bytes the PTY receives #480 (tailnet 항목 두 번 셈, 제품): 설정에서 방식을 바꾸고 바로 켜면 Tailscale을 읽는 패스가 둘 돌아, 둘째가 바뀐 환경을 읽고 항목을 한 번 더 더했습니다. 설정 변경은 패스를 한 번 "빚진" 것으로만 적고 패스가 읽은 변경을 모두 갚으므로 둘째는 돌지 않습니다. Tailscale 호출도 줄어듭니다.
  • Remove scripts, tests and documentation that CI no longer needs #435 (승인 안 된 폰의 시작이 revoked 대신 timeout, 시험): "폰 없음" 프레임을 기다렸는데 짝짓기 전에 쌓인 낡은 프레임이 맞아, 해제가 적용되기 전에 시작이 들어갔습니다. 폰이 목록에 오른 프레임을 먼저 읽고, 그다음 해제의 빈 목록을 기다립니다.
  • Wait out an agent_pane_busy refusal, which Herdr prints on stderr #524 (app executable, 제품): macOS에서는 명령의 출력 pipe를 만드는 순간(만든 뒤 따로 close-on-exec를 켭니다) 다른 스레드가 띄운 자식이 그 pipe를 쥘 수 있고, hided는 pipe가 닫히길 기다렸기 때문에 몇 ms에 끝난 tailscale 명령이 15초 기한까지 갔습니다. 운영에서도 pane 시작과 겹치면 상태 읽기가 실패하고, 두 번 연속이면 노출이 내려갑니다. 이제 명령이 끝난 시점에 답을 읽습니다 (플랫폼 계층에 이미 있는 OwnedChild::capture_until, 같은 15초 기한, 출력 1 MiB 상한). 상한을 넘는 status --json이 없도록 status는 피어를 뺀 읽기(--peers=false)로 묻습니다. 전체 답은 피어당 약 1.2 KB라 약 900대 tailnet에서 상한을 넘어 Mobile이 막히는데, hided는 피어 필드를 읽지 않습니다. 앞선 시험 전용 600초 기한(status_within)은 없앴습니다.
  • Web shell: weekly usage, ⌘K search and browser displays #158 (ping, 로컬 한 번): 닫지 않습니다. 실패는 셸 소켓에 15초 동안 프레임이 하나도 없었다는 뜻이고 낡은 프레임으로는 설명되지 않습니다. 패스가 tailscale 명령의 15초 기한에 묶인 것과 맞아 #524와 같은 원인일 가능성이 크지만, 그 실행에서 명령이 15초에 걸렸는지 기록이 없어 원인은 확정하지 못했습니다.

Review

  • 판단해 주세요: #158을 이 PR에서 닫지 않고 두는 것이 맞는지 (이슈의 만료일 2026-10-29이 이미 지났습니다. 같은 원인이라는 증거가 없어 닫는다고 쓰지 않았습니다).
  • 조심해서 볼 파일: hided/src/mobile/tailscale.rs - status가 --peers=false로 묻고, 명령 실행이 wait_with_output(pipe 끝까지 대기)에서 blocking 작업 위의 capture_until로 바뀌었습니다. future가 먼저 버려져도 blocking 작업이 15초 기한 안에 자식 트리를 끝냅니다 (이전의 kill_on_drop 자리).
  • 조심해서 볼 파일: hided/src/mobile/mod.rs - 패스 합치기(PassOwed): take가 설정을 읽는 같은 Inner 잠금 안이라 놓치는 변경이 없고, 시계와 Settings 열기는 강제 패스라 그대로입니다.
  • 조심해서 볼 파일: hided/tests/it/mobile.rs, support/fake_tailscale.rs - paired_phone이 폰이 목록에 오른 프레임까지 읽고, 대역에 status를 붙잡는 문(hold-status)과 출력을 쥔 프로세스를 남기는 문(hold-pipes)이 생겼습니다.
  • 비용 검토: 상시 작업 추가 없음. 명령마다 blocking 작업 하나(15초, 1 MiB 상한)이고 패스 수는 줄었습니다 (docs/PERFORMANCE_TESTING.md 표 갱신).

Evidence

  • 확인한 것 (Assert the alternate-screen wheel contract on the bytes the PTY receives #480, Remove scripts, tests and documentation that CI no longer needs #435): 원인은 CI 실패 로그의 순서 분석으로 확정했습니다. #480은 switched false 뒤에 serve.failed add, 그 뒤 serve.removed가 오고 serve.funnel_on은 한 번뿐이라 패스 둘이 켜진 상태로 돈 것; #435는 start.answered revoked-1 timeout과 그 폰의 terminal.input_discarded가 phone.revoked 로그보다 앞선 것. 20회 반복(아래)은 고치기 전 기준 비율이 없어 이 분석을 보강할 뿐 단독 증거가 아닙니다.
  • 확인한 것 (Wait out an agent_pane_busy refusal, which Herdr prints on stderr #524 원인, 고치기 전 코드, 이 Mac mini macOS): 같은 프로세스의 스레드 6개가 sleep 20을 900개 띄우는 동안 tailscale status 대역을 동시에 4~8개씩 반복 호출했습니다. 첫 실험 4349회 중 3초 timeout 1회; 자식의 종료와 pipe 끝을 따로 잰 실험에서 exit_after=9ms인데 3초 안에 끝이 오지 않은 경우가 잡혔고(시작이 느린 경우는 0), 제품 호출도 같은 실행에서 1회 timeout. 한 번의 우연이 아니라 두 실행에서 같은 모양입니다.
  • 확인한 것 (Wait out an agent_pane_busy refusal, which Herdr prints on stderr #524 고침, 같은 조건): 고친 코드로 3번 반복해 제품 호출 6335회 모두 성공, 3초 넘은 것 0. 그중 한 실행은 같은 때 옛 방식 대조군에서 exit_after=15ms인데 끝이 안 오는 경우가 잡혔는데도 제품 호출은 0건이었습니다.
  • 확인한 것 (출력 상한과 실제 크기): 상한이 필요한 이유는 끝없이 쓰는 자식이 hided를 키우면 안 되기 때문이고(원칙 15) capture_until이 받는 최대가 1 MiB입니다. 이 Mac(Tailscale 1.96.5, 피어 27개)에서 status --json은 34,332바이트(피어당 약 1.16 KB), --peers=false는 2,967바이트(피어 0, 사용자 0), serve status --json은 295바이트입니다. hided가 읽는 BackendState, Self, CurrentTailnet, CertDomains는 피어 없는 답에도 그대로 있고, 이 크기는 tailnet 크기와 무관합니다. 피어를 넣은 전체 답은 약 900대에서 1 MiB를 넘습니다. 시험 a_tailnet_too_big_to_list_its_peers_still_answers_status는 전체 답이 1 MiB를 넘는 tailnet(1,500대)에서 플래그를 빼면 child output exceeds 1048576 bytes로 실패합니다.
  • 확인한 것 (시험이 고침을 지킴): 새 시험 둘을 고침만 되돌리고 돌리면 실패합니다. a_process_left_holding_the_command_s_output_does_not_hold_its_answer는 이슈 본문과 같은 timed out after 15s로, two_changes_that_meet_a_running_pass_cost_one_pass_more는 패스 합치기를 되돌리면 tailscale status가 7번 돌아(고친 코드는 6번 모두 4번) 상한 4를 넘어 실패합니다. 출력 밖에 있는 보유자는 hide-platform의 기존 세 시스템 계약 시험 a_pipe_holder_outside_the_tree_does_not_hold_the_answer가 맡습니다.
  • 확인한 것 (이 Mac mini): hided 단위 617개와 통합 136개 통과(36개는 원래 ignore), clippy -D warnings와 fmt 깨끗. 이 Mac mini에서 verify-cargo.sh test가 workspace 전체를 돌 때 hide-agent-hooks의 메모리 시험 둘(훅 기한 1250ms 초과)이 부하 속에서 실패했고 이 PR이 건드리지 않은 크레이트입니다.
  • 확인한 것 (CI 20회): 고친 코드(d4f23c551) 위에 네 시험(Remove scripts, tests and documentation that CI no longer needs #435 Assert the alternate-screen wheel contract on the bytes the PTY receives #480 Wait out an agent_pane_busy refusal, which Herdr prints on stderr #524 #158의 것)을 각각 20번 등록한 프로브 커밋(6b1960ad7, 다음 커밋에서 되돌림)을 PR의 rust 레인(ubuntu, nextest ci 프로필, 재시도 1회)에서 돌려 전체 4808개가 통과했고 프로브 80개가 모두 첫 시도에 통과했습니다 (재시도와 FLAKY 줄 없음, run 42377510005). 고치기 전 비율을 재지 않아 고침 전후를 가르는 증거는 아니고, 이 코드에서 20회 연속 통과했다는 확인입니다.
  • 확인하지 못한 것: 위 20회 반복은 PR의 rust 레인(ubuntu)이라 macOS의 pipe 상속은 재현하지 못합니다. #524의 근거는 위 mini 실험과 시험입니다. 고치기 전 코드로 같은 반복을 돌려 재현율을 재지는 않았습니다. #158의 실패 실행에서 tailscale 명령이 실제로 15초에 걸렸는지는 기록이 없어 확인하지 못했습니다. 이 PR의 macOS 전용 시험 레인은 PR CI에 없고 야간 레인에 있습니다. --peers=false는 이 Mac의 1.96.5 도움말에서 확인했고 더 오래된 Tailscale CLI에서의 지원은 확인하지 못했습니다.

…own frames in the hided mobile tests

A mobile_method followed at once by mobile_enable spawned two passes, and the
second read Tailscale after a test had changed the fake under the first, so the
funnel test counted two serve adds (with-hide/hide-private#480). A settings
change now owes one pass and a pass settles every change it read.

The unadmitted-phone test waited for a no-phones frame that a frame published
before the pairing also matched, so the start ran before the revoke and
answered timeout (#435). The phone is listed first, then revoked.

The app-executable test no longer reads through the 15 s command deadline of
a loaded machine (#524); #158 shared the stale-frame wait.
On macOS the standard library makes a pipe and marks it close-on-exec in two
calls. A child another thread starts between them keeps the write end for as
long as it lives, so hided's `wait_with_output` waited for a pipe that stayed
open and ran a `tailscale` command that had exited in milliseconds to its 15 s
deadline. Measured on macOS with other threads starting long-lived children: a
command exited after 9 ms and its output did not close in 3 s.

Every tailscale command now runs as an owned child read by
`OwnedChild::capture_until` on a blocking task, which answers when the command
has exited and its tree has ended, under the same 15 s deadline and a 1 MiB
output bound. This removes the test-only `status_within` deadline.

Two tests hold the change: a command that leaves a process holding its output
answers at its exit, and two settings changes that meet a running pass cost one
pass more. Both fail with the fix reverted.
@yansfil yansfil changed the title fix: run one Mobile pass per settings change and stop the phone-link tests from reading stale frames fix: run one Mobile pass per settings change and read tailscale commands at their exit Nov 7, 2026
…its the output bound

The full `tailscale status --json` lists every peer at about 1.2 KB each: 34 KB
on a tailnet of 27, 3 KB without the peers. The 1 MiB bound that came with
reading a command at its exit is reached at some 900 peers, which would have
failed every status read and left Mobile blocked where the unbounded read
worked. hided reads none of the peers' fields, so it asks with `--peers=false`:
the answer no longer follows the size of the tailnet, and the bound stays for
a child that writes without end.

A test with a tailnet whose full answer is past the bound holds the flag, and
the pass-count test waits for a second forced pass so the tasks queued ahead of
it have run before it counts.
@yansfil
yansfil added this pull request to the merge queue Nov 7, 2026
Merged via the queue into main with commit 0058631 Nov 7, 2026
38 checks passed
@yansfil
yansfil deleted the fix/flaky-phone-link branch November 7, 2026 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant