Skip to content

fix(device-lock): publish lock and ticket records whole (CHE-10242) [squash] - #349

Draft
congvc-bot-x99[bot] wants to merge 4 commits into
mainfrom
agent/x99-claude-sonnet/che-10242-43c0a8051bd4
Draft

congvc-bot-x99[bot] wants to merge 4 commits into
mainfrom
agent/x99-claude-sonnet/che-10242-43c0a8051bd4

Conversation

@congvc-bot-x99

Copy link
Copy Markdown

Status

Draft. Head d1bf3d1. Author: x99-claude-sonnet. Needs a different-lab review (RGS-1) on this exact head. The author does not merge.

Change

Stage 1 of CHE-1142. The device lock and queue tickets were created empty, then written. A live worker paused for more than 5 s between the two calls lost its lock or its ticket to the malformed-record reaper.

  • _publish_exclusive(path, payload) writes the whole record to <name>.<hex>.tmp in the same folder, then os.links it into place. It always unlinks the temp file. It returns False on FileExistsError. No fsync.
  • _try_acquire_owner_lock_unguarded and reserve publish through it. The re-entrant and stale-check branch is unchanged. reserve keeps its name format and its 8 tries.
  • If os.link raises an OSError other than FileExistsError, that call falls back to create-then-write. One warning is logged per process.
  • cleanup_stale_locks also deletes *.tmp files older than 60 s in the lock folder and in each *.queue folder. Fresh temp files stay.
  • _MALFORMED_LOCK_GRACE_SECONDS and the malformed-record reaping stay, for records from older code and for corrupt files.

Not changed: the broker handoff path, transfer_reservation, requeue_starting, every NACK decision, queue order, the Windows retry helpers.

Blast Radius

Every caller of DeviceExecutionLock.acquire and reserve goes through the changed code. graphify affected lists device_ownership.py, agent_qa/worker.py, bridge_session_service.py, device_pool.py, server_lifecycle.py, sdk/agent.py and chat_session_worker.py among the importers. The lock file is now created with mode 0o600. A temp name matches none of the *.lock, *.wait scanners. A filesystem without hard links keeps today's behavior and logs one warning. A break shows as a failed DeviceBusyError path or as the warning in the log. Proof level: 2 (unit).

Evidence

Red on main (tests 1, 2, 4, 5 and 6 fail, test 3 passes):

FAILED tests/unit/runtime/test_device_lock.py::test_a_paused_writer_never_yields_two_owners
FAILED tests/unit/runtime/test_device_lock.py::test_a_paused_ticket_keeps_its_place
FAILED tests/unit/runtime/test_device_lock.py::test_hard_link_failure_falls_back_and_warns_once
FAILED tests/unit/runtime/test_device_lock.py::test_cleanup_removes_only_old_publication_temp_files
FAILED tests/unit/admin_console/test_host_nack_races.py::test_nack_preserves_a_worker_paused_before_owner_metadata_write
5 failed, 1 passed, 40 deselected in 2.17s

Green on this head:

uv run pytest tests/unit/runtime/test_device_lock.py tests/unit/admin_console/test_host_nack_races.py tests/unit/admin_console/test_host_admission.py tests/unit/admin_console/test_device_execution_reservation.py -q
132 passed in 16.22s

uv run ruff format --check . and uv run ruff check . pass.

Flake note: one earlier run of the same command, under host load (98 s), failed test_host_admission.py::test_nack_after_the_worker_spawned_is_refused_and_keeps_the_run. That file then passed 3 times alone and the full command passed again. The cause is not found. The CI workflow result is not yet read.

Refs CHE-1142

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.

0 participants