Skip to content

Extractions report whether their subject is present - #409

Open
agorischek wants to merge 6 commits into
mainfrom
schema/subject-presence
Open

agorischek wants to merge 6 commits into
mainfrom
schema/subject-presence

Conversation

@agorischek

Copy link
Copy Markdown
Collaborator

What changed

Refs #373. This is Phase 1 of the subject-presence design (docs/design/proposals/subject-presence.md): the contract. An extraction can now say whether what its projection describes exists at the examined revision, so later phases can tell "this change adds the workflow" from "this workflow declares no jobs".

Schema. extraction/v0 gains an optional presence: "present" | "absent". Omitted means not reported, which is unknown and never present. The JSON Schema requires an absent extraction to have no items and a nonempty missingInputs. The docs note that v1 will make presence required.

Engine (native and Wasm):

  • Parses presence and keeps it as written, either value. It's in the canonical bytes when written, so extractions that omit it keep their bytes and digests.
  • New validation codes: invalid-presence, absent-with-items and absent-without-missing-input.
  • A presence difference between reruns is non-determinism: vary reports /presence.
  • New pure function projections_engine::presence_change(before, after), exposed as the presence operation and engine.presence(before, after). It returns {before, after, change, inferred}, where change is added, removed, absent, present or unknown.
    • An omitted side is inferred present when it has items, since an absent extraction can't have any.
    • An omitted side is inferred absent when it has no items and names missing inputs (the legacy heuristic).
    • Otherwise an omitted side is unknown.
    • inferred is true when either side was inferred.
  • presenceChange and extractionPresence in @githubnext/projections-schemas mirror the function in TypeScript for synchronous callers (the kit and hosts in Phase 3). New presence cases in the shared conformance corpus hold the Rust engine, native and Wasm JS, and the TS mirror to the same answers.

SDK helpers:

  • Rust: Context::subject_exists(path) and Context::subject_matches(glob, files) check anchors of the subject. finish (now -> Result<Value>) writes presence: absent when no anchor checked exists, present when any does. It fails when an absent extraction returned items. An explicit presence is kept, and input_exists stays for auxiliary inputs.
  • Node: request.subjectExists(path) and request.subjectMatches(glob).
  • Python: request.subject_exists(path) and request.subject_matches(glob).
  • extraction() and result() accept presence and fill in presence and missingInputs from the checks. extractor-helpers.json gains files and checks, so both helpers are pinned on real file trees.

Docs:

  • docs/contracts/extractions.md gains a Presence section, and docs/contracts/extractors.md an "An absent subject" section.
  • docs/contracts.md documents the presence operation.
  • Updated the first-extractor guide, SKILL.md and its generated copy, plus the regenerated schema, extractor-SDK and renderer-kit references.
  • New proposal: docs/design/proposals/subject-presence.md.

No built-in extractor changes here, so no built-in output or digest changes. Phase 2 makes built-ins write presence on every extraction, which changes their digests once.

Evidence

  • cargo test -p projections-engine -p projections-extractor-sdk -p projections-extractor-go-public-api -p projections-extractor-prisma-schema -p projections-extractor-workspace-dependencies -p projections-extractor-tetragon-policies: passed, 0 failures. This covers:

    • the new validation codes;
    • the canonical bytes of an unreported extraction pinned unchanged;
    • absent, present-empty and unreported digests all differing;
    • the rerun presence difference;
    • the conformance corpus;
    • SDK anchor cases: all missing gives absent, some missing gives present with missingInputs, and absent with items is an error.
  • cargo check --workspace --all-targets: passed.

  • node --test packages/engine/js/test/*.test.mjs: 257/257 passed, with the corpus run through the native and Wasm engines.

  • npm test --workspace @githubnext/projections-schemas: 25/25 passed, including the TS mirror against the corpus and the generated-file check.

  • node --test packages/cli/test/extractor-helpers.test.mjs: 39/39 passed (Node and Python).

  • node --test packages/sdk/test/extractor.test.ts: 9/9 passed. node packages/sdk/scripts/extractor-module.mjs --check also passed.

  • tsc --noEmit for packages/sdk, packages/engine/js and packages/schemas: passed.

  • npm run tools -- check --fast: format, lint, considered, cargo-fmt, cargo-check and the repository rules passed.

  • Generated files:

    • docs/reference/schemas/extraction.md, docs/reference/extractor-sdk.md and docs/reference/renderer-kit.md were regenerated with tools/scripts/reference-docs.mjs --only schemas,rust-sdk,renderer-sdk.
    • docs/agents/create-projection.md was not regenerated. Its generator needs projections help authoring with every renderer built, which this environment couldn't do, so I mirrored the SKILL.md edit verbatim. npm run docs:check in CI verifies it.
  • Documentation that this change affects is updated, and generated reference pages are regenerated (npm run docs:generate).

  • Fixes include a regression test.

  • A changelog fragment at changelog.d/<this PR's number>.md describes what users will notice, or the PR has the no changelog label (see changelog.d/README.md).

  • No credentials, private source or machine-specific paths are included.

agorischek and others added 5 commits December 5, 2026 01:07
… operation

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
…sence

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
…ts/subjectMatches, presenceChange

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
… skill, and the subject-presence proposal

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Subject-anchor scope and normalization bugs can misreport presence or produce invalid missing inputs, while short-circuiting validation accepts malformed relationship collections.

4 open issues
What changed in this PR

Adds the subject-presence contract to Projections, laying groundwork for distinguishing missing subjects from empty ones in #373. Built-in extractor adoption and viewer changes remain deferred.

Changes:

  • Adds optional presence, validation, canonical encoding, and presence comparison APIs.
  • Adds subject-anchor helpers for Rust, Node, and Python.
  • Extends conformance tests, documentation, and generated references.
File Description
packages/​sdk/​src/​extractor/​subject.ts Tracks subject anchors and presence.
packages/​sdk/​src/​extractor/​result.ts Includes presence in extraction results.
packages/​sdk/​src/​extractor/​request.ts Adds subject-check methods.
packages/​schemas/​test/​contracts.test.mjs Tests presence conformance.
packages/​schemas/​src/​typebox/​extraction.ts Defines presence constraints.
packages/​schemas/​src/​repository/​fixtures.ts Extends fixture formats.
packages/​schemas/​src/​presence.ts Adds synchronous presence classification.
packages/​schemas/​src/​index.ts Exports presence types and APIs.
packages/​schemas/​schemas/​extraction/​v0.json Updates generated extraction schema.
packages/​schemas/​internal/​extractor-helpers.json Updates helper fixture schema.
packages/​schemas/​internal/​conformance.json Allows presence operations.
packages/​schemas/​fixtures/​extractor-helpers.json Adds subject-check cases.
packages/​schemas/​fixtures/​conformance.json Adds presence contract cases.
packages/​extractors/​workspace-dependencies/​tests/​managers.rs Adapts to fallible finish.
packages/​extractors/​tetragon-policies/​tests/​extractions.rs Adapts to fallible finish.
packages/​extractors/​sdk/​tests/​source.rs Tests subject-anchor behavior.
packages/​extractors/​sdk/​src/​entry.rs Propagates finalization errors.
packages/​extractors/​sdk/​src/​context.rs Tracks anchors and finalizes presence.
packages/​extractors/​prisma-schema/​tests/​prisma.rs Adapts to fallible finish.
packages/​extractors/​go-public-api/​src/​lib.rs Updates test result propagation.
packages/​engine/​tests/​volatility.rs Tests presence differences between reruns.
packages/​engine/​tests/​validation.rs Tests presence validation and digests.
packages/​engine/​src/​volatility/​rerun.rs Reports presence differences.
packages/​engine/​src/​presence.rs Implements presence classification and validation.
packages/​engine/​src/​parse/​request.rs Dispatches presence requests.
packages/​engine/​src/​parse/​extraction.rs Parses and validates presence.
packages/​engine/​src/​parse/​encode.rs Encodes reported presence.
packages/​engine/​src/​model/​extraction.rs Stores and exposes presence.
packages/​engine/​src/​lib.rs Exports presence APIs.
packages/​engine/​js/​test/​engine.test.mjs Runs presence conformance requests.
packages/​engine/​js/​src/​engine.ts Exposes engine.presence.
packages/​cli/​test/​extractor-helpers/​driver.py Executes Python subject checks.
packages/​cli/​test/​extractor-helpers/​driver.mjs Executes Node subject checks.
packages/​cli/​test/​extractor-helpers.test.mjs Creates fixture file trees.
packages/​cli/​templates/​SKILL.md Documents subject checks for authors.
packages/​cli/​python/​projections/​__init__.py Adds Python presence helpers.
packages/​cli/​node/​extractor.mjs Updates bundled Node helpers.
docs/​reference/​schemas/​extraction.md Documents the presence field.
docs/​reference/​renderer-kit.md Updates extraction type reference.
docs/​reference/​extractor-sdk.md Documents Rust SDK additions.
docs/​guides/​first-extractor.md Demonstrates absent-subject handling.
docs/​design/​proposals/​subject-presence.md Describes design and migration phases.
docs/​contracts/​extractors.md Defines absent-subject output.
docs/​contracts/​extractions.md Specifies presence semantics.
docs/​contracts.md Documents the presence operation.
docs/​agents/​create-projection.md Mirrors authoring guidance.
changelog.d/​409.md Announces the contract and helpers.

Review effort: Balanced

Comment thread packages/engine/src/presence.rs Resolved
Comment thread packages/extractors/sdk/src/context.rs Resolved
Comment thread packages/sdk/src/extractor/request.ts Resolved
Comment thread packages/sdk/src/extractor/subject.ts Resolved
- Pass cx.files() to subject_matches directly in the SDK tests (clippy unnecessary_to_owned).
- Engine presence: check entities and relationships both before combining them.
- Rust subject_matches: drop a leading ./ before compiling the glob; reject an empty one.
- Node and Python anchors: reject rooted anchors before trimming, without a polynomial regex;
  reject a glob that names the project; refuse path anchors outside a declared scope, as Rust does.
- Helper fixture schema: write the checks pair with prefixItems (JSON Schema 2020-12).

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants