Skip to content

[Bug] Permanent Stuck of update-job.json with 'already running' Block on Subsequent Updates when Update Worker Crashes #587

Closed

Description

@jhste102lab

Client or integration

  • OpenCodex dashboard (GUI 업데이트) / CLI (ocx system update run --yes)

Area

  • Service lifecycle (업데이트 잡 상태 관리)

Summary

업데이트 워커 프로세스가 비정상 종료되면 ~/.opencodex/update-job.json의 상태가 running 또는 restarting으로 영구 고착(stuck)되어, 이후 GUI 업데이트 버튼이나 ocx system update run --yes를 누를 때마다 무조건 An update job is already running (update_already_running, HTTP 409)만 반환하고 업데이트가 진행되지 않습니다.

코드를 추적한 결과 상태 판정이 신뢰할 수 없게 설계되어 있어 고착 상태에서 자동으로 회복할 수단이 없습니다.

근본 원인 (검증한 코드 위치):

  1. 워커 PID가 디스크 파일에 기록되지 않음
    src/update/job.ts:255의 writeJob(job)이 spawn 이전에 호출되고, src/update/job.ts:264의 child.pid는 HTTP 응답 객체에만 추가될 뿐 update-job.json에는 저장되지 않습니다. 결과적으로 "이전 job의 워커가 아직 살아있는가?"를 검증할 방법이 코드상 존재하지 않습니다.

  2. stale/OBAN(오래된 잡) 판정이 전혀 없음
    readUpdateJob(src/update/job.ts:121-130)은 JSON 파일만 읽고 updatedAt의 경과 시간을 전혀 검사하지 않습니다. 업데이트 최대 시간은 UPDATE_TIMEOUT_MS=180s(src/update/job.ts:27) + 재시작 안정성 창 ~15s인데, 그보다 훨씬 오래된 running 상태도 신선한 것과 동일하게 취급합니다.

  3. 취소/리셋 명령·엔드포인트 부재
    ocx system update는 check/run/status만 있고(src/cli/system-command.ts:68-93), 서버측 /api/update/run(src/server/management/config-routes.ts:244-262)에도 stuck job을 해제할 수단이 없습니다.

  4. guard 자체
    src/update/job.ts:228-232의 startUpdateJob() guard는 단순히 상태 값만 보고 무조건 reject합니다.

이 동작을 명시하는 테스트도 tests/update-job.test.ts:683-705("a running job prevents a second update job")에 있어, 의도된(고착 가능성을 각오했던) 동작입니다.

기대 동작: 워커가 죽었거나 잡이 충분히 오래되었으면 stale로 판정해 자동으로 해제하고 새 업데이트를 허용해야 합니다.

Reproduction

  1. ocx start --port 10100 (또는 서비스 설치 상태)에서 프로키시를 띄운다.
  2. ocx system update run --yes --channel latest를 실행해 GUI/CLI 업데이트 잡을 시작한다.
  3. 업데이트 워커가 비정상 종료되는 상황을 만든다 — 예: 워커 프로세스를 강제 kill(kill -9 <worker pid>), 시스템 강제 재부팅, 정전, 또는 워커 내부에서 throw되어 잡 상태가 갱신되기 전에 종료.
  4. 잡이 종료된 후 다시 ocx system update run --yes를 실행한다.
  5. 관찰: An update job is already running (409)만 반환되고 업데이트가 영원히 진행되지 않음.

워크어라운드(즉시 회피): rm -f ~/.opencodex/update-job.json (또는 $OPENCODEX_HOME/update-job.json)을 실행하면 다음 업데이트 시도가 정상 작동합니다.

Version

  • @bitkyc08/opencodex v2.7.42
  • commit: 7cb15bff4efd7beafc49d0a125432230c6ec9461 (2026-07-28, main HEAD 기준)

Operating system

  • Ubuntu 24.04 (재현 환경). 단, 코드상 플랫폼 무관하며 Windows/macOS에서도 동일하게 발생합니다 (src/update/job.ts 시작 경로는 process.platform 분기 없이 동일 로직).

Provider and model

  • 해당 없음 (업데이트/서비스 수명주기 문제)

Logs or error output

HTTP 409 {"error":"An update job is already running","code":"update_already_running"}

영향받는 코드 (합厌):

  • src/update/job.ts:228 — startUpdateJob guard (PID/신선도 검증 없음)
  • src/update/job.ts:121 — readUpdateJob (updatedAt 미검사)
  • src/update/job.ts:255-264 — writeJob이 spawn 전 호출, child.pid 미기록
  • src/cli/system-command.ts:68 — update 명령에 취소/리셋 부재
  • src/server/management/config-routes.ts:244 — /api/update/run에 stale 해제 부재
  • tests/update-job.test.ts:683 — 의도된 고착 동작을 명시하는 테스트

제안하는 수정 방향

startUpdateJob()의 guard를 "살아있음 + 신선도" 기반으로 변경:

  1. spawn 직후 워커 PID를 파일에 write (src/update/job.ts:263 근처 writeJob({ ...job, pid: child.pid })).
  2. running/restarting 잡을 reject 하기 전, 기존 잡에 대해:
    • isProcessAlive(job.pid) (src/lib/process-control.ts:4에 이미 존재)로 워커가 죽었으면 stale로 판정.
    • updatedAt 경과가 임계치(예: ~5분)를 초과하면 stale로 판정.
    • stale이면 해당 잡을 failed로 갱신하고 새 잡을 허용(또는 자동으로 무시하고 진행).
  3. (선택) 서버측 /api/update/run 또는 ocx system update cancel로 명시적 리셋 옵션 추가.

위 (1)과 (2)를 같이 넣는 것이 가장 신뢰도가 높습니다 — PID가 기록되어야 stale 판정이 안전하고, PID만으로는 워커가 detached/세션 분리된 경우 검증이 불완전할 수 있어 신선도 타임아웃이 보완 역할을 합니다.

Checks

Translated Message

Original language: Korean

Client or integration

  • OpenCodex dashboard (GUI update) / CLI (ocx system update run --yes)

Area

  • Service lifecycle (update job status management)

Summary

When the update worker process crashes abnormally, the state of ~/.opencodex/update-job.json becomes permanently stuck as running or restarting, causing an HTTP An update job is already running (update_already_running, HTTP 409) response every time the GUI update button or ocx system update run --yes is pressed, and preventing updates from proceeding.

Upon tracking the code, it was found that the state determination is poorly designed, with no means for automatic recovery from a stuck state.

Root causes (verified code locations):

  1. Worker PID not recorded in disk file
    src/update/job.ts:255's writeJob(job) is called before spawn, and src/update/job.ts:264's child.pid is only added to the HTTP response object and not saved in update-job.json. As a result, there is no way in the code to verify "Is the previous job's worker still alive?"

  2. No stale/OBAN (old job) determination
    readUpdateJob (src/update/job.ts:121-130) only reads the JSON file and does not check the elapsed time of updatedAt. The maximum update time is UPDATE_TIMEOUT_MS=180s (src/update/job.ts:27) + restart stability window ~15s, but running states older than that are treated the same as fresh ones.

  3. Lack of cancel/reset commands/endpoints
    ocx system update only has check/run/status (src/cli/system-command.ts:68-93), and the server-side /api/update/run (src/server/management/config-routes.ts:244-262) does not provide a way to release stuck jobs.

  4. Guard itself
    src/update/job.ts:228-232's startUpdateJob() guard simply checks the state value and always rejects.

There are also tests specifying this behavior at tests/update-job.test.ts:683-705 ("a running job prevents a second update job"), indicating it is an intended behavior (prepared for potential stuck).

Expected behavior: If the worker is dead or the job is old enough, it should be determined stale and automatically released to allow new updates.

Reproduction

  1. Start the proxy in ocx start --port 10100 (or service installation state).
  2. Execute ocx system update run --yes --channel latest to start a GUI/CLI update job.
  3. Create a situation where the update worker crashes abnormally — e.g., forcibly kill the worker process (kill -9 <worker pid>), force system reboot, power outage, or throw from within the worker before job state updates.
  4. After the job has terminated, execute ocx system update run --yes again.
  5. Observe: Only An update job is already running (409) is returned, and the update never proceeds.

Workaround (immediate avoidance): Executing rm -f ~/.opencodex/update-job.json (or $OPENCODEX_HOME/update-job.json) will allow the next update attempt to work normally.

Version

  • @bitkyc08/opencodex v2.7.42
  • commit: 7cb15bff4efd7beafc49d0a125432230c6ec9461 (as of 2026-07-28, main HEAD)

Operating system

  • Ubuntu 24.04 (reproduction environment). However, platform independent in the code, it occurs the same on Windows/macOS (src/update/job.ts starting path has the same logic without process.platform branches).

Provider and model

  • Not applicable (update/service lifecycle issue)

Logs or error output

HTTP 409 {"error":"An update job is already running","code":"update_already_running"}

Affected code (incidental):

  • src/update/job.ts:228 — startUpdateJob guard (no PID/freshness validation)
  • src/update/job.ts:121 — readUpdateJob (no updatedAt check)
  • src/update/job.ts:255-264 — writeJob called before spawn, child.pid not recorded
  • src/cli/system-command.ts:68 — lack of cancel/reset in update command
  • src/server/management/config-routes.ts:244 — absence of stale release in /api/update/run
  • tests/update-job.test.ts:683 — test specifying intended stuck behavior

Suggested modification direction

Change the guard of startUpdateJob() to be based on "alive + freshness":

  1. Write the worker PID to the file immediately after spawn (writeJob({ ...job, pid: child.pid }) near src/update/job.ts:263).
  2. Before rejecting running/restarting jobs, for the existing job:
    • Determine it stale if the worker is dead (isProcessAlive(job.pid) already exists in src/lib/process-control.ts:4).
    • Determine it stale if the updatedAt elapsed time exceeds a threshold (e.g., ~5 minutes).
    • If stale, update the job to failed and allow a new job (or ignore and proceed automatically).
  3. (Optional) Add an explicit reset option on the server-side /api/update/run or ocx system update cancel.

Including both (1) and (2) together provides the highest reliability — recording the PID is necessary for safe stale determination, and relying solely on the PID may lead to incomplete validation when the worker is detached/session separated, making freshness timeout a complementary role.

Activity

  1. added
    bug
    on Jul 28, 2026
  2. changed the title [-][Bug] 업데이트 워커 비정상 종료 시 update-job.json 영구 고착으로 이후 모든 업데이트가 'already running' 차단[/-] [+][Bug] Permanent Stuck of update-job.json with 'already running' Block on Subsequent Updates when Update Worker Crashes[/+] on Jul 28, 2026
  3. github-actions commented on Jul 28, 2026

    @github-actions
    Contributor

    Automated translation bookkeeping — detected language: English.

  4. Ingwannu commented on Jul 28, 2026

    @Ingwannu
    Owner

    Confirmed on the current dev branch.

    The active job state is persisted before the detached worker is spawned, but the returned child PID is never written back to update-job.json. The existing guard then treats every running/restarting record as live indefinitely.

    I am going to:

    • persist the worker PID immediately after a successful spawn;
    • recover automatically when that PID is no longer alive;
    • recover legacy no-PID records only after a conservative stale window;
    • preserve exclusion for fresh or demonstrably live jobs;
    • handle spawn failures explicitly; and
    • add regression coverage and update the relevant behavior documentation.
  5. Ingwannu commented on Jul 28, 2026

    @Ingwannu
    Owner

    Fixed on dev in commit 7710185c.

    The dashboard now persists the detached update worker PID, refuses a second update while that PID is alive, recovers immediately when the worker PID is dead, and recovers legacy no-PID active records after a conservative ten-minute window. Synchronous/asynchronous worker startup failures are also persisted as failed jobs instead of leaving an active record behind.

    Regression coverage includes live/dead PID behavior, legacy stale-window behavior, replacement PID persistence, and spawn failure state. The full pre-push suite passed: 5,700 tests, TypeScript typecheck, GUI lint, and privacy scan.

    This will be included in the next release cut from dev.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bug

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions