Skip to content

fix(orchestrator): guard trusted exploration handoffs - #1966

Open
blak0p wants to merge 2 commits into
Gentleman-Programming:mainfrom
blak0p:fix/guarded-no-reread-policy
Open

fix(orchestrator): guard trusted exploration handoffs#1966
blak0p wants to merge 2 commits into
Gentleman-Programming:mainfrom
blak0p:fix/guarded-no-reread-policy

Conversation

@blak0p

@blak0p blak0p commented Jul 29, 2026

Copy link
Copy Markdown

🔗 Linked Issue

Closes #1178


🏷️ PR Type

  • type:bug — Bug fix (non-breaking change that fixes an issue)
  • type:feature
  • type:docs
  • type:refactor
  • type:chore
  • type:breaking-change

📝 Summary

Adds a guarded trusted-exploration handoff policy so complete, current exploration results can suppress broad redundant rereads while still requiring targeted verification. Incomplete or untrustworthy handoffs trigger narrowly scoped exploration instead, and the trust boundary does not extend to implementation, review, apply, or verification handoffs.


📂 Changes

28 files changed: 114 additions, 1 deletion, 113 net lines.

File / Area What Changed
internal/assets/*/sdd-orchestrator.md (12 files) Add the trusted exploration handoff guard to all orchestrator assets.
internal/assets/assets_test.go Verify all 12 assets carry the bounded policy vocabulary.
internal/components/sdd/inject.go Add the policy to the dynamic delegation-hard-gates migration.
internal/components/sdd/inject_test.go Verify migration, preservation, and idempotence across prompt variants.
testdata/golden/* (13 files) Update generated SDD output goldens.

🧪 Test Plan

Exact verification run locally on Fedora/Linux:

  • go test ./... -count=1 — PASS
  • go build ./... && go vet ./... — PASS
  • go test ./internal/components/sdd ./internal/assets -count=1 — PASS
  • go run ./internal/gofmtcheck — PASS
  • Focused tests cover all 12 orchestrator assets, migration of marked/unmarked/fresh prompts, user-tail preservation, and idempotence.
  • Fedora npm environment checked: npm 11.17.0, Node v26.5.0, prefix /home/linuxbrew/.linuxbrew; no npm check applies to this Go-only change.
  • E2E Docker test — not run; this change is covered by the focused and full Go suites.
  • Manual interactive test — not applicable; behavior is prompt generation and is covered by unit/golden tests.

🤖 Automated Checks

The PR workflow will evaluate cognitive load, issue linkage and approval, the exact type label, unit tests, Go format, and E2E status. Review-driven development is disabled globally for this delivery; no review receipt or approval is being claimed.


✅ Contributor Checklist

  • PR is linked to an issue with status:approved
  • PR stays within 400 changed lines (115 changed lines)
  • I have added the appropriate type:* label — maintainer action may be required; see below
  • Unit tests pass (go test ./... -count=1)
  • Go format passes (go run ./internal/gofmtcheck)
  • E2E tests pass — not run; Docker E2E is not applicable to this prompt-generation-only change
  • Documentation/assets updated where behavior changed
  • My commit follows Conventional Commits format
  • My commit does not include a Co-Authored-By trailer

💬 Notes for Reviewers

Please verify the trust boundary: only complete, current exploration handoffs suppress broad rereads; targeted verification remains required, and trust never transfers to later implementation/review/apply/verification handoffs.

Pending maintainer actions

  • Ensure exactly one PR label, type:bug, is applied if the API did not apply it automatically. Contributor permissions do not allow applying PR labels, so no label mutation was attempted.
  • Review and merge when maintainer workflow permits.

Summary by CodeRabbit

  • New Features

    • Added a “trusted exploration handoff” rule to supported orchestration workflows to allow suppressing broad rereads only for complete, current handoffs that include root cause plus actionable paths/symbols.
    • Maintains targeted verification requirements and restricts trust to exploration only (not implementation/review/apply/verification).
  • Bug Fixes

    • Improved managed prompt migration so incomplete or misleading preserved content no longer prevents the safety policy update.
  • Tests

    • Added/expanded test coverage for policy inclusion, idempotent migration behavior, and correct handling of “complete-looking” user tails.

@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds trusted exploration handoff guardrails to every SDD orchestrator asset, updates preserved OpenCode delegation-hard-gates migration, and adds contract tests for asset coverage and migration behavior.

Changes

Trusted exploration handoff safeguards

Layer / File(s) Summary
Orchestrator handoff policy
internal/assets/*/sdd-orchestrator.md, internal/assets/assets_test.go
All SDD orchestrator variants define required handoff evidence, targeted verification, narrow exploration fallback, and an exploration-only trust boundary; a contract test validates these clauses across assets.
Preserved prompt migration
internal/components/sdd/inject.go, internal/components/sdd/inject_test.go
OpenCode delegation-hard-gates migration injects the new policy, detects incomplete managed blocks, preserves user content, and verifies idempotency across legacy and fresh prompts.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested labels: type:bug

Suggested reviewers: alan-thegentleman

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and accurately summarizes the new trusted exploration handoff guard.
Linked Issues check ✅ Passed The PR adds the trusted exploration handoff rule to all orchestrator assets and injection, with tests, matching the issue's goal to avoid redundant rereads.
Out of Scope Changes check ✅ Passed The changes stay focused on orchestrator handoff policy, prompt injection, and tests, with no obvious unrelated scope.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
internal/components/sdd/inject.go (1)

1121-1137: 🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

Validate the marker-delimited managed block, not the entire prompt.

Global string checks conflict with the contract that preserves arbitrary user-owned tails and can either accept stale policy content or reject valid prompts.

  • internal/components/sdd/inject.go#L1121-L1137: extract the managed block and require the complete trusted-exploration clause set before returning through the fast path.
  • internal/components/sdd/inject_test.go#L952-L956: count policy markers only inside that block and assert the preserved user tail byte-for-byte at its expected boundary.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/components/sdd/inject.go` around lines 1121 - 1137, The fast-path
validation in internal/components/sdd/inject.go around the marker checks must
inspect only the marker-delimited managed block, requiring the complete
trusted-exploration clause set there before returning; do not validate arbitrary
prompt-tail content. Update the corresponding test in
internal/components/sdd/inject_test.go to count policy markers within that block
and assert the user-owned tail is preserved byte-for-byte at its expected
boundary.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/assets/assets_test.go`:
- Around line 125-130: Update the bounded mandatory delegation section parsing
in the test to validate start before slicing content. Check whether the first
strings.Index call found "#### Mandatory Delegation Triggers", fail immediately
when absent, then compute the relative end index for "#### Native Checking
Contract" and retain the existing missing-section failure and delegation slice
behavior.

In `@internal/components/sdd/inject_test.go`:
- Around line 952-956: Update the migration assertions around
ensurePreservedOpenCodeDelegationHardGates to extract the managed block before
counting the corrected handoff phrase and migration marker, so user-owned
content cannot affect uniqueness checks. Replace the broad strings.Contains(got,
userTail) assertion with a byte-exact boundary check using the appropriate
suffix assertion, while retaining the idempotence comparison.

---

Outside diff comments:
In `@internal/components/sdd/inject.go`:
- Around line 1121-1137: The fast-path validation in
internal/components/sdd/inject.go around the marker checks must inspect only the
marker-delimited managed block, requiring the complete trusted-exploration
clause set there before returning; do not validate arbitrary prompt-tail
content. Update the corresponding test in internal/components/sdd/inject_test.go
to count policy markers within that block and assert the user-owned tail is
preserved byte-for-byte at its expected boundary.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: de101d11-a5c7-4cc3-ba14-ba7158ca0bf1

📥 Commits

Reviewing files that changed from the base of the PR and between 3ecf60b and 4a3bdc3.

⛔ Files ignored due to path filters (13)
  • testdata/golden/combined-claude-claudemd.golden is excluded by !testdata/**
  • testdata/golden/combined-windsurf-global-rules.golden is excluded by !testdata/**
  • testdata/golden/sdd-antigravity-rulesmd.golden is excluded by !testdata/**
  • testdata/golden/sdd-claude-claudemd.golden is excluded by !testdata/**
  • testdata/golden/sdd-codex-agentsmd-lowcost.golden is excluded by !testdata/**
  • testdata/golden/sdd-codex-agentsmd-powerful.golden is excluded by !testdata/**
  • testdata/golden/sdd-codex-agentsmd.golden is excluded by !testdata/**
  • testdata/golden/sdd-cursor-rules.golden is excluded by !testdata/**
  • testdata/golden/sdd-gemini-geminimd.golden is excluded by !testdata/**
  • testdata/golden/sdd-kiro-instructions.golden is excluded by !testdata/**
  • testdata/golden/sdd-opencode-multi-settings.golden is excluded by !testdata/**
  • testdata/golden/sdd-vscode-instructions.golden is excluded by !testdata/**
  • testdata/golden/sdd-windsurf-global-rules.golden is excluded by !testdata/**
📒 Files selected for processing (15)
  • internal/assets/antigravity/sdd-orchestrator.md
  • internal/assets/assets_test.go
  • internal/assets/claude/sdd-orchestrator.md
  • internal/assets/codex/sdd-orchestrator.md
  • internal/assets/cursor/sdd-orchestrator.md
  • internal/assets/gemini/sdd-orchestrator.md
  • internal/assets/generic/sdd-orchestrator.md
  • internal/assets/hermes/sdd-orchestrator.md
  • internal/assets/kimi/sdd-orchestrator.md
  • internal/assets/kiro/sdd-orchestrator.md
  • internal/assets/opencode/sdd-orchestrator.md
  • internal/assets/qwen/sdd-orchestrator.md
  • internal/assets/windsurf/sdd-orchestrator.md
  • internal/components/sdd/inject.go
  • internal/components/sdd/inject_test.go

Comment thread internal/assets/assets_test.go Outdated
Comment thread internal/components/sdd/inject_test.go Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/components/sdd/inject_test.go`:
- Around line 982-987: Update userTail in
TestEnsurePreservedOpenCodeDelegationHardGatesIgnoresCompleteLookingUserTail to
include every required fast-path phrase, including the 4-file rule, Write rule,
Semantic guard, targeted verification, and handoff prohibition. Keep the managed
incomplete block unchanged so the test verifies fast-path checks use only
user-owned content rather than the whole prompt.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: d0ddccf8-10c4-45d8-af6c-2918b17e3b2b

📥 Commits

Reviewing files that changed from the base of the PR and between 4a3bdc3 and 330724a.

📒 Files selected for processing (3)
  • internal/assets/assets_test.go
  • internal/components/sdd/inject.go
  • internal/components/sdd/inject_test.go

Comment on lines +982 to +987
func TestEnsurePreservedOpenCodeDelegationHardGatesIgnoresCompleteLookingUserTail(t *testing.T) {
const incomplete = "<!-- gentle-ai:delegation-hard-gates-migration -->\n" +
"### Mandatory Delegation Triggers (Non-Skippable)\n" +
"<!-- /gentle-ai:delegation-hard-gates-migration -->"
const userTail = "\n\n#### User-Owned Policy\nfully mandatory\nBounded read rule\n" +
"complete, current exploration handoff\n" + nativeReviewAuthorityRuleText

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Make the user tail satisfy every fast-path clause.

The fixture omits rules such as 4-file rule, Write rule, Semantic guard, targeted verification, and the handoff prohibition. A regression that checks the whole prompt instead of managed would still fail its incomplete block requirements and migrate, so this test would not detect it. Populate userTail with every required fast-path phrase while keeping the managed block incomplete.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/components/sdd/inject_test.go` around lines 982 - 987, Update
userTail in
TestEnsurePreservedOpenCodeDelegationHardGatesIgnoresCompleteLookingUserTail to
include every required fast-path phrase, including the 4-file rule, Write rule,
Semantic guard, targeted verification, and handoff prohibition. Keep the managed
incomplete block unchanged so the test verifies fast-path checks use only
user-owned content rather than the whole prompt.

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.

fix(orchestrator): orchestrator re-reads files after sub-agent exploration returns complete analysis, wasting tokens

1 participant