Skip to content

feat(termux-worker): canonical worker.js deploy script (#2791 stage 3) - #2931

Merged
seoseo-ai merged 1 commit into
mainfrom
feat/2791-native-worker-deploy
Nov 27, 2026
Merged

seoseo-ai merged 1 commit into
mainfrom
feat/2791-native-worker-deploy

Conversation

@seoseo-ai

@seoseo-ai seoseo-ai commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

2026-11-27 jingun: PR2 #2929가 a470f853로 머지돼 이 PR을 main 위로 다시 쌓았습니다(PR3 커밋만 cherry-pick, 새 head). 지금 diff는 PR3 4개 파일뿐입니다.

Stacked PR: base는 #2929(2b, feat/2791-native-worker-restart)입니다. #2929가 머지되면 base를 main으로 바꾼 뒤 머지합니다. diff에는 3단계 변경만 보입니다.

요약

#2791 3단계입니다. 오너 결정(2026-11-27)을 따릅니다.

  • (1) worker.js 재기동은 배포 쪽 책임입니다.
  • (2) 정본 위치는 ccc-node scripts/a2a-termux-native-worker-deploy.sh입니다.

롤아웃마다 따로 쓰던 임시 스크립트(11-24 termux-rollout-267d018.sh)의 동작을 정본으로 옮겼습니다. 원본은 읽기 전용으로만 확인했고, 비밀값은 없었습니다. 원본이 직접 하던 유휴 판정(pgrep -P)과 SIGTERM은 #2929의 restart-worker --if-idle로 대체했습니다.

동작

  • 기본은 dry-run입니다. artifact 검증, 계획 출력, restart-worker --if-idle --dry-run 게이트까지만 하고 노드는 바꾸지 않습니다.
  • --apply일 때 순서는 다음과 같습니다(원본 스크립트와 같은 흐름).
    1. 유휴 게이트. busy이면 exit 10으로 끝나고 아무것도 바꾸지 않습니다.
    2. 백업을 만듭니다. 대상은 worker root(node_modules 제외) tgz와, artifact가 교체할 node_modules 패키지 tgz입니다. 둘 다 tar tzf로 확인한 뒤에만 다음 단계로 갑니다.
    3. dist/·scripts/·handlers/를 덮어쓰고, artifact에 든 패키지를 교체합니다.
    4. 재기동 전에 확인합니다. 하나라도 실패하면 정확히 롤백(추가된 파일까지 제거)하고 exit 20으로 끝나며, 재기동하지 않습니다.
      • build revision이 대상과 같은지
      • artifact에 scripts/worker-artifact-rollout-guard.mjs --deployed가 있으면 그 결과(--no-guard로 끌 수 있음)
      • --smoke-cmd(A2A_WORKER_ROOT를 넘겨 실행)
    5. restart-worker --if-idle로 worker.js만 SIGTERM합니다. 하네스가 registered with와 health sup_count=1 workers=1 tunnel=UP을 확인합니다.
      • 그 사이 busy가 되면: 롤백, exit 10. 워커에는 신호를 보내지 않았습니다.
      • 검증에 실패하면: 롤백한 뒤 이전 파일로 다시 재기동, exit 30.
    6. <worker_root>/.deploy-source-sha를 원자적으로 씁니다.
  • 그 밖의 안전장치
    • 동시 배포는 flock으로 막습니다(exit 4).
    • tar에 절대경로·..·디바이스·밖을 가리키는 링크가 있으면 거부합니다.
    • 롤백 자체가 실패하면 exit 31과 함께 백업 경로를 출력합니다.
  • 노드 이름과 env 경로는 하드코딩하지 않았습니다(--env-file 필수). 원본에 있던 a2a-nexus 전용 link smoke는 범용 --smoke-cmd로 넘길 수 있습니다.

docs: docs/a2a-claude-worker.md("Deploying dist/worker.js"). changelog: changelog.d/2791-native-worker-deploy.md

검증 (로컬, jingun)

  • scripts/a2a-termux-native-worker-deploy.test.sh (신규): PASS=33 FAIL=0. 가짜 하네스(A2A_NATIVE_WORKER_HARNESS)와 가짜 node를 썼습니다.
    • 사용법·artifact 검증: 인자 없음, artifact 없음, worker.js 없음, revision 불일치, 잘못된 sha, ..가 든 tar → 모두 rc 2. root는 그대로이고 게이트도 호출하지 않습니다.
    • dry-run 계획: rc 0이고 게이트만 호출합니다. 바뀐 것도 백업도 없습니다.
    • 유휴 거부: 게이트가 busy이면 rc 10, supervisor가 없으면 rc 3이고 아무것도 바뀌지 않습니다.
    • 성공 경로(디렉터리·tar 둘 다): 파일과 패키지가 교체되고 무관한 패키지는 그대로입니다. .deploy-source-sha, 백업 2개가 생기고, 재기동 시점에 새 파일이 보이며, staging은 정리됩니다.
    • 롤백 경로: smoke 실패와 guard ok:false는 rc 20이고 root가 정확히 복원되며 재기동하지 않습니다. 검증 실패는 rc 30이고 복원한 뒤 이전 코드로 다시 재기동합니다. 재기동 시점에 busy이면 rc 10이고 복원됩니다.
    • lock을 잡고 있으면 rc 4입니다.
  • 변이 테스트(red 확인): rollback을 no-op으로 바꾸면 4개가 FAIL합니다. 게이트의 busy 거부를 없애면 2개가 FAIL합니다.
  • #2929의 테스트(restart 28/0, self-update 499/0, health 53/0, worker 57/0)는 이 브랜치에서도 그대로입니다.
  • 정적 점검: shellcheck -S warning, canon-node-name-scan.sh --repo-wide ok, changelog_fragments.py check ok

운영자 할 일: Wiki ND-1086 수정 (이 PR은 Wiki를 고치지 않습니다)

pages/nodes/gongyung/RUNBOOK.md의 [ND-1086] Native A2A worker 절(143행 이후)이 낡은 supervisor 경로를 적고 있습니다. 대교 쪽 노드 문서에 같은 문구가 있는지도 함께 확인해 주세요. 고치기 전에 노드에서 crontab -l, pgrep -af 'a2a-termux-native-worker.sh supervise'로 현재 상태를 확인한 뒤 PR-first(wiki-agent write-path → wiki-agent pr)로 반영해 주세요.

항목 지금 ND-1086 문구(낡음) 바꿀 내용
supervisor ~/.hermes/scripts/native-worker-supervisor.sh (터널+워커 루프), launcher ~/.hermes/scripts/native-worker-launch.sh ~/ccc-node/scripts/a2a-termux-native-worker.sh supervise --env-file <env>. 정본, flock singleton. 레거시 스크립트는 ND-1236 이후 쓰지 않습니다.
생존 감시·기동 Termux:Boot start-nativeworker.sh 중심 crontab canonical-native-worker-health(RB-411)가 5분마다 a2a-termux-native-worker-health.sh --self-heal을 실행합니다. Boot 항목은 실측한 뒤 적습니다.
로그 ~/.hermes/logs/native-worker-supervisor.log ~/.hermes/logs/a2a-native-worker-supervisor.log, ~/.hermes/logs/a2a-native-worker-health.log(health가 띄운 supervisor의 stdout, 곧 registered with 줄이 여기로 갑니다)
확인 명령 pgrep -f "node.real.*dist/worker.js", 레거시 로그 tail bash ~/ccc-node/scripts/a2a-termux-native-worker-health.sh --env-file <env> --no-self-heal --json(supervisor_count=1, workers=1, tunnel=UP, stale=[])
재기동·배포 (신규) 없음 worker만: a2a-termux-native-worker.sh restart-worker --if-idle. supervise 변경 시: restart-supervisor --if-idle. worker.js 배포: scripts/a2a-termux-native-worker-deploy.sh --env-file <env> --artifact <tgz> --target-sha <sha>(dry-run을 먼저 하고 승인 후 --apply). self-update 자동 재기동은 opt-in CCC_SELF_UPDATE_NATIVE_SUPERVISOR_RESTART=1(기본 0).

범위 밖 / 게이트

  • 이 PR은 노드에서 아무것도 실행하지 않습니다.
  • 실제 Termux 롤아웃(--apply), 스위치 켜기, 라이브 재기동은 머지 뒤 노드별로 따로 승인받습니다.

Refs #2791

🤖 Generated with Claude Code

@seoseo-ai
seoseo-ai requested a review from jinon86 as a code owner November 27, 2026 06:31
@seoseo-ai
seoseo-ai deleted the branch feat/2791-native-worker-restart November 27, 2026 06:53
@seoseo-ai seoseo-ai closed this Nov 27, 2026
@seoseo-ai seoseo-ai reopened this Nov 27, 2026
@seoseo-ai
seoseo-ai changed the base branch from feat/2791-native-worker-restart to main November 27, 2026 06:53
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>
@seoseo-ai
seoseo-ai force-pushed the feat/2791-native-worker-deploy branch from e85eb43 to d9a2c8d Compare November 27, 2026 06:54

@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 1b6ce9d Nov 27, 2026
17 checks passed
@seoseo-ai
seoseo-ai deleted the feat/2791-native-worker-deploy branch November 27, 2026 07:14
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