Skip to content

feat(termux-worker): idle-gated restart-worker / restart-supervisor (#2791 stage 2b) - #2929

Merged
seoseo-ai merged 2 commits into
mainfrom
feat/2791-native-worker-restart
Nov 27, 2026
Merged

seoseo-ai merged 2 commits into
mainfrom
feat/2791-native-worker-restart

Conversation

@seoseo-ai

Copy link
Copy Markdown
Collaborator

요약

#2791 2단계(2b)입니다. Termux 네이티브 워커에 유휴 게이트를 거친 재기동 도구를 추가합니다. 오너 결정(2026-11-27, 세 항목 모두 1번)을 따릅니다.

  • worker.js 재기동은 배포 쪽 책임입니다. self-update는 경고만 하고 워커를 재기동하지 않습니다.
  • supervise 자동 재기동은 기본 off이며, 노드별로 opt-in합니다.

PR1 #2928(ctime 탐지)과는 다른 파일을 고칩니다. 이 PR은 origin/main 기준입니다. 3단계 배포 스크립트 PR은 이 브랜치 위에 쌓습니다.

변경

scripts/a2a-termux-native-worker.sh

  • restart-worker --if-idle [--env-file P] [--dry-run]
    • supervisor의 dist/worker.js 자식에만 SIGTERM을 보냅니다. supervise 루프가 8초 뒤 설치본으로 다시 띄우고, 터널은 유지됩니다.
  • restart-supervisor --if-idle [--env-file P] [--dry-run]
    • 같은 게이트를 통과하면 stop한 뒤 health --self-heal 경로로 다시 띄웁니다. cron과 같은 경로입니다.
    • 터널이 잠깐 끊깁니다.
  • 유휴 판정은 #2138의 BUSY_MAX 의미를 cgroup 대신 워커 pid의 프로세스 트리에 적용합니다.
    • 워커 자손 중 A2A_NATIVE_WORKER_BUSY_MAX_SECONDS(기본값은 CCC_SELF_UPDATE_BUSY_MAX_SECONDS, 없으면 1800)보다 젊은 프로세스가 있으면 busy입니다.
    • 그보다 오래된 자손은 hung으로 보고 막지 않습니다. hung=N으로 보고만 하고 kill하지 않습니다.
    • 나이는 CLOCK_BOOTTIME으로 잽니다. 트리를 읽지 못하면 fail-closed(rc 11)입니다.
  • busy이면 rc 10으로 끝나고 아무 신호도 보내지 않습니다. 이유는 stderr와 supervisor 로그에 남깁니다. --if-idle 없이 부르면 rc 2이며, 무조건 재기동하는 모드는 없습니다.
  • 재기동 후 검증: 아래가 모두 맞아야 result=ok입니다. 하나라도 어긋나면 rc 30입니다.
    • 같은 supervisor(supervisor 모드에서는 새 supervisor) 아래에 새 worker 자식이 있음
    • supervisor 또는 health 로그에 새 registered with 줄이 있음
    • settle(기본 20초) 동안 생존함
    • health --json 결과가 sup_count=1 workers=1 tunnel=UP rc=0
  • rc: 0 ok / 2 사용법·env / 3 supervisor 없음 또는 worker가 1개가 아님 / 10 busy / 11 판정 불가 / 30 미검증
  • --env-file을 생략하면 실행 중인 supervisor의 argv에서 가져옵니다.

scripts/ccc-self-update.sh (step 5c)

  • 기본 동작은 그대로입니다. native-worker-stale … action=none으로 경고만 남깁니다.
  • CCC_SELF_UPDATE_NATIVE_SUPERVISOR_RESTART=1(opt-in)인 노드에서만 동작합니다.
    • 대상: 자기 체크아웃 스크립트를 실행하는 stale supervise 루프. 줄은 action=restart-supervisor로 남고 restart-supervisor --if-idle을 호출합니다.
    • 결과는 native-supervisor-restart result=<ok|deferred-busy|deferred-unknown|failed> rc=…로 로그에만 남깁니다.
    • busy이면 다음 tick으로 미룹니다. tick은 실패시키지 않습니다. 상한은 …_RESTART_TIMEOUT(300초)입니다.
  • stale worker.js는 opt-in이어도 action=none입니다(배포 쪽 책임).
  • 다른 경로의 supervise도 action=none입니다.

docs: docs/a2a-claude-worker.md, docs/self-update.md. changelog: changelog.d/2791-native-worker-idle-restart.md

검증 (로컬, jingun)

  • scripts/a2a-termux-native-worker-restart.test.sh (신규): PASS=28 FAIL=0
    • mock /proc 트리에서 유휴 게이트를 확인했습니다: 자식 없음 → idle, 젊은 자식 → busy, BUSY_MAX 초과 자식 → hung, 그 아래 젊은 손자 → busy, 무관한 프로세스는 무시, stat을 못 읽으면 → 11.
    • 실제 supervisor와 가짜 worker로 확인한 것:
      • dry-run
      • busy일 때 두 명령 모두 rc 10이고 프로세스는 그대로임
      • 트리를 못 읽으면 rc 11
      • hung 자식이 있어도 restart-worker가 되고 검증까지 통과함(supervisor는 같고 worker만 바뀜)
      • 등록이 없으면 rc 30
      • restart-supervisor 재기동 후 검증 통과
  • 변이 테스트(red 확인)
    • busy 판정을 끄면 10개가 FAIL합니다.
    • self-update의 opt-in 매칭을 끄면 3개가 FAIL합니다.
  • scripts/ccc-self-update.test.sh: PASS=499 FAIL=0 (+6)
  • 기존 테스트: a2a-termux-native-worker-health.test.sh 53/0, a2a-termux-native-worker.test.sh 57/0
  • 정적 점검
    • shellcheck -S warning(변경 파일 4개) clean
    • CCC_HARNESS_PHASE=static validate-harness.sh PASS
    • canon-node-name-scan.sh --repo-wide ok(baseline 일치)
    • changelog_fragments.py check ok

범위 밖 / 게이트

  • 노드에서 실행하는 것은 이 PR에 없습니다. 아래는 머지 뒤 노드별로 따로 승인받습니다.
    • 노드에서 스위치 켜기
    • 라이브 worker·supervisor 재기동

Refs #2791

🤖 Generated with Claude Code

…2791 stage 2b)

Adds `restart-worker --if-idle` and `restart-supervisor --if-idle` to
scripts/a2a-termux-native-worker.sh. restart-worker SIGTERMs only the
supervisor's dist/worker.js child so the supervise loop relaunches it with
the tunnel kept up; restart-supervisor stops the supervisor and respawns it
through the health check's --self-heal path.

The idle gate keeps #2138's BUSY_MAX meaning on the worker's process tree
(a descendant younger than A2A_NATIVE_WORKER_BUSY_MAX_SECONDS is a running
handler; older ones are hung and do not block) and fails closed when the
tree is unreadable. Busy exits 10 and signals nothing; there is no
unconditional mode. A restart is ok only after a new worker child, a fresh
"registered with" line, a settle window, and health sup_count=1 workers=1
tunnel=UP (else rc 30).

Self-update keeps warning about a stale worker.js (its restart belongs to
the deploy side). A stale supervise loop of its own checkout is restarted
only with CCC_SELF_UPDATE_NATIVE_SUPERVISOR_RESTART=1 (default 0); busy
defers to the next tick.

Refs #2791

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@seoseo-ai
seoseo-ai requested a review from jinon86 as a code owner November 27, 2026 06:25
…ngs (#2791)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@jinon86 jinon86 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved after exact-head validation and fresh operator authorization using the relay-held jinon86 credential.

@seoseo-ai
seoseo-ai added this pull request to the merge queue Nov 27, 2026
Merged via the queue into main with commit a470f85 Nov 27, 2026
17 checks passed
@seoseo-ai
seoseo-ai deleted the feat/2791-native-worker-restart branch November 27, 2026 06:53
@seoseo-ai
seoseo-ai restored the feat/2791-native-worker-restart branch November 27, 2026 06:53
@seoseo-ai
seoseo-ai deleted the feat/2791-native-worker-restart branch November 27, 2026 06:53
seoseo-ai pushed a commit that referenced this pull request Nov 27, 2026
scripts/a2a-termux-native-worker-deploy.sh replaces the per-rollout ad-hoc
Termux worker rollout scripts (owner decision 2026-11-27: the deploy side
owns the worker.js restart; the script lives in ccc-node).

Dry-run by default (plan + idle gate). --apply: idle gate via
`restart-worker --if-idle --dry-run`, backups of the worker root and the
replaced node_modules packages, copy dist/ scripts/ handlers/, check the
build revision, the artifact's own rollout guard and an optional
--smoke-cmd, then `restart-worker --if-idle` (registered with + health
sup_count=1 workers=1 tunnel=UP) and write .deploy-source-sha. Failures
roll the root back exactly; busy never signals the worker. Unsafe tar
members are refused.

Stacked on #2929 (stage 2b).

Refs #2791

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

2 participants