Skip to content

fix(onboard): forward enabled messaging channels into policy preset suggestions - #2069

Merged
ericksoa merged 4 commits into
mainfrom
fix/2014-onboard-forward-messaging-channels-to-presets
Apr 19, 2026
Merged

ericksoa merged 4 commits into
mainfrom
fix/2014-onboard-forward-messaging-channels-to-presets

Conversation

@laitingsheng

@laitingsheng laitingsheng commented Apr 19, 2026 •

Copy link
Copy Markdown
Contributor

The Balanced tier omits messaging presets by default, so a user who enabled telegram, slack, or discord in the messaging step would still see the matching preset unchecked at the policy step. Extract the seed-suggestions logic from setupPoliciesWithSelection into a pure helper and forward enabledChannels alongside the existing brave and local-inference additions.

Closes #2014

Summary

Related Issue

Changes

Type of Change

  • Code change (feature, bug fix, or refactor)
  • Code change with doc updates
  • Doc only (prose changes, no code sample modifications)
  • Doc only (includes code sample changes)

Verification

  • npx prek run --all-files passes
  • npm test passes
  • Tests added or updated for new or changed behavior
  • No secrets, API keys, or credentials committed
  • Docs updated for user-facing behavior changes
  • make docs builds without warnings (doc changes only)
  • Doc pages follow the style guide (doc changes only)
  • New doc pages include SPDX header and frontmatter (new pages only)

AI Disclosure

  • AI-assisted — tool:

Signed-off-by: Tinson Lai [email protected]

Summary by CodeRabbit

  • New Features

    • Enhanced setup suggestions to include selected messaging channels, web-search and local-inference options, and to prefer newly selected channels when resuming setup.
    • Sessions now persist nullable messaging channel selections and sanitize non-string entries.
  • Bug Fixes

    • Messaging reachability checks (e.g., Telegram) now run only when a token-backed channel remains enabled.
  • Tests

    • Added unit tests for suggestion logic, channel inclusion/deduplication/filtering, and session persistence/round-trip behavior.

…uggestions

The Balanced tier omits messaging presets by default, so a user who
enabled telegram, slack, or discord in the messaging step would still see
the matching preset unchecked at the policy step. Extract the
seed-suggestions logic from setupPoliciesWithSelection into a pure helper
and forward enabledChannels alongside the existing brave and
local-inference additions.

Closes #2014

Co-Authored-By: Claude <[email protected]>
Signed-off-by: Tinson Lai <[email protected]>
@coderabbitai

coderabbitai Bot commented Apr 19, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 4eacb766-bbc2-48dc-aa12-e8cb9c563540

📥 Commits

Reviewing files that changed from the base of the PR and between 595dc19 and c261f9d.

📒 Files selected for processing (1)
  • src/lib/onboard.ts

📝 Walkthrough

Walkthrough

Updated onboarding to persist selected messagingChannels, prefer newly-selected channels when resuming, and extracted policy suggestion logic into a new exported helper computeSetupPresetSuggestions; tests added for the helper and session persistence; minor Telegram preflight gating adjusted.

Changes

Cohort / File(s) Summary
Policy suggestion logic
src/lib/onboard.ts
Added and exported computeSetupPresetSuggestions(tierName, options = {}); replaced inline preset-assembly with this helper; Telegram preflight now checks enabled.has("telegram").
Session model & persistence
src/lib/onboard-session.ts
Added `messagingChannels: string[]
Tests — onboarding helper
test/onboard.test.ts
Replaced dynamic CommonJS require with direct ESM imports; added computeSetupPresetSuggestions tests covering defaults, channel inclusion/deduplication, known-preset filtering, brave retention, local-inference for local providers, and null-channel handling.
Tests — session persistence
src/lib/onboard-session.test.ts
Added tests asserting messagingChannels roundtrip, non-string entries are filtered, and new sessions default messagingChannels to null.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant CLI as Onboard CLI
  participant Onboard as onboard.ts
  participant SessionStore as Session (persist)
  participant Presets as computeSetupPresetSuggestions

  User->>CLI: select messaging channels
  CLI->>Onboard: record selection
  Onboard->>SessionStore: save messagingChannels (string[] | null)
  User->>CLI: resume onboarding -> choose tier
  CLI->>SessionStore: load session
  SessionStore->>Onboard: return messagingChannels
  CLI->>Onboard: provide tierName + enabledChannels
  Onboard->>Presets: computeSetupPresetSuggestions(tierName, { enabledChannels, webSearchConfig, provider, knownPresetNames })
  Presets->>Onboard: return ordered preset suggestions
  Onboard->>CLI: present suggested presets
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰
I hopped through prompts and saved each chosen thread,
Telegram and Slack snugly tucked in my head.
Presets now follow the paths that users ran,
A rabbit cheers—onboarding flows as planned! 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.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 accurately summarizes the main change: forwarding enabled messaging channels into policy preset suggestions, matching the core objective of the PR.
Linked Issues check ✅ Passed The PR addresses issue #2014 by forwarding enabled messaging channels into policy preset suggestions so they are auto-selected when previously configured.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the messaging channel persistence and preset suggestion issue. Session schema changes support the core objective of carrying channels through onboarding.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/2014-onboard-forward-messaging-channels-to-presets

Comment @coderabbitai help to get the list of available commands and usage tips.

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

Actionable comments posted: 2

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

Inline comments:
In `@src/lib/onboard.ts`:
- Around line 5264-5269: computeSetupPresetSuggestions is being called with
enabledChannels that can be an empty array during a resumed flow, which loses
previously recorded channel configuration and omits messaging presets. Update
the argument passed to computeSetupPresetSuggestions so enabledChannels is
derived from the saved session state when present (e.g., use
sessionState.recordedChannels or session.channels if non-empty) instead of
blindly using the local enabledChannels; keep the other params (tierName,
webSearchConfig, provider, knownPresetNames) unchanged and ensure the fallback
remains the original enabledChannels when no recorded channels exist.

In `@test/onboard.test.ts`:
- Line 57: Replace the CommonJS require for computeSetupPresetSuggestions and
getSuggestedPolicyPresets with an ESM named import: remove the require statement
and add these two symbols to the existing ESM import block at the top of the
test file (import { computeSetupPresetSuggestions, getSuggestedPolicyPresets }
from "../dist/lib/onboard.js"); ensure you don’t create duplicate imports if
either symbol is already imported and run the tests to confirm the ESM import
works in the test environment.
🪄 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: c18cc642-03c7-4b5d-9c41-f9dc250c1a38

📥 Commits

Reviewing files that changed from the base of the PR and between 4e6508d and 6b08fad.

📒 Files selected for processing (2)
  • src/lib/onboard.ts
  • test/onboard.test.ts

Comment thread src/lib/onboard.ts Resolved
Comment thread test/onboard.test.ts Resolved
laitingsheng and others added 2 commits April 19, 2026 03:50
…orts in tests

Address CodeRabbit review on #2069:

1. On resume, setupMessagingChannels() is skipped when the sandbox step is
   already complete, so selectedMessagingChannels defaults to []. The
   downstream computeSetupPresetSuggestions() then had nothing to forward,
   leaving messaging presets unchecked again. Add messagingChannels to the
   Session schema, normalizeSession, createSession defaults, SessionUpdates,
   and filterSafeUpdates — mirroring the existing policyPresets shape — so
   the value written at onboard.ts:6167 actually persists to disk. The policy
   step now reads latestSession.messagingChannels as a fallback when the live
   selection is empty.

2. Replace the createRequire shim in test/onboard.test.ts with a plain ESM
   import — the named exports resolve through the existing import block.

Co-Authored-By: Claude <[email protected]>
Signed-off-by: Tinson Lai <[email protected]>

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

Actionable comments posted: 1

Caution

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

⚠️ Outside diff range comments (1)
src/lib/onboard.ts (1)

6165-6169: ⚠️ Potential issue | 🟠 Major

Persist configured channels, not raw toggle selections.

setupMessagingChannels() can return channels the user toggled on but never finished configuring. Those names are now written to session state and later fed back into computeSetupPresetSuggestions(), so the policy step can auto-suggest/select a preset for a channel that was never actually configured.

Possible fix
       startRecordedStep("sandbox", { sandboxName, provider, model });
-      selectedMessagingChannels = await setupMessagingChannels();
+      selectedMessagingChannels = (await setupMessagingChannels()).filter((name) => {
+        const channel = MESSAGING_CHANNELS.find((c) => c.name === name);
+        return Boolean(
+          channel &&
+            (getCredential(channel.envKey) ||
+              normalizeCredentialValue(process.env[channel.envKey])),
+        );
+      });
       onboardSession.updateSession((current) => {
         current.messagingChannels = selectedMessagingChannels;
         return current;
       });
@@
           enabledChannels:
             selectedMessagingChannels.length > 0
               ? selectedMessagingChannels
               : recordedMessagingChannels,

Also applies to: 6264-6267

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/lib/onboard.ts` around lines 6165 - 6169, The session is being updated
with raw toggle selections from setupMessagingChannels() which can include
channels the user never finished configuring; change the update to persist only
fully configured channels (e.g., filter selectedMessagingChannels for channels
with completed config/required fields) before calling
onboardSession.updateSession so computeSetupPresetSuggestions() only sees actual
configured channels. Update the logic where selectedMessagingChannels is set
(from setupMessagingChannels()) to either have setupMessagingChannels return
only configured channels or apply a filter/validation step prior to writing to
onboardSession.messagingChannels; apply the same change to the other occurrence
referenced (the block around lines 6264-6267).
🧹 Nitpick comments (1)
src/lib/onboard.ts (1)

5376-5391: Move this helper to typed CLI code to keep session/preset logic under tsconfig.cli.json.

This helper adds decision logic to a file under @ts-nocheck, contrary to the guideline that src/lib/ should use TypeScript with type-checking. The helper depends only on tiers.resolveTierPresets() and the LOCAL_INFERENCE_PROVIDERS constant—both readily available in typed context. Moving it to a typed helper module (e.g., onboard-session.ts or a new utility file) would bring this logic under type safety while keeping the plumbing cohesive.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/lib/onboard.ts` around lines 5376 - 5391, Move the
computeSetupPresetSuggestions helper out of the `@ts-nocheck` file into a typed
CLI module (e.g., onboard-session.ts or a new utils file compiled under
tsconfig.cli.json), reimplementing it with proper TypeScript types for
parameters (tierName: string, options: { enabledChannels?: string[];
webSearchConfig?: any; provider?: string; knownPresetNames?: string[] }) and
exporting it; update callers to import the new function; ensure the
implementation uses tiers.resolveTierPresets(...) and the
LOCAL_INFERENCE_PROVIDERS constant from the typed modules and preserves the same
add/suggestions logic for enabledChannels, webSearchConfig ("brave") and
provider ("local-inference").
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/lib/onboard-session.ts`:
- Around line 208-210: The normalization for overrides.messagingChannels
currently filters non-string entries and returns [] for malformed non-empty
arrays, which conflates corrupt input with an intentional empty selection;
update the logic in filterSafeUpdates (and the other similar places handling
overrides.messagingChannels) to only accept the array if every element is a
string (e.g., Array.isArray(overrides.messagingChannels) &&
overrides.messagingChannels.every(v => typeof v === "string")), otherwise set
messagingChannels to null so malformed input does not erase previously saved
selections; apply the same validation pattern to the other occurrences
referenced (the other messagingChannels normalization sites).

---

Outside diff comments:
In `@src/lib/onboard.ts`:
- Around line 6165-6169: The session is being updated with raw toggle selections
from setupMessagingChannels() which can include channels the user never finished
configuring; change the update to persist only fully configured channels (e.g.,
filter selectedMessagingChannels for channels with completed config/required
fields) before calling onboardSession.updateSession so
computeSetupPresetSuggestions() only sees actual configured channels. Update the
logic where selectedMessagingChannels is set (from setupMessagingChannels()) to
either have setupMessagingChannels return only configured channels or apply a
filter/validation step prior to writing to onboardSession.messagingChannels;
apply the same change to the other occurrence referenced (the block around lines
6264-6267).

---

Nitpick comments:
In `@src/lib/onboard.ts`:
- Around line 5376-5391: Move the computeSetupPresetSuggestions helper out of
the `@ts-nocheck` file into a typed CLI module (e.g., onboard-session.ts or a new
utils file compiled under tsconfig.cli.json), reimplementing it with proper
TypeScript types for parameters (tierName: string, options: { enabledChannels?:
string[]; webSearchConfig?: any; provider?: string; knownPresetNames?: string[]
}) and exporting it; update callers to import the new function; ensure the
implementation uses tiers.resolveTierPresets(...) and the
LOCAL_INFERENCE_PROVIDERS constant from the typed modules and preserves the same
add/suggestions logic for enabledChannels, webSearchConfig ("brave") and
provider ("local-inference").
🪄 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: a094aaa4-81d6-450a-8bf0-2c2c569e8e7c

📥 Commits

Reviewing files that changed from the base of the PR and between 6b08fad and 595dc19.

📒 Files selected for processing (4)
  • src/lib/onboard-session.test.ts
  • src/lib/onboard-session.ts
  • src/lib/onboard.ts
  • test/onboard.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • test/onboard.test.ts

Comment thread src/lib/onboard-session.ts Resolved
…Channels return

A channel toggled on but left without a bot token still landed in the
returned array because the no-token branch continue'd without removing the
name from the `enabled` Set. The bogus selection then flowed into the
Docker build args, the session record, and the policy-preset picker — all
claiming the channel was configured when no credential had been saved.

Delete the name from `enabled` in the no-token branch and derive the
return value from the Set so only channels with credentials survive.

Co-Authored-By: Claude <[email protected]>
Signed-off-by: Tinson Lai <[email protected]>

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

Looks good — clean refactor of preset suggestion logic, correct channel forwarding with credential gating, solid test coverage. Minor nits (recordedMessagingChannels defaults to [] vs null for consistency, no unit test for the resume fallback path) are non-blocking.

@ericksoa
ericksoa merged commit ee5b41d into main Apr 19, 2026
16 checks passed
@wscurran wscurran added the bug-fix PR fixes a bug or regression label Jun 8, 2026
@wscurran wscurran added the NV QA Bugs found by the NVIDIA QA Team label Jun 26, 2026
@cv
cv deleted the fix/2014-onboard-forward-messaging-channels-to-presets branch June 28, 2026 00:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug-fix PR fixes a bug or regression NV QA Bugs found by the NVIDIA QA Team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[All Platform][Agent] Onboarding does not carry selected messaging channels into policy presets

3 participants