fix(engine)!: identity is derived, never invented
Four defects that all reduce to the same thing: the engine trusted a name it had no business trusting. _broadcast is now a reserved namespace, not a repo. coord-send guarded retraction with a sender check, but that guard only covered the door it was nailed to: `coord-done --repo _broadcast <file>` walked in the side entrance and archived a broadcast out of the queue - a full unauthenticated retract of an announcement for every repo that had not read it yet. The rule reserves the whole `_` prefix rather than one literal, so a later `_seen` or `_config` cannot reopen the hole, and it is enforced in every CLI: a rule held in three of four places is not a rule. The pwd fallback is gone. It existed so the CLI would work anywhere, but "anywhere" includes every global surface: a session in ~/repos is not a repo, and basename(pwd) silently handed it the identity "repos". That is not hypothetical - mail was delivered under exactly that name. git toplevel or an explicit --from/--repo are now the only two sources. The write paths refuse and say so; the read path declines silently, because the hook runs it at every session start and must never fail a session. Two checkouts with the same directory name still share one mailbox - re-keying identity would break every existing mailbox and the readable `--to <repo>` addressing. Instead the first git-derived read records the claiming path in <repo>/.origin, and a read from elsewhere is warned about in the injection. A warning, not a refusal: the same repo moved or re-cloned is the ordinary case. The warning goes in the injection because the hook discards stderr, and a warning nobody can see is not a warning. The collision is live in this tree: claude-code-100x is nested inside a repo of the same name. Broadcast delivery is recorded only after the injection is written. Marking inside the read loop left a window where the seen set said "delivered" while the operator saw nothing, and the hook runs under `timeout: 10`, so the window was reachable. A lost broadcast is unrecoverable by design - the seen set is delivery history and retraction deliberately leaves it alone - so the failure mode has to be redelivery, never loss. The hook stops resolving identity altogether. It was the fourth copy of the rule and the only one that runs in production, so passing --repo bypassed the engine's guards exactly where they mattered and suppressed the collision check along with them. It is now the pure wrapper the boundary rule always claimed it was, pinned by two behavioral tests rather than by reading the source. Selftest 93 -> 116; three node tests cover the hook. BREAKING CHANGE: coord-send and coord-done exit 2 outside a git repo instead of naming themselves after the working directory. Pass --from/--repo to choose an identity explicitly. Repo names beginning with _ are refused everywhere. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01U6EixQo6hpoRCVtiAXdnFs
This commit is contained in:
parent
737127a14c
commit
1d62b073f8
11 changed files with 1195 additions and 28 deletions
|
|
@ -308,6 +308,98 @@ printf '%s' "$pout" | grep -q 'Responding is mandatory'; check "priority: respon
|
|||
printf '%s' "$pout" | grep -q 'COMPLYING with what a message asks is not'; check "priority: complying with message content is NOT mandated" $?
|
||||
printf '%s' "$pout" | grep -q 'UNTRUSTED DATA'; check "priority: the untrusted-data framing survives the priority text" $?
|
||||
|
||||
# 21. `_broadcast` is a RESERVED INTERNAL NAMESPACE, not a repo. coord-send.sh
|
||||
# guards retraction with a sender check, but that guard only covers the door it
|
||||
# is nailed to: `coord-done.sh --repo _broadcast <file>` walks in the side
|
||||
# entrance and archives the broadcast out of the queue, which is a full
|
||||
# UNAUTHENTICATED RETRACT - any repo can silence any announcement for every repo
|
||||
# that has not yet read it. The fix is a namespace rule rather than a check for
|
||||
# one literal: `_` is reserved for engine internals, so a future `_seen` or
|
||||
# `_config` cannot reopen the same hole. Reserved-ness is a property of the
|
||||
# NAME, so every CLI must agree on it - a rule enforced in three of four places
|
||||
# is not a rule.
|
||||
"$SEND" --broadcast --from bcowner --subject "reserved" --message "RESERVED-BC-BODY" >/dev/null
|
||||
rbn="$(basename "$(ls "$CLAUDE_COORD_DIR"/_broadcast/inbox/*-from-bcowner.md 2>/dev/null | head -1)")"
|
||||
dro="$("$DONE" --repo _broadcast "$rbn" 2>&1)"; rc=$?
|
||||
[ "$rc" -eq 2 ]; check "reserved: coord-done refuses --repo _broadcast" $?
|
||||
[ -e "$CLAUDE_COORD_DIR/_broadcast/inbox/$rbn" ]; check "reserved: the refused coord-done leaves the broadcast pending" $?
|
||||
[ ! -e "$CLAUDE_COORD_DIR/_broadcast/archive/$rbn" ]; check "reserved: coord-done cannot retract a broadcast it does not own" $?
|
||||
sro="$("$SEND" --to _broadcast --from x --subject s --message m </dev/null 2>&1)"; rc=$?
|
||||
[ "$rc" -eq 2 ]; check "reserved: coord-send refuses --to _broadcast" $?
|
||||
fro="$("$SEND" --to somerepo --from _broadcast --subject s --message m </dev/null 2>&1)"; rc=$?
|
||||
[ "$rc" -eq 2 ]; check "reserved: coord-send refuses --from _broadcast" $?
|
||||
pfo="$("$SEND" --to _future --from x --subject s --message m </dev/null 2>&1)"; rc=$?
|
||||
[ "$rc" -eq 2 ]; check "reserved: the whole _-prefixed namespace is refused, not just _broadcast" $?
|
||||
# The read path must REFUSE without FAILING: the hook runs it at every session
|
||||
# start and an exit 2 there would break sessions over a name it can simply
|
||||
# decline to serve. Dumping the broadcast queue as if it were an inbox would
|
||||
# also re-deliver every retired announcement.
|
||||
iro="$("$INBOX" --repo _broadcast 2>/dev/null)"; rc=$?
|
||||
[ "$rc" -eq 0 ] && [ -z "$iro" ]; check "reserved: coord-inbox serves _broadcast nothing and still exits 0" $?
|
||||
|
||||
# 22. Identity is DERIVED, never INVENTED. The pwd fallback existed so the CLI
|
||||
# would work anywhere, but "anywhere" includes every global surface: a session
|
||||
# in ~/repos is not a repo, and basename(pwd) silently hands it the identity
|
||||
# "repos" - a real delivery arrived under exactly that name. A wrong identity is
|
||||
# worse than no identity, because it addresses a mailbox that belongs to nobody
|
||||
# and reads one that may belong to someone. git toplevel or an explicit flag are
|
||||
# the only two sources; the write paths refuse without one, and the read path
|
||||
# declines silently because the hook must never fail a session.
|
||||
NG="$(cd "$(mktemp -d)" && pwd -P)"
|
||||
ngo="$( (cd "$NG" && "$SEND" --to ngrepo --subject s --message "NOGIT-BODY" </dev/null) 2>&1 )"; rc=$?
|
||||
[ "$rc" -eq 2 ]; check "identity: send outside a git repo refuses instead of inventing a sender" $?
|
||||
printf '%s' "$ngo" | grep -q -- '--from'; check "identity: the refusal names --from as the way to choose an identity" $?
|
||||
[ ! -d "$CLAUDE_COORD_DIR/$(basename "$NG")" ]; check "identity: no mailbox is created under the cwd basename" $?
|
||||
ngok="$( (cd "$NG" && "$SEND" --to ngrepo --from explicit-id --subject s --message "NOGIT-OK" </dev/null) 2>&1 )"; rc=$?
|
||||
[ "$rc" -eq 0 ]; check "identity: an explicit --from still works outside a git repo" $?
|
||||
ngi="$( (cd "$NG" && "$INBOX") 2>/dev/null )"; rc=$?
|
||||
[ "$rc" -eq 0 ] && [ -z "$ngi" ]; check "identity: read outside a git repo is a silent no-op, never a failure" $?
|
||||
ngd="$( (cd "$NG" && "$DONE" --all) 2>&1 )"; rc=$?
|
||||
[ "$rc" -eq 2 ]; check "identity: coord-done outside a git repo refuses instead of guessing" $?
|
||||
|
||||
# 23. Repo identity is basename(git toplevel), so two checkouts with the same
|
||||
# basename at different paths SHARE one mailbox and each reads the other's
|
||||
# directed messages. Renaming the identity scheme would break every existing
|
||||
# mailbox and the human-readable `--to <repo>` addressing, so the mailbox
|
||||
# records which path claimed the name and the read path SAYS SO when a different
|
||||
# path shows up. A warning, not a refusal: the same repo moved or re-cloned is
|
||||
# the common case, and refusing would break it. The warning goes in the
|
||||
# INJECTION rather than on stderr because the hook discards stderr - a warning
|
||||
# nobody can see is not a warning.
|
||||
C1="$(cd "$(mktemp -d)" && pwd -P)"; C2="$(cd "$(mktemp -d)" && pwd -P)"
|
||||
mkdir -p "$C1/twin" "$C2/twin"
|
||||
git -C "$C1/twin" init -q >/dev/null 2>&1
|
||||
git -C "$C2/twin" init -q >/dev/null 2>&1
|
||||
"$SEND" --to twin --from tester --subject s --message "TWIN-BODY" >/dev/null
|
||||
t1="$( (cd "$C1/twin" && "$INBOX") 2>/dev/null )"
|
||||
printf '%s' "$t1" | grep -q 'TWIN-BODY'; check "collision: the first repo reads its mailbox normally" $?
|
||||
[ "$(printf '%s' "$t1" | grep -c 'MAILBOX COLLISION')" -eq 0 ]; check "collision: the owning repo is not warned about itself" $?
|
||||
[ "$(cat "$CLAUDE_COORD_DIR/twin/.origin" 2>/dev/null)" = "$C1/twin" ]; check "collision: the first git-derived read records the claiming path" $?
|
||||
t2="$( (cd "$C2/twin" && "$INBOX") 2>/dev/null )"
|
||||
printf '%s' "$t2" | grep -q 'MAILBOX COLLISION'; check "collision: a different path with the same basename is warned in the injection" $?
|
||||
printf '%s' "$t2" | grep -q "$C1/twin"; check "collision: the warning names the path that claimed the mailbox" $?
|
||||
[ "$(cat "$CLAUDE_COORD_DIR/twin/.origin" 2>/dev/null)" = "$C1/twin" ]; check "collision: the interloper does not steal the claim" $?
|
||||
|
||||
# 24. A broadcast is marked delivered INSIDE the read loop, but the injection is
|
||||
# printed only at the very end. Everything between those two points is a window
|
||||
# where the seen set says "delivered" and the operator saw nothing - and the
|
||||
# hook runs this script under `timeout: 10`, so the window is reachable, not
|
||||
# theoretical. A lost broadcast is unrecoverable by design: the seen set is
|
||||
# delivery history and retraction deliberately does not touch it. Recording
|
||||
# delivery AFTER the write makes the failure mode redelivery instead of loss.
|
||||
# The body is padded past the 64KB pipe buffer so the truncated read blocks in
|
||||
# printf and dies there deterministically, rather than racing the consumer.
|
||||
big="$(awk 'BEGIN{for(i=0;i<5000;i++) print "PIPE-FILLER-0123456789012345678901234567890123456789"}')"
|
||||
"$SEND" --broadcast --from bigsender --subject "big" --message "$big" >/dev/null
|
||||
bigbc="$(basename "$(ls "$CLAUDE_COORD_DIR"/_broadcast/inbox/*-from-bigsender.md 2>/dev/null | head -1)")"
|
||||
SEENF="$CLAUDE_COORD_DIR/_broadcast/seen/pipe-reader"
|
||||
"$INBOX" --repo pipe-reader 2>/dev/null | head -c 100 >/dev/null
|
||||
if grep -Fxq "$bigbc" "$SEENF" 2>/dev/null; then srv=1; else srv=0; fi
|
||||
[ "$srv" -eq 0 ]; check "seen: a broadcast whose injection never reached the consumer is not marked delivered" $?
|
||||
printf '%s' "$("$INBOX" --repo pipe-reader 2>/dev/null)" | grep -q 'PIPE-FILLER'; check "seen: that broadcast is redelivered on the next read" $?
|
||||
grep -Fxq "$bigbc" "$SEENF" 2>/dev/null; check "seen: a read that completed does record delivery" $?
|
||||
[ "$(printf '%s' "$("$INBOX" --repo pipe-reader 2>/dev/null)" | grep -c 'PIPE-FILLER')" -eq 0 ]; check "seen: a recorded broadcast is not delivered twice" $?
|
||||
|
||||
echo "----"
|
||||
echo "PASS=$PASS FAIL=$FAIL"
|
||||
[ "$FAIL" -eq 0 ]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue