Skip to content

lane-handoff skips the swap lifecycle when its lane-state read dies of SIGPIPE (pipefail + awk exit) #245

Open

Description

@brettheap

The finding

lane-handoff reads the lane's lifecycle state through a pipeline that can kill its own producer. On main a41adb6:

  • lane-handoff:116 sets set -uo pipefail.
  • lifecycle_begin (lane-handoff:1439-1440) reads the state with:
    lcb_now="$(LANES_NO_FETCH=1 "$LANES_EDIT" lane-state "$lane" 2>/dev/null \
    	| awk -F"\t" '$1 == "state" { print $2; exit }')" || lcb_rc=$?
  • lanes-edit.sh lane-state (the arm at lanes-edit.sh:16713) prints its eleven fields with one printf '%s\n' "$lst_out" (:16727). Those fields are built by lane_state_read (:12354, its printfs at :12370-12376), and state is the first line.

awk exits as soon as it has read the state line. That builtin printf can reach the pipe in more than one write, the first line alone, ahead of the rest. If awk has exited between those writes, the next one hits a closed pipe and lanes-edit.sh is killed by SIGPIPE (exit 141). Under pipefail the pipeline's status is then 141, even though the state value was read correctly. lifecycle_begin treats any status but 0 or 8 as a failed read (:1441-1445). It prints "the lane lifecycle could not be read (… exited 141)" and returns, so the handoff records no transition.

The symptom

The swap's records (handoff, PAUSED) still complete, and the handoff exits 0, but:

  • the lane stays RUNNING, never taken to SWAPPING or SWAPPED;
  • the inventory is never taken, so its messages are missing, including "the worktree inventory was not recorded for " in a case that expects it.

Seen in CI, each time as the shell suite's lane-state … exited 141 from lifecycle_begin:

run branch / sha job case
39090138534 #213, merge with main f595e44 tests-no-submodule repoRC-14, "a handoff whose inventory write is refused …": expected SWAPPING, got RUNNING; expected the "inventory was not recorded" line
39076536893, attempt 1 #213 2f690dc tests-no-submodule the same repoRC-14 case (attempt 2 passed)
39072753012 fix/hygiene-workspace-host-paths c1a30df tests repoRC-5: expected lifecycle: RUNNING -> SWAPPING and SWAPPING -> SWAPPED

c1a30df changes no lane tooling against main: its diff from f5c3bcd is a brainstorm document, a spec receipt and tests/test_repo_hygiene.py. So this is main's own behaviour, not #213's. #213's hunks do not touch the lane-state arm, lane_state_read or lane-handoff.

Probes

All on one workstation (bash 5.2.21, load 35 to 66 on 32 cores):

  • The write split. printf '%s\n' "$x" with a multi-line $x, read by a reader already blocked in read: the first line arrived ALONE in its own read in 2 of 150 runs, and in 1 of 60 in a second batch. It came as ['state\tRUNNING\n', 'generation\t3\nfile\t…\n']. The rest of the time the writes had all landed before the reader woke. So the builtin's output is more than one write, the first line first.

  • The real pipeline, which fails rarely. lanes-edit.sh lane-state (main f5c3bcd) into the awk above, under pipefail, in a one-row sandbox register:

    • 0 of 100 exits with 141;
    • 0 of 40 with both processes pinned to one CPU, the writer under nice -n 19 and then under SCHED_IDLE.

    CI hits it a few times per hundred suite runs. Its runners are smaller and the suite calls lifecycle_begin once per handoff case.

I took no direct syscall trace; there is no strace on this workstation.

What would fix it

Any one of these, in lifecycle_begin and at the same pattern elsewhere in lane-handoff. :1454-1455 reads operation the same way, with its status unchecked.

  1. Let awk read to EOF instead of exiting: awk -F'\t' '$1 == "state" && !seen { print $2; seen = 1 }'. The producer then never writes into a closed pipe.
  2. Capture lane-state's output first and parse it after: lcb_all="$(… lane-state …)" || lcb_rc=$?, then awk over $lcb_all. The status is then the producer's own, with no pipeline at all.
  3. Treat 141 from the producer as a completed read only when the field arrived: a status of 141 with a non-empty state is a read that happened. This is the narrowest fix and the least obvious one to read.

Option 2 keeps the 0, 8 and 10 meanings of lane-state intact and is the easiest to reason about. A sweep for other | awk '… exit', | head and | grep -q readers of a lanes-edit.sh call under pipefail belongs with it. #138 item 15 is the same family at lanes:414.

Whose it is

lane-handoff is lane openRepoTools-3's tooling. Amendment 23 act 2 (lane openRepoShape-2) rewrites it, so the fix may belong in that rewrite rather than in a patch to today's file.

Filed by lane openRepoTools-4 from the #213 investigation.

🤖 Generated with Claude Code

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions