diff --git a/docs/ADRs/0017-credential-isolation-for-sandboxed-agents.md b/docs/ADRs/0017-credential-isolation-for-sandboxed-agents.md index 60aed52173..fc0ba88326 100644 --- a/docs/ADRs/0017-credential-isolation-for-sandboxed-agents.md +++ b/docs/ADRs/0017-credential-isolation-for-sandboxed-agents.md @@ -18,6 +18,9 @@ Date: 2026-04-01 Accepted (credential delivery tiers extended by [ADR 0025](0025-provider-credential-delivery-for-sandboxed-agents.md)) +The default prefetch model is standardized for handled entity content by +[ADR 0141](0141-deterministic-filtered-entity-context-staging.md). + ## Context When sandboxed agents need to perform operations requiring credentials (e.g. reading or writing GitHub issues), the credential must be kept away from the agent process. A compromised agent with access to a credential can exfiltrate it — once the credential leaves the sandbox, the attacker can use it without any sandbox constraints. diff --git a/docs/ADRs/0076-slash-command-entity-context-separation.md b/docs/ADRs/0076-slash-command-entity-context-separation.md index b4cdcab800..2a78da1e01 100644 --- a/docs/ADRs/0076-slash-command-entity-context-separation.md +++ b/docs/ADRs/0076-slash-command-entity-context-separation.md @@ -20,6 +20,11 @@ Accepted Extends entity-context rules for conversation surfaces in [ADR 0086](0086-conversation-surface-for-agent-participation.md). +Terminology note: this ADR uses *entity context* for a dispatch-layer routing +category. [ADR 0141](0141-deterministic-filtered-entity-context-staging.md) +later names the distinct filtered data snapshot staged for a handled Git-forge +entity *entity-context-snapshot*. + Refines [ADR 0002](0002-initial-fullsend-design.md) (initial design) and reinforces [ADR 0020](0020-composable-single-responsibility-agents-with-individual-sandboxes.md) (single-responsibility agents). diff --git a/docs/ADRs/0141-deterministic-filtered-entity-context-staging.md b/docs/ADRs/0141-deterministic-filtered-entity-context-staging.md new file mode 100644 index 0000000000..00c86ea48d --- /dev/null +++ b/docs/ADRs/0141-deterministic-filtered-entity-context-staging.md @@ -0,0 +1,177 @@ +--- +title: "141. Deterministic filtered entity-context-snapshot staging" +status: Accepted +relates_to: + - agent-architecture + - security-threat-model +topics: + - entity-context-snapshot + - security + - harness + - token-cost +--- + +# 141. Deterministic filtered entity-context-snapshot staging + +Date: 2026-09-07 + +## Status + +Accepted + +## Context + +[Issue #6407](https://github.com/fullsend-ai/fullsend/issues/6407) identifies +that agents and harness scripts repeatedly fetch the issue or change proposal +they are handling, including comments, reviews, checks, and logs. Those +tool calls spend tokens, make runs depend on runtime network access, and give +each consumer a different view when the entity changes during a run. + +Forge content is also untrusted input. Fetching it directly from inside the +sandbox bypasses the deterministic point where Fullsend can bound, normalize, +redact, and label content before it reaches an agent. This decision generalizes +the preferred prefetch model from +[ADR 0017](0017-credential-isolation-for-sandboxed-agents.md) to every issue and +change-proposal run. + +This ADR's *entity-context-snapshot* is the staged data snapshot. It is distinct +from the dispatch-layer routing category called entity context in +[ADR 0076](0076-slash-command-entity-context-separation.md). The qualified +name is intentional: it identifies the data structure without redefining ADR +0076's established routing term. + +[ADR 0133](0133-actor-attributed-data-security-boundary.md) defines the +security boundary for actor-attributed source data: authorization is evaluated +for the actor of each current source revision, authorization permits data to be +considered but does not make its text safe, and every admitted record must pass +the common filtering, delimitation, and fail-closed rules. This ADR applies +that boundary to the deterministic snapshot path rather than defining a second +trust model. + +## Decision + +Before the harness pre-script, `fullsend run` uses `forge.Client` to assemble +one immutable snapshot of the handled entity. The runner applies a mandatory, +deterministic content pipeline to each complete selected source: Unicode safety +normalization, secret and sensitive-data redaction, injection scanning, then +size limits. A detector failure or timeout aborts snapshot assembly. It fails +closed when required data cannot be fetched or safely represented. Filtered +content is the only copy exposed to scripts and the agent; the manifest records +every truncation, replacement, finding, and fetch error without retaining +rejected content. + +Record admission follows ADR 0133 and the role thresholds selected by the +agent's harness under [ADR 0054](0054-require-authorization-on-all-agent-dispatch-paths.md) +and [ADR 0098](0098-entity-first-harness-evaluation.md). Fullsend verifies the +source record's current-revision actor and current authorization independently +of the event sender, poller, retrieval credential, or discovery provenance. +Unauthorized, unattributed, or unverifiable comments and reviews are omitted +and represented by bounded manifest gaps; they are not exposed as raw or +filtered text. For a bot actor, Fullsend uses the provider-backed exact +`actor.bot_role` recognition defined by [ADR 0107](0107-bot-identity-resolution-for-dispatch-authorization.md); +the human repository-role threshold does not apply. A bot with no recognized +role, or with an unavailable or unverifiable lookup, remains omitted. Future +ADRs may broaden admission to additional provider-backed bot identities, but +this ADR does not invent a second bot-role mechanism. Successful authorization +is therefore an admission prerequisite, not a claim that the record is +trustworthy or can change platform authority. + +The handled entity's body is actor-attributed content and follows the same +current-revision attribution and authorization rule. If its author is missing, +unverifiable, unauthorized, or fails filtering, Fullsend records an +entity-scope gap and aborts snapshot assembly; "required entity body" means +required only after successful admission and filtering. + +The snapshot is written outside the repository clone. Host-side pre- and +post-scripts receive `FULLSEND_CONTEXT_DIR` pointing to an access-restricted +temporary directory outside the retained run-output tree; inside the sandbox +the same variable points to the runner-owned reserved sibling path +`/sandbox/entity-context-snapshot`. Fullsend must reject any checkout or `host_files` +destination that would overlap that path, and must abort if the reserved path +already exists with unexpected contents. Fullsend uploads that directory after +sandbox creation and before repository/runtime execution. Consumers therefore +use the same variable and relative paths on both sides of the sandbox boundary, +and the context cannot be staged or committed accidentally with repository +files. + +The exact tree, schemas, canonical serialization, stable record-key derivation, +filter statuses, and compatibility rules are the versioned +[entity-context-snapshot v1 specification](../normative/entity-context-snapshot/v1/README.md). +Content records and mutable observation state are separate: resolving or +reordering a thread changes its state/index files, never an unchanged comment +or review body. No runner-clock timestamp enters the staged tree. Given the +same complete normalized acquisition inputs defined by the v1 specification— +including forge responses, authorization-provider results, effective admission +policy, collection profile, size bounds, filter version, and active +credential-redaction registry—implementations produce the same paths and bytes; +breaking that guarantee requires a new major specification. + +The snapshot contains forge state that cannot be reconstructed from the target +Git checkout. It does not copy diffs, commit history, changed-file manifests, +or repository revision metadata. Fullsend provisions sufficient Git objects and +refs separately; controllers derive and filter diffs or commit projections for +agents and sub-agents that need them. Git object IDs appear in the +entity-context-snapshot to relate reviews, threads, comments, and agent runs to +repository state, and as the collected target revision in check metadata. + +Each comment and review is a self-contained attributed record whose filename +sorts chronologically. The initial body uses the same record format and sorts +first. Order files define whole-conversation and review-focused projections and +refer to the same records rather than copying content. New replies append +without rewriting unchanged record files. Review-thread relationships, commit +references, and immutable Fullsend agent-run receipts preserve enough provenance +to relate a finding, the reviewed revision, a subsequent fix, and a re-review. + +The pre-script may inspect the host snapshot and skip the run. At assembly time, +Fullsend retains the exact `index.json` bytes, or a digest of those bytes, in +host-private run state outside `FULLSEND_CONTEXT_DIR`. After the pre-script, +Fullsend compares the on-disk root index with that retained value and aborts on +any difference; it does not accept a rewritten index or re-parse it as the root +of trust. Only after that comparison does it verify child digests and the exact +manifest path set against the assembly-time index. Fullsend removes extra paths +or aborts assembly before upload. The sandbox copy is agent-immutable: it is +exposed through a read-only bind mount, or, where that is unavailable, a +root-owned tree with mode `0555` directories and `0444` files while the agent +runs unprivileged with `CAP_FOWNER` and equivalent write-overriding +capabilities removed. If neither mechanism can be enforced, Fullsend aborts +before launching the agent. + +When a runtime injects staged context into a model request, it emits each +ordered record as a distinct content block, followed by relationship and +mutable-state blocks and then run-specific instructions. It must not collapse +the records into one changing prompt block when cache reuse is intended. +Provider prompt caching remains an optimization, not a conformance guarantee; +agents that read records through tools still pay the corresponding tool-result +tokens. Deterministic order projections remain navigation aids for selective +reads. Runtime forge reads for entity-context-snapshot source kinds are denied by +default. An explicitly configured host-side extension may fetch a kind outside +the snapshot only when it applies the same versioned pipeline and fail-closed +rules and exposes no raw payload to the sandbox; it records the omission and +extension result outside the immutable v1 snapshot. A present extension +configuration that cannot be parsed denies every runtime entity-context-snapshot fetch. +Extension output uses the snapshot's `filter_version`, filter statuses +including `rejected`, and the same detector-failure abort rules. V1 extension +output outside the manifest is host-only and never sandbox-visible. Making an +extension result sandbox-visible requires a versioned schema that lists its +path in the manifest and subjects it to the same filtering, digest, +permissions, exact-path, and cleanup rules. + +The host snapshot uses a mode-`0700` directory and mode-`0600` files. Those +host permissions do not make a sandbox copy read-only. Fullsend removes the +sandbox copy after its last sandbox consumer and the host copy after +the post-script, on success, failure, skip, or handled cancellation; startup +also scavenges orphaned context directories after abnormal termination. Context +is excluded from retained run artifacts by construction. Diagnostics may retain +only bounded counts, digests, and filtering findings, never bodies or logs. + +## Consequences + +- Agents start with one filtered, versioned view and avoid duplicate forge reads, but token and provider-cache savings are conditional on selective projections and segmented runtime injection rather than automatic consequences of staging files. +- Fullsend must provision the Git objects and refs required by each run, let controllers derive and filter repository projections on demand, and add segmented context input, cache-boundary support, and efficiency telemetry before claiming an improvement. +- Shipped and custom review, fix, and code agents must migrate from mutable sticky summaries and single-body hand-offs to discovered entity-context-snapshot projections, publish immutable per-run result receipts while retaining human-facing summaries, and anchor decisions to record keys and revisions. +- Forge adapters must expose review/reply relationships, locations, reviewed-revision references, checks, and immutable agent-result references through `forge.Client`; unavailable or unrecoverable forge history is an explicit manifest gap, not a silent omission. +- Snapshot assembly adds bounded startup latency and storage and can become stale, so collection profiles avoid indiscriminate log/history fetching and deterministic post-processing still validates relevant revisions before any forge mutation. +- The actor-attributed data boundary, including fresh authorization, common + filtering, redaction, delimitation, and fail-closed behavior, is inherited + from ADR 0133; future snapshot or retrieval paths must preserve that boundary + rather than treating this file layout as a security mechanism by itself. diff --git a/docs/architecture.md b/docs/architecture.md index 38731196ab..56d60b32ac 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -181,6 +181,18 @@ repo baseline and overrides) (contract: [`docs/normative/prescript-output/v1`](normative/prescript-output/v1/README.md)), replacing the inline workflow pre-checks and their scaffold script copies ([ADR 0072](ADRs/0072-pre-script-output-protocol.md)). +- Deterministic forge entity-context-snapshot (v1): before the pre-script, the + runner fetches one + bounded entity snapshot through `forge.Client`, filters untrusted content, + and stages a versioned per-record file tree with relationship, projection, + and immutable agent-run lineage metadata outside the repository. Repository + diffs and commit history remain derived from the separately provisioned Git + checkout; the entity-context-snapshot carries Git object IDs only as + relationship anchors. + Scripts and the sandbox use `FULLSEND_CONTEXT_DIR` with the same relative + paths; runtimes may inject ordered records as separate cacheable input blocks + ([ADR 0141](ADRs/0141-deterministic-filtered-entity-context-staging.md), + constrained by [ADR 0133](ADRs/0133-actor-attributed-data-security-boundary.md)). - CEL-guarded overlays: an `overlays:` list of CEL-guarded config overlays generalizes the `forge:` block, letting harness authors condition scripts, skills, env vars, and other fields on any event diff --git a/docs/normative/entity-context-snapshot/v1/README.md b/docs/normative/entity-context-snapshot/v1/README.md new file mode 100644 index 0000000000..3d94b786cf --- /dev/null +++ b/docs/normative/entity-context-snapshot/v1/README.md @@ -0,0 +1,778 @@ +# Entity-context-snapshot v1 + +This specification defines the deterministic, filtered entity-context-snapshot +adopted by [ADR 0141](../../../ADRs/0141-deterministic-filtered-entity-context-staging.md) +under the actor-attributed data boundary in [ADR 0133](../../../ADRs/0133-actor-attributed-data-security-boundary.md). +It is the contract between forge adapters, `fullsend run`, harness scripts, and +agent runtimes. + +Here, *entity-context-snapshot* means the staged data snapshot for a handled +Git-forge entity. The qualified name distinguishes this data structure from +the dispatch-layer routing category called *entity context* in +[ADR 0076](../../../ADRs/0076-slash-command-entity-context-separation.md), +which determines the agent or slash command that may handle an issue, change +proposal, or conversation. Entity-context-snapshot v1 applies only to GitHub, +GitLab, and Forgejo work items and change proposals. A non-forge `work_item`, +such as Jira, does not start v1 +snapshot assembly; the runner records an `unsupported_entity` diagnostic +outside the tree and continues under that integration's existing input +contract. This host-only `unsupported_entity` diagnostic is unrelated to the +`gaps[].code` value `unsupported` for an omitted or partial in-tree scope and +never appears in a schema document. Runtime entity-context-snapshot forge reads +remain denied. + +## Tree + +The singleton JSON documents and the two top-level order views shown below are +always emitted. Array-valued sections are empty when there is nothing to +report. Record, thread, review-view, check, and log entries are emitted only +when selected by `collection.json`. JSON documents use their linked schemas. + +```text +context/ +├── index.json +├── collection.json +├── entity/metadata.json +├── records/-.md +├── threads/.order +├── views/ +│ ├── timeline.order +│ ├── unresolved-review.order +│ └── reviews/.order +├── relations/reviews.json +├── history/agent-runs.json +├── checks// +│ ├── metadata.json +│ └── log.txt +└── state/ + ├── actors.json + └── threads.json +``` + +`index.json` conforms to [`index.schema.json`](index.schema.json) and enumerates +every other staged file. `collection.json`, `entity/metadata.json`, +`relations/reviews.json`, `history/agent-runs.json`, check metadata, +`state/actors.json`, and `state/threads.json` conform respectively to +[`collection.schema.json`](collection.schema.json), +[`entity.schema.json`](entity.schema.json), +[`reviews.schema.json`](reviews.schema.json), +[`agent-runs.schema.json`](agent-runs.schema.json), +[`check.schema.json`](check.schema.json), +[`actor-state.schema.json`](actor-state.schema.json), and +[`thread-state.schema.json`](thread-state.schema.json). Files under `threads/` +contain only ordered relative paths to records. Files under `views/` are +deterministic projections containing those same paths, one per LF-terminated +line. `views/timeline.order` and `views/unresolved-review.order` exist even when +empty. + +Manifest `media_type` values are closed by file role: JSON documents use +`application/json`, comment/review/entity records use `text/markdown`, and +order views plus check logs use `text/plain`. Producers must emit the value +specified for the role; media-type parameters and alternate spellings are not +valid v1 values. + +The canonical empty singleton documents are `{"reviews":[],"threads":[]}` for +`relations/reviews.json`, `{"runs":[]}` for `history/agent-runs.json`, +`{"actors":[]}` for `state/actors.json`, and `{"threads":[]}` for +`state/threads.json`, serialized under RFC 8785. An empty order view is a +zero-byte file. + +## Stable records and mutable state + +A record key is the lowercase hexadecimal SHA-256 of four UTF-8 strings. In +order, the strings are `://`, +``, the record kind, and the forge record ID. Encode each +string as UTF-8 and concatenate them with exactly one U+0000 byte between +adjacent fields and no trailing U+0000. Commas and spaces shown in prose are +not part of the input. For example, the four fields +`github://github.com`, `R_kgDOExample`, `comment`, and `IC_kwDOExample` produce +the byte sequence `github://github.com\0R_kgDOExample\0comment\0IC_kwDOExample` +and the key +`c73645a72a9c5de28d71e3e1efe235b9a5d02ee6dfe7dc0ef06cf3d0e5ee3421`. + +`source.forge` is `github`, `gitlab`, or `forgejo`. `source.host` is the +lowercase DNS name, with a port from 1 through 65535 appended as decimal +`:` if and only if the HTTPS port is not 443, and no scheme or path. +The default port is always omitted. `source.repository_id` and each forge +record ID use these positive mappings: + +- GitHub uses the GraphQL node ID exposed as `node_id` for the repository and + each entity, comment, review, check run, or review thread. +- GitLab uses the global project or record `id`, serialized in base-10 without + leading zeroes; a discussion thread uses its opaque API `id`. Project-scoped + issue or merge-request `iid` values are display numbers and are not IDs here. +- Forgejo uses the numeric repository or record `id`, serialized in base-10 + without leading zeroes. Issue and change-proposal `number` values are display + numbers and are not IDs here. + +Actor IDs follow the same rule: GitHub `node_id`, or the GitLab/Forgejo numeric +user `id` in base-10 without leading zeroes. References to a deleted actor +retain the immutable ID when the forge exposes it and otherwise use `null`. + +`source.repository` is a navigation value, not a hash input: GitHub uses +lowercase `owner/repository`; GitLab uses the API's canonical +`path_with_namespace`; Forgejo uses lowercase API `full_name`. All forms use +literal `/` separators with no leading/trailing slash or percent encoding. +Repository transfers and renames therefore do not rewrite record keys. + +Source kinds used in key derivation are `comment`, `review`, `check`, `thread`, +and `entity`. Manifest record entries use only `entity`, `comment`, `review`, +and `check`; `thread` keys identify relationship and ordering data under +`relations/` and `threads/`, not files under `records/`. A selected object that +lacks its required canonical ID produces an `invalid_metadata` gap and is not +assigned an adapter-specific substitute. + +The tree contains forge entity state that is not reconstructible from the +target Git checkout. Diffs, commits, changed-file lists, branches, and revision +topology are repository context and are not staged here. Fullsend provides the +required Git objects and refs separately, and controllers may derive filtered +diff or history projections outside this tree. Git object IDs occur here as +relationship values in review, thread, and agent-run documents, and as the +collected target revision in check metadata `head_sha`. + +Comment and review Markdown files are self-contained records with this exact +UTF-8 layout; header values are canonical JSON strings (or `null`) on one line: + +```text +Fullsend-Record: "comment" +Source-ID: "opaque-forge-id" +Author-ID: "opaque-actor-id" +Created-At: "2026-09-08T10:15:30.000000000Z" + +Filtered Markdown body. +``` + +`Fullsend-Record` is `"entity"`, `"comment"`, or `"review"`. The header order +and blank line are fixed. `"entity"` is required for the reserved entity-body +record; `"comment"` and `"review"` identify ordinary conversation records. +`Author-ID` may be `null` when the forge withholds or has +deleted the actor. The immutable actor ID is included because attribution is +part of the source record. The current login stays in `index.json` and +`state/actors.json`: it may change after an account rename without the record +changing. Navigation URLs are intentionally omitted from the staged tree; +forge, host, repository, and immutable record IDs provide provenance, while a +host-side adapter can construct a link when a human needs one. Effective +repository role is also excluded because permissions can change without the +comment changing. +The file contains no update time, ordering, thread membership, review location, +resolution, outdated, or minimized state; those properties belong in +`index.json`, `relations/`, or `state/`. Consequently, resolving a thread, +renaming an actor or repository, changing an actor's permission, or inserting +an earlier record must not rename or rewrite an unchanged record. Changing its +body or immutable attribution ID changes that record's bytes and digest. + +Before a comment is admitted to the snapshot, the producer applies the +current [authorization contract](../../../normative/authorization/v1/README.md), +which implements ADR 0054 and its later, explicitly documented extensions. +This ADR deliberately borrows only that contract's forge-neutral role ordering +and minimum-role thresholds for the selected agent category: observation +agents require `triage` or above, while mutation agents require `write` or +above. It does not apply event-specific `transition.kind` rules or exceptions +because comment admission is not event authorization. A human comment author +whose verified role meets the selected agent threshold is trusted as an +eligible command source and the comment is admitted; lower or unverified human +roles are omitted and count in the `comments` scope's `authorization_failed` +gap. For a bot actor, the producer MUST establish provider-positive bot identity +and resolve the exact registered `actor.bot_role` under [ADR 0107](../../../ADRs/0107-bot-identity-resolution-for-dispatch-authorization.md). +The bot's snapshot actor state retains `role: bot`; the human repository-role +threshold does not apply. A bot with no recognized role, or with an unavailable +or unverifiable lookup, is omitted and counted in the same authorization gap. +This is the intentional v1 trust boundary: users who may invoke the agent, and +Fullsend-registered bots admitted by ADR 0107, may provide its command inputs. +The handled entity body is actor-attributed content and MUST pass the same +current-revision attribution and authorization rule before it is staged. A +missing, unverifiable, unauthorized, or unsafe entity body emits an +entity-scope `authorization_failed` or filtering gap and aborts assembly; the +required entity body is required only after successful admission and filtering. +Label-transition and bot-review event exceptions authorize an event path only; +they do not by themselves authorize arbitrary bot-authored comment content. An +omitted formal review is counted in the `reviews` scope's +`authorization_failed` gap by the same rule; it is not charged only to +`comments`. Every admitted entity, comment, or review still passes the complete +filter pipeline below, including Unicode safety that removes invisible text and +unnecessary control characters, secret redaction, prompt-injection scanning, +and byte bounds. + +The initial issue or change-proposal body uses the same layout with +`Fullsend-Record: "entity"`, the entity's stable ID, immutable author ID, and +creation time. This makes it the first self-contained turn. + +## Ordering files and prompt assembly + +An ordinary record filename is +`records/-.md`. `` is its source `created_at` +normalized to UTC as `YYYYMMDDTHHMMSSnnnnnnnnnZ`, with exactly nine fractional +second digits and no punctuation other than `T` and `Z`. The entity-body record +uses the reserved key `00000000T000000000000000Z`, so it always sorts first. +Creation time is immutable forge data; edits do not rename a record. + +Every order/view file lists only records that have an emitted `content_path`; +rejected comments and reviews never create dangling order lines. The entity +record is always present because an entity-body rejection aborts assembly. +`views/timeline.order` lists that entity record and retained comment/review +records in canonical chronology. Each `threads/.order` lists that +thread's retained records in forge order. `views/unresolved-review.order` +lists retained records in unresolved, non-outdated review threads, ordered by +thread creation time and key and then forge thread order. A +`views/reviews/.order` file is emitted only for a retained formal +review; it lists that review followed by retained records in threads associated +with it. A record path appears at most once in any one order file. Paths contain +no whitespace or shell metacharacters, so a host consumer may materialize a +projection with `xargs cat`, but runtimes use the segmented contract below. + +A runtime that injects a projection into a model request emits each referenced +record as a distinct, ordered content block. Relationship, history, mutable +state, and run-specific instruction blocks follow the stable record blocks. +The runtime must not concatenate all records into one content block when +prompt-cache reuse is intended: appending to that block would change its digest +and lose the otherwise reusable record prefix. A runtime may mark boundaries +using provider-specific cache controls, but provider cache behavior is not a +v1 conformance guarantee. Reading the same files through agent tools avoids +forge calls but still incurs tool-result tokens. + +A normal later reply adds one lexically later file and extends applicable order +files, leaving earlier record blocks byte-identical. A backfilled earlier +record, edit, deletion, or attribution change invalidates reuse from the first +affected block onward. Consumers never infer resolution from record content. + +Checks are a change-proposal-only source. A collection profile for a +`work_item` cannot select `reviews`, `checks`, or `check_logs`; those sources +are not represented as empty scopes or fetch gaps. Check status is observation +state in `checks//metadata.json`; its +log file contains only filtered log bytes. A growing or replaced forge log is +changed content and may change `log.txt`. A new check attempt has a new forge +record ID and therefore a new record key; v1 has no separate synthesized +attempt number. Its `created_at` is the forge's +immutable check-run creation time and is also the check manifest record's +`created_at`; a runner first-observed time is forbidden. Check status is +normalized to `queued`, `in_progress`, or `completed`; conclusions are +`success`, `failure`, `neutral`, `cancelled`, `skipped`, `timed_out`, +`action_required`, or `stale`. +Queued checks have no start, completion, or conclusion fields. In-progress +checks require `started_at` and have no completion or conclusion. Completed +checks require `completed_at`, `conclusion`, and `never_started`. +`never_started: true` is emitted only when the forge explicitly reports that +the job never started; for a completed `skipped` or `cancelled` outcome, the +adapter treats a missing native `started_at` as that explicit never-started +report. It forbids `started_at` and is limited to `failure`, `skipped`, or +`cancelled`. This includes GitHub `startup_failure`, which maps to the v1 +`failure` conclusion. `never_started: false` requires `started_at`; adapters +must not set it on an ordinary `failure` merely because `started_at` is absent. +Consumers must use the explicit flag and must not infer never-started state from +an omitted timestamp. + +At collection start, the producer captures the target change-proposal HEAD +revision and retains only checks whose forge-reported revision equals that +`head_sha`. Every retained check records that exact SHA in its check metadata; +the field is required even when a forge exposes only a generic check-run +endpoint. A missing, malformed, or mismatched check revision is +`invalid_metadata` and the check is not emitted. The producer must not fetch +logs or synthesize a check for any other revision. +Check manifest records carry `created_at` but no `author_id` or `author`. + +Adapters use these exhaustive v1 native-status mappings: + +- GitHub `queued`, `waiting`, `requested`, and `pending` map to `queued`; + `in_progress` maps to `in_progress`; `completed` maps to `completed` and its + native conclusion maps identically to the v1 conclusion vocabulary, except + `startup_failure`, which maps to `failure` with `never_started: true`. + Completed `skipped` and `cancelled` runs with no native `started_at` also + emit `never_started: true`; all other completed conclusions require + `never_started: false` and a native `started_at`. +- GitLab `created`, `waiting_for_resource`, `waiting_for_callback`, `preparing`, `pending`, `scheduled`, + and `manual` map to `queued`; `running` and `canceling` map to `in_progress`; + `success`, `failed`, `canceled`, and `skipped` map to `completed` with + conclusions `success`, `failure`, `cancelled`, and `skipped`, respectively. + For completed `canceled` and `skipped` jobs, a null native `started_at` is + the explicit never-started report and emits `never_started: true`; otherwise + they emit `never_started: false`. A `failed` job with no native `started_at` + remains ordinary failure and is `invalid_metadata`. +- Forgejo `pending`, `waiting`, and `blocked` map to `queued`; `running` maps to + `in_progress`; `success`, `failure`, `error`, `warning`, `cancelled`, + `canceled`, and `skipped` map to `completed` with conclusions `success`, + `failure`, `failure`, `neutral`, `cancelled`, `cancelled`, and `skipped`, + respectively. For completed `cancelled`, `canceled`, and `skipped` jobs, a + null native `started_at` is the explicit never-started report and emits + `never_started: true`; otherwise they emit `never_started: false`. + +Any native status or conclusion not listed above is `invalid_metadata`; an +adapter must not invent another mapping. Any mapped check whose forge data +cannot satisfy `check.schema.json`'s status-specific timestamp requirements is +also `invalid_metadata`. Completed checks with `never_started: true` require +`completed_at` and omit `started_at`; all other completed checks require both +timestamps. `completed_at` is the native terminal timestamp when present. If a +never-started completed check has no native terminal timestamp, the adapter +uses its immutable source `created_at` as the canonical fallback; this records +the only source-derived time available and is not a runner-observed completion +time. If either required source timestamp is absent or invalid, the check is +`invalid_metadata`. Native timestamp fields +forbidden for the mapped status are omitted rather than copied. + +## Relationships, history, and collection profiles + +`relations/reviews.json` preserves normalized formal review outcomes and the +association between reviews, replies, reviewed revisions, and code locations +separately from mutable resolution state. Review states use `approved`, +`changes_requested`, `commented`, and `dismissed`, matching normalized-event +v1. Forge sides such as GitHub `LEFT` and `RIGHT` are lowercased to `left` and +`right`. Reviewed revisions and location fields are optional because forges +expose different subsets. `state/threads.json` references the actor that +resolved each resolved thread, and `relations/reviews.json` references the +actor that dismissed each dismissed review. A nullable reference explicitly +records that the forge did not expose the actor; a nullable dismissal timestamp +does the same when the forge exposes the disposition but not its time. Actor +references resolve through `state/actors.json`. + +Review adapters use these exhaustive v1 mappings: + +- GitHub `APPROVED`, `CHANGES_REQUESTED`, `COMMENTED`, and `DISMISSED` map to + their lowercase v1 equivalents. `PENDING` reviews are unsubmitted and are + omitted. +- GitLab approval summaries and current-approver lists do not have immutable + review record IDs and are not formal v1 review records. GitLab discussion + notes are staged as comments and threads. When immutable approval history is + unavailable, the `reviews` scope records a partial `history_unavailable` gap. +- Forgejo `APPROVED`, `REQUEST_CHANGES`, `COMMENT`, and `DISMISSED` map to + `approved`, `changes_requested`, `commented`, and `dismissed`, respectively. + `PENDING` and `REQUEST_REVIEW` rows are unsubmitted reviewer requests and are + omitted. + +Formal review timestamp mapping is also exhaustive. The record's +`created_at`, its filename order key, and the relationship `submitted_at` all +use the canonical submission time. For GitHub this is native `submittedAt`; +native `createdAt` is the start of a pending review and is not used for a +submitted record. A submitted GitHub review without `submittedAt` is +`invalid_metadata`. Forgejo uses native `submitted_at` when present and uses +native `created_at` only when the completed review exposes no separate +submission field; if neither is present it is `invalid_metadata`. GitLab has +no formal v1 review records, so discussion notes use their native note +`created_at` as comment time and have no `submitted_at`. Adapters must not use +runner-observed time as a fallback. + +Any other native formal-review state is `invalid_metadata`. GitHub uses its +native outdated observation. For GitLab and Forgejo thread APIs that expose no +outdated equivalent, producers emit `outdated: false`; they never infer it from +the current diff. + +The `threads` arrays in `relations/reviews.json` and `state/threads.json` have +exactly the same unique `thread_key` set. Every relationship thread therefore +has an explicit state row, including unresolved threads with `resolved: false` +and an explicit `outdated` boolean. Missing, duplicate, or extra thread-state +rows make the `reviews` scope unusable and add an `invalid_metadata` gap. + +`state/actors.json` contains the current, forge-verified effective repository +permission for each referenced author, resolver, and dismisser. Roles use the +[ADR 0054](../../../ADRs/0054-require-authorization-on-all-agent-dispatch-paths.md) +and normalized-event v1 vocabulary: `admin`, `maintain`, `write`, +`triage`, `read`, `none`, and `external`; snapshot actor state additionally +accepts `role: bot` as an explicit non-authority marker outside that +permission-only enum. Each row states whether the actor is a `human` or +`bot`. For `kind: bot`, producers set `role: bot` and `role_verified: false`: +the marker records the known actor kind, while the false verification bit +records that no human repository permission was resolved; it does not negate a +separate, successful ADR 0107 `actor.bot_role` admission check. For `kind: human`, +`role_verified: false` is paired with `role: null` and means consumers must +fail closed rather than infer authority from forge association labels such as +GitHub `authorAssociation`; a permission lookup failure, including a +collaborator API 404, uses that representation. A future ADR may define a +broader provider-backed bot allow-list or mapping, but registered bot roles +already follow ADR 0107. The authorization contract's narrow +transition-specific exceptions for GitHub label changes and submitted bot +reviews remain event-path exceptions; they do not authorize arbitrary bot +comments without the applicable bot-role admission. + +Entity-context-snapshot and normalized-event v1 carry independently versioned +copies of the actor-role vocabulary. The snapshot-only `bot` marker is not a +normalized-event repository permission and must not be projected into one; +each value must validate against the schema of the document that uses it. + +Every non-null `author_id`, `resolved_by_actor_id`, and +`dismissed_by_actor_id` referenced anywhere in the snapshot appears exactly +once in the actor array. JSON Schema cannot express uniqueness by one object +property, so producers enforce this cross-document invariant. Consumers treat +a duplicate or missing actor row exactly like `role_verified: false`. The actor +array sorts by actor ID. Because permissions and dispositions are mutable +observation state, changing them changes state or relationship documents but +not record files. Role values are observed during snapshot assembly, not +copied from a historical comment event. + +`history/agent-runs.json` +contains only immutable, forge-observable Fullsend run receipts and relates an +agent result to its input revision, result records, and resulting commit. A +receipt's `input_revision` is the lowercase SHA-256 of the RFC 8785 +`index.json` bytes consumed by that run; `input_head_sha`, when present, is the +separate Git revision checked out for the run. Receipt status is `success`, +`failure`, `cancelled`, `skipped`, or `timed_out`. A mutable sticky comment may +be a human-facing summary, but it is not canonical +run history and its overwritten versions cannot be reconstructed from a forge +that does not expose edit history. + +`collection.json` is the exact collection configuration and conforms to +`collection.schema.json`. Its source-kind array sorts by ASCII byte order. +The required `admission.human_min_role` records the effective per-record human +threshold (`triage` for observation or `write` for mutation); registered bot +roles follow ADR 0107 and do not use that human threshold. The producer derives +this value from the selected harness before serializing and hashing +`collection.json`. `entity_kind` must match the entity metadata kind. For `work_item`, the only +valid non-entity sources are `comments` and `agent_runs`; reviews, checks, and +check logs are inapplicable and cannot be selected. A profile that violates +these entity-kind rules is invalid before fetching or assembly and aborts +collection; it is never represented as an empty scope or an `unsupported` +gap. `change_proposal` profiles may select the full v1 source set. +Non-entity records first enter the corresponding canonical order from +[Ordering and determinism](#ordering-and-determinism); `record_selection` +retains either the oldest or newest `max_records_per_source` entries for each +included source, then output ordering follows the same chronology rules. +When a bound drops records, the producer emits exactly one `profile_bound` gap +for each affected scope, with `count` equal to the number dropped. Counts from +multiple bounds for the same scope and code are aggregated, and the gaps array +contains at most one row for each `(scope, code)` pair, sorted by scope and +code. Dropping labels because of `max_labels` emits an `entity`-scope +`profile_bound` gap whose count is the number of dropped labels and sets the +entity-metadata filter status to `truncated`; it is never silent. +After comment and review record selection, thread `record_keys`, reply edges, +thread order files, and review views contain only retained records that have an +emitted `content_path`. A reply edge is emitted only when both endpoints remain +and have content paths. A thread with no such records is omitted from both +relationship and state arrays and has no order or view file; dangling record +keys and order lines are forbidden. +`check_log_selection` is `none`, `failed`, or `all`. `failed` means the parent +check conclusion is `failure`, `timed_out`, `action_required`, or `stale`; +`cancelled`, `skipped`, and `neutral` checks are not failed. `check_logs` can be +included only with `checks`. Check record selection and +`max_records_per_source` are applied first. Logs are then selected only from +the retained parent checks and use the parent's `created_at` and `record_key` +for deterministic order; logs are not a second independently counted record +source. Bounds apply after the +full-source security pipeline described below: `max_record_bytes` bounds each +record body, `max_log_bytes` bounds each log, and +`max_metadata_string_bytes` bounds each source-derived display string. Labels +first sort canonically and then retain the first `max_labels` entries. +Structural strings cannot be truncated. +Exceeding `max_metadata_string_bytes` makes a structural value invalid. +`max_source_bytes` is the pre-decode acquisition cap described below. +`collection_profile` equals the lowercase SHA-256 of the exact RFC 8785 +`collection.json` bytes and therefore also equals that file's manifest digest. +Profiles must not vary based on runner time or an agent's intermediate choices. +For a retained check, the index record has `log_path` if and only if +`check_log_selection` selected its log and filtering produced the file without +an unusable `invalid_metadata` or `unsafe_content` gap. + +Missing data from a valid selected source is represented in `index.json.gaps`; +it is never silently treated as an empty history. Inapplicable sources are +rejected by the collection profile before fetching and therefore do not create +an empty scope or a gap. Scopes are `entity`, `comments`, `reviews`, +`checks`, `check_logs`, `agent_runs`, and `actors`. `profile_bound` and +`history_unavailable` gaps have `usability: partial`; consumers may use present +records but must not claim the scope is complete. `unsupported`, +`authorization_failed`, `fetch_failed`, `source_too_large`, +`invalid_metadata`, and `unsafe_content` have `usability: unusable`; consumers +must not make an authority or completeness decision from that scope. Any +unusable `entity`-scope gap for the required entity body or metadata aborts +snapshot assembly, including `authorization_failed`, `fetch_failed`, +`source_too_large`, `invalid_metadata`, and `unsafe_content`; Fullsend must not +launch scripts or an agent with that snapshot. The same gap codes remain +non-aborting unusable gaps for optional scopes. Any `actors` gap makes +authorization unusable and therefore fails closed. Runtimes +and host scripts +must inspect relevant gaps before consuming records or state. + +## Canonical bytes + +JSON is UTF-8 serialized with the JSON Canonicalization Scheme (RFC 8785), with +no byte-order mark or trailing newline. Arrays use the order defined below; +objects use RFC 8785 member ordering. + +Every JSON timestamp is normalized to UTC and serialized with exactly nine +fractional-second digits as `YYYY-MM-DDTHH:MM:SS.nnnnnnnnnZ`. Offset forms, +omitted fractions, and other equivalent RFC 3339 spellings are not canonical. +Git object IDs are serialized as lowercase hexadecimal strings. + +Properties marked required by a schema are always emitted. If a required +property is nullable and its normalized source value is unavailable, it is +emitted as JSON `null`. A non-required property is emitted only when its +normalized source value is available; otherwise it is omitted and is never +synthesized as `null` or with a default value. + +Text bodies and logs are UTF-8 after the v1 filter pipeline, use LF line +endings, and have no byte-order mark. Line-ending normalization canonicalizes a +non-empty body or log to exactly one trailing LF before `filter.status` is +computed. The byte bound includes that LF. To bound non-empty text, remove all +trailing LFs, retain the longest prefix ending at a UTF-8 code-point boundary +whose bytes plus one LF fit the bound, then append one LF. An empty body +contributes zero bytes after the record header's required blank line; an empty +log is a zero-byte file. + +The pipeline operates on the complete selected source in this order: + +1. decode and normalize line endings, then apply Unicode safety normalization; +2. redact secrets and sensitive data from the complete normalized source; +3. scan the complete redacted source for prompt injection and reject it when + policy says it cannot be represented safely; +4. for record bodies and logs, apply the configured byte bound at a UTF-8 + code-point boundary and enforce the single trailing LF rule; and +5. if step 4 removed bytes, scan the exact emitted bytes again for prompt + injection and reject them if unsafe in isolation. + +Secret and sensitive-data detectors must never run only on a truncated prefix. +Because redaction precedes the bound, a secret match cannot straddle an +uninspected truncation boundary. Injection detection covers both the complete +redacted source and the exact truncated bytes the consumer would receive. +An input exceeding the profile's `max_source_bytes` is not decoded and adds an +unusable `source_too_large` gap; no prefix is emitted. A pipeline component +error, timeout, or unavailable detector aborts snapshot assembly; it never +passes through original bytes. + +Every `filter_version` strips and records findings for, at minimum, Unicode tag +characters U+E0000--U+E007F; zero-width U+200B--U+200D and U+FEFF; +bidirectional controls U+202A--U+202E and U+2066--U+2069; variation selectors +U+FE00--U+FE0F and U+E0100--U+E01EF; and interlinear annotations +U+FFF9--U+FFFB. A filter version may cover more classes, but it cannot weaken +these invariants. + +Fullsend's shipped filter version must not be weaker than its Unicode safety +scanner at the commit that accepts this specification. That scanner also +removes nulls, terminal escapes, LRM/RLM, word joiners, other format (`Cf`) +characters, and applies reported NFKC normalization. Those additional +transformations are bound to the shipped `filter_version`; they are not +silently added to the portable character-class floor above, and changing their +output requires a new filter version. + +The v1 redaction floor detects exact run credentials registered by Fullsend; +OpenAI, Anthropic, GitHub, GitLab, Slack, Google, AWS, Stripe, SendGrid, +Hugging Face, npm, PyPI, Vault, and age secret prefixes; private-key blocks; +authorization headers; secret-named environment and JSON values; database URL +passwords; and structured SSN, payment-card, and IBAN values. Exact pattern and +validation semantics are part of `filter_version`. A later filter version may +add detectors but must not remove or narrow this floor. + +The deterministic injection floor rejects matches for instruction override, +system-prompt replacement, unrestricted-role requests, concealment from the +user, credential-file or environment exfiltration, hidden HTML instructions, +and translate-then-execute requests. Exact patterns and thresholds are part of +`filter_version`; ML detectors may supplement them only when their model, +threshold, and deterministic execution contract are also versioned. No +detector reliably blocks every visible prompt injection. The entire +entity-context-snapshot tree is therefore untrusted snapshot-derived data: +this includes `index.json`, entity metadata, relations, history, state, +check metadata and logs, order files, and all record bodies. Runtimes must +keep those blocks distinct from run-specific instructions, prohibit following +instructions from any snapshot-derived block, and retain least-privilege tool +and credential boundaries as the primary defense. Filtering and authorization +are not bot bypasses: a bot identity is subject to the same comment admission +and content filtering rules as a human identity. + +`filter.status` is: + +- `unchanged`: emitted bytes equal normalized source bytes; +- `modified`: one or more replacements or redactions were applied; +- `truncated`: a size bound removed source bytes, whether or not earlier filters + also changed them; findings still report every replacement and redaction; +- `rejected`: no content file is emitted because the source could not be + represented safely. + +Source-derived display strings in JSON metadata pass through Unicode safety, +redaction, and complete-source injection scanning, then are bounded at a UTF-8 +code-point boundary with no trailing LF added. Bound display strings first; drop +empty optional values, re-unique labels, then sort labels and apply +`max_labels`. A required singleton title that becomes empty or unsafe aborts +assembly like a rejected entity body. Required nullable entity.author, +record.author, and actor.login values become JSON `null` when unsafe or empty. +An unsafe or empty check name or agent name rejects only its affected optional +record with an `unsafe_content`/`invalid_metadata` gap; it never aborts an +otherwise valid entity snapshot. Unsafe labels are dropped and findings are +retained. A truncated display string is scanned again exactly as emitted +before canonical serialization. This includes entity titles and labels; entity +and manifest-record author logins; actor logins; check names; and agent names. +Redaction reduces exposure but does not promise anonymization; +provider retention and prompt caching of remaining content are governed by the +configured provider trust boundary, not by this cleanup guarantee. + +Structural strings are not rewritten because doing so could change identity or +target a different resource. Canonical IDs use the mappings above. Repository +paths and review file paths MUST undergo the complete source-value filter +pipeline, including Unicode safety, secret redaction, and prompt-injection +scanning, before strict structural validation. An unsafe path is never rewritten: +the producer omits the affected optional record or relationship, and aborts when +a required singleton depends on it. The `repository_path` and `source.host` schema patterns +use only RE2-compatible syntax and enforce their printable alphabet; producers +additionally enforce the documented segment, leading-slash, trailing-slash, +port-range, and default-port rules. A validator that cannot compile or +evaluate any security pattern must report a validation error and abort required +snapshot assembly; it must never ignore the pattern or fall back to a weaker +constraint. v1 deliberately restricts `repository_path` to the +printable-ASCII allow-list encoded by `common.schema.json` (including its +explicit punctuation set and excluding non-ASCII letters and apostrophes); this +is an explicit compatibility and security boundary, not an implicit Unicode +normalization. Non-ASCII or other out-of-alphabet values are structurally +invalid. Repository file paths are relative, +slash-separated, contain no `.` or `..` segment, percent sign or percent-encoded +dot, slash, or backslash, control character, or non-rendering class named above. +The host port is 1 through 65535, and `:443` is rejected because the default +port is omitted. These values are untrusted forge data and must never be +interpolated into shell commands; generated order-file paths have a separate +shell-safe contract. +Source URLs +are intentionally not part of the agent-visible v1 tree; forge, host, +repository, and immutable record IDs provide provenance without copying +navigation URLs into staged metadata. An unsafe structural value, whether its +property is required or optional, produces an unusable `invalid_metadata` or +`unsafe_content` gap. For optional records and their related files, that gap +omits the selected source as described above. Required singleton structural +values cannot be omitted: an unsafe, missing, or schema-invalid entity `id`, or +index `source` field +(`host`, `repository_id`, or `repository`), aborts snapshot assembly rather +than emitting an invalid singleton or dangling manifest. Structural values are +never emitted after filtering or truncation. + +All structural IDs use the schema's `common.schema.json` `structural_id` +definition, which excludes whitespace, control characters, slashes, and shell +separators. Adapters apply the narrower forge mapping before schema validation: +GitHub node IDs use `[A-Za-z0-9][A-Za-z0-9_=-]*` (the schema's +`github_node_id` definition); GitLab and Forgejo numeric IDs use +`[1-9][0-9]*`; GitLab discussion IDs use +`[A-Za-z0-9][A-Za-z0-9._:-]*`; and filter finding codes use +`[a-z][a-z0-9._-]*`. Every GitHub-sourced structural ID uses the same +`github_node_id` mapping, including entity, record, actor, review, thread, +check, and agent-run IDs; the standalone child schemas rely on the adapter +check because they do not carry `source.forge`. A value outside its forge mapping is `invalid_metadata`; +it is rejected or the affected optional record is omitted rather than +rewritten. Unsafe required IDs abort assembly. + +`index.json.filter` records filtering of source-derived values in the index. +Manifest file entries require `filter` for entity, review, agent-run, check +metadata, check logs, and actor JSON documents. A `check_log` entry's filter +describes the emitted log bytes only; the parent check record's filter remains +the separate summary of filtered check metadata. Each manifest value summarizes +the filtered bytes for its own document or file. +Generated collection, state-without-display-text, and order documents do not +invent filter findings. + +Every emitted file other than the root `index.json` has a manifest `sha256` +over its emitted bytes. The assembler retains the exact root `index.json` bytes, +or a digest of them, in host-private run state outside the context tree. After +the host pre-script, Fullsend compares the on-disk root index with that retained +assembly value and aborts on any difference; it never treats a rewritten +on-disk index as the root of trust. Only the retained assembly index is used to +verify child digests and the exact manifest path set. A rejected non-entity +source has a record but no content path or file entry and adds an +`unsafe_content` gap for its scope. A rejected or missing entity-body record +aborts snapshot assembly, and Fullsend must not launch scripts or an agent with +that snapshot. + +Verification, upload, and cleanup MUST reject symlinks and special files at the +context root and every path component, and MUST require regular files beneath +real directories. After the root-index comparison, Fullsend MUST verify child +bytes into an immutable, digest-verified upload snapshot (for example, a private +copy with concurrent writers excluded and immutable/read-only enforcement), or +hold an equivalent exclusive writer-blocking capability. No-follow handles alone +are insufficient because an already-open regular file can still be truncated or +overwritten in place. The uploaded bytes MUST be the exact bytes verified against +the retained assembly manifest; if immutability or writer exclusion cannot be +enforced, assembly aborts before scripts or the agent launch. + +Findings contain codes and counts, not rejected source text. Filters and bounds +are identified by `filter_version`; changing emitted bytes for the same input +requires a new filter version. Removing or reinterpreting a status requires v2. + +## Ordering and determinism + +Manifest `records[]` entries are sorted by each record's real source +`created_at`, then by the record key's ASCII byte order; the reserved +entity-body order key does not change this array order. Record filenames are +sorted by their filename order key, which reserves +`00000000T000000000000000Z` for the entity body so it sorts first. `files[]` +remains path-sorted, and check paths do not embed an order key. Formal review +arrays sort by `submitted_at` and then review ID. Relationship thread arrays +sort by `created_at` and then thread ID; each +thread's `record_keys`, `replies`, and `.order` lines preserve forge thread +order. Mutable thread-state arrays sort by the thread key's ASCII byte order. +Actor-state arrays sort by actor ID's UTF-8 byte order. Agent receipts sort by +completion time and ID; each receipt's `result_record_keys` sort by ASCII byte +order. Entity labels sort by their filtered UTF-8 byte order. Manifest files +sort by path, gaps by scope and code, and filter findings by code. Other arrays +state their ordering in their owning schema before being added to v1. + +`generated_at` or another runner-clock value is forbidden anywhere under the +context root. Acquisition timing belongs in run telemetry outside the staged +tree. Source-provided timestamps, entity update time, Git object IDs used as +relationship values, and forge check record IDs are permitted. Determinism is +defined over the complete normalized acquisition inputs: forge responses, +authorization-provider results, effective admission policy, collection +profile, size bounds, filter version, and the active credential-redaction +registry. With those inputs identical, the complete tree has identical paths +and bytes; stale authorization or filtering state MUST NOT be reused. + +## Lifecycle and access + +The host tree is created outside both the repository and retained run-output +tree with directory mode `0700` and file mode `0600`. The sandbox copy is +agent-immutable: Fullsend exposes it through a read-only bind mount, or, when +that is unavailable, uses a root-owned tree with mode `0555` directories and +`0444` files while the agent runs unprivileged with `CAP_FOWNER` and equivalent +write-overriding capabilities removed. A plain mode-`0600` copy owned by the +agent does not satisfy this contract; if neither mechanism can be enforced, +Fullsend aborts before launching the agent. Fullsend removes the sandbox copy +after the runtime's last use and the host copy after the post-script on every +controlled exit, including skip, failure, and cancellation. Fullsend also +scavenges abandoned context trees on startup after an unclean termination. + +Artifact collectors must exclude entity-context-snapshot trees. Retained diagnostics +may contain bounded record counts, content digests, filter codes/counts, and +cleanup errors, but never entity bodies, comment/review bodies, or logs. + +## Compatibility + +Consumers must reject an unsupported `schema_version` or `filter_version`; they +must validate `index.json`, `collection.json`, `entity/metadata.json`, +`relations/reviews.json`, `history/agent-runs.json`, check metadata documents, +`state/actors.json`, and `state/threads.json` against their v1 schemas. Other +emitted files follow the byte contracts above. The files under +`docs/normative/entity-context-snapshot/v1/` form one local schema bundle: consumers +must load every sibling `*.schema.json` file into the same resolver registry, +keyed by its `$id` and filename, before validating any document. Relative +references such as `common.schema.json#/$defs/timestamp` resolve to sibling +files within that directory. `$id` values are stable schema identifiers, not +documented HTTP endpoints; consumers must not fetch them over the network, and +an unavailable sibling or unresolved reference is a validation error. The +schemas are closed: +adding a property, record kind, enum value, or status is a breaking change. +Changing path derivation, canonical bytes, required fields, field meaning, or +ordering likewise requires +`docs/normative/entity-context-snapshot/v2/` and a superseding ADR. + +The schema committed with the accepting ADR defines v1. Subsequent additions, +even an optional property, require v2: older closed-schema consumers would +reject them, and `schema_version` has no minor-version representation. + +## Relationship to normalized-event v1 + +Entity-context-snapshot stages only work items (issues) and change proposals +(PRs or MRs); normalized-event's `conversation` entity kind from ADR 0086 is +outside this version's scope. Entity-context-snapshot `kind` uses +normalized-event's `work_item` and `change_proposal` values. +Entity-context-snapshot `id` is the forge's immutable +opaque object ID because it participates in stable path derivation, while +`number` is the positive display number projected into normalized-event +`entity.id` for routing. Adapters must preserve that explicit mapping rather +than treating the two `id` fields as interchangeable. + +Entity state is normalized to `open` or `closed` for work items and to `open`, +`closed`, or `merged` for change proposals. Adapters use these exhaustive v1 +mappings: + +- GitHub issue `OPEN` and `CLOSED` map to `open` and `closed`. A pull request + with `merged: true` maps to `merged`; otherwise `OPEN` and `CLOSED` map to + `open` and `closed`. +- GitLab issue and merge-request `opened` and `closed` map to `open` and + `closed`; merge-request `merged` maps to `merged`. Merge-request `locked` + is GitLab's merge-in-progress lock and maps to `open`; the separate + `discussion_locked` field is omitted from entity metadata v1. +- Forgejo issue and pull-request `open` and `closed` map to `open` and `closed`; + a pull request with `merged: true` maps to `merged` regardless of its native + closed state. + +Any other native state on an optional record is `invalid_metadata`; adapters +must not invent another mapping. Because entity metadata and body are required +singletons, an unrepresentable entity state aborts snapshot assembly instead +of emitting an entity gap. diff --git a/docs/normative/entity-context-snapshot/v1/actor-state.schema.json b/docs/normative/entity-context-snapshot/v1/actor-state.schema.json new file mode 100644 index 0000000000..1b0f58b119 --- /dev/null +++ b/docs/normative/entity-context-snapshot/v1/actor-state.schema.json @@ -0,0 +1,56 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://fullsend.ai/normative/entity-context-snapshot/v1/actor-state.schema.json", + "title": "ActorState", + "type": "object", + "required": ["actors"], + "properties": { + "actors": { + "type": "array", + "uniqueItems": true, + "items": { + "type": "object", + "required": ["id", "kind", "login", "role", "role_verified"], + "properties": { + "id": { "$ref": "common.schema.json#/$defs/structural_id" }, + "kind": { "enum": ["human", "bot"] }, + "login": { "type": ["string", "null"], "minLength": 1 }, + "role": { + "oneOf": [ + { "$ref": "common.schema.json#/$defs/actor_role" }, + { "const": "bot" }, + { "type": "null" } + ] + }, + "role_verified": { "type": "boolean" } + }, + "allOf": [ + { + "if": { "properties": { "kind": { "const": "bot" } }, "required": ["kind"] }, + "then": { + "properties": { + "role": { "const": "bot" }, + "role_verified": { "const": false } + } + } + }, + { + "if": { "properties": { "kind": { "const": "human" } }, "required": ["kind"] }, + "then": { "properties": { "role": { "not": { "const": "bot" } } } } + }, + { + "if": { "properties": { "role_verified": { "const": true } }, "required": ["role_verified"] }, + "then": { "properties": { "role": { "$ref": "common.schema.json#/$defs/actor_role" } } }, + "else": { + "properties": { + "role": { "oneOf": [{ "const": "bot" }, { "type": "null" }] } + } + } + } + ], + "additionalProperties": false + } + } + }, + "additionalProperties": false +} diff --git a/docs/normative/entity-context-snapshot/v1/agent-runs.schema.json b/docs/normative/entity-context-snapshot/v1/agent-runs.schema.json new file mode 100644 index 0000000000..f01384380e --- /dev/null +++ b/docs/normative/entity-context-snapshot/v1/agent-runs.schema.json @@ -0,0 +1,37 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://fullsend.ai/normative/entity-context-snapshot/v1/agent-runs.schema.json", + "title": "AgentRuns", + "type": "object", + "required": ["runs"], + "properties": { + "runs": { + "type": "array", + "items": { + "type": "object", + "required": ["id", "agent", "status", "input_revision", "result_record_keys", "completed_at"], + "properties": { + "id": { "$ref": "common.schema.json#/$defs/structural_id" }, + "agent": { "type": "string", "minLength": 1 }, + "status": { "enum": ["success", "failure", "cancelled", "skipped", "timed_out"] }, + "input_revision": { + "$ref": "common.schema.json#/$defs/record_key", + "description": "SHA-256 of the canonical index.json consumed by this run." + }, + "input_head_sha": { "$ref": "common.schema.json#/$defs/git_oid" }, + "result_record_keys": { + "type": "array", + "items": { "$ref": "common.schema.json#/$defs/record_key" }, + "uniqueItems": true, + "description": "Result record keys sorted by ASCII byte order." + }, + "resulting_commit_sha": { "$ref": "common.schema.json#/$defs/git_oid" }, + "started_at": { "$ref": "common.schema.json#/$defs/timestamp" }, + "completed_at": { "$ref": "common.schema.json#/$defs/timestamp" } + }, + "additionalProperties": false + } + } + }, + "additionalProperties": false +} diff --git a/docs/normative/entity-context-snapshot/v1/check.schema.json b/docs/normative/entity-context-snapshot/v1/check.schema.json new file mode 100644 index 0000000000..9300db01a3 --- /dev/null +++ b/docs/normative/entity-context-snapshot/v1/check.schema.json @@ -0,0 +1,53 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://fullsend.ai/normative/entity-context-snapshot/v1/check.schema.json", + "title": "CheckMetadata", + "type": "object", + "required": ["id", "name", "status", "created_at", "head_sha"], + "properties": { + "id": { "$ref": "common.schema.json#/$defs/structural_id" }, + "name": { "type": "string", "minLength": 1 }, + "status": { "enum": ["queued", "in_progress", "completed"] }, + "conclusion": { "enum": ["success", "failure", "neutral", "cancelled", "skipped", "timed_out", "action_required", "stale"] }, + "created_at": { "$ref": "common.schema.json#/$defs/timestamp" }, + "head_sha": { + "$ref": "common.schema.json#/$defs/git_oid", + "description": "The target change-proposal HEAD SHA observed at collection time; only checks for that exact SHA are retained." + }, + "started_at": { "$ref": "common.schema.json#/$defs/timestamp" }, + "never_started": { + "type": "boolean", + "description": "Required for completed checks. True only when the forge explicitly reports a never-started terminal, including a completed skipped or cancelled outcome with no native started_at under the adapter mapping; false requires started_at." + }, + "completed_at": { + "$ref": "common.schema.json#/$defs/timestamp", + "description": "Native terminal timestamp when available. For never_started true, an absent native terminal timestamp is canonically represented by the source created_at value; this is not a runner-observed completion time." + } + }, + "allOf": [ + { + "if": { "properties": { "status": { "const": "queued" } }, "required": ["status"] }, + "then": { "not": { "anyOf": [{ "required": ["started_at"] }, { "required": ["completed_at"] }, { "required": ["conclusion"] }, { "required": ["never_started"] }] } } + }, + { + "if": { "properties": { "status": { "const": "in_progress" } }, "required": ["status"] }, + "then": { + "required": ["started_at"], + "not": { "anyOf": [{ "required": ["completed_at"] }, { "required": ["conclusion"] }, { "required": ["never_started"] }] } + } + }, + { + "if": { "properties": { "status": { "const": "completed" } }, "required": ["status"] }, + "then": { + "required": ["completed_at", "conclusion", "never_started"], + "if": { "properties": { "never_started": { "const": true } }, "required": ["never_started"] }, + "then": { + "properties": { "conclusion": { "enum": ["cancelled", "skipped", "failure"] } }, + "not": { "required": ["started_at"] } + }, + "else": { "required": ["started_at"] } + } + } + ], + "additionalProperties": false +} diff --git a/docs/normative/entity-context-snapshot/v1/collection.schema.json b/docs/normative/entity-context-snapshot/v1/collection.schema.json new file mode 100644 index 0000000000..fd85499ea2 --- /dev/null +++ b/docs/normative/entity-context-snapshot/v1/collection.schema.json @@ -0,0 +1,75 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://fullsend.ai/normative/entity-context-snapshot/v1/collection.schema.json", + "title": "EntityContextSnapshotCollection", + "type": "object", + "required": ["entity_kind", "admission", "included_sources", "record_selection", "check_log_selection", "bounds"], + "properties": { + "entity_kind": { + "enum": ["work_item", "change_proposal"], + "description": "The forge entity kind being collected; source selection is constrained by this value." + }, + "admission": { + "type": "object", + "required": ["human_min_role"], + "properties": { + "human_min_role": { + "enum": ["triage", "write"], + "description": "The effective minimum current forge role for human entity, comment, and review authors: triage for observation runs or write for mutation runs. Registered bot roles follow ADR 0107 and do not use this human threshold." + } + }, + "additionalProperties": false + }, + "included_sources": { + "type": "array", + "items": { "enum": ["entity", "comments", "reviews", "checks", "check_logs", "agent_runs"] }, + "contains": { "const": "entity" }, + "uniqueItems": true, + "description": "Source kinds sorted by ASCII byte order; entity is always present." + }, + "record_selection": { + "enum": ["oldest", "newest"], + "description": "Which end of canonical source order is retained when a record-count bound applies." + }, + "check_log_selection": { + "enum": ["none", "failed", "all"], + "description": "Which selected checks have logs collected." + }, + "bounds": { + "type": "object", + "required": ["max_records_per_source", "max_source_bytes", "max_record_bytes", "max_log_bytes", "max_metadata_string_bytes", "max_labels"], + "properties": { + "max_records_per_source": { "type": "integer", "minimum": 1 }, + "max_source_bytes": { "type": "integer", "minimum": 1 }, + "max_record_bytes": { "type": "integer", "minimum": 1 }, + "max_log_bytes": { "type": "integer", "minimum": 1 }, + "max_metadata_string_bytes": { "type": "integer", "minimum": 1 }, + "max_labels": { "type": "integer", "minimum": 0 } + }, + "additionalProperties": false + } + }, + "allOf": [ + { + "if": { "properties": { "entity_kind": { "const": "work_item" } }, "required": ["entity_kind"] }, + "then": { + "properties": { + "included_sources": { + "items": { "enum": ["entity", "comments", "agent_runs"] } + } + } + } + }, + { + "if": { "properties": { "included_sources": { "contains": { "const": "check_logs" } } }, "required": ["included_sources"] }, + "then": { + "properties": { + "included_sources": { "contains": { "const": "checks" } }, + "check_log_selection": { "enum": ["failed", "all"] } + } + }, + "else": { "properties": { "check_log_selection": { "const": "none" } } } + } + ], + "additionalProperties": false +} diff --git a/docs/normative/entity-context-snapshot/v1/common.schema.json b/docs/normative/entity-context-snapshot/v1/common.schema.json new file mode 100644 index 0000000000..571627664d --- /dev/null +++ b/docs/normative/entity-context-snapshot/v1/common.schema.json @@ -0,0 +1,50 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://fullsend.ai/normative/entity-context-snapshot/v1/common.schema.json", + "title": "EntityContextSnapshotCommonDefinitions", + "$defs": { + "timestamp": { + "type": "string", + "format": "date-time", + "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}[.][0-9]{9}Z$" + }, + "git_oid": { + "type": "string", + "pattern": "^[0-9a-f]{40}([0-9a-f]{24})?$" + }, + "record_key": { + "type": "string", + "pattern": "^[0-9a-f]{64}$" + }, + "structural_id": { + "type": "string", + "pattern": "^[A-Za-z0-9][A-Za-z0-9._:=-]*$", + "description": "Forge or receipt identifier. Structural IDs use a printable, separator-safe ASCII alphabet and are never rewritten. Forge-specific mappings further restrict this alphabet." + }, + "github_node_id": { + "type": "string", + "pattern": "^[A-Za-z0-9][A-Za-z0-9_=-]*$", + "description": "GitHub GraphQL node_id. Every GitHub-sourced structural ID uses this adapter mapping before schema validation." + }, + "finding_code": { + "type": "string", + "pattern": "^[a-z][a-z0-9._-]*$" + }, + "repository_path": { + "type": "string", + "minLength": 1, + "pattern": "^[A-Za-z0-9._/~!$&()+,;=:@#\\[\\]{} -]+$", + "allOf": [ + { "not": { "pattern": "^/" } }, + { "not": { "pattern": "/$" } }, + { "not": { "pattern": "//" } }, + { "not": { "pattern": "(^|/)\\.{1,2}(/|$)" } }, + { "not": { "pattern": "%" } }, + { "not": { "pattern": "[\u200b-\u200d\u202a-\u202e\u2066-\u2069\ufeff\ufe00-\ufe0f\ufff9-\ufffb]" } } + ] + }, + "actor_role": { + "enum": ["admin", "maintain", "write", "triage", "read", "none", "external"] + } + } +} diff --git a/docs/normative/entity-context-snapshot/v1/entity.schema.json b/docs/normative/entity-context-snapshot/v1/entity.schema.json new file mode 100644 index 0000000000..50860ca85d --- /dev/null +++ b/docs/normative/entity-context-snapshot/v1/entity.schema.json @@ -0,0 +1,43 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://fullsend.ai/normative/entity-context-snapshot/v1/entity.schema.json", + "title": "EntityMetadata", + "type": "object", + "required": ["kind", "id", "number", "title", "state", "author_id", "author", "created_at", "updated_at", "labels"], + "properties": { + "kind": { "enum": ["work_item", "change_proposal"] }, + "id": { + "$ref": "common.schema.json#/$defs/structural_id", + "description": "Immutable opaque forge object ID used for record keys; distinct from normalized-event v1 entity.id." + }, + "number": { + "type": "integer", + "minimum": 1, + "description": "Positive forge display number projected into normalized-event v1 entity.id." + }, + "title": { "type": "string", "minLength": 1 }, + "state": { "enum": ["open", "closed", "merged"] }, + "author_id": { + "oneOf": [ + { "$ref": "common.schema.json#/$defs/structural_id" }, + { "type": "null" } + ] + }, + "author": { "type": ["string", "null"], "minLength": 1 }, + "created_at": { "$ref": "common.schema.json#/$defs/timestamp" }, + "updated_at": { "$ref": "common.schema.json#/$defs/timestamp" }, + "labels": { + "type": "array", + "items": { "type": "string" }, + "uniqueItems": true, + "description": "Filtered label strings sorted by UTF-8 byte order." + } + }, + "allOf": [ + { + "if": { "properties": { "kind": { "const": "work_item" } }, "required": ["kind"] }, + "then": { "properties": { "state": { "enum": ["open", "closed"] } } } + } + ], + "additionalProperties": false +} diff --git a/docs/normative/entity-context-snapshot/v1/index.schema.json b/docs/normative/entity-context-snapshot/v1/index.schema.json new file mode 100644 index 0000000000..deae280f90 --- /dev/null +++ b/docs/normative/entity-context-snapshot/v1/index.schema.json @@ -0,0 +1,252 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://fullsend.ai/normative/entity-context-snapshot/v1/index.schema.json", + "title": "EntityContextSnapshotIndex", + "type": "object", + "required": ["schema_version", "filter_version", "collection_profile", "filter", "source", "entity", "files", "records", "gaps"], + "properties": { + "schema_version": { "const": 1 }, + "filter_version": { "type": "string", "minLength": 1 }, + "collection_profile": { "$ref": "common.schema.json#/$defs/record_key" }, + "filter": { + "allOf": [ + { "$ref": "#/$defs/filter" }, + { "properties": { "status": { "enum": ["unchanged", "modified", "truncated"] } } } + ] + }, + "source": { + "type": "object", + "required": ["forge", "host", "repository_id", "repository"], + "properties": { + "forge": { "enum": ["github", "gitlab", "forgejo"] }, + "host": { + "type": "string", + "pattern": "^[a-z0-9.-]+(:([1-9]|[1-9][0-9]{1,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5]))?$", + "allOf": [{ "not": { "pattern": ":443$" } }] + }, + "repository_id": { "$ref": "common.schema.json#/$defs/structural_id" }, + "repository": { + "allOf": [ + { "$ref": "common.schema.json#/$defs/repository_path" }, + { "pattern": "^[^/]+(/[^/]+)+$" } + ] + } + }, + "allOf": [ + { + "if": { "properties": { "forge": { "const": "github" } }, "required": ["forge"] }, + "then": { + "properties": { + "repository_id": { "$ref": "common.schema.json#/$defs/github_node_id" }, + "repository": { "pattern": "^[a-z0-9_.-]+/[a-z0-9_.-]+$" } + } + } + }, + { + "if": { "properties": { "forge": { "enum": ["gitlab", "forgejo"] } }, "required": ["forge"] }, + "then": { "properties": { "repository_id": { "pattern": "^[1-9][0-9]*$" } } } + }, + { + "if": { "properties": { "forge": { "const": "forgejo" } }, "required": ["forge"] }, + "then": { "properties": { "repository": { "pattern": "^[a-z0-9_.-]+/[a-z0-9_.-]+$" } } } + } + ], + "additionalProperties": false + }, + "entity": { + "type": "object", + "required": ["kind", "id"], + "properties": { + "kind": { "enum": ["work_item", "change_proposal"] }, + "id": { + "$ref": "common.schema.json#/$defs/structural_id", + "description": "Immutable opaque forge object ID; distinct from the positive display number in normalized-event v1 entity.id." + }, + "updated_at": { "$ref": "common.schema.json#/$defs/timestamp" } + }, + "additionalProperties": false + }, + "files": { + "type": "array", + "items": { "$ref": "#/$defs/file" } + }, + "records": { + "type": "array", + "items": { "$ref": "#/$defs/record" } + }, + "gaps": { + "type": "array", + "items": { "$ref": "#/$defs/gap" }, + "description": "At most one row per (scope, code) pair; producers aggregate counts before canonical serialization and sort by scope then code." + } + }, + "allOf": [ + { + "if": { + "properties": { + "source": { + "properties": { "forge": { "const": "github" } }, + "required": ["forge"] + } + }, + "required": ["source"] + }, + "then": { + "properties": { + "source": { + "properties": { + "repository_id": { "$ref": "common.schema.json#/$defs/github_node_id" } + } + }, + "entity": { + "properties": { + "id": { "$ref": "common.schema.json#/$defs/github_node_id" } + } + }, + "records": { + "items": { + "properties": { + "id": { "$ref": "common.schema.json#/$defs/github_node_id" }, + "author_id": { + "oneOf": [ + { "$ref": "common.schema.json#/$defs/github_node_id" }, + { "type": "null" } + ] + } + } + } + } + } + } + } + ], + "additionalProperties": false, + "$defs": { + "filter": { + "type": "object", + "required": ["status", "findings"], + "properties": { + "status": { "enum": ["unchanged", "modified", "truncated", "rejected"] }, + "findings": { + "type": "array", + "items": { + "type": "object", + "required": ["code", "count"], + "properties": { + "code": { "$ref": "common.schema.json#/$defs/finding_code" }, + "count": { "type": "integer", "minimum": 1 } + }, + "additionalProperties": false + } + } + }, + "additionalProperties": false + }, + "file": { + "type": "object", + "required": ["path", "role", "media_type", "bytes", "sha256"], + "properties": { + "path": { + "type": "string", + "pattern": "^(collection[.]json|entity/metadata[.]json|records/([0-9]{8}T[0-9]{15}Z)-[0-9a-f]{64}[.]md|threads/[0-9a-f]{64}[.]order|views/(timeline|unresolved-review)[.]order|views/reviews/[0-9a-f]{64}[.]order|relations/reviews[.]json|history/agent-runs[.]json|checks/[0-9a-f]{64}/(metadata[.]json|log[.]txt)|state/(actors|threads)[.]json)$" + }, + "role": { + "enum": ["collection", "entity_metadata", "entity_record", "comment_record", "review_record", "thread_order", "timeline_view", "unresolved_review_view", "review_view", "reviews", "agent_runs", "check_metadata", "check_log", "actor_state", "thread_state"] + }, + "media_type": { + "enum": ["application/json", "text/markdown", "text/plain"] + }, + "bytes": { "type": "integer", "minimum": 0 }, + "sha256": { "$ref": "common.schema.json#/$defs/record_key" }, + "filter": { + "allOf": [ + { "$ref": "#/$defs/filter" }, + { "properties": { "status": { "enum": ["unchanged", "modified", "truncated"] } } } + ] + } + }, + "allOf": [ + { + "if": { "properties": { "role": { "enum": ["collection", "entity_metadata", "reviews", "agent_runs", "check_metadata", "actor_state", "thread_state"] } }, "required": ["role"] }, + "then": { "properties": { "media_type": { "const": "application/json" } } } + }, + { + "if": { "properties": { "role": { "enum": ["entity_record", "comment_record", "review_record"] } }, "required": ["role"] }, + "then": { "properties": { "media_type": { "const": "text/markdown" } } } + }, + { + "if": { "properties": { "role": { "enum": ["thread_order", "timeline_view", "unresolved_review_view", "review_view", "check_log"] } }, "required": ["role"] }, + "then": { "properties": { "media_type": { "const": "text/plain" } } } + }, + { + "if": { "properties": { "role": { "enum": ["entity_metadata", "reviews", "agent_runs", "check_metadata", "check_log", "actor_state"] } }, "required": ["role"] }, + "then": { "required": ["filter"] } + } + ], + "additionalProperties": false + }, + "gap": { + "type": "object", + "required": ["scope", "code", "usability", "count"], + "properties": { + "scope": { "enum": ["entity", "comments", "reviews", "checks", "check_logs", "agent_runs", "actors"] }, + "code": { "enum": ["profile_bound", "history_unavailable", "unsupported", "authorization_failed", "fetch_failed", "source_too_large", "invalid_metadata", "unsafe_content"] }, + "usability": { "enum": ["partial", "unusable"] }, + "count": { "type": "integer", "minimum": 1 } + }, + "allOf": [ + { + "if": { "properties": { "code": { "enum": ["profile_bound", "history_unavailable"] } }, "required": ["code"] }, + "then": { "properties": { "usability": { "const": "partial" } } }, + "else": { "properties": { "usability": { "const": "unusable" } } } + } + ], + "additionalProperties": false + }, + "record": { + "type": "object", + "required": ["kind", "id", "record_key", "created_at", "filter"], + "properties": { + "kind": { "enum": ["entity", "comment", "review", "check"] }, + "id": { "$ref": "common.schema.json#/$defs/structural_id" }, + "record_key": { "$ref": "common.schema.json#/$defs/record_key" }, + "content_path": { "type": "string", "pattern": "^records/[0-9]{8}T[0-9]{15}Z-[0-9a-f]{64}[.]md$" }, + "metadata_path": { "type": "string", "pattern": "^checks/[0-9a-f]{64}/metadata[.]json$" }, + "log_path": { "type": "string", "pattern": "^checks/[0-9a-f]{64}/log[.]txt$" }, + "author_id": { + "oneOf": [ + { "$ref": "common.schema.json#/$defs/structural_id" }, + { "type": "null" } + ] + }, + "author": { "type": ["string", "null"], "minLength": 1 }, + "created_at": { "$ref": "common.schema.json#/$defs/timestamp" }, + "updated_at": { "$ref": "common.schema.json#/$defs/timestamp" }, + "filter": { "$ref": "#/$defs/filter" } + }, + "allOf": [ + { + "if": { "properties": { "kind": { "const": "check" } }, "required": ["kind"] }, + "then": { "not": { "anyOf": [{ "required": ["author_id"] }, { "required": ["author"] }] } }, + "else": { "required": ["author_id", "author"] } + }, + { + "if": { "properties": { "filter": { "properties": { "status": { "const": "rejected" } } } } }, + "then": { "not": { "anyOf": [{ "required": ["content_path"] }, { "required": ["metadata_path"] }, { "required": ["log_path"] }] } }, + "else": { + "if": { "properties": { "kind": { "const": "check" } } }, + "then": { + "required": ["metadata_path"], + "not": { "required": ["content_path"] } + }, + "else": { + "required": ["content_path"], + "not": { "anyOf": [{ "required": ["metadata_path"] }, { "required": ["log_path"] }] } + } + } + } + ], + "additionalProperties": false + } + } +} diff --git a/docs/normative/entity-context-snapshot/v1/reviews.schema.json b/docs/normative/entity-context-snapshot/v1/reviews.schema.json new file mode 100644 index 0000000000..b1ec013f60 --- /dev/null +++ b/docs/normative/entity-context-snapshot/v1/reviews.schema.json @@ -0,0 +1,85 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://fullsend.ai/normative/entity-context-snapshot/v1/reviews.schema.json", + "title": "ReviewRelationships", + "type": "object", + "required": ["reviews", "threads"], + "properties": { + "reviews": { + "type": "array", + "items": { + "type": "object", + "required": ["id", "record_key", "state", "submitted_at"], + "properties": { + "id": { "$ref": "common.schema.json#/$defs/structural_id" }, + "record_key": { "$ref": "common.schema.json#/$defs/record_key" }, + "state": { "enum": ["approved", "changes_requested", "commented", "dismissed"] }, + "reviewed_sha": { "$ref": "common.schema.json#/$defs/git_oid" }, + "submitted_at": { "$ref": "common.schema.json#/$defs/timestamp" }, + "dismissed_at": { + "oneOf": [ + { "$ref": "common.schema.json#/$defs/timestamp" }, + { "type": "null" } + ] + }, + "dismissed_by_actor_id": { + "oneOf": [ + { "$ref": "common.schema.json#/$defs/structural_id" }, + { "type": "null" } + ] + } + }, + "allOf": [ + { + "if": { "properties": { "state": { "const": "dismissed" } }, "required": ["state"] }, + "then": { "required": ["dismissed_at", "dismissed_by_actor_id"] }, + "else": { "not": { "anyOf": [{ "required": ["dismissed_at"] }, { "required": ["dismissed_by_actor_id"] }] } } + } + ], + "additionalProperties": false + } + }, + "threads": { + "type": "array", + "items": { + "type": "object", + "required": ["id", "thread_key", "created_at", "order_path", "record_keys", "replies"], + "properties": { + "id": { "$ref": "common.schema.json#/$defs/structural_id" }, + "thread_key": { "$ref": "common.schema.json#/$defs/record_key" }, + "created_at": { "$ref": "common.schema.json#/$defs/timestamp" }, + "order_path": { "type": "string", "pattern": "^threads/[0-9a-f]{64}[.]order$" }, + "record_keys": { + "type": "array", + "items": { "$ref": "common.schema.json#/$defs/record_key" }, + "uniqueItems": true + }, + "replies": { + "type": "array", + "items": { + "type": "object", + "required": ["record_key", "parent_record_key"], + "properties": { + "record_key": { "$ref": "common.schema.json#/$defs/record_key" }, + "parent_record_key": { "$ref": "common.schema.json#/$defs/record_key" } + }, + "additionalProperties": false + } + }, + "review_id": { "$ref": "common.schema.json#/$defs/structural_id" }, + "review_record_key": { "$ref": "common.schema.json#/$defs/record_key" }, + "reviewed_sha": { "$ref": "common.schema.json#/$defs/git_oid" }, + "path": { "$ref": "common.schema.json#/$defs/repository_path" }, + "line": { "type": "integer", "minimum": 1 }, + "side": { "enum": ["left", "right"] }, + "start_line": { "type": "integer", "minimum": 1 }, + "original_line": { "type": "integer", "minimum": 1 }, + "original_start_line": { "type": "integer", "minimum": 1 }, + "original_side": { "enum": ["left", "right"] } + }, + "additionalProperties": false + } + } + }, + "additionalProperties": false +} diff --git a/docs/normative/entity-context-snapshot/v1/thread-state.schema.json b/docs/normative/entity-context-snapshot/v1/thread-state.schema.json new file mode 100644 index 0000000000..8ce7e6e794 --- /dev/null +++ b/docs/normative/entity-context-snapshot/v1/thread-state.schema.json @@ -0,0 +1,38 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://fullsend.ai/normative/entity-context-snapshot/v1/thread-state.schema.json", + "title": "ThreadState", + "type": "object", + "required": ["threads"], + "properties": { + "threads": { + "type": "array", + "items": { + "type": "object", + "required": ["id", "thread_key", "resolved", "outdated"], + "properties": { + "id": { "$ref": "common.schema.json#/$defs/structural_id" }, + "thread_key": { "$ref": "common.schema.json#/$defs/record_key" }, + "resolved": { "type": "boolean" }, + "resolved_by_actor_id": { + "oneOf": [ + { "$ref": "common.schema.json#/$defs/structural_id" }, + { "type": "null" } + ] + }, + "outdated": { "type": "boolean" }, + "minimized": { "type": "boolean" } + }, + "allOf": [ + { + "if": { "properties": { "resolved": { "const": true } }, "required": ["resolved"] }, + "then": { "required": ["resolved_by_actor_id"] }, + "else": { "not": { "required": ["resolved_by_actor_id"] } } + } + ], + "additionalProperties": false + } + } + }, + "additionalProperties": false +} diff --git a/docs/normative/normalized-event/v1/README.md b/docs/normative/normalized-event/v1/README.md index 4c20e6071f..d86fb420af 100644 --- a/docs/normative/normalized-event/v1/README.md +++ b/docs/normative/normalized-event/v1/README.md @@ -85,6 +85,12 @@ remains the normative stricter check. Adding a new `transition.kind` is **non-breaking** — CEL triggers use boolean expressions, not exhaustive enum matching. +Normalized-event and entity-context-snapshot v1 carry independently versioned +copies of the actor-role vocabulary. The entity-context-snapshot `bot` marker +is a non-authority kind marker, not a normalized-event repository permission, +and must not be projected into `event.actor.role`; adapters validate each +document against its own schema. + ## Adapters Input drivers map native forge events into this struct: diff --git a/docs/problems/security-threat-model.md b/docs/problems/security-threat-model.md index 0cd38da66f..c5513c542d 100644 --- a/docs/problems/security-threat-model.md +++ b/docs/problems/security-threat-model.md @@ -58,6 +58,9 @@ The attack surface is the same as for visible prompt injection — PR descriptio - **Edge and proxy guardrails** — Some organizations filter or moderate **outbound** model traffic (prompts or completions) or tool invocations at a **gateway** in front of providers and MCP servers — for example policy-as-code, rate limits, or vendor moderation hooks. That can add defense in depth and consistent telemetry, but it does not remove the need for **in-agent** separation of trusted instructions from untrusted forge content; see [landscape.md](../landscape.md#agent-gateway). A compromised gateway policy is a concentrated risk, so gateway configuration should be governed like other agent infrastructure. - **Input sanitization** — strip or flag non-rendering Unicode characters before content reaches agents. Specific character classes to target: Tag characters (U+E0000–U+E007F), zero-width characters (U+200B, U+200C, U+200D, U+FEFF), bidirectional overrides (U+202A–U+202E, U+2066–U+2069), and variation selectors. This is more tractable than general prompt injection detection because the characters themselves are the signal — their mere presence in a PR description or code comment is suspicious, regardless of what they encode. However, some of these characters have legitimate uses in internationalized text, so stripping must be context-aware or at minimum flag rather than silently remove. + Deterministic filtering and finding disclosure for fetched entity content is + decided in [ADR 0141](../ADRs/0141-deterministic-filtered-entity-context-staging.md) + under the actor-attributed admission and filtering boundary of [ADR 0133](../ADRs/0133-actor-attributed-data-security-boundary.md). - **Separation of data and instructions** — agent prompts should clearly delineate between "system instructions" and "untrusted input being analyzed" - **Multi-agent verification** — a reviewing agent's decision is checked by a separate security agent that specifically looks for injection patterns - **Principle of least privilege** — agents should have the minimum permissions needed. A reviewing agent doesn't need merge authority.