Publish the pidfile and its identity pin as ONE transition (issue #1238). The pidfile rename is the
single commit point. Just before it, a BRIDGE pin is renamed into place holding the old record's
line and the new one, so whichever pid the pidfile names at any instant, the pin carries that pid's
own line and verifyIdentityPin checks it as the complete record it belongs to. After the
commit, the settled pin (the new line alone) replaces the bridge.
Reachable on-disk states, in order: before bridge-pin, the OLD complete record (or nothing, on a
first start). After bridge-pin, the OLD pid checked against its own line, so a pin that was
refusing a reused pid keeps refusing it. After publish-pid, the NEW pid checked against its own
line. After publish-pin, the NEW complete record. No state is torn and none drops to the unpinned
legacy shape. A legacy old record (a pidfile with no pin) is carried as a NO_START_TOKEN
line, so it stays legacy until the commit. An old pin that is torn or has no line for the old pid
has nothing to carry, so until the commit it refuses as a torn pairing, as it already did. A
pidfile that exists but cannot be read is not a first start: the publish throws before its first
rename, leaving the record as it was.
When identityRecord cannot establish a token (ps-less host, or a pid whose start could not be
read - same rule as writeIdentityPin), the new line carries NO_START_TOKEN and
publish-pin removes the pin, leaving the legacy shape writeIdentityPin would have left. A crash
after the commit reads that same legacy record, never the new pid paired with the old pin.
Writers of one path are serialized by an advisory lock (${path}.publish.lock) held from the read
of the old line to the settled pin: the launcher and the daemon it starts both publish the same
record, and an unserialized bridge or settle could overwrite a newer publish. Teardown removes a
record under the same lock (removePidPair). A crashed holder's lock is reclaimed by the
next writer.
Its renames go through one publishRenamer, which retries the brief refusal Windows gives a
rename over a record another handle holds open, on one backoff budget for the whole publish. A
refusal that outlasts the budget throws like any other step, leaving the state the previous step
reached.
On any throw, the temporaries are removed (finally, best-effort) and the error rethrown; the
temporary names are never read by any reader (${path}.publish.<pid>.<hex>, the same claim-file
pattern claimAuthPidSlot uses for .claim.).
Publish the pidfile and its identity pin as ONE transition (issue #1238). The pidfile rename is the single commit point. Just before it, a BRIDGE pin is renamed into place holding the old record's line and the new one, so whichever pid the pidfile names at any instant, the pin carries that pid's own line and verifyIdentityPin checks it as the complete record it belongs to. After the commit, the settled pin (the new line alone) replaces the bridge.
Reachable on-disk states, in order: before
bridge-pin, the OLD complete record (or nothing, on a first start). Afterbridge-pin, the OLD pid checked against its own line, so a pin that was refusing a reused pid keeps refusing it. Afterpublish-pid, the NEW pid checked against its own line. Afterpublish-pin, the NEW complete record. No state is torn and none drops to the unpinned legacy shape. A legacy old record (a pidfile with no pin) is carried as a NO_START_TOKEN line, so it stays legacy until the commit. An old pin that is torn or has no line for the old pid has nothing to carry, so until the commit it refuses as a torn pairing, as it already did. A pidfile that exists but cannot be read is not a first start: the publish throws before its first rename, leaving the record as it was.When
identityRecordcannot establish a token (ps-less host, or a pid whose start could not be read - same rule as writeIdentityPin), the new line carries NO_START_TOKEN andpublish-pinremoves the pin, leaving the legacy shapewriteIdentityPinwould have left. A crash after the commit reads that same legacy record, never the new pid paired with the old pin.Writers of one path are serialized by an advisory lock (
${path}.publish.lock) held from the read of the old line to the settled pin: the launcher and the daemon it starts both publish the same record, and an unserialized bridge or settle could overwrite a newer publish. Teardown removes a record under the same lock (removePidPair). A crashed holder's lock is reclaimed by the next writer.Its renames go through one publishRenamer, which retries the brief refusal Windows gives a rename over a record another handle holds open, on one backoff budget for the whole publish. A refusal that outlasts the budget throws like any other step, leaving the state the previous step reached.
On any throw, the temporaries are removed (
finally, best-effort) and the error rethrown; the temporary names are never read by any reader (${path}.publish.<pid>.<hex>, the same claim-file pattern claimAuthPidSlot uses for.claim.).