Skip to content

feat(cli): Interactive review for RR. - #3317

Merged
c-r33d merged 4 commits into
interactive-resolutionfrom
interactive-resolution-prompter
Apr 20, 2026
Merged

feat(cli): Interactive review for RR.#3317
c-r33d merged 4 commits into
interactive-resolutionfrom
interactive-resolution-prompter

Conversation

@c-r33d

@c-r33d c-r33d commented Apr 17, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR adds planner-time interactive review for registered resources that span multiple namespaces during namespaced policy migration.

When --interactive is enabled, the planner now:

  • detects conflicting registered resources,
  • prompts the user to choose the target namespace,
  • filters the resource down to bindings for that namespace,
  • updates any required action resolution so the final plan can proceed cleanly.

Prompt updates

The interactive prompt was also cleaned up so that:

  • titles and descriptions render separately,
  • the registered resource identifier is shown in the title,
  • namespace options read clearly as migration choices.

Scope

This change is intentionally limited to registered resource conflict review only.

It does not add:

  • broader planner summaries,
  • other interactive resolution flows,
  • non-RR interactive review behavior.

Summary by CodeRabbit

Release Notes

  • New Features

    • Interactive migration mode now available via --interactive flag. When enabled, users are prompted to manually review and resolve namespace conflicts for policy resources during migration. Users can select the appropriate destination namespace for each affected resource, with clear feedback on migration status.
  • Tests

    • Added comprehensive test coverage for interactive migration functionality.

@c-r33d
c-r33d requested a review from a team as a code owner April 17, 2026 15:15
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the namespaced policy migration tool by adding an interactive review capability. When the planner encounters registered resources with conflicting namespace bindings, it now pauses to prompt the user for a target namespace. This ensures that the final migration plan is clean and actionable by resolving ambiguities at planner-time rather than failing or requiring manual intervention later.

Highlights

  • Interactive Review Flow: Introduced an interactive review mechanism for registered resources that span multiple namespaces during policy migration, allowing users to select a target namespace via a CLI prompt.
  • CLI Integration: Updated the migrate namespaced-policy command to support an --interactive flag, which enables the new reviewer during the planning phase.
  • Prompting Infrastructure: Added a generic, testable prompting interface using charmbracelet/huh to handle user input for conflict resolution.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.


The planner pauses, choices wait, To fix the namespace, seal the fate. With interactive prompt in hand, We guide the resources to the land.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request introduces an interactive review mode for namespaced policy migration, allowing users to resolve conflicts when registered resources span multiple target namespaces. It adds a new InteractiveReviewer interface, a charmbracelet/huh based implementation for terminal prompts, and integrates this flow into the migration planner. Feedback includes a critical bug fix in the resource filtering logic where values were being cleared before iteration, a suggestion to cache network calls within the review loop to improve performance, and a recommendation to use native library methods for rendering prompt descriptions.

Comment thread otdfctl/migrations/namespacedpolicy/interactive_review.go Outdated
Comment thread otdfctl/migrations/namespacedpolicy/interactive_review.go Outdated
Comment thread otdfctl/migrations/namespacedpolicy/interactive_prompt.go
@coderabbitai

coderabbitai Bot commented Apr 17, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 7cc194f9-3b17-4790-ba10-e1a5f3585582

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch interactive-resolution-prompter

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 and usage tips.

@github-actions

Copy link
Copy Markdown
Contributor
Benchmark results, click to expand

Benchmark authorization.GetDecisions Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 215.75395ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 104.39882ms

Benchmark Statistics

Name № Requests Avg Duration Min Duration Max Duration

Bulk Benchmark Results

Metric Value
Total Decrypts 100
Successful Decrypts 100
Failed Decrypts 0
Total Time 425.840688ms
Throughput 234.83 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 46.673960107s
Average Latency 465.029738ms
Throughput 107.13 requests/second

@github-actions

Copy link
Copy Markdown
Contributor
Benchmark results, click to expand

Benchmark authorization.GetDecisions Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 196.787908ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 104.688464ms

Benchmark Statistics

Name № Requests Avg Duration Min Duration Max Duration

Bulk Benchmark Results

Metric Value
Total Decrypts 100
Successful Decrypts 100
Failed Decrypts 0
Total Time 406.359699ms
Throughput 246.09 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 40.014922023s
Average Latency 397.846904ms
Throughput 124.95 requests/second

@c-r33d

c-r33d commented Apr 20, 2026

Copy link
Copy Markdown
Contributor Author

@gemini review

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request introduces an interactive review workflow for the namespaced-policy migration command, enabling users to manually resolve conflicts when registered resources are associated with multiple namespaces. Key additions include an InteractiveReviewer interface, a concrete implementation using the huh library for terminal prompts, and integration into the migration planner. Review feedback highlights opportunities to improve code safety by properly initializing internal maps in the resolver struct, clarifying misleading error messages, and replacing manual field copying in cloneAction with a more robust cloning strategy.

Comment thread otdfctl/migrations/namespacedpolicy/interactive_review.go Outdated
Comment thread otdfctl/migrations/namespacedpolicy/interactive_review.go
Comment thread otdfctl/migrations/namespacedpolicy/interactive_review.go Outdated
@github-actions

Copy link
Copy Markdown
Contributor
Benchmark results, click to expand

Benchmark authorization.GetDecisions Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 189.397504ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 89.713239ms

Benchmark Statistics

Name № Requests Avg Duration Min Duration Max Duration

Bulk Benchmark Results

Metric Value
Total Decrypts 100
Successful Decrypts 100
Failed Decrypts 0
Total Time 415.328735ms
Throughput 240.77 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 40.314611991s
Average Latency 401.769184ms
Throughput 124.02 requests/second

@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: 6

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@otdfctl/migrations/namespacedpolicy/interactive_prompt.go`:
- Around line 45-82: Replace the string-select confirm UI in HuhPrompter.Confirm
with huh.NewConfirm: change the local choice variable from string to bool, build
the form with
huh.NewConfirm().Title(...).Description(...).Affirmative(confirmLabel).Negative(cancelLabel).Value(&choice)
(instead of huh.NewSelect), run the form the same way, and replace the
label-equality check (choice != confirmLabel) with a boolean check (if !choice {
return ErrInteractiveReviewAborted }). Keep the existing error handling around
form.Run() and the defaulting of confirmLabel/cancelLabel.
- Around line 45-113: The Confirm and Select methods currently ignore their
context parameter (signature uses unnamed _), and call form.Run(), which blocks;
rename the parameter to ctx context.Context in both HuhPrompter.Confirm and
HuhPrompter.Select and replace form.Run() with form.RunWithContext(ctx) so the
huh.Form honors cancellation/timeouts (references: HuhPrompter.Confirm,
HuhPrompter.Select, form.Run -> form.RunWithContext).

In `@otdfctl/migrations/namespacedpolicy/interactive_review.go`:
- Around line 31-43: The HuhInteractiveReviewer struct exports Prompter while
handler and pageSize are unexported—make Prompter unexported to be consistent
and only set via NewHuhInteractiveReviewer: change the field name to prompter
(lowercase) and update NewHuhInteractiveReviewer to set prompter accordingly;
also update any usage sites and the existing prompter() receiver (rename to
resolvePrompter() or inline its nil-check at call sites) so there are no
identifier collisions and the nil-check logic still runs.
- Around line 119-137: Add a one-line comment above the reset of
resource.Unresolved, resource.AlreadyMigrated, and resource.NeedsCreate
explaining that we intentionally clear those fields and then call
resolveExistingRegisteredResource (using registeredResources[chosen.GetId()]) to
re-resolve the resource for the newly chosen namespace
(filtered.GetId()/chosen.GetId()), matching the planner semantics implemented in
resolver.resolveRegisteredResource so the subsequent AlreadyMigrated/NeedsCreate
computation is correct.
- Around line 62-118: The reviewRegisteredResource function currently calls
retriever.listActionsForNamespaces and
retriever.listRegisteredResourcesForNamespaces and builds a new resolver every
time for the same chosen namespace; to fix, add a per-namespace cache (keyed by
chosen.GetId()) in the higher-level Review loop or in the reviewer struct and
use it from reviewRegisteredResource so you fetch and store for each namespace
only once per Review invocation: on first encounter call
listActionsForNamespaces/listRegisteredResourcesForNamespaces and save the
resulting customActions, standardActions and registeredResources (and the
constructed resolver) in the cache, and on subsequent calls for the same chosen
namespace reuse those cached values instead of re-calling the retriever or
rebuilding resolver (refer to functions reviewRegisteredResource,
retriever.listActionsForNamespaces,
retriever.listRegisteredResourcesForNamespaces, and resolver).
- Around line 194-221: The prompt builds an options slice in
registeredResourceConflictPrompt that appends the abort option but the consumer
later iterates a separate candidates list (not containing abort) and relies on
the selected value equality check (selected == interactiveReviewAbortOption) to
short-circuit; add a brief comment immediately above the abort-check in the
interactive review handler (the block that checks selected ==
interactiveReviewAbortOption before calling selectedNamespace) stating that the
abort option is appended to options and that the candidates list excludes it, so
the equality check must remain to correctly short-circuit — reference
registeredResourceConflictPrompt, SelectPrompt/options, candidates,
selectedNamespace, and interactiveReviewAbortOption.
🪄 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

Run ID: 33e6538f-d39a-4551-a157-04937c350f36

📥 Commits

Reviewing files that changed from the base of the PR and between a9c6427 and 3f4fe08.

📒 Files selected for processing (7)
  • otdfctl/cmd/migrate/namespaced_policy.go
  • otdfctl/migrations/namespacedpolicy/execute.go
  • otdfctl/migrations/namespacedpolicy/interactive_prompt.go
  • otdfctl/migrations/namespacedpolicy/interactive_review.go
  • otdfctl/migrations/namespacedpolicy/interactive_review_test.go
  • otdfctl/migrations/namespacedpolicy/planner.go
  • otdfctl/migrations/namespacedpolicy/planner_test.go

Comment thread otdfctl/migrations/namespacedpolicy/interactive_prompt.go Outdated
Comment thread otdfctl/migrations/namespacedpolicy/interactive_prompt.go Outdated
Comment thread otdfctl/migrations/namespacedpolicy/interactive_review.go
Comment thread otdfctl/migrations/namespacedpolicy/interactive_review.go Outdated
Comment thread otdfctl/migrations/namespacedpolicy/interactive_review.go
Comment thread otdfctl/migrations/namespacedpolicy/interactive_review.go
elizabethhealy
elizabethhealy previously approved these changes Apr 20, 2026
Comment thread otdfctl/migrations/namespacedpolicy/interactive_review.go Outdated
Comment thread otdfctl/migrations/namespacedpolicy/interactive_review.go Outdated
@github-actions

Copy link
Copy Markdown
Contributor
Benchmark results, click to expand

Benchmark authorization.GetDecisions Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 172.273781ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 93.76083ms

Benchmark Statistics

Name № Requests Avg Duration Min Duration Max Duration

Bulk Benchmark Results

Metric Value
Total Decrypts 100
Successful Decrypts 100
Failed Decrypts 0
Total Time 417.288825ms
Throughput 239.64 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 39.529393222s
Average Latency 393.242113ms
Throughput 126.49 requests/second

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Govulncheck found vulnerabilities ⚠️

The following modules have known vulnerabilities:

  • examples
  • otdfctl
  • sdk
  • service
  • lib/fixtures
  • tests-bdd

See the workflow run for details.

@c-r33d
c-r33d merged commit 46251d0 into interactive-resolution Apr 20, 2026
35 checks passed
@c-r33d
c-r33d deleted the interactive-resolution-prompter branch April 20, 2026 21:06
c-r33d added a commit that referenced this pull request Apr 20, 2026
## Summary

This PR adds planner-time interactive review for registered resources
that span multiple namespaces during namespaced policy migration.

  When --interactive is enabled, the planner now:

  - detects conflicting registered resources,
  - prompts the user to choose the target namespace,
  - filters the resource down to bindings for that namespace,
- updates any required action resolution so the final plan can proceed
cleanly.

  ## Prompt updates

  The interactive prompt was also cleaned up so that:

  - titles and descriptions render separately,
  - the registered resource identifier is shown in the title,
  - namespace options read clearly as migration choices.

  ## Scope

This change is intentionally limited to registered resource conflict
review only.

  It does not add:

  - broader planner summaries,
  - other interactive resolution flows,
  - non-RR interactive review behavior.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

## Release Notes

* **New Features**
* Interactive migration mode now available via `--interactive` flag.
When enabled, users are prompted to manually review and resolve
namespace conflicts for policy resources during migration. Users can
select the appropriate destination namespace for each affected resource,
with clear feedback on migration status.

* **Tests**
* Added comprehensive test coverage for interactive migration
functionality.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
c-r33d added a commit that referenced this pull request Apr 20, 2026
## Summary

This PR tightens the namespacedpolicy planner so registered resources
are the only construct that can remain soft-unresolved during planning.
All other policy constructs now fail fast when their target namespace or
required dependencies cannot be derived.

It also cleans up resolver guard behavior so parent resolver functions
own nil/source validation, while child helpers focus on namespace and
existing-target resolution. For registered resources, unresolved state
is now represented internally as a typed object
  with a machine-checkable reason code plus a human-readable message.

In addition, we have merged in changes for interactively handling
`Registered Resources` that are unresolved. [RR
Interactive](#3317)

  ## What Changed

- Removed top-level Unresolved handling from actions, subject condition
sets, subject mappings, and obligation triggers.
- Kept registered resources as the only planner construct with soft
unresolved behavior.
  - Added a typed RR unresolved model with:
      - Reason
      - Message
- Preserved the existing artifact shape by continuing to emit the
unresolved message as a string in the finalized plan.
- Simplified action, subject condition set, and subject mapping resolver
guard logic so invalid derived entries fail fast in the parent resolver.
- Removed stale unresolved dependency/result handling from subject
mapping dependency resolution.
- Skipped registered resources with no AAVs during derivation and
documented that behavior inline.

  ## Why

The planner had accumulated multiple soft-unresolved paths that no
longer matched the intended contract. This made the resolution flow
harder to reason about and made tests rely on string matching for
unresolved behavior.

  This change makes the model stricter and simpler:

  - non-RR derivation/resolution failures are hard failures
  - RR namespace conflicts remain the only reviewable unresolved case
- tests can now assert a typed unresolved reason instead of brittle
strings
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants