Skip to content

fix: align narrative state outputs with schema#19500

Closed
BrianCLong wants to merge 1 commit intomainfrom
codex/implement-graph-schema-in-neo4j
Closed

fix: align narrative state outputs with schema#19500
BrianCLong wants to merge 1 commit intomainfrom
codex/implement-graph-schema-in-neo4j

Conversation

@BrianCLong
Copy link
Copy Markdown
Owner

Motivation

  • Ensure the narrative CI fixture outputs are schema-valid and deterministic so downstream schema validation and policy gates can reliably operate.
  • Avoid non-deterministic or mis-scoped outputs by including a config_hash and scoping fixture state transition files to a stable path.
  • Update repository metadata and docs so the evidence bundle and roadmap reflect the refined lane-1 scaffold.

Description

  • Added a formal schemas/narrative/narrative_state.schema.json and updated the pipeline to emit a config_hash and write state_transitions.json to out/narratives/fixture/ for deterministic fixture runs.
  • Updated intelgraph/pipelines/narrative_ci/steps/40_state_machine.ts to read config/defaults.yml, compute a SHA-256 config_hash via lib/hash.ts, and emit stable JSON using lib/json_stable.ts.
  • Aligned the evidence bundler steps/50_bundle_evidence.ts, README, and evidence/index.json to reference the scoped fixture output path and new evidence ID.
  • Added pipeline primitives and artifacts: config/defaults.yml, lib/{hash,ids,json_stable,schema_validate}.ts, fixture step implementations (30_*/31_*/32_*), schema artifacts (schemas/narrative/*), OPA policies and fixtures, and a narrative-ci GitHub Actions workflow to validate the full fixture pipeline in CI.
  • Updated docs/roadmap/STATUS.json with a timestamped revision note describing the refined narrative CI lane-1 scaffold.

Testing

  • No automated tests were executed locally for this patch; changes were validated by static inspection and committed.
  • The repository narrative-ci workflow is configured to run the fixture pipeline (npx tsx intelgraph/pipelines/narrative_ci/steps/50_bundle_evidence.ts --fixture), run schema validation (npx tsx intelgraph/pipelines/narrative_ci/lib/schema_validate.ts out schemas/narrative), execute OPA policy tests (opa test .github/policies/narrative_ci -v), and enforce a determinism grep gate for timestamp-like keys.
  • CI runs remain the authoritative validation for these changes and should be observed for pass/fail results after merge.

Codex Task

@BrianCLong BrianCLong added the codex Codex-owned implementation work label Mar 7, 2026 — with ChatGPT Codex Connector
@chatgpt-codex-connector
Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request establishes a new Narrative CI pipeline designed to produce schema-valid and deterministic outputs. It introduces formal JSON schemas for various narrative-related data structures, implements mechanisms for consistent output generation through configuration hashing and stable JSON serialization, and integrates Open Policy Agent (OPA) policies to enforce data quality and traceability. The changes also include comprehensive updates to documentation and evidence bundling to align with the new pipeline's structure and outputs, ensuring reliable operation for downstream validation and policy gates.

Highlights

  • Formal Schema Introduction: Introduced formal JSON schemas for narrative state, metrics, graph, tests, and provenance receipts to ensure the validity and structure of all pipeline outputs.
  • Deterministic Output Generation: Implemented mechanisms for deterministic output generation across pipeline steps, utilizing configuration hashing and stable JSON stringification to guarantee consistent results for CI fixtures.
  • New Narrative CI Pipeline Establishment: Established a comprehensive Narrative CI pipeline, including new scoring steps (seeding, handoff, compression), a state machine, and an evidence bundler, supported by new utility functions for hashing, ID generation, and schema validation.
  • OPA Policy Integration: Integrated Open Policy Agent (OPA) policies for determinism (preventing timestamp-like keys) and traceability (ensuring provenance for inferred nodes), complete with passing and failing fixtures.
  • Documentation and Evidence Alignment: Updated documentation, the project roadmap, and the evidence index to reflect the new pipeline structure, output paths, and evidence IDs, ensuring all references are current and accurate.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • .github/policies/narrative_ci/determinism.rego
    • Added an OPA policy to enforce determinism by denying timestamp-like keys in JSON payloads.
  • .github/policies/narrative_ci/fixtures/determinism_fail.json
    • Added a JSON fixture designed to fail the determinism policy due to a 'created_at' field.
  • .github/policies/narrative_ci/fixtures/determinism_pass.json
    • Added a JSON fixture designed to pass the determinism policy.
  • .github/policies/narrative_ci/fixtures/traceability_fail.json
    • Added a JSON fixture designed to fail the traceability policy due to missing provenance.
  • .github/policies/narrative_ci/fixtures/traceability_pass.json
    • Added a JSON fixture designed to pass the traceability policy.
  • .github/policies/narrative_ci/traceability.rego
    • Added an OPA policy to ensure all inferred nodes have associated provenance.
  • docs/roadmap/STATUS.json
    • Updated the 'last_updated' timestamp and 'revision_note'.
    • Added a new initiative 'narrative-ci-lane1' to the roadmap.
  • evidence/index.json
    • Added a new evidence entry for 'EVD-NARRATIVE-CI-METRICS-001'.
  • intelgraph/pipelines/narrative_ci/README.md
    • Added a new README providing an overview of the Narrative CI Pipeline, local run instructions, validation steps, evidence outputs, tuning guidance, and rollback procedures.
  • intelgraph/pipelines/narrative_ci/config/defaults.yml
    • Added a new configuration file defining default thresholds and lists for various pipeline parameters.
  • intelgraph/pipelines/narrative_ci/lib/hash.ts
    • Added a utility function for SHA-256 hashing.
  • intelgraph/pipelines/narrative_ci/lib/ids.ts
    • Added utility functions for building evidence IDs and generating stable hashes.
  • intelgraph/pipelines/narrative_ci/lib/json_stable.ts
    • Added a utility function for stable JSON stringification by sorting object keys.
  • intelgraph/pipelines/narrative_ci/lib/schema_validate.ts
    • Added a script to validate JSON outputs against defined schemas using Ajv.
  • intelgraph/pipelines/narrative_ci/steps/30_score_seeding.ts
    • Added a new pipeline step to score seeding density, incorporating config hashing and stable JSON output.
  • intelgraph/pipelines/narrative_ci/steps/31_score_handoff.ts
    • Added a new pipeline step to score handoff candidates, incorporating config hashing and stable JSON output.
  • intelgraph/pipelines/narrative_ci/steps/32_score_compression.ts
    • Added a new pipeline step to score compression ratios, incorporating config hashing and stable JSON output.
  • intelgraph/pipelines/narrative_ci/steps/40_state_machine.ts
    • Added a new pipeline step to write narrative state transitions, incorporating config hashing and stable JSON output.
  • intelgraph/pipelines/narrative_ci/steps/50_bundle_evidence.ts
    • Added a new pipeline step to bundle evidence, orchestrating other steps, generating reports, and updating the evidence index.
  • intelgraph/schema/narrative.graph.yml
    • Added a YAML schema defining nodes and edges for a narrative graph, including provenance.
  • schemas/narrative/narrative_graph.schema.json
    • Added a JSON schema for validating the narrative graph structure.
  • schemas/narrative/narrative_metrics.schema.json
    • Added a JSON schema for validating narrative metrics outputs, including x-targets for specific files.
  • schemas/narrative/narrative_state.schema.json
    • Added a JSON schema for validating narrative state transitions, including x-targets.
  • schemas/narrative/narrative_tests.schema.json
    • Added a JSON schema for validating narrative test results.
  • schemas/narrative/provenance_receipt.schema.json
    • Added a JSON schema for validating provenance receipts.
Ignored Files
  • Ignored by pattern: .github/workflows/** (1)
    • .github/workflows/narrative-ci.yml
Activity
  • Changes were validated through static inspection.
  • The repository's narrative-ci workflow was configured to run the fixture pipeline, perform schema validation, execute OPA policy tests, and enforce a determinism grep gate.
  • CI runs are considered the authoritative validation for these changes.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 7, 2026

Warning

Rate limit exceeded

@BrianCLong has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 15 minutes and 21 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6a5c1788-1e9f-4157-a8b0-8ff30ad86793

📥 Commits

Reviewing files that changed from the base of the PR and between 68c99c3 and 3137e99.

📒 Files selected for processing (26)
  • .github/policies/narrative_ci/determinism.rego
  • .github/policies/narrative_ci/fixtures/determinism_fail.json
  • .github/policies/narrative_ci/fixtures/determinism_pass.json
  • .github/policies/narrative_ci/fixtures/traceability_fail.json
  • .github/policies/narrative_ci/fixtures/traceability_pass.json
  • .github/policies/narrative_ci/traceability.rego
  • .github/workflows/narrative-ci.yml
  • docs/roadmap/STATUS.json
  • evidence/index.json
  • intelgraph/pipelines/narrative_ci/README.md
  • intelgraph/pipelines/narrative_ci/config/defaults.yml
  • intelgraph/pipelines/narrative_ci/lib/hash.ts
  • intelgraph/pipelines/narrative_ci/lib/ids.ts
  • intelgraph/pipelines/narrative_ci/lib/json_stable.ts
  • intelgraph/pipelines/narrative_ci/lib/schema_validate.ts
  • intelgraph/pipelines/narrative_ci/steps/30_score_seeding.ts
  • intelgraph/pipelines/narrative_ci/steps/31_score_handoff.ts
  • intelgraph/pipelines/narrative_ci/steps/32_score_compression.ts
  • intelgraph/pipelines/narrative_ci/steps/40_state_machine.ts
  • intelgraph/pipelines/narrative_ci/steps/50_bundle_evidence.ts
  • intelgraph/schema/narrative.graph.yml
  • schemas/narrative/narrative_graph.schema.json
  • schemas/narrative/narrative_metrics.schema.json
  • schemas/narrative/narrative_state.schema.json
  • schemas/narrative/narrative_tests.schema.json
  • schemas/narrative/provenance_receipt.schema.json
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch codex/implement-graph-schema-in-neo4j

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new narrative CI pipeline with a strong focus on creating deterministic and schema-valid outputs. The changes are comprehensive, adding new schemas, OPA policies for validation, and several pipeline steps. My review focuses on ensuring the implementation aligns with the goal of determinism and follows good software engineering practices. I've identified a few areas for improvement, including some code duplication that could be refactored, a potential source of non-determinism in the evidence bundling step, and a minor data inconsistency. Overall, this is a solid contribution that significantly enhances the CI process.

};

const stamp = {
generated_at: new Date().toISOString(),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

Using new Date().toISOString() introduces a non-deterministic value into the stamp.json file. This seems to contradict the pull request's primary goal of ensuring deterministic outputs. Every run will produce a different stamp.json, and thus a different evidence bundle hash. If full determinism is desired for fixture runs, consider using a fixed timestamp or sourcing the timestamp from a stable source (e.g., commit timestamp).

"incomplete": 0,
"not_started": 5,
"total": 17,
"total": 21,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The total in the summary appears to be inconsistent. It was increased from 17 to 21 (a jump of 4), but only one new item was added to the initiatives array. Furthermore, the sum of rc_ready (8), partial (2), incomplete (0), and not_started (5) is 15, which does not match either the old or the new total. Please verify and correct the summary values to ensure data consistency.

Comment on lines +9 to +11
export function stableHash(input: string): string {
return createHash('sha256').update(input).digest('hex');
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

This stableHash function duplicates the functionality of the sha256 function already defined in intelgraph/pipelines/narrative_ci/lib/hash.ts. To avoid code duplication and improve maintainability, this function should be removed. Please use the sha256 function from hash.ts instead.

process.exit(1);
}

const ajv = new Ajv({ allErrors: true, strict: false });
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Using strict: false with AJV is not recommended as it can miss potential issues in schemas. Please consider setting strict: true to enable stricter validation and catch a wider range of schema errors. If strict: false is required for a specific reason, please add a comment explaining why.

const ajv = new Ajv({ allErrors: true, strict: true });

Comment on lines +1 to +23
import { mkdir, readFile, writeFile } from 'node:fs/promises';
import path from 'node:path';
import { sha256 } from '../lib/hash.js';
import { stableStringify } from '../lib/json_stable.js';

const outDir = path.resolve('out/metrics');
await mkdir(outDir, { recursive: true });

const configPath = path.resolve('intelgraph/pipelines/narrative_ci/config/defaults.yml');
const configContents = await readFile(configPath, 'utf-8');
const payload = {
run_id: 'fixture-run',
config_hash: sha256(configContents),
scores: [],
};

await writeFile(
path.join(outDir, 'seeding_density.json'),
`${stableStringify(payload)}\n`,
'utf-8',
);

console.log('Seeding density scores written');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

This script, along with 31_score_handoff.ts, 32_score_compression.ts, and 40_state_machine.ts, contains a significant amount of duplicated code for reading the configuration, hashing it, and writing a fixture file. To improve maintainability and adhere to the DRY (Don't Repeat Yourself) principle, consider refactoring this logic into a shared utility function.

For example, you could create a writeFixture function in a new lib/fixture_writer.ts file that encapsulates the common logic. The individual step files would then become much simpler, just calling this function with their specific data.

Copy link
Copy Markdown
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

🤖 Auto-approved by Mega Merge Orchestrator

@BrianCLong
Copy link
Copy Markdown
Owner Author

Temporarily closing to reduce Actions queue saturation and unblock #22241. Reopen after the golden-main convergence PR merges.

1 similar comment
@BrianCLong
Copy link
Copy Markdown
Owner Author

Temporarily closing to reduce Actions queue saturation and unblock #22241. Reopen after the golden-main convergence PR merges.

@BrianCLong BrianCLong closed this Mar 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

codex Codex-owned implementation work queue:blocked

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant