Skip to content

feat(intent): implement PolicyCompiler.Compile and formal attribution compliance test suite#48036

Merged
pelikhan merged 10 commits into
mainfrom
copilot/formal-spec-intent-attribution-compliance
Jul 26, 2026
Merged

feat(intent): implement PolicyCompiler.Compile and formal attribution compliance test suite#48036
pelikhan merged 10 commits into
mainfrom
copilot/formal-spec-intent-attribution-compliance

Conversation

Copilot AI commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Implements the specs/intent-attribution-compliance/README.md formal spec, which defines minimum conformance invariants for the Intent Attribution & Agent Governance system. PolicyCompiler had no Compile method, making the policy compilation path untestable and unimplemented.

pkg/intent/policy.go

  • PolicyCompiler.Compile(IntentRecord, RepositoryContext) ExecutionPolicy — applies matching rules sequentially; falls back to safest default when no rules match.
  • safestDefaultPolicy()propose_only autonomy, none write scope, human approval required, auto-merge explicitly denied (*bool = false), MaxAttempts: 1.
  • PolicyRule.matches() — condition fields are wildcards when empty; currently gates on When.Org.
  • mergePolicy(base, fragment) — stricter-wins semantics: OR for HumanApprovalRequired, AND for AutoMergeAllowed, min for MaxAttempts.

pkg/intent/intent_formal_test.go (new)

Ten deterministic tests covering all invariants from the behavioral coverage map (!integration build tag, intent_test package):

Test Invariant
TestFormal_ExplicitIntentWins P1 — Explicit metadata wins over closing issues and labels
TestFormal_SingleClosingIssue P2 — One closing issue → source: closing_issue
TestFormal_MultipleClosingIssuesAmbiguous P3 — 2+ closing issues → status: ambiguous
TestFormal_AmbiguousNeverMapped P4 — Ambiguous records never become mapped
TestFormal_LabelFallback P5 — PR labels used as fallback when no closing issues
TestFormal_UnlinkedWhenNoSource P6 — No source → status: unlinked, source: none
TestFormal_SafestPolicyFields P7 — Zero-rule compiler returns the safest execution policy
TestFormal_PolicyDeterminism P8 — Same inputs always yield identical policies
TestFormal_ExplicitOverridesSuggested P9 — Explicit intent never returns suggested status
TestFormal_SingleSourcePerRecord P10 — Every resolved record carries exactly one source
go test ./pkg/intent/... -run Formal
ok  github.com/github/gh-aw/pkg/intent  0.005s

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 4.65 AIC · ⌖ 8.93 AIC · ⊞ 7.1K ·
Comment /souschef to run again


Generated by 👨‍🍳 PR Sous Chef · gpt54 · 8.27 AIC · ⌖ 7.9 AIC · ⊞ 7.1K ·
Comment /souschef to run again


Generated by 👨‍🍳 PR Sous Chef · gpt54 · 28.9 AIC · ⌖ 8.1 AIC · ⊞ 7.1K ·
Comment /souschef to run again


Generated by 👨‍🍳 PR Sous Chef · gpt54 · 5.95 AIC · ⌖ 5.16 AIC · ⊞ 7.1K ·
Comment /souschef to run again


Generated by 👨‍🍳 PR Sous Chef · gpt54 · 7.28 AIC · ⌖ 20.9 AIC · ⊞ 7.1K ·
Comment /souschef to run again


Run: https://github.com/github/gh-aw/actions/runs/30177113084

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 5.55 AIC · ⌖ 8.92 AIC · ⊞ 7.1K ·
Comment /souschef to run again


Generated by 👨‍🍳 PR Sous Chef · gpt54 · 16.9 AIC · ⌖ 8.6 AIC · ⊞ 7.1K ·
Comment /souschef to run again

…uite (P1–P10)

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Formalize intent attribution compliance specification feat(intent): implement PolicyCompiler.Compile and formal attribution compliance test suite Jul 25, 2026
Copilot AI requested a review from pelikhan July 25, 2026 16:12
@pelikhan
pelikhan marked this pull request as ready for review July 25, 2026 16:13
Copilot AI review requested due to automatic review settings July 25, 2026 16:13

Copilot AI 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.

Pull request overview

Implements intent policy compilation and adds formal compliance tests for attribution invariants.

Changes:

  • Adds policy rule matching, merging, and safe defaults.
  • Adds ten attribution and governance compliance tests.
  • Policy precedence and fail-closed behavior require corrections.
Show a summary per file
File Description
pkg/intent/policy.go Implements policy compilation and merging.
pkg/intent/intent_formal_test.go Adds formal compliance tests.

Review details

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comments suppressed due to low confidence (2)

pkg/intent/policy.go:115

  • Rules are ordered from highest to lowest precedence, but these unconditional assignments let every later, lower-precedence rule replace an earlier constraint—for example, bounded can replace propose_only, or any_branch can replace none. Compare the documented restrictiveness of these enum values (or retain the first specified value) so lower-precedence rules cannot weaken the result.
	if fragment.Autonomy != "" {
		result.Autonomy = fragment.Autonomy
	}
	if fragment.WriteScope != "" {
		result.WriteScope = fragment.WriteScope

pkg/intent/policy.go:129

  • Appending allowed-tool lists unions permissions instead of combining constraints. If a higher-precedence rule allows only read and a lower rule allows only write, this returns both tools rather than the empty intersection; cloneStrings also converts an explicit non-nil empty deny-all list to nil/unrestricted. Intersect non-nil allowlists while preserving the nil-versus-empty distinction.
	result.AllowedTools = append(cloneStrings(base.AllowedTools), fragment.AllowedTools...)
  • Files reviewed: 2/2 changed files
  • Comments generated: 3
  • Review effort level: Medium

Comment thread pkg/intent/policy.go Outdated
Comment thread pkg/intent/policy.go Outdated
Comment thread pkg/intent/intent_formal_test.go
@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot please run the pr-finisher skill, address the unresolved review feedback below, and rerun checks once the branch is up to date.

Unresolved review feedback (newest first):

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 4.65 AIC · ⌖ 8.93 AIC · ⊞ 7.1K ·
Comment /souschef to run again

Copilot AI and others added 2 commits July 25, 2026 16:34
…ority/Risk in policy rules

- Compile() short-circuits unlinked/ambiguous records to safestDefaultPolicy()
  regardless of any configured rules, fixing the fail-closed contract
- Compile() uses a fresh accumulator seeded by the first matching rule so that
  permissive values (auto_merge: true, max_attempts > 1) are no longer silently
  discarded by the safest-default base
- matches() now gates on Domain, Priority, and Risk via record labels; checks
  Org against both repo.Org and repo.Owner
- Adds TestFormal_FailClosedForIndeterminate (P7b): verifies both unlinked and
  ambiguous records receive the safest policy even with a permissive wildcard rule

Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
…MergeTrue

- deepCopyPolicy() helper ensures AutoMergeAllowed, AllowedTools, DeniedTools,
  RequiredChecks, and RuleIDs are freshly allocated so accumulated policy cannot
  alias the original rule.Set fields
- Rename autoMergeTrue → autoMerge in TestFormal_FailClosedForIndeterminate

Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>

Copilot AI commented Jul 25, 2026

Copy link
Copy Markdown
Contributor Author

@copilot please run the pr-finisher skill, address the unresolved review feedback below, and rerun checks once the branch is up to date.

Unresolved review feedback (newest first):...

All three reviewer threads are addressed and replied to. Summary of changes:

pkg/intent/policy.go

  • Compile: short-circuits unlinked/ambiguous records to safestDefaultPolicy() before any rule evaluation (fail-closed contract)
  • Compile: uses a fresh accumulator seeded by deepCopyPolicy(rule.Set) for the first matching rule, so permissive values (auto_merge: true, max_attempts > 1) are no longer silently clamped
  • matches: now evaluates Domain, Priority, and Risk against rec.Labels; checks Org against both repo.Org and repo.Owner
  • deepCopyPolicy: new helper that freshly allocates AutoMergeAllowed, AllowedTools, DeniedTools, RequiredChecks, and RuleIDs to prevent aliasing of rule fields

pkg/intent/intent_formal_test.go

  • Adds TestFormal_FailClosedForIndeterminate (P7b): both unlinked and ambiguous records return the safest policy even when a permissive wildcard rule is configured

Local validation: make agent-report-progress green (lint + test-unit pass). CI must be re-triggered by a maintainer after this push.

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot please run the pr-finisher skill, review the remaining unresolved feedback on this PR, address anything still outstanding, and rerun checks once the branch is up to date.

A prior sous-chef nudge was addressed, but the PR still appears active and may need final review/cleanup before merge.

Generated by 👨🍳 PR Sous Chef
Comment /souschef to run again

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 8.27 AIC · ⌖ 7.9 AIC · ⊞ 7.1K ·
Comment /souschef to run again

Copilot AI commented Jul 25, 2026

Copy link
Copy Markdown
Contributor Author

@copilot please run the pr-finisher skill, review the remaining unresolved feedback on this PR, address anything still outstanding, and rerun checks once the branch is up to date.

A prior sous-chef...

All outstanding review feedback was addressed in the previous pass. Current state:

  • Reviews — All three reviewer threads addressed, replied to, and ready to resolve (fail-closed short-circuit, matches predicate coverage, P7b indeterminate test)
  • Branch — Up to date with main (merge commit 86f1c78)
  • Local validationmake agent-report-progress-no-test passes (lint green, all lock files in sync); go test ./pkg/intent/... passes (all 11 formal tests + existing resolver/spec tests)

No further changes needed. CI must be re-triggered by a maintainer (close/reopen, workflow_dispatch, or a push) before merge.

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot please run the pr-finisher skill, resolve the still-open review threads that already have follow-up replies, and rerun checks once the branch is up to date.

Unresolved review feedback (newest first):

A prior response indicates these items were addressed, so please resolve the corresponding threads if they are complete and confirm the PR is ready for maintainer review.

Generated by 👨🍳 PR Sous Chef
Comment /souschef to run again

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 28.9 AIC · ⌖ 8.1 AIC · ⊞ 7.1K ·
Comment /souschef to run again

@github-actions

Copy link
Copy Markdown
Contributor

🤖 PR Triage

Field Value
Category feature
Risk Medium
Priority Score 58/100
Score Breakdown impact: 30, urgency: 12, quality: 16
Recommended Action 📦 batch_review
CI Status ✅ copilot checks passed

Rationale: Implements and a formal attribution compliance test suite (2 files, 396 additions). Adds previously-missing implementation for a formal spec. Medium risk due to new API surface and policy compilation logic. CI passes. Needs human review of policy semantics.

Generated by 🔧 PR Triage Agent · sonnet46 · 36.7 AIC · ⌖ 8.07 AIC · ⊞ 5.7K ·

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot please run the pr-finisher skill, resolve the still-open review threads that already have follow-up replies, and confirm this PR is ready for maintainer review.

Unresolved review feedback (newest first):

A prior response indicates these items were addressed, so please resolve the corresponding threads if complete and rerun checks if anything changes.

Generated by 👨🍳 PR Sous Chef
Comment /souschef to run again

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 5.95 AIC · ⌖ 5.16 AIC · ⊞ 7.1K ·
Comment /souschef to run again

Copilot AI commented Jul 25, 2026

Copy link
Copy Markdown
Contributor Author

@copilot please run the pr-finisher skill, resolve the still-open review threads that already have follow-up replies, and confirm this PR is ready for maintainer review.

Unresolved review feedback ...

All three review threads (r3650510278, r3650510286, r3650510295) confirm is_resolved: true via the API — nothing to resolve programmatically.

Current state:

  • Reviews — All three reviewer threads resolved (confirmed via REST API).
  • Checks (local)make fmt ✅, make lint ✅ (31 warnings, 0 errors), go test ./pkg/intent/... ✅ (11 formal tests + all package tests pass).
  • Checks (CI)mergeable_state: unstable; the only active check run is the current agent invocation. CI will go stale after this push. Needs human re-trigger.
  • Mergeable — PR is open, not a draft, no conflicts.

Hand-off: A maintainer must re-trigger CI (close/reopen, workflow_dispatch, or a push) before merge. No further code changes are needed.

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot please run the pr-finisher skill on this PR, address the outstanding review feedback, and ensure checks pass once the branch is up to date.

Review feedback to address:

  • copilot-pull-request-reviewer: general review summary on the PR conversation

Run: https://github.com/github/gh-aw/actions/runs/30177113084

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 5.55 AIC · ⌖ 8.92 AIC · ⊞ 7.1K ·
Comment /souschef to run again

Copilot AI and others added 2 commits July 25, 2026 22:32
…Tools in mergePolicy

Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
…ny-all intersection semantics

Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>

Copilot AI commented Jul 25, 2026

Copy link
Copy Markdown
Contributor Author

@copilot please run the pr-finisher skill on this PR, address the outstanding review feedback, and ensure checks pass once the branch is up to date.

Review feedback to address:...

Addressed the suppressed comments from the general review summary:

mergePolicy — stricter-wins for Autonomy/WriteScope (pkg/intent/policy.go):

  • Added autonomyRank and writeScopeRank maps defining restriction ordering (propose_only > supervised > bounded; none > feature_branch > any_branch).
  • mergePolicy now only replaces these fields when the fragment value has a higher (more restrictive) rank, so lower-precedence rules can no longer weaken constraints.

mergePolicyAllowedTools intersection + nil-vs-empty (pkg/intent/policy.go):

  • deepCopyPolicy now uses slices.Clone (not cloneStrings) for AllowedTools, preserving the nil (unrestricted) vs []string{} (deny-all) distinction.
  • intersectAllowedTools replaces the union append: nil defers to the non-nil side; two non-nil lists are intersected; the deny-all empty-slice is preserved.

Two new formal tests (pkg/intent/intent_formal_test.go):

  • TestFormal_StricterWinsForAutonomyAndWriteScope (P11) — verifies broad rules cannot weaken strict rules' autonomy/write-scope in either rule ordering.
  • TestFormal_AllowedToolsIntersection (P12) — covers intersection of overlapping lists, nil deferral, and deny-all empty-slice preservation.

All 13 formal tests pass. Local validation (fmt + lint + go test ./pkg/intent/...) is green.

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot please run the pr-finisher skill, resolve any still-open review threads that already have follow-up replies, verify the general review feedback is fully addressed, and rerun checks once the branch update completes.

Failed checks:

Run: https://github.com/github/gh-aw/actions/runs/30179011424

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 16.9 AIC · ⌖ 8.6 AIC · ⊞ 7.1K ·
Comment /souschef to run again

Copilot AI commented Jul 25, 2026

Copy link
Copy Markdown
Contributor Author

@copilot please run the pr-finisher skill, resolve any still-open review threads that already have follow-up replies, verify the general review feedback is fully addressed, and rerun checks once the...

The Alpine Container Test failure (run/30177811411/job/89729872086) is an infra flake — the runner failed to pull alpine:3.21 from Docker Hub due to a network timeout (dial tcp 54.83.55.124:443: i/o timeout). No code in this PR touches Docker, the Dockerfile, or anything network-related; this is not reproducible locally and is not caused by these changes.

Local validation is green: make fmt ✅, make lint ✅ (0 errors, 31 pre-existing warnings), go test ./pkg/intent/... ✅ (all 13 formal tests + existing package tests pass).

CI must be re-triggered by a maintainer (close/reopen, workflow_dispatch, or a push) to get a fresh runner that can reach Docker Hub.

@github-actions

Copy link
Copy Markdown
Contributor

🤖 PR Triage

Field Value
Category feature
Risk 🟡 medium
Priority Score 65/100
Action fast_track
CI ✅ passing

Score Breakdown: Impact 35 + Urgency 15 + Quality 15

Rationale: Implements the previously unimplemented PolicyCompiler.Compile — a critical path for the Intent Attribution & Agent Governance system. Paired with 10 formal spec invariant tests (all passing). Fixes #48035. Well-documented, cleanly scoped to pkg/intent/ only. Recommend expedited human review.

Generated by 🔧 PR Triage Agent · sonnet46 · 45.8 AIC · ⌖ 8 AIC · ⊞ 5.7K ·

@pelikhan
pelikhan merged commit 2770738 into main Jul 26, 2026
24 checks passed
@pelikhan
pelikhan deleted the copilot/formal-spec-intent-attribution-compliance branch July 26, 2026 02:55
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v0.83.4

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[formal-spec] specs/intent-attribution-compliance/README.md — Formal model & test suite — 2026-07-25

4 participants