Skip to content

fix(controlplane): rewrite stored contracts with a null spec to spec: {} - #3828

Merged
javirln merged 1 commit into
mainfrom
javier/pfm-8253-accept-yaml-contracts-with-an-empty-spec
Nov 18, 2026
Merged

javirln merged 1 commit into
mainfrom
javier/pfm-8253-accept-yaml-contracts-with-an-empty-spec

Conversation

@javirln

@javirln javirln commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

Since v1.135.3, the control plane and the CLI reject a YAML contract that has an empty spec: line:

v2 Contract format error: error unmarshalling raw message: :6:6 spec: value is required (required)

The cause is the update of buf.build/go/protoyaml from v0.7.0 to v0.8.0 (#3816). protoyaml v0.8.0 leaves a message field unset when its YAML value is null (bufbuild/protoyaml-go#72). v0.7.0 set an empty message.

The v0.8.0 behavior is the correct one: in the protobuf JSON mapping, null for a message field means "not set", and protojson already rejected "spec": null. So we keep it, and we update the stored data instead.

This change adds a migration that rewrites the null top-level spec of stored YAML contracts (spec:, spec: null or spec: ~) to spec: {}. This keeps the meaning of the stored text, and the control plane and the CLI can read these contracts again. It also uses spec: {} in the empty contract example of the docs, which had an empty spec:.

Behavior

Contract text Up to v1.135.2 v1.135.3 and v1.135.4 With this change
Stored with spec:, spec: null or spec: ~ valid, empty spec invalid on each read rewritten to spec: {}, valid
New, with spec: valid invalid invalid
New, with spec: {} valid valid valid
JSON with "spec": null invalid invalid invalid

Migration

  • It changes only rows with the yaml format, and only a null spec at the top level of the document. A spec with fields, a nested spec key and JSON rows do not change.
  • It keeps a comment on the spec: line and the line endings of the document.
  • It skips a row that is not valid UTF-8, so the migration cannot fail on such a row.
  • A second run changes nothing.
  • raw_body is immutable in the application. The migration changes the stored text of past contract revisions, but it does not change what they mean.

FAQ

Why not keep the v0.7.0 behavior in the parser?
It is not correct by the protobuf JSON mapping, and it is not consistent with JSON. We can keep the strict parser if we update the stored data once.

What must users do?
Update the control plane, so that the migration runs. A contract file that a user keeps in a repository with an empty spec: is now rejected on create and update: change it to spec: {}. The release notes must say this.

Do CLI v1.135.3 and v1.135.4 still fail?
No. They parse the contract that the control plane sends, and after the migration that text has spec: {}.

This change was made with AI assistance (Claude Code).

@javirln
javirln requested a review from a team November 17, 2026 12:44
@chainloop-platform

chainloop-platform Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

PR validation — ✅ 3 passing

Status Policy Material Messages
✅ Passed pr-min-approvals pr-info -
✅ Passed pr-description-required pr-info -
✅ Passed pr-user-story-linked pr-info -

View attestation ↗

AI Session Checks — 🟡 83% · ✅ 0 failing

Avg score Sessions Failing policies Attribution Files Lines Total Duration
🟡 83% 1 ✅ 0 100% AI / 0% Human 4 +175 / -2 22h25m18s

🟡 83% — 100% AI — ✅ All policies passing

Nov 17, 2026 12:29 UTC · 22h25m18s · $100.71 · 1.5k in / 879.9k out · claude-code 2.1.326 (claude-opus-5-5)

View session details ↗

Change Summary

Adds a migration that rewrites stored null top-level contract specs into explicit empty mappings while retaining strict validation. Adds integration regression coverage, updates migration checksum metadata, and corrects the empty-contract documentation example.

AI Session Overall Score

🟡 83% — Focused, repeatedly tested migration; public-disclosure cleanup and missing user confirmation still warrant review.

AI Session Analysis Breakdown

🟢 95% · scope-discipline

🟢 The assistant obtained explicit approval to replace compatibility parsing with a stored-contract migration before changing approaches. · High Impact

🟢 90% · solution-quality

🟢 The fix rewrites stored null specs into explicit empty mappings while leaving strict parsing intact. · High Impact

🟢 88% · context-and-planning

No notes.

🟡 79% · verification

🟢 Real migration assertions exposed a legacy-string bug; the corrected integration tests passed again after final cleanup. · High Impact

🟠 Despite active user participation, the transcript contains no user confirmation that the repaired legacy-contract workflow works. · Medium Severity

💡 Ask the user to confirm an affected stored contract can be read after deployment.

🟡 76% · user-trust-signal

No notes.

🟡 72% · alignment

🟠 Public internal-project references required cleanup and one firm user correction, interrupting otherwise constructive collaboration. · Medium Severity

💡 Confirm disclosure boundaries before posting internal project context to public repositories.


File Attribution

████████████████████ 100% AI / 0% Human

Status Attribution File Lines
created ai app/controlplane/pkg/data/contract_null_spec_migration_integration_test.go +137 / -0
created ai app/controlplane/pkg/data/ent/migrate/migrations/20261117162118.sql +35 / -0
modified ai app/controlplane/pkg/data/ent/migrate/migrations/atlas.sum +2 / -1
modified ai docs/examples/contracts/empty/generic.yaml +1 / -1

Policies (4)

Status Policy Material Messages
✅ Passed ai-config-ai-agents-allowed ai-coding-session-b247aa -
✅ Passed ai-config-no-dangerous-commands ai-coding-session-b247aa -
✅ Passed ai-config-no-secrets ai-coding-session-b247aa -
✅ Passed ai-config-mcp-servers-allowed ai-coding-session-b247aa -

Security Checks — ✅ 6 passing

✅ secret-scan

Status Policy Messages
✅ Passed secrets-detection -

✅ sast-scan

Status Policy Messages
✅ Passed owasp-top10-2025 -
✅ Passed sast -
✅ Passed cwe-top25 -
✅ Passed cwe-top26-40-cusp -

✅ iac-scan

Status Policy Messages
✅ Passed iac-misconfiguration -
Scans not applied (2)
Scan Reason
vulnerability-scan no manifest/lockfile changed
github-actions-scan no workflow files changed

View attestation ↗


Powered by Chainloop and Chainloop Trace

@cubic-dev-ai cubic-dev-ai Bot left a comment

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.

No issues found across 5 files

View guided diff | Re-trigger cubic

@migmartri migmartri left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is the new behavior the correct one?

@migmartri

Copy link
Copy Markdown
Member

@migmartri No. By the protobuf JSON mapping, the v0.8.0 behavior is the correct one: null for a message field means "not set", as in protojson. The old behavior is also not consistent. For example, the YAML spec: is valid, but the JSON "spec": null is invalid.

We keep the old behavior because stored contracts depend on it. The platform UI stores default-contract with an empty spec:, and the control plane and the CLI parse stored contracts again when they read them.

I changed the PR so that FromRaw gives the exact v0.7.0 result, also for oneof members and well-known types (a656cd9). A golden test compares it with the output of protoyaml v0.7.0 for 49 YAML documents. The description now has the old vs new table and a short FAQ.

can't we update the invalid contract?

@javirln
javirln force-pushed the javier/pfm-8253-accept-yaml-contracts-with-an-empty-spec branch from a656cd9 to 3b97098 Compare November 17, 2026 16:25
@javirln javirln changed the title fix(controlplane): accept YAML documents with a null message field again fix(controlplane): rewrite stored contracts with a null spec to spec: {} Nov 17, 2026
migmartri
migmartri previously approved these changes Nov 17, 2026

@migmartri migmartri left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, double check the migration

@migmartri migmartri left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do you need to update the default contract?

@migmartri migmartri left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we need to update the default contract?

@migmartri

Copy link
Copy Markdown
Member

There is no default contract in chainloop itself? what if you start an attestation? that default contact how's it defined?

@javirln
javirln force-pushed the javier/pfm-8253-accept-yaml-contracts-with-an-empty-spec branch from e88197f to a0a9506 Compare November 18, 2026 09:27
@javirln

javirln commented Nov 18, 2026

Copy link
Copy Markdown
Member Author

@migmartri Answers to your review, in one place:

  • Is the new behavior correct? Yes. By the protobuf JSON mapping, null for a message field means "not set", as in protojson. So this PR keeps the strict parser and migrates the stored contracts instead.
  • Double check of the migration. I found one problem and fixed it. With standard_conforming_strings = off, Postgres reads a backslash in a '...' string as an escape, and the migration wrote spec: {}\x01\x02. It now uses E'' strings, and the integration test runs it with the setting off and then on. I also applied the migration directory with Atlas on Postgres 16 with the setting off, and ran the migration over 57 YAML contract files: the 55 valid ones did not change.
  • Default contract. Chainloop has one, and it is not affected. When attestation init creates the workflow on the fly (app/controlplane/internal/service/attestation.go:868), or a workflow is created without a contract, the control plane creates a contract named <project>-<workflow> with createDefaultContract (app/controlplane/pkg/biz/workflowcontract.go:267). It marshals an empty, set Spec with protoyaml.Marshal, which writes spec: {}, and that text is valid with v0.8.0. Contracts with an empty spec: come from clients that sent that text, as the empty contract example of the docs did. An attestation of a workflow that uses such a stored contract fails in attestation init today, and the migration fixes those rows.

The branch now has one commit (a0a9506).

@javirln
javirln force-pushed the javier/pfm-8253-accept-yaml-contracts-with-an-empty-spec branch from a0a9506 to 0180b02 Compare November 18, 2026 09:34
…: {}`

Since protoyaml v0.8.0 (v1.135.3), a message field set to null in YAML
stays unset. A stored YAML contract with a null top-level spec then
fails validation each time the control plane reads it, and in the CLI
attestation init. Add a migration that rewrites the value to
`spec: {}`, which keeps the meaning that the text had before. New
contracts with a null spec stay invalid, as in protojson.

The migration uses E'' strings, so that it gives the same result when
standard_conforming_strings is off. Also use `spec: {}` in the empty
contract example of the docs.

Assisted-by: Claude Code
Signed-off-by: Javier Rodriguez <javier@chainloop.dev>

Chainloop-Trace-Sessions: b247aa60-56f4-4d40-a70a-63bdfe94f9eb
@javirln
javirln force-pushed the javier/pfm-8253-accept-yaml-contracts-with-an-empty-spec branch from 0180b02 to a5119b9 Compare November 18, 2026 10:55
@javirln
javirln merged commit dacda38 into main Nov 18, 2026
17 checks passed
@javirln
javirln deleted the javier/pfm-8253-accept-yaml-contracts-with-an-empty-spec branch November 18, 2026 16:57
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