Skip to content

fix(daily-report): 데몬 여럿이 같은 날 리포트를 중복 발행하지 않게 파일 잠금으로 직렬화 (AGT-4902) - #919

Open
unohee wants to merge 1 commit into
mainfrom
heewonoh/agt-4902-daily-report-lock
Open

unohee wants to merge 1 commit into
mainfrom
heewonoh/agt-4902-daily-report-lock

Conversation

@unohee

@unohee unohee commented Nov 14, 2026 •

Copy link
Copy Markdown
Collaborator

무엇

  • generateDailyReports 한 번의 실행 전체를 src/support/fileLock.ts의 비동기 withFileLock(~/.openswarm/daily-reporter-watermark.json.lock)으로 감쌌습니다. watermark 읽기부터 마지막 쓰기까지 잠금 안에서 일어나므로, 두 번째 인스턴스는 기다렸다가 첫 번째가 남긴 기록을 읽고 이미 발행한 프로젝트를 건너뜁니다(완료된 날이면 통째로 skip).
  • 대기 상한은 15분입니다. 넘으면 그 실행은 경고만 남기고 건너뜁니다. 다른 인스턴스가 발행 중이고, 그 인스턴스가 끝내지 못한 프로젝트는 다음 창에서 다시 시도됩니다.
  • 죽은 소유자의 잠금은 withFileLock의 기존 dead-pid 회수로 처리됩니다.

왜

AGT-4902 (AGT-3443 잔여). reportInFlight는 한 프로세스 안만 막습니다. 같은 cron 시각에 데몬 두 개가 돌면 둘 다 빈 watermark를 읽고 같은 프로젝트 상태 업데이트를 두 번 올렸습니다.

이슈는 runnerState.ts의 withFileLockSync/withRunnerStateLock 재사용을 제안했지만, 둘 다 동기 작업만 감쌀 수 있어서 네트워크 호출을 포함하는 실행에는 맞지 않습니다. 같은 소유권 규칙을 쓰는 비동기 짝인 withFileLock을 썼습니다.

검증

  • npx vitest run src/automation/dailyReporter → 4 files, 10 tests 통과(기존 7 + 신규 3).
  • 신규 dailyReporter.lock.test.ts: (1) 별도 모듈 인스턴스 두 개를 동시에 돌려도 프로젝트당 발행 1회이고 watermark가 complete, (2) 살아 있는 소유자가 잠금을 쥐고 있으면 발행 없이 skip하고 그 잠금을 건드리지 않음, (3) 죽은 pid의 잠금은 회수하고 발행.
  • 잠금을 빼면 세 테스트가 모두 실패하는 것을 확인했습니다(mutation check).
  • npm run typecheck 통과, oxlint 0 warnings.

알려진 한계

withFileLock의 stale 판정은 kill(pid, 0)만 쓰고 namespace 증명이 없습니다(withRunnerStateLock과 다름). 컨테이너 안의 데몬이 ~/.openswarm을 호스트 데몬과 공유하면, 다른 pid namespace의 살아 있는 잠금을 죽은 것으로 보고 회수할 수 있습니다. 같은 namespace에서 도는 일반 배치에서는 해당하지 않습니다.

… a file lock (AGT-4902)

reportInFlight only guarded one process. Two daemons firing the same cron
both read an empty watermark and published every project twice. A run now
holds an async file lock next to the watermark from the watermark read to
the last write; the second instance waits, reads the first one's record and
skips what was published. A lock held past the wait skips the run; a dead
holder's lock is reclaimed.
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