diff --git a/CHANGELOG.md b/CHANGELOG.md index d0e464692..81f3e4bd6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 payload is unchanged. Under `--quiet` the audit now skips its queries entirely rather than running them to discard the output. +- **Actor matching decodes an exact `--` run to `/` instead of collapsing it to + a generic separator** (be-p7dzx, bundled be-vc51). Identity comparison — used + by `ExpectedAssignee` on release and update, and by claim/close/unclaim + authorization — canonicalizes a run of `.`, `_` or `-` to one separator so the + same identity spelled under different layers' conventions compares equal. An + exact two-byte `--` run is now excluded from that collapse: it is gascity's + session-name encoding of a rig-qualified agent's `/`, so it decodes to `/`. + **Compatibility:** `gastown--mayor` now matches `gastown/mayor`, and stops + matching `gastown__mayor` and `gastown-mayor`. That is the intended fix rather + than a side effect — `gastown--mayor` is the agent `mayor` on rig `gastown` + while `gastown__mayor` is the dotted alias `gastown.mayor`, so matching them + was a widening — but any stored `--` spelling that is NOT a gascity slash + encoding changes equivalence class silently, with no error to notice. Longer + or mixed runs, `__` and `---` included, are unaffected and still collapse. + ### Fixed - **Disabling telemetry no longer strands the queued eventsData backlog diff --git a/backend/conformance/releaser_contract.go b/backend/conformance/releaser_contract.go index a7f551cc1..ea702e6e9 100644 --- a/backend/conformance/releaser_contract.go +++ b/backend/conformance/releaser_contract.go @@ -214,6 +214,11 @@ func RunReleaserRefusesAForeignClaimUntilForced(t *testing.T, ctx context.Contex // SEPARATOR-INSENSITIVE AND NOTHING ELSE (canonicalActor, ga-5ksp5): a run of // ".", "_" or "-" matches any other such run, so an expectation spelled under // one layer's separator convention releases a claim stored under another's. +// The one exception is an exact "--" run: it is gascity's encoding of a +// rig-qualified agent's "/" and decodes to "/", so "a--b" matches "a/b" and +// not "a__b" (ga-2vy9p2). This tier does not pin that limb — the respelling +// exercised below is "-" -> "_", which is unaffected — but the contract text +// must not claim a rule the implementation no longer has. // NOTHING ELSE IS FORGIVEN, and the padded limb is the half that says so: an // implementation that reached for strings.TrimSpace to make the respelled limb // pass would release on an expectation the caller never actually held. diff --git a/internal/httpapi/apigen/types.gen.go b/internal/httpapi/apigen/types.gen.go index c799eea7f..94499c0c7 100644 --- a/internal/httpapi/apigen/types.gen.go +++ b/internal/httpapi/apigen/types.gen.go @@ -1610,7 +1610,7 @@ type ReleaseIssueRequest struct { // // A MATCH REPLACES THE OWNERSHIP FENCE, so `actor` need not be the holder. Sending it beside `force` is a 400: the two are answers to the same question and they disagree. // - // THE COMPARISON IS SEPARATOR-INSENSITIVE AND NOTHING ELSE. A run of `.`, `_` or `-` matches any other such run, so `agent-a`, `agent_a` and `agent.a` are one holder — that is deliberate, so a caller naming the holder under a different layer's spelling is a match rather than a mismatch. NOTHING ELSE IS FORGIVEN: the value is not trimmed and not case-folded, so `" agent-a"` and `Agent-a` are both refusals. The server trims only far enough to tell a blank expectation from a real one and never sends the trimmed form on, so a caller that pads its expectation loses EVERY time rather than intermittently. Compose it from a holder a read gave you. + // THE COMPARISON IS SEPARATOR-INSENSITIVE AND NOTHING ELSE. A run of `.`, `_` or `-` matches any other such run, so `agent-a`, `agent_a` and `agent.a` are one holder — that is deliberate, so a caller naming the holder under a different layer's spelling is a match rather than a mismatch. THE ONE EXCEPTION IS AN EXACT `--` RUN: that is gascity's session-name encoding of a rig-qualified agent's `/`, so it decodes to `/` instead of collapsing. `a--b` matches `a/b`, and no longer matches `a__b` or `a-b`. Those name different identities — `a--b` is the agent `b` on rig `a`, `a__b` is the dotted alias `a.b` — so treating them as one holder was a widening, and removing it is the point of the exception. Longer or mixed runs, `__` included, still collapse. NOTHING ELSE IS FORGIVEN: the value is not trimmed and not case-folded, so `" agent-a"` and `Agent-a` are both refusals. The server trims only far enough to tell a blank expectation from a real one and never sends the trimmed form on, so a caller that pads its expectation loses EVERY time rather than intermittently. Compose it from a holder a read gave you. // // THE EMPTY STRING IS A 400, and this is the one place this member disagrees with `UpdateIssueRequest.expected_assignee`, where an empty string is a real guard meaning "expected unassigned". Here "release a row nobody holds" describes no release at all; a caller that wants to assert a row is unheld is asking a READER a question, not asking this operation to do nothing. Absent, and only absent, selects the unconditional path. // diff --git a/internal/httpapi/spec/openapi.v0.yaml b/internal/httpapi/spec/openapi.v0.yaml index 0400718f8..083823133 100644 --- a/internal/httpapi/spec/openapi.v0.yaml +++ b/internal/httpapi/spec/openapi.v0.yaml @@ -9493,7 +9493,14 @@ components: A run of `.`, `_` or `-` matches any other such run, so `agent-a`, `agent_a` and `agent.a` are one holder — that is deliberate, so a caller naming the holder under a different layer's spelling is a - match rather than a mismatch. NOTHING ELSE IS FORGIVEN: the value + match rather than a mismatch. THE ONE EXCEPTION IS AN EXACT `--` + RUN: that is gascity's session-name encoding of a rig-qualified + agent's `/`, so it decodes to `/` instead of collapsing. `a--b` + matches `a/b`, and no longer matches `a__b` or `a-b`. Those name + different identities — `a--b` is the agent `b` on rig `a`, `a__b` + is the dotted alias `a.b` — so treating them as one holder was a + widening, and removing it is the point of the exception. Longer or + mixed runs, `__` included, still collapse. NOTHING ELSE IS FORGIVEN: the value is not trimmed and not case-folded, so `" agent-a"` and `Agent-a` are both refusals. The server trims only far enough to tell a blank expectation from a real one and never sends the trimmed form on, so diff --git a/internal/storage/dolt/claim_verify.go b/internal/storage/dolt/claim_verify.go index af375d798..1096892a6 100644 --- a/internal/storage/dolt/claim_verify.go +++ b/internal/storage/dolt/claim_verify.go @@ -9,6 +9,7 @@ import ( "go.opentelemetry.io/otel/metric" "github.com/steveyegge/beads/internal/storage" + storageissueops "github.com/steveyegge/beads/internal/storage/issueops" "github.com/steveyegge/beads/internal/types" ) @@ -56,11 +57,18 @@ func claimedBy(actor string) claimPostcondition { // claimedAs is claimedBy for a claim whose request overrides the assignee or // status the bare claim would have written. +// +// The assignee check is identity-equivalence (storageissueops.ActorMatches), +// not byte equality: the claim CAS treats a reclaim under a different +// spelling of the actor it already holds as idempotent and authorizes it +// without rewriting the stored spelling (ClaimIssueInTx's idempotent-reclaim +// branch), so verify must recognize that same identity or it fails loudly on +// a write the CAS legitimately authorized (be-vc51, ga-2vy9p2). func claimedAs(assignee string, status types.Status) claimPostcondition { return claimPostcondition{ op: "claim", want: func(gotAssignee string, gotStatus types.Status) bool { - return gotAssignee == assignee && gotStatus == status + return storageissueops.ActorMatches(gotAssignee, assignee) && gotStatus == status }, desc: fmt.Sprintf("assignee=%q status=%q", assignee, status), } @@ -112,7 +120,11 @@ func guardedUpdatePostcondition(opts storage.UpdateIssueOptions, updates map[str return claimPostcondition{ op: "guarded-update", want: func(assignee string, status types.Status) bool { - if setsAssignee && assignee != newAssignee { + // Identity-equivalence, not byte equality — same reason as + // claimedAs above: a coordination write that sets assignee to a + // respelling of an identity must verify against that identity, + // not the exact spelling requested (be-vc51, ga-2vy9p2). + if setsAssignee && !storageissueops.ActorMatches(assignee, newAssignee) { return false } if setsStatus && status != types.Status(newStatus) { diff --git a/internal/storage/dolt/claim_verify_test.go b/internal/storage/dolt/claim_verify_test.go index 8f15d04a7..4bc056e13 100644 --- a/internal/storage/dolt/claim_verify_test.go +++ b/internal/storage/dolt/claim_verify_test.go @@ -256,3 +256,36 @@ func TestClaimUnclaimVerifiedEndToEnd(t *testing.T) { t.Fatalf("post-unclaim state: assignee=%q status=%q", assignee, status) } } + +// TestClaimVerifyAcceptsRespelledReclaim proves the claim CAS's +// idempotent-reclaim branch (issueops.ClaimIssueInTx: same actor, +// already in_progress, succeeds without rewriting the stored spelling) does +// not then fail its own verify-after-write re-read when the reclaim names the +// held identity under a different spelling (be-vc51, ga-2vy9p2). Without the +// fix, claimedAs's postcondition compares the re-read assignee to the +// requested spelling byte-for-byte, so a CAS-authorized respelled reclaim +// fails loudly with "did not land" even though it holds the issue. +func TestClaimVerifyAcceptsRespelledReclaim(t *testing.T) { + s, cleanup := setupTestStore(t) + defer cleanup() + ctx, cancel := testContext(t) + defer cancel() + s.serverMode = true + + id := claimVerifyTestIssue(t, s) + if err := rawClaim(t, s, id, "gastown__mayor"); err != nil { + t.Fatalf("seed claim under one spelling: %v", err) + } + + if err := s.ClaimIssue(ctx, id, "gastown.mayor"); err != nil { + t.Fatalf("respelled reclaim: %v", err) + } + + assignee, status, err := s.readClaimState(ctx, id) + if err != nil { + t.Fatalf("read claim state: %v", err) + } + if assignee != "gastown__mayor" || status != types.StatusInProgress { + t.Fatalf("respelled reclaim must keep the stored spelling: assignee=%q status=%q", assignee, status) + } +} diff --git a/internal/storage/dolt/issue_operations_claim_verify_test.go b/internal/storage/dolt/issue_operations_claim_verify_test.go index 32b574d54..626b53ec6 100644 --- a/internal/storage/dolt/issue_operations_claim_verify_test.go +++ b/internal/storage/dolt/issue_operations_claim_verify_test.go @@ -99,6 +99,37 @@ func TestIssueOperationsClaimVerifyPostcondition(t *testing.T) { holds: [][2]string{{"carol", "open"}, {"carol", "in_progress"}}, rejects: [][2]string{{"bob", "open"}}, }, + { + // be-vc51/ga-2vy9p2: the CAS authorizes a reclaim under a + // different spelling of the same identity without rewriting the + // stored spelling (issueops.ClaimIssueInTx's idempotent-reclaim + // branch), so the postcondition must recognize the stored + // spelling as the same actor rather than requiring a byte-exact + // match against the requested one — and must still reject a + // genuinely different identity (gastown.dog-3) or a widened + // cross-axis spelling (gastown--mayor, the rig-qualified slash + // axis, is not gastown__mayor, the dot axis). + name: "bare claim accepts a respelled identity of the same actor (ga-2vy9p2)", + request: publicops.UpdateRequest{Actor: "gastown.mayor", IssueID: "bd-1", Claim: true}, + wantVerified: true, + wantDesc: `assignee="gastown.mayor" status="in_progress"`, + holds: [][2]string{{"gastown.mayor", "in_progress"}, {"gastown__mayor", "in_progress"}}, + rejects: [][2]string{{"gastown--mayor", "in_progress"}, {"gastown.dog-3", "in_progress"}, {"someone-else", "in_progress"}}, + }, + { + // Same asymmetry as above, at the guarded-update site + // (claim_verify.go's guardedUpdatePostcondition): a coordination + // write that sets assignee to a respelling of an identity must + // verify against identity equivalence, not byte equality. + name: "guarded assignee transfer accepts a respelled identity of the written value (ga-2vy9p2)", + request: publicops.UpdateRequest{Actor: "alice", IssueID: "bd-1", ExpectedAssignee: assignee("bob"), Patch: publicops.IssuePatch{ + Assignee: publicops.Field[string]{Set: true, Value: "gastown.mayor"}, + }}, + wantVerified: true, + wantDesc: `assignee="gastown.mayor"`, + holds: [][2]string{{"gastown.mayor", "open"}, {"gastown__mayor", "in_progress"}}, + rejects: [][2]string{{"gastown--mayor", "open"}, {"bob", "open"}}, + }, { name: "guarded status write", request: publicops.UpdateRequest{Actor: "alice", IssueID: "bd-1", ExpectedStatus: status(types.StatusOpen), Patch: publicops.IssuePatch{ diff --git a/internal/storage/issueops/identity.go b/internal/storage/issueops/identity.go index ccac9a240..6c926df5a 100644 --- a/internal/storage/issueops/identity.go +++ b/internal/storage/issueops/identity.go @@ -11,11 +11,32 @@ import "strings" // string, never the substitution itself (ga-wzl83). None of ".", "_", "-" // carries meaning in an identity string: each is always a positional // separator between a rig and a role/agent name, never part of either name. -// Collapsing any run of them to one canonical separator lets two spellings -// of the same identity compare equal without weakening comparisons between +// Collapsing a run of them to one canonical separator lets two spellings of +// the same identity compare equal without weakening comparisons between // genuinely different identities, whose non-separator characters still // differ (e.g. "gastown.mayor" vs "gastown.dog-3" stay distinct). // +// A run that is the exact two-byte sequence "--" is a second, distinct axis: +// gascity's session-name encoding (session_name.go) substitutes "--" for a +// rig-qualified agent's "/" — a DIFFERENT identity from one substituting "_" +// or "__" for a dotted alias's "." — so it decodes to a literal "/" instead +// of collapsing into the generic "_" separator (ga-2vy9p2). Any other run, +// including "__" and longer or mixed runs, still collapses to "_": those +// keep meaning nothing but "here was some separator". A raw "/" already +// passes through unchanged (it hits the default case below), which is what +// makes the "--" decode land on the same canonical form: "gastown/mayor" and +// "gastown--mayor" both canonicalize to "gastown/mayor", while +// "gastown--mayor" and "gastown__mayor" no longer collapse to the same +// value — collapsing them was a real widening: "gastown--mayor" is a +// rig-qualified agent named "mayor", "gastown__mayor" is a dotted alias +// "gastown.mayor"; treating them as the same actor was wrong regardless of +// whether either happens to be held by the same principal today. +// +// Byte-scanned rather than rune-scanned so a 2-byte lookahead can detect an +// exact "--" run: safe because '.', '_', '-' are single-byte ASCII that never +// appear as a continuation byte of a multi-byte UTF-8 rune, so slicing on +// them cannot split one. +// // Empty stays empty: an actual absence of an actor must never canonicalize // to the same value as a non-empty one, or a caller comparing against an // unassigned issue would start matching everyone. @@ -32,18 +53,24 @@ func canonicalActor(s string) string { } var b strings.Builder b.Grow(len(s)) - inSeparator := false - for _, r := range s { - switch r { - case '.', '_', '-': - if !inSeparator { - b.WriteByte('_') - inSeparator = true + i := 0 + for i < len(s) { + c := s[i] + if c == '.' || c == '_' || c == '-' { + j := i + for j < len(s) && (s[j] == '.' || s[j] == '_' || s[j] == '-') { + j++ } - default: - b.WriteRune(r) - inSeparator = false + if s[i:j] == "--" { + b.WriteByte('/') + } else { + b.WriteByte('_') + } + i = j + continue } + b.WriteByte(c) + i++ } return b.String() } diff --git a/internal/storage/issueops/identity_parity_test.go b/internal/storage/issueops/identity_parity_test.go index 189272ebf..98470ea45 100644 --- a/internal/storage/issueops/identity_parity_test.go +++ b/internal/storage/issueops/identity_parity_test.go @@ -36,6 +36,9 @@ func TestIdentityCanonicalizationParityWithValidation(t *testing.T) { {name: "mixed separators each collapse to one canonical separator", in: "gastown.dog-3"}, {name: "leading separator is preserved as a separator, not dropped", in: ".mayor"}, {name: "trailing separator is preserved as a separator, not dropped", in: "mayor."}, + {name: "exact double-hyphen separator decodes to the rig-qualified slash (ga-2vy9p2)", in: "gastown--mayor"}, + {name: "raw slash passes through unchanged", in: "gastown/mayor"}, + {name: "a hyphen run longer than two is not the exact slash spelling and falls back to generic collapse", in: "gastown---mayor"}, } for _, tc := range canonicalCases { t.Run("CanonicalActor/"+tc.name, func(t *testing.T) { @@ -57,6 +60,9 @@ func TestIdentityCanonicalizationParityWithValidation(t *testing.T) { {name: "genuinely different identities do not match", assignee: "gastown.mayor", actor: "gastown.dog-3"}, {name: "both empty match", assignee: "", actor: ""}, {name: "empty assignee never matches a non-empty actor", assignee: "", actor: "mayor"}, + {name: "double-hyphen and double-underscore spellings no longer widen to the same identity (ga-2vy9p2)", assignee: "gastown--mayor", actor: "gastown__mayor"}, + {name: "double-hyphen spelling matches its raw-slash identity (ga-2vy9p2)", assignee: "gastown--mayor", actor: "gastown/mayor"}, + {name: "raw slash and raw dot stay genuinely distinct identities", assignee: "gastown/mayor", actor: "gastown.mayor"}, } for _, tc := range matchCases { t.Run("ActorMatches/"+tc.name, func(t *testing.T) { diff --git a/internal/validation/issue.go b/internal/validation/issue.go index e445cceb5..c59f4e4b2 100644 --- a/internal/validation/issue.go +++ b/internal/validation/issue.go @@ -80,11 +80,32 @@ func NotPinned(force bool) IssueValidator { // string, never the substitution itself (ga-wzl83). None of ".", "_", "-" // carries meaning in an identity string: each is always a positional // separator between a rig and a role/agent name, never part of either name. -// Collapsing any run of them to one canonical separator lets two spellings -// of the same identity compare equal without weakening comparisons between +// Collapsing a run of them to one canonical separator lets two spellings of +// the same identity compare equal without weakening comparisons between // genuinely different identities, whose non-separator characters still // differ (e.g. "gastown.mayor" vs "gastown.dog-3" stay distinct). // +// A run that is the exact two-byte sequence "--" is a second, distinct axis: +// gascity's session-name encoding (session_name.go) substitutes "--" for a +// rig-qualified agent's "/" — a DIFFERENT identity from one substituting "_" +// or "__" for a dotted alias's "." — so it decodes to a literal "/" instead +// of collapsing into the generic "_" separator (ga-2vy9p2). Any other run, +// including "__" and longer or mixed runs, still collapses to "_": those +// keep meaning nothing but "here was some separator". A raw "/" already +// passes through unchanged (it hits the default case below), which is what +// makes the "--" decode land on the same canonical form: "gastown/mayor" and +// "gastown--mayor" both canonicalize to "gastown/mayor", while +// "gastown--mayor" and "gastown__mayor" no longer collapse to the same +// value — collapsing them was a real widening: "gastown--mayor" is a +// rig-qualified agent named "mayor", "gastown__mayor" is a dotted alias +// "gastown.mayor"; treating them as the same actor was wrong regardless of +// whether either happens to be held by the same principal today. +// +// Byte-scanned rather than rune-scanned so a 2-byte lookahead can detect an +// exact "--" run: safe because '.', '_', '-' are single-byte ASCII that never +// appear as a continuation byte of a multi-byte UTF-8 rune, so slicing on +// them cannot split one. +// // Empty stays empty: an actual absence of an actor must never canonicalize // to the same value as a non-empty one, or AssigneeMatches would start // accepting an empty actor against an assigned issue. @@ -94,18 +115,24 @@ func CanonicalActor(s string) string { } var b strings.Builder b.Grow(len(s)) - inSeparator := false - for _, r := range s { - switch r { - case '.', '_', '-': - if !inSeparator { - b.WriteByte('_') - inSeparator = true + i := 0 + for i < len(s) { + c := s[i] + if c == '.' || c == '_' || c == '-' { + j := i + for j < len(s) && (s[j] == '.' || s[j] == '_' || s[j] == '-') { + j++ } - default: - b.WriteRune(r) - inSeparator = false + if s[i:j] == "--" { + b.WriteByte('/') + } else { + b.WriteByte('_') + } + i = j + continue } + b.WriteByte(c) + i++ } return b.String() } diff --git a/internal/validation/issue_test.go b/internal/validation/issue_test.go index d75f5d04b..8139f987c 100644 --- a/internal/validation/issue_test.go +++ b/internal/validation/issue_test.go @@ -159,6 +159,9 @@ func TestCanonicalActor(t *testing.T) { {name: "mixed separators each collapse to one canonical separator", in: "gastown.dog-3", want: "gastown_dog_3"}, {name: "leading separator is preserved as a separator, not dropped", in: ".mayor", want: "_mayor"}, {name: "trailing separator is preserved as a separator, not dropped", in: "mayor.", want: "mayor_"}, + {name: "exact double-hyphen separator decodes to the rig-qualified slash (ga-2vy9p2)", in: "gastown--mayor", want: "gastown/mayor"}, + {name: "raw slash passes through unchanged", in: "gastown/mayor", want: "gastown/mayor"}, + {name: "a hyphen run longer than two is not the exact slash spelling and falls back to generic collapse", in: "gastown---mayor", want: "gastown_mayor"}, } for _, tt := range tests { @@ -182,6 +185,9 @@ func TestActorMatches(t *testing.T) { {name: "genuinely different identities do not match", assignee: "gastown.mayor", actor: "gastown.dog-3", want: false}, {name: "both empty match", assignee: "", actor: "", want: true}, {name: "empty assignee never matches a non-empty actor", assignee: "", actor: "mayor", want: false}, + {name: "double-hyphen and double-underscore spellings no longer widen to the same identity (ga-2vy9p2)", assignee: "gastown--mayor", actor: "gastown__mayor", want: false}, + {name: "double-hyphen spelling matches its raw-slash identity (ga-2vy9p2)", assignee: "gastown--mayor", actor: "gastown/mayor", want: true}, + {name: "raw slash and raw dot stay genuinely distinct identities", assignee: "gastown/mayor", actor: "gastown.mayor", want: false}, } for _, tt := range tests { diff --git a/issueops/issueops.go b/issueops/issueops.go index 63107540b..8784bc24d 100644 --- a/issueops/issueops.go +++ b/issueops/issueops.go @@ -288,7 +288,9 @@ type UpdateRequest struct { // // THE COMPARISON IS SEPARATOR-INSENSITIVE, exactly as // ReleaseRequest.ExpectedAssignee documents: a run of ".", "_" or "-" - // matches any other such run, and nothing else is forgiven. + // matches any other such run — except an exact "--" run, which decodes to + // "/" as gascity's rig-qualified agent encoding, so "a--b" matches "a/b" + // rather than "a__b" — and nothing else is forgiven. ExpectedAssignee *string // ExpectedStatus requires the current status to match. It must be nil when // Claim is true. diff --git a/issueops/releaser.go b/issueops/releaser.go index c8fd42529..608547c49 100644 --- a/issueops/releaser.go +++ b/issueops/releaser.go @@ -55,7 +55,14 @@ type ReleaseRequest struct { // "_" or "-" matches any other such run, so "agent-a", "agent_a" and // "agent.a" are one holder — that is deliberate, so a caller naming the // holder under a different layer's spelling is a match rather than a - // mismatch (ga-5ksp5). NOTHING ELSE IS FORGIVEN: the value is not trimmed + // mismatch (ga-5ksp5). THE ONE EXCEPTION IS AN EXACT "--" RUN: that is + // gascity's session-name encoding of a rig-qualified agent's "/", so it + // decodes to "/" rather than collapsing. "a--b" matches "a/b" and no + // longer matches "a__b" or "a-b" — "a--b" is the agent "b" on rig "a" + // while "a__b" is the dotted alias "a.b", so treating them as one holder + // was a widening, and removing it is the point of the exception + // (ga-2vy9p2). Longer or mixed runs, "__" included, still collapse. + // NOTHING ELSE IS FORGIVEN: the value is not trimmed // and not case-folded, so " agent-a" and "Agent-a" are both refusals. The // validation below trims only far enough to tell a blank expectation from a // real one, and never writes the trimmed form back — the no-mutation