Skip to content

feat(cli): create the trace workflow on init, attached to the AI coding session contract - #3415

Merged
migmartri merged 3 commits into
mainfrom
feat/trace-init-creates-workflow
Sep 8, 2026
Merged

migmartri merged 3 commits into
mainfrom
feat/trace-init-creates-workflow

Conversation

@migmartri

@migmartri migmartri commented Sep 8, 2026 •

Copy link
Copy Markdown
Member

What

chainloop trace init and chainloop trace run now create the Chainloop workflow the trace attestations target, attached to the chainloop-ai-coding-session workflow contract when the organization has it, and to the control plane's default contract otherwise.

Until now the workflow was created implicitly by the pre-push hook, always with an empty per-project contract and with nobody reading the output, so traced AI coding sessions were never governed by a contract.

  • New --contract flag on trace init and trace run overrides the contract name. It is used only when the workflow is created and is not persisted to .chainloop.yml, so the push path stays unchanged.
  • A contract that does not exist is not created: the workflow falls back to the control plane's default contract. A contract named explicitly with --contract must exist.
  • Existing workflows are never modified, and re-running trace init is a no-op for the workflow.
  • trace init fails before writing hooks or .chainloop.yml when the workflow cannot be created. trace run only warns and runs the session anyway, since the attestation still creates the workflow.
  • Updating .chainloop.yml now preserves the user's comments, key order and indentation instead of re-marshalling the file from a map.

No control-plane or API change. One integration test case pins the behaviour trace relies on: an organization-level contract can be attached while the project is still being created.

Closes #3416

AI assistance

This change was produced with AI assistance (Claude Code); every commit carries an Assisted-by: Claude Code trailer.

🤖 Posted by Maximus bot (Claude Code) on behalf of @migmartri

…ng session contract

`chainloop trace init` and `trace run` now create the Chainloop workflow the
trace attestations target, attached to the `chainloop-ai-coding-session`
contract when the organization has it and to the control plane's default
contract otherwise. Until now the workflow was created implicitly by the
pre-push hook, always with an empty contract and with nobody reading the
output, so trace sessions were never governed by a contract.

The contract name can be overridden with the new `--contract` flag on both
commands. It is resolved when the workflow is created and not persisted to
.chainloop.yml, so the push path is unchanged. Existing workflows are never
modified. `trace init` fails before writing anything when the workflow cannot
be created; `trace run` warns and runs the session anyway.

Updating .chainloop.yml now preserves the user's comments, key order and
indentation instead of re-marshalling the file from a map.

Assisted-by: Claude Code
Signed-off-by: Miguel Martinez Trivino <miguel@chainloop.dev>

Chainloop-Trace-Sessions: 90463ef4-5d43-4c6b-8369-d85c131c0ba8
@chainloop-platform

chainloop-platform Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

AI Session Checks — ⚠️ 1 session(s) missing

Missing AI Coding Sessions

We detected commits in this PR that were AI-assisted, but the matching Chainloop Trace session(s) could not be found in Chainloop.

Please make sure the AI coding session evidence has been sent by the Chainloop CLI, or add the skip-ai-session label to this PR to bypass this check.

Learn more about Chainloop Trace.


Security Checks — ✅ 7 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 -

PR info

Status Policy Messages
✅ Passed pr-user-story-linked -
✅ Passed pr-description-required -

⏭️ 3 scans not applied

Scan Reason
vulnerability-scan no manifest/lockfile changed
github-actions-scan no workflow files changed
iac-scan no IaC 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.

All reported issues were addressed across 15 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread app/cli/pkg/action/trace_run.go
Comment thread app/cli/internal/trace/config/config.go Outdated
Comment thread app/cli/internal/trace/config/config_test.go Outdated
Comment thread app/cli/documentation/cli-reference.mdx Outdated
jiparis
jiparis previously approved these changes Sep 8, 2026

@jiparis jiparis 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.

LGTM, thanks!

`chainloop trace init` reported a missing credential as "authentication error:
chainloop is not authenticated; run 'chainloop config save' first: rpc error:
..." while `chainloop workflow list` reported the same condition as
`authentication required, please run "chainloop auth login"`. The mapping in
main.go matched on the gRPC status message, which grpc rewrites with the whole
error chain as soon as the error is wrapped, so the trace path never matched
and fell through to the generic branch. The advice was wrong too: `config save`
sets the endpoint, not the credentials.

The mapping now lives in action.AuthErrorMessage, which digs the status out of
a wrapped error, and is the only place that renders a credential problem: the
top-level handler uses it, and so does `trace run`, which logs the failure
rather than returning it.

Also addresses the review of the previous commit:

- `trace run` fails instead of warning when a contract named with --contract
  cannot be attached, since the attestation path carries no contract name and
  would silently bind the default one.
- .chainloop.yml keeps the indentation width it already uses instead of being
  rewritten with two spaces.
- The formatting test uses a non-alphabetical fixture and compares the whole
  file, so a map round-trip cannot pass unnoticed.
- Shorter command help; the flag descriptions carry the details.

Assisted-by: Claude Code
Signed-off-by: Miguel Martinez Trivino <miguel@chainloop.dev>

Chainloop-Trace-Sessions: 90463ef4-5d43-4c6b-8369-d85c131c0ba8
Signed-off-by: Miguel Martinez Trivino <miguel@chainloop.dev>
The four user-visible strings were written out nine times across three tests.

Assisted-by: Claude Code
Signed-off-by: Miguel Martinez Trivino <miguel@chainloop.dev>

Chainloop-Trace-Sessions: 90463ef4-5d43-4c6b-8369-d85c131c0ba8

@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.

All reported issues were addressed across 14 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread app/cli/pkg/action/trace_workflow.go
Comment thread app/cli/internal/trace/config/config.go
@migmartri
migmartri merged commit bc95e6c into main Sep 8, 2026
16 of 17 checks passed
@migmartri
migmartri deleted the feat/trace-init-creates-workflow branch September 8, 2026 16:18
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.

trace does not attach the AI coding session contract to its workflow

2 participants