diff --git a/docs/normative/trace-context/v1/README.md b/docs/normative/trace-context/v1/README.md index a215698bf4..0dd72de61e 100644 --- a/docs/normative/trace-context/v1/README.md +++ b/docs/normative/trace-context/v1/README.md @@ -18,8 +18,8 @@ identity components. | Installation | 128-bit ID provisioned with the signing key pair | same | same | | Forge instance | web base URL (`https://github.com`, or a GHES host) | web base URL (`https://gitlab.com`, or a self-hosted host) | site base URL | | Container | repository `id`; for a PR, the base repository, never the fork | project `id`; for an MR, the target project, never the fork | project `id` | -| Entity kind | `work_item` (issue), `change_proposal` (PR) | `work_item` (issue), `change_proposal` (MR) | `work_item` (issue; Jira has no change proposal) | -| Entity | `work_item`: issue REST `id`; `change_proposal`: pull-request REST `id` = GraphQL `fullDatabaseId` (`BigInt`), never the issue-space ID | issue or MR database `id` (not the IID) | issue `id` | +| Entity kind | `work_item` (issue), `change_proposal` (PR), `conversation` (Discussion) | `work_item` (issue), `change_proposal` (MR); no conversation | `work_item` (issue; Jira has no change proposal or conversation) | +| Entity | `work_item`: issue REST `id`; `change_proposal`: pull-request REST `id` = GraphQL `fullDatabaseId` (`BigInt`), never the issue-space ID; `conversation`: Discussion database `id` = GraphQL `databaseId`, never the node ID | issue or MR database `id` (not the IID) | issue `id` | A GitHub PR has both a pull-request ID and a different issue-space ID. The `change_proposal` identity must use the pull-request ID from @@ -32,6 +32,16 @@ object, resolve the pull-request ID through a trusted forge-adapter read succeeds, keep the identity unresolved rather than substituting the issue-space ID or display number. +A GitHub Discussion is a `conversation`, never a `work_item` or +`change_proposal`, even though Discussions share the repository's display +number sequence with issues and PRs. Its entity component is the Discussion +database ID carried as `discussion.id` in `discussion` and +`discussion_comment` webhook payloads, also exposed as GraphQL `databaseId`; +its container is the repository `id`. The GraphQL node ID and the Discussion +number are not identity components. Until a trusted read yields that +database ID, the conversation identity stays unresolved. GitLab and Jira +entities never use the `conversation` kind. + The instance string is the normalized, trusted deployment base URL: lowercase `scheme://host`, using `http` or `https`, followed by the case-sensitive, URL-escaped deployment path prefix, with trailing slashes removed. For @@ -90,6 +100,9 @@ traces regardless of key state. ID — and therefore a new identity. A previously published envelope fails the binding check and the moved entity falls back. A move is never treated as a rename. +- Converting a GitHub issue to a Discussion, or a Discussion to an issue, + changes the entity kind and is therefore a new binding, even if a + database ID were reused; published envelopes fail the binding check. - Changing the configured deployment URL (a Jira site rename, a GHES hostname change, a GitLab `external_url` change) is also a new binding: published envelopes fail the binding check and entities fall back. @@ -108,7 +121,8 @@ The derivation is: `uint16(33) || "fullsend.tracecontext.identity.v1" || uint16(N) || instance[N] || uint64(container) || byte(kind) || uint64(entity)`. `N` counts UTF-8 bytes, container/entity are in `[1, 2^63−1]`, and kind - is `0x01` (work item) or `0x02` (change proposal). + is `0x01` (work item), `0x02` (change proposal), or `0x03` + (conversation). - TraceID = the first 16 digest bytes; the anchor SpanID = the next 8. - An all-zero result (probability 2⁻¹²⁸ for the trace, 2⁻⁶⁴ for the span) replaces only that ID's final byte with `0x01`, so derived IDs are valid. @@ -131,6 +145,9 @@ For `https://github.com`, container `274390431`, kind `0x01`, and entity Concatenate those hex lines before hashing. The TraceID is `c9bdb0e38247ebbe2e0f1039250c32d4`; the anchor is `892a346c55356aca`. +The same binding with kind `0x03` (a GitHub conversation) changes only that +kind byte and derives TraceID `bf80a0459b29786a2dfd3f544de477af` and anchor +`f9428a9e85988c3e`. Additional independent GitLab/Jira vectors and an SDK exporter lifecycle test are linked from the [implementation reference](../../../reference/trace-context.md). @@ -150,7 +167,7 @@ the magic through the nonce — there are no unsigned fields. | 30 | 2 | Instance length N | `1 ≤ N ≤ 253` | | 32 | N | Forge instance | normalized form, UTF-8, no NUL | | 32+N | 8 | Container ID | `int64 ≥ 1` | -| 40+N | 1 | Entity kind | `0x01` work item, `0x02` change proposal | +| 40+N | 1 | Entity kind | `0x01` work item, `0x02` change proposal, `0x03` conversation | | 41+N | 8 | Entity ID | `int64 ≥ 1`; bound envelopes only — pending markers omit these 8 bytes, retaining the kind byte | | · | 16 | Trace ID | nonzero | | · | 8 | Parent/anchor Span ID | nonzero | @@ -259,7 +276,8 @@ fallback or guess. ## Compatibility The [conformance vectors](../../../reference/trace-context.md#conformance-evidence) -pin the exact signed bytes of one envelope per domain and provenance kind. +pin the exact signed bytes of one envelope per domain and provenance kind, +plus one bound `conversation` envelope. **v1 is provisional** until the first pull request that publishes carriers merges. No production carrier exists yet, so the wire layout, derivation, @@ -268,3 +286,9 @@ contract gaps surface in review. From the first carrier-publishing pull request onward, any such change is a compatibility break that requires a new version byte and a reviewed migration path. Unknown versions must reject cleanly. + +The `conversation` kind (`0x03`) was added to v1 under this provision, +before any carrier was published. It defines a new kind byte value only: the +derivation input, wire bytes, and conformance vectors of existing +`work_item` and `change_proposal` identities are unchanged, so their +derived and stored contexts stay valid. diff --git a/docs/reference/trace-context.md b/docs/reference/trace-context.md index ddec2d2b2c..c22f12a794 100644 --- a/docs/reference/trace-context.md +++ b/docs/reference/trace-context.md @@ -45,11 +45,21 @@ trusted forge read, following the [identity contract](../normative/trace-context `GetPullRequestInfo` currently returns branch/repository context without that database ID; its result alone cannot resolve trace identity. +`KindConversation` identifies a GitHub Discussion by its repository ID and +Discussion database ID (webhook `discussion.id`, GraphQL `databaseId`). No +forge adapter reads Discussions yet: GitHub Discussion ingress is tracked +under the conversation-surface work for +[ADR 0086](../ADRs/0086-conversation-surface-for-agent-participation.md). +Until a trusted read supplies that database ID, the conversation identity +stays unresolved. The package cannot tell forges apart, so callers must +never construct `KindConversation` for GitLab or Jira entities. + ## Go API | Symbol | Purpose | |--------|---------| | `Identity` | The immutable binding tuple | +| `EntityKind` | `KindWorkItem`, `KindChangeProposal`, or `KindConversation` (GitHub Discussion) | | `Identity.Resolved` | Whether the forge-side components are present and valid: a canonical instance, IDs ≥ 1, and a defined kind | | `DeriveFallback` | The v1 deterministic fallback context | | `NormalizeInstance` | Canonical deployment base URL, including its path prefix | @@ -65,14 +75,17 @@ database ID; its result alone cannot resolve trace identity. ## Conformance evidence - [`identity_test.go`](https://github.com/fullsend-ai/fullsend/blob/main/internal/telemetry/tracecontext/identity_test.go) - contains independent fallback vectors, deployment-prefix separation checks, + contains independent fallback vectors (including a GitHub conversation), + conversation convergence and kind-separation checks, + deployment-prefix separation checks, cross-process convergence, root-dot, port, and IPv6 spelling canonicalization and zone rejection, mixed-escape path rejection, a normalization fuzz target asserting the canonical form re-normalizes to itself, and SDK exporter lifecycle assertions. - [`envelope_test.go`](https://github.com/fullsend-ai/fullsend/blob/main/internal/telemetry/tracecontext/envelope_test.go) contains independent signed-wire vectors for both domains and all provenance - kinds, binding checks, empty/default/padded-port convergence, zero-value fallback, + kinds plus a bound conversation envelope, conversation admission and + fallback, binding checks, empty/default/padded-port convergence, zero-value fallback, pending-scope admission (container-scoped markers, stale markers beside bound envelopes), unresolved identities suppressing every carrier kind, malformed-input cases, and parser fuzzing. diff --git a/internal/telemetry/tracecontext/envelope_test.go b/internal/telemetry/tracecontext/envelope_test.go index a812db75ef..4dc36b910c 100644 --- a/internal/telemetry/tracecontext/envelope_test.go +++ b/internal/telemetry/tracecontext/envelope_test.go @@ -268,6 +268,92 @@ func TestCrossBindingReplay(t *testing.T) { } } +// goldenConversationHex is the bound, no-provenance golden envelope with +// kind 0x03 (GitHub conversation); every other byte before the signature +// matches goldenBoundNoneHex. Independently constructed with Python struct +// + cryptography Ed25519; the same construction with kind 0x01 reproduces +// goldenBoundNoneHex. +const goldenConversationHex = "46535443010165b60673d6ed884ba0a1a2a3a4a5a6a7a8a9aaabacadaeaf001268747470733a2f2f6769746875622e636f6d00000000105add9f03000000009328a1a24f3a9c1b2d8e4a7c9f0b1e2d3c4a5b6da1b2c3d4e5f6071800101112131415161718191a1b1c1d1e1f8f818531da3fe5435756fde420aec3001d23d8266d3723194891aff293eb46c286ca92e261e0bc0fd639fdc1a0c70fbfc06870d834928f173a433ffd0be7fc05" + +func goldenConversationIdentity() Identity { + id := goldenIdentity() + id.Kind = KindConversation + return id +} + +// TestAdmit_ConversationIdentity covers trace identity carried and +// verified for a GitHub conversation: the wire vector, repeated launches, +// distinct conversations, kind separation from the existing kinds, and +// invalid or missing stored context falling back. +func TestAdmit_ConversationIdentity(t *testing.T) { + t.Parallel() + key, keys := goldenKeys(t) + want := mustHex(t, goldenConversationHex) + + env := goldenEnvelope(DomainBound, ProvenanceNone) + env.Kind = KindConversation + require.NoError(t, env.Sign(key)) + require.Equal(t, want, env.Marshal(), "conversation wire bytes differ from the conformance vector") + parsed, err := Parse(want) + require.NoError(t, err) + assert.Equal(t, env, parsed) + + // Repeated launches on one conversation admit the same context. + admitted := Result{Outcome: OutcomeAdmitted, TraceID: env.TraceID, ParentSpanID: env.ParentSpanID} + for range 2 { + assert.Equal(t, admitted, Admit(goldenConversationIdentity(), keys, want)) + } + + // A distinct conversation, or another kind with the same IDs, rejects + // the envelope; a work-item envelope never admits for a conversation. + other := goldenConversationIdentity() + other.Entity++ + assert.Equal(t, fallback(ReasonBindingMismatch), Admit(other, keys, want)) + other = goldenConversationIdentity() + other.Container++ + assert.Equal(t, fallback(ReasonBindingMismatch), Admit(other, keys, want)) + for _, kind := range []EntityKind{KindWorkItem, KindChangeProposal} { + other = goldenConversationIdentity() + other.Kind = kind + assert.Equal(t, fallback(ReasonBindingMismatch), Admit(other, keys, want), "kind %#02x", byte(kind)) + } + workItem, _ := signedGolden(t, DomainBound, ProvenanceNone) + assert.Equal(t, fallback(ReasonBindingMismatch), Admit(goldenConversationIdentity(), keys, workItem)) + + badSignature := bytes.Clone(want) + badSignature[len(badSignature)-1] ^= 0x01 + otherKey := ed25519.NewKeyFromSeed(bytes.Repeat([]byte{7}, ed25519.SeedSize)) + otherPub := otherKey.Public().(ed25519.PublicKey) + unresolved := goldenConversationIdentity() + unresolved.Entity = 0 + + for _, tc := range []struct { + name string + expected Identity + keys map[[8]byte]ed25519.PublicKey + candidates [][]byte + reason string + }{ + {"absent", goldenConversationIdentity(), keys, nil, ReasonAbsent}, + {"malformed", goldenConversationIdentity(), keys, [][]byte{want[:len(want)-1]}, ReasonMalformed}, + {"bad signature", goldenConversationIdentity(), keys, [][]byte{badSignature}, ReasonBadSignature}, + {"unknown key", goldenConversationIdentity(), map[[8]byte]ed25519.PublicKey{KeyID(otherPub): otherPub}, [][]byte{want}, ReasonUnknownKey}, + {"conflicting carrier", goldenConversationIdentity(), keys, [][]byte{want, workItem}, ReasonConflictingCarrier}, + {"unresolved", unresolved, keys, [][]byte{want}, ReasonUnresolved}, + } { + t.Run(tc.name, func(t *testing.T) { + assert.Equal(t, fallback(tc.reason), Admit(tc.expected, tc.keys, tc.candidates...)) + }) + } + + // A conversation-scoped pending marker grants only the pending wait. + pending := goldenEnvelope(DomainPending, ProvenanceNone) + pending.Kind = KindConversation + require.NoError(t, pending.Sign(key)) + assert.Equal(t, Result{Outcome: OutcomePending, Reason: ReasonPending}, Admit(goldenConversationIdentity(), keys, pending.Marshal())) + assert.Equal(t, fallback(ReasonBindingMismatch), Admit(goldenIdentity(), keys, pending.Marshal())) +} + func TestResult_ZeroValueFallsBack(t *testing.T) { t.Parallel() var result Result diff --git a/internal/telemetry/tracecontext/identity.go b/internal/telemetry/tracecontext/identity.go index 7e3e879f1a..7ebc81e0ef 100644 --- a/internal/telemetry/tracecontext/identity.go +++ b/internal/telemetry/tracecontext/identity.go @@ -22,8 +22,9 @@ import ( ) // EntityKind distinguishes the entity kinds that can share a forge -// container. GitLab issue and merge-request database IDs come from -// independent spaces, so the kind is part of every identity. +// container. GitLab issue and merge-request database IDs, and GitHub +// issue and Discussion database IDs, come from independent spaces, so the +// kind is part of every identity. type EntityKind byte const ( @@ -32,11 +33,15 @@ const ( // KindChangeProposal is a GitHub pull request or a GitLab merge // request. Jira has no change-proposal entity in this contract. KindChangeProposal EntityKind = 0x02 + // KindConversation is a GitHub Discussion. GitLab and Jira have no + // conversation entity in this contract. The package cannot tell + // forges apart, so callers must not construct this kind for them. + KindConversation EntityKind = 0x03 ) // Valid reports whether k is a defined entity kind. func (k EntityKind) Valid() bool { - return k == KindWorkItem || k == KindChangeProposal + return k == KindWorkItem || k == KindChangeProposal || k == KindConversation } // Identity is the immutable binding of a forge entity (ADR 0154, D01): diff --git a/internal/telemetry/tracecontext/identity_test.go b/internal/telemetry/tracecontext/identity_test.go index abbed0786e..d13a68b5c2 100644 --- a/internal/telemetry/tracecontext/identity_test.go +++ b/internal/telemetry/tracecontext/identity_test.go @@ -157,6 +157,56 @@ func TestDeriveFallback_IIDsAreNotIdentity(t *testing.T) { assert.NotEqual(t, fa, fb, "the same IID in another project is a different entity") } +// conversationIdentity is a resolved GitHub Discussion binding: the +// repository database ID and the Discussion database ID. +func conversationIdentity() Identity { + return Identity{Instance: "https://github.com", Container: 274390431, Kind: KindConversation, Entity: 7340001} +} + +// TestDeriveFallback_ConversationIdentity covers GitHub conversation +// identity: repeated launches on one Discussion converge, distinct +// Discussions (including the same ID under another repository) do not, +// and the kind keeps a conversation apart from a work item or change +// proposal that shares its numeric IDs. +func TestDeriveFallback_ConversationIdentity(t *testing.T) { + t.Parallel() + require.True(t, KindConversation.Valid()) + require.True(t, conversationIdentity().Resolved()) + + first, ok := DeriveFallback(conversationIdentity()) + require.True(t, ok) + again, ok := DeriveFallback(conversationIdentity()) + require.True(t, ok) + assert.Equal(t, first, again, "repeated launches on one Discussion must share a trace") + assert.True(t, first.TraceID.IsValid()) + assert.True(t, first.AnchorSpanID.IsValid()) + + other := conversationIdentity() + other.Entity++ + got, ok := DeriveFallback(other) + require.True(t, ok) + assert.NotEqual(t, first, got, "distinct Discussions must not share a trace") + + other = conversationIdentity() + other.Container++ + got, ok = DeriveFallback(other) + require.True(t, ok) + assert.NotEqual(t, first, got, "the same Discussion ID under another repository is a different entity") + + for _, kind := range []EntityKind{KindWorkItem, KindChangeProposal} { + other = conversationIdentity() + other.Kind = kind + got, ok = DeriveFallback(other) + require.True(t, ok) + assert.NotEqual(t, first, got, "kind %#02x must not alias a conversation", byte(kind)) + } + + unresolved := conversationIdentity() + unresolved.Entity = 0 + _, ok = DeriveFallback(unresolved) + assert.False(t, ok, "an unresolved Discussion ID must not derive a fallback") +} + // TestDeriveFallback_ConcurrentFirstEvents is V01: concurrent first events // converge on the same fallback. Run with -race. func TestDeriveFallback_ConcurrentFirstEvents(t *testing.T) { @@ -383,8 +433,10 @@ func TestDeriveFallback_FixedVectors(t *testing.T) { {Identity{Instance: "https://gitlab.com", Container: 101, Kind: KindChangeProposal, Entity: 555}, "002166756c6c73656e642e7472616365636f6e746578742e6964656e746974792e7631001268747470733a2f2f6769746c61622e636f6d000000000000006502000000000000022b", "407b66d9453075850f3ee7ef31d6ff1e", "a39491edef0440ae"}, {Identity{Instance: "https://acme.atlassian.net", Container: 10000, Kind: KindWorkItem, Entity: 10100}, "002166756c6c73656e642e7472616365636f6e746578742e6964656e746974792e7631001a68747470733a2f2f61636d652e61746c61737369616e2e6e65740000000000002710010000000000002774", "535e9f2c6d8bd8a814edd68dceb60e9a", "7e00bd92068701ac"}, {Identity{Instance: "https://gitlab.example.com/gitlab", Container: 101, Kind: KindChangeProposal, Entity: 555}, "002166756c6c73656e642e7472616365636f6e746578742e6964656e746974792e7631002168747470733a2f2f6769746c61622e6578616d706c652e636f6d2f6769746c6162000000000000006502000000000000022b", "71c6f9ad9a13f7244356f839e29687fa", "8f2d2a176bde1f88"}, + // GitHub conversation: the V01 binding with kind 0x03. + {Identity{Instance: "https://github.com", Container: 274390431, Kind: KindConversation, Entity: 2468913570}, "002166756c6c73656e642e7472616365636f6e746578742e6964656e746974792e7631001268747470733a2f2f6769746875622e636f6d00000000105add9f03000000009328a1a2", "bf80a0459b29786a2dfd3f544de477af", "f9428a9e85988c3e"}, } { - t.Run(tc.id.Instance, func(t *testing.T) { + t.Run(fmt.Sprintf("%s/kind-%d", tc.id.Instance, tc.id.Kind), func(t *testing.T) { digest := sha256.Sum256(mustHex(t, tc.preimage)) assert.Equal(t, tc.traceID, fmt.Sprintf("%x", digest[:16])) assert.Equal(t, tc.anchor, fmt.Sprintf("%x", digest[16:24]))