Skip to content

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

Open
pelikhan with Copilot wants to merge 7 commits into
mainfrom
copilot/formal-spec-intent-attribution-compliance
Open

feat(intent): implement PolicyCompiler.Compile and formal attribution compliance test suite#48036
pelikhan with Copilot wants to merge 7 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

…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

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 rerun checks once the branch is up to date.

Unresolved review feedback (new...

All three threads (r3650510295, r3650510286, r3650510278) were addressed in code (commits 74d27ad, be0ea7d) and replied to. The GitHub GraphQL API is blocked in this sandbox, so I cannot programmatically resolve the threads — a maintainer will need to click "Resolve conversation" on each.

The PR is otherwise ready: all 27 tests pass, lint is clean, branch is up to date with main.

@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

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