Skip to content

feat: put a finished mission's agents to sleep and wake sleeping agents for letters - #1866

Merged
yansfil merged 9 commits into
mainfrom
gen-prd/mission-worker-sleep
Oct 30, 2026
Merged

yansfil merged 9 commits into
mainfrom
gen-prd/mission-worker-sleep

Conversation

@yansfil

@yansfil yansfil commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Closes with-hide/hide-private#366
Related: PRD agents/prd/mission-worker-sleep/prd.md

Summary

  • 자고 있는 에이전트에게 보낸 편지가 이제 거절되지 않고 받아집니다. request, block 편지는 에이전트를 깨우고, report, progress 편지는 깰 때까지 기다립니다.
  • 편지로 깨우기는 한 번에 4개까지만 돕니다. 깨우기에 실패하면 그 편지는 전달 실패가 되고, 보낸 쪽은 Hide가 보낸 안내 편지를 받습니다. 깨우기를 기다리는 동안은 편지의 1시간 기한이 멈춥니다.
  • 편지 하나는 받는 에이전트를 한 번만 깨웁니다. 이미 울렸거나 한 번 깨운 request/block은 다음 잠에서 다시 깨우지 않고, 그 잠 동안 기한이 흐릅니다. 그래서 아무도 읽지 않는 편지가 재우기와 깨우기를 되풀이시키지 않습니다.
  • 미션 노드가 끝나면 그 노드의 일꾼과 검사자가 쉬는 대로 잠듭니다. Conductor는 재우지 않고, 화면에 떠 있거나 일하는 중이면 다음 분에 다시 봅니다.
  • 새 명령 hide agent sleep <id> [--actor <id>]: 에이전트 자신이나 부모가 재울 수 있고, 안 되면 이유와 다음 행동을 돌려줍니다.

Review

  • 판단해 주세요: 깨운 뒤 벨은 그 에이전트에게 한 번 울리고, 가장 오래된 편지가 앞에 섭니다. 실측에서는 먼저 온 report가 "· and 1 more"로 request를 함께 알렸고, request 자신의 bell_sent는 false로 남습니다. 기존 벨 설계 그대로입니다.
  • 질문: 편지로 깨운 뒤에는 깨운 request가 아니라 가장 오래된 편지(실측에서는 report)가 벨 앞에 서서, request는 "and 1 more"로만 보입니다. 깨운 request가 벨 앞에 서야 할까요? 바꾼다면 이 PR이 아닌 후속 작업입니다.
  • 판단해 주세요: "한 번만 깨운다"와 "이미 울린 request/block은 잠든 동안에도 기한이 흐른다"는 PRD D-13/B3 문장에 없는 예외입니다. PRD는 고치지 않고 이 판단을 여기서 받습니다.
  • 판단해 주세요: 편지로 깨워도 안 읽은 완료 표시가 사라집니다(깨우기는 한 번 본 것으로 셉니다). PRD Risks에서 받아들인 동작입니다.
  • 판단해 주세요: 미션 재우기 표시, 깨운 편지 목록, 보낸 쪽 안내 편지는 메모리에만 있습니다. 재시작하면 재우기는 시간 규칙으로 돌아가고, 편지마다 한 번 더 깨울 수 있고, 안내 편지는 잃을 수 있습니다.
  • 조심해서 볼 파일: herdr-core/src/runtime/agent_sleep/letters.rs - runtime mutex 안의 깨우기 큐, 한 번만 깨우기, 실패 경로, 안내 편지 스레드의 drop guard.
  • 조심해서 볼 파일: herdr-core/src/delivery/ledger.rs, worker.rs - 저장소 스레드가 매 패스 읽는 잠든 수신자와 기한 멈춤 규칙(Sleeper::pausing), 깬 뒤 기한 재계산(resume_woken).
  • 조심해서 볼 파일: herdr-core/src/runtime/agent_sleep/missions.rs - 끝이 실제로 내려앉을 때만 표시를 쓰는 규칙, 거절되면 다음 분에 재시도.
  • 비용 검토: 코디네이터 틱은 dirty 플래그 하나만 봅니다. 잠든 에이전트도 빚진 일도 없으면 바로 돌아갑니다. 큐는 잠든 에이전트 수, 실패와 깨운 편지 목록은 원장의 대기 편지 수에 묶입니다.
  • 기능과 무관한 커밋: 3b4ce7b test: prove timed_out_gh_and_its_pipe_holding_helper_are_terminated ... - 셸의 pid 대신, 파이프가 닫힌 것으로 gh와 도우미 종료를 증명합니다.

Evidence

  • 확인한 것 (실제 Herdr): 새 e2e web/e2e/mission-worker-sleep.spec.ts가 고정 버전 Herdr와 격리된 hided, Claude 대역(fixture shim)에서 최종 빌드 기준 7번 통과(약 2.6분씩). 한 번의 실패는 스펙의 세션 읽기 경합이었고 poll로 고쳤습니다.
  • 확인한 것 (실제 Herdr): 부모의 hide agent sleep -> ending, 다시 물으면 asleep. 잠든 일꾼에게 report는 pending으로 받아지고 아무도 깨우지 않음. request가 resume으로 깨워 같은 세션으로 복귀. 운영자 pane의 포커스와 Herdr 포커스 유지.
  • 확인한 것 (실제 Herdr): 깬 뒤 벨 한 번이 request를 함께 알림. 수면 72시간 설정에서 일하는 노드는 아무도 재우지 않고, dropped로 바꾸면 일꾼이 trigger mission으로 잠듦. 아직 pending인 request는 다시 깨우지 않음(편지 깨우기 정확히 1번).
  • 확인한 것: 전체 로컬 실행 두 번(a334711)에서 herdr-core lib 테스트 3501개 통과. 이후 집중 실행: mission_worker_sleep, delivery::ledger, delivery::worker 49개, hided guide·cli 93개, clippy -D warnings.
  • 확인한 것: 회귀 테스트 a_request_wakes_its_recipient_once_and_a_rung_one_not_at_all은 고치기 전 코드에서 실패하는 것을 확인했습니다. 기한 규칙의 ledger 테스트는 새 함수에 대한 것이라 고치기 전에는 컴파일되지 않습니다.
  • 확인하지 못한 것: 로컬 S1(verify-cargo.sh test 전체)은 운영자 승인으로 뺐습니다. 부하 15~30에서 이 브랜치 밖의 시간 제한 테스트만 실패했습니다: with-hide/hide-private#332, withhide.dev에 Hide 소개 사이트 구축 #338, Verify native Windows listener attribution and cleanup #368. 전체 테스트는 PR CI가 맡습니다.
  • 확인하지 못한 것: 진짜 Claude·Codex 에이전트, 창을 닫는 종류(Grok, OpenCode, Pi, omp)의 처음부터 끝까지, 재시작, 5개 이상 동시 종료, Windows와 Linux 실기기.
Verification record
  • PRD: agents/prd/mission-worker-sleep/prd.md (sha256 f1bdebeb7591b90674dc3e7894f0ce76b0bfefe836577c415473403a1e09cd81)
  • Base a891332 → head bed6646, verified 2026-10-30T06:14:08.025Z: PASS
  • Verification report: agents/runs/mission-worker-sleep/verification-report.json and agents/runs/mission-worker-sleep/verification-report.md; source fingerprint 430b6550a3424e9d73cb409cb3b68d651fe29dd6f9488fd5286baf6d75f12c3e
  • Suites:
    • S1: EXCLUDED bash scripts/verify-cargo.sh test
    • S2: GREEN bash scripts/verify-cargo.sh lint (exit 0)
  • Reviews:
    • Fidelity: 030a638 PASS, Fix now 1 (busy checkout failed a dormant letter wake) fixed in a334711; a334711 PASS; c355b7e PASS, Fix now 2 (spec did not assert the request pending; header claimed B12) fixed in 68f3ea8.
    • Code: 030a638 needs changes, Fix now 2 + Medium 1 fixed in a334711; a334711 approve; 3b4ce7b (test only) approve; c355b7e approve, residual gap (a once-woken letter paused forever while asleep) fixed in 4167873; 68f3ea8 approve, Fix now 1 (rung report lost its B3 pause) fixed in bed6646, confirmed closed.
    • Follow-up improvements: tests for the pane-closing sleep route (B1, B2, B4), the sender note thread, the mission four-sleep cap; one mark per agent across two nodes; PRD D-13/B3 wording for the once-per-letter exception; a runtime test of wake, awake, sleep again, wake.
  • Evidence: none registered separately.
  • Changed paths: 32 (see Files changed)
  • Delivery: mode pr, branch gen-prd/mission-worker-sleep, base main

…ts for letters

A letter to a registered agent Hide put to sleep is now taken instead of refused: a request or block wakes the agent with its conversation resumed (at most four letter wakes at once, in arrival order, without moving the operator's screen), a report or progress waits for its next wake, and the delivery deadline does not run while it sleeps. A failed wake leaves the letters that waited on it undelivered and tells their senders why.

When a mission node finishes (done, failed, dropped, its pull request merged or closed, or its mission closed), its worker and bound checkers are put to sleep once they rest off screen; a refused end is tried again the next minute, and a woken worker is not slept again for the same finish.

hide agent sleep <id> [--actor <id>] puts an agent to sleep for itself or its parent, answering ending or asleep, or a refusal code with its next action.
…ng its letters

A dormant wake refused for a passing reason (a busy checkout, no free transition, a close not yet confirmed) and an in-pane wake with no connection now stay queued; an agent whose wake failed no longer pauses its letters' delivery hour; a mission mark is spent when a pane-closing sleep landed and its registration moved on; and a mark is kept while its node machine does not answer. hide agent sleep's contract lists agent_pane_required.
…y the pipes closing, not the shell's pid

Under a loaded full workspace run the fake gh's shell sometimes did not reach its first line before the 3 s deadline, so the pid file the test unwrapped was missing (with-hide/hide-private#366). run_gh answers only once both pipes reach end of file, and gh and every helper hold them until they end, so an answer before the helper's minute proves the whole tree was killed; the pid, when the shell wrote it, still has to be dead.
A request that rang or that already woke its recipient kept the sleeper's route waiting, so an agent that slept again by the hours, its mission or hide agent sleep was woken by the same pending letter each time. Each letter now wakes its recipient once and a letter whose bell rang wakes no one; the set is memory beside the wake queue. The docs also say a failed sleeper's hour runs again and a wake that cannot start leaves a new request to expire without a note.
…l Herdr

After the wake one bell rings for the worker's turn, led by the oldest pending letter and counting the request with it. The fixture conversation is written now so turning sleep on does not find it hours idle, the mission sleep is asserted by its trigger, a pending request does not wake the worker after its mission sleep, waits are quietFor windows and debug output moved into failure messages.
…ter sleep

Once a letter wakes its recipient at most once, a letter that rang or whose wake started before the current sleep wakes no one, so pausing its deadline for that sleep left its sender waiting until something else woke the agent. Only a letter waiting for its recipient's wake now pauses its hour (Sleeper::pausing); the letters that woke someone are kept with when, and a wake that ends during its own start marks its letters too.
… sleeps

Only a request or block wakes its recipient, so only those stop pausing their hour once they rang or woke it; a report or progress waits for the next wake, rung or not (PRD B3).
@yansfil
yansfil merged commit f5ad167 into main Oct 30, 2026
61 checks passed
@yansfil
yansfil deleted the gen-prd/mission-worker-sleep branch October 30, 2026 07:00
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