Skip to content

feat: bulk test channels, close #1219#1228

Merged
looplj merged 1 commit intorelease/v0.9.xfrom
dev-tmp
Mar 31, 2026
Merged

feat: bulk test channels, close #1219#1228
looplj merged 1 commit intorelease/v0.9.xfrom
dev-tmp

Conversation

@looplj
Copy link
Copy Markdown
Owner

@looplj looplj commented Mar 31, 2026

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

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 a batch health check feature for channels, enabling users to run concurrent test requests and recover healthy channels in bulk. The implementation includes a new ChannelsBulkTestDialog component, updates to the channel management table, and backend support for bulk recovery and flexible error parsing for OpenAI-compatible providers. Review feedback suggests optimizing React state updates by batching changes, improving the efficiency of the concurrent test queue by avoiding shift(), and simplifying the dialog's initialization logic by removing unnecessary state.

Comment on lines +192 to +194
failedChannels.forEach((channel) => {
setResultStatus(channel, 'idle', { error: undefined, latency: undefined });
});
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.

medium

Calling setResultStatus inside a loop triggers multiple state updates and re-renders. While React 18 batches updates in most cases, it is more efficient and cleaner to perform a single state update with the entire batch of changes for the failed channels.

Suggested change
failedChannels.forEach((channel) => {
setResultStatus(channel, 'idle', { error: undefined, latency: undefined });
});
setResults((prev) => {
const next = { ...prev };
failedChannels.forEach((channel) => {
next[channel.id] = {
...next[channel.id],
channelID: channel.id,
channelName: channel.name,
status: 'idle',
error: undefined,
latency: undefined,
};
});
return next;
});

Comment on lines +153 to +158
const queue = [...runnableChannels];
const workerCount = Math.min(MAX_CONCURRENT_TESTS, queue.length);

const workers = Array.from({ length: workerCount }, async () => {
while (queue.length > 0) {
const channel = queue.shift();
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.

medium

Using Array.prototype.shift() inside a loop has O(N) complexity, making the overall process O(N^2) relative to the number of channels. While the number of channels is likely small, it is better practice to use a simple index pointer to track the next item in the queue.

      const queue = [...runnableChannels];
      const workerCount = Math.min(MAX_CONCURRENT_TESTS, queue.length);
      let nextIndex = 0;

      const workers = Array.from({ length: workerCount }, async () => {
        while (nextIndex < queue.length) {
          const channel = queue[nextIndex++];

const { open, setOpen, selectedChannels, resetRowSelection, setSelectedChannels } = useChannels();
const testChannel = useTestChannel({ silent: true });
const bulkRecoverChannels = useBulkRecoverChannels();
const [dialogContent, setDialogContent] = useState<HTMLDivElement | null>(null);
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.

medium

The dialogContent state and the associated ref on DialogContent appear to be unnecessary for initializing the results. The isDialogOpen state alone is sufficient to trigger the initialization effect when the dialog opens. Removing this state simplifies the component and avoids potential issues with ref-based effects.

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 4 additional findings.

Open in Devin Review

@looplj looplj merged commit 3900e62 into release/v0.9.x Mar 31, 2026
3 checks passed
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.

1 participant