@agentsignalnet/claude-plugin 0.2.92 → 0.2.94
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
package/scripts/inbox-daemon.mjs
CHANGED
|
@@ -768,6 +768,19 @@ const HELD_TOO_LONG_MS = LONGEST_HOLD_MS * 6;
|
|
|
768
768
|
const UNREADABLE_BEFORE_DEBRIS = 10;
|
|
769
769
|
|
|
770
770
|
async function claimStartup() {
|
|
771
|
+
/*
|
|
772
|
+
A BACKSTOP CANNOT BE TESTED WHILE THE THING IN FRONT OF IT WORKS.
|
|
773
|
+
|
|
774
|
+
The reconciliation after registration exists for the case where this lock
|
|
775
|
+
fails -- which has happened on a real machine and which I could not
|
|
776
|
+
reproduce. There is no way to prove that second line holds without
|
|
777
|
+
arranging for the first to be absent, so this switch exists to arrange it.
|
|
778
|
+
|
|
779
|
+
Test-only, and never set by the plugin or documented as a setting. Nothing
|
|
780
|
+
reads it except two-watchers-cannot-both-win.
|
|
781
|
+
*/
|
|
782
|
+
if (process.env.AGENTSIGNAL_NO_STARTUP_LOCK === '1') return () => {};
|
|
783
|
+
|
|
771
784
|
const rest = (ms) => new Promise((done) => setTimeout(done, ms));
|
|
772
785
|
let unreadable = 0;
|
|
773
786
|
|
|
@@ -963,6 +976,60 @@ writeFileSync(myWatcherPath, JSON.stringify(me), { mode: 0o600 });
|
|
|
963
976
|
// whole point of having held it across the decision.
|
|
964
977
|
releaseStartup();
|
|
965
978
|
|
|
979
|
+
/** Undo the registration this process just wrote, before standDown exists. */
|
|
980
|
+
function standDownEarly() {
|
|
981
|
+
try {
|
|
982
|
+
unlinkSync(myWatcherPath);
|
|
983
|
+
} catch {
|
|
984
|
+
/* never written, or already gone */
|
|
985
|
+
}
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
/**
|
|
989
|
+
* AND RECONCILE, because the lock is not to be trusted on its own.
|
|
990
|
+
*
|
|
991
|
+
* Everything above assumes the startup lock serialised the decision. On
|
|
992
|
+
* 2026-08-21 at 13:50:46 it did not, on a machine running the version that
|
|
993
|
+
* added it -- two daemons superseded the same incumbent seven milliseconds
|
|
994
|
+
* apart and both started, and both were still running hours later. I could not
|
|
995
|
+
* reproduce it: five racers against seeded debris, three rounds, all clean. So
|
|
996
|
+
* the reason the lock failed is still unknown.
|
|
997
|
+
*
|
|
998
|
+
* What is not unknown is the SHAPE of the damage. Two processes get past the
|
|
999
|
+
* lock, both register, and nothing afterwards ever looks again -- so the
|
|
1000
|
+
* duplicate is permanent, and every urgent message interrupts twice until
|
|
1001
|
+
* somebody notices by hand.
|
|
1002
|
+
*
|
|
1003
|
+
* This is the check that does not depend on the lock being right. Both
|
|
1004
|
+
* processes are registered by now, so both can see each other, and a TOTAL
|
|
1005
|
+
* ORDER decides without either needing to know what the other saw.
|
|
1006
|
+
*
|
|
1007
|
+
* LOWEST PID WINS, and the tiebreak matters more than which way it points:
|
|
1008
|
+
* mtime cannot separate two processes running the SAME file -- that is exactly
|
|
1009
|
+
* the case here -- and "equal mtimes stand down" is unusable when it would have
|
|
1010
|
+
* both stand down and leave the machine with no watcher at all. A pid is
|
|
1011
|
+
* unique, present on both sides, and gives the same answer to each.
|
|
1012
|
+
*
|
|
1013
|
+
* Only among rivals sharing this mtime. A genuinely newer build has already
|
|
1014
|
+
* been dealt with above and must not be stood down to on a pid comparison.
|
|
1015
|
+
*
|
|
1016
|
+
* Called at startup AND on every tick, because one look is not enough: see the
|
|
1017
|
+
* note at the interval below for the interleaving a single look loses.
|
|
1018
|
+
*/
|
|
1019
|
+
function yieldToLowerPid(exit) {
|
|
1020
|
+
const twins = livingWatchers(lockRoot).filter((rival) => rival.mtime === me.mtime);
|
|
1021
|
+
const usurper = twins.find((rival) => rival.pid < process.pid);
|
|
1022
|
+
if (!usurper) return false;
|
|
1023
|
+
say(
|
|
1024
|
+
`pid ${usurper.pid} is watching the same build; standing down ` +
|
|
1025
|
+
'(the startup lock did not serialise this, which is a separate bug)',
|
|
1026
|
+
);
|
|
1027
|
+
exit();
|
|
1028
|
+
process.exit(0);
|
|
1029
|
+
}
|
|
1030
|
+
|
|
1031
|
+
yieldToLowerPid(standDownEarly);
|
|
1032
|
+
|
|
966
1033
|
// Best effort, and correctness does not depend on it -- a start that finds
|
|
967
1034
|
// this entry checks the pid before believing it. It is here so an ordinary
|
|
968
1035
|
// stop leaves nothing behind, rather than leaving the next start to reason
|
|
@@ -1003,5 +1070,14 @@ for (const identity of identities()) {
|
|
|
1003
1070
|
|
|
1004
1071
|
await tick();
|
|
1005
1072
|
setInterval(() => {
|
|
1073
|
+
// Reconcile on every tick, not only at startup. Registering and looking are
|
|
1074
|
+
// two steps, so a one-shot check at startup loses a race it is supposed to
|
|
1075
|
+
// settle: if the higher pid registers first and looks before the lower one
|
|
1076
|
+
// has registered, it sees an empty registry and stays -- and the lower pid,
|
|
1077
|
+
// looking afterwards, is the one entitled to stay. Both keep watching, which
|
|
1078
|
+
// is the exact duplicate this check exists to prevent. Looking again each
|
|
1079
|
+
// tick converges whatever the order was, because the late registration is
|
|
1080
|
+
// visible by the next one.
|
|
1081
|
+
if (yieldToLowerPid(standDown)) return;
|
|
1006
1082
|
tick().catch((error) => complain(`Unexpected: ${error.stack ?? error.message}`));
|
|
1007
1083
|
}, intervalMs);
|