Skip to content

fix: revert redis notifier watch change#314

Merged
iFurySt merged 1 commit intoAmoyLab:mainfrom
kx-byte:main
Apr 22, 2026
Merged

fix: revert redis notifier watch change#314
iFurySt merged 1 commit intoAmoyLab:mainfrom
kx-byte:main

Conversation

@kx-byte
Copy link
Copy Markdown
Contributor

@kx-byte kx-byte commented Apr 22, 2026

Summary by Sourcery

Bug Fixes:

  • Ensure the Redis notifier only delivers new messages by starting consumption from the special latest-message ID instead of an explicitly fetched last ID.

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Apr 22, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR simplifies Redis stream watching for MCP config updates by reverting a previous optimization and always starting the consumer from the latest message ID, ensuring Watch only delivers new updates after subscription begins.

Sequence diagram for RedisNotifier Watch starting from latest Redis stream message

sequenceDiagram
    actor WatchCaller
    participant RedisNotifier
    participant RedisClient
    participant RedisStream
    participant MCPConfigChannel

    WatchCaller->>RedisNotifier: Watch(ctx)
    activate RedisNotifier
    RedisNotifier->>RedisNotifier: create buffered channel (size 10)
    RedisNotifier->>RedisNotifier: start goroutine
    deactivate RedisNotifier

    par WatchLoop
        activate RedisNotifier
        RedisNotifier->>RedisNotifier: lastID = $
        loop read new messages
            RedisNotifier->>RedisClient: XRead from RedisStream starting at lastID
            RedisClient-->>RedisNotifier: new messages
            RedisNotifier->>MCPConfigChannel: push *MCPConfig
            RedisNotifier->>RedisNotifier: update lastID to latest message ID
        end
        deactivate RedisNotifier
    and ContextCancellation
        WatchCaller-->>RedisNotifier: ctx.Done()
        RedisNotifier->>MCPConfigChannel: close channel
    end

    MCPConfigChannel-->>WatchCaller: delivers only messages published after Watch started
Loading

Class diagram for RedisNotifier Watch behavior change

classDiagram
    class RedisNotifier {
        - client RedisClient
        - streamName string
        + Watch(ctx Context) MCPConfigChannel
    }

    class RedisClient {
        + XRead(streamName string, lastID string) RedisMessages
    }

    class Context {
        + Done() DoneChannel
    }

    class MCPConfigChannel {
        + receive() MCPConfig
        + close()
    }

    class RedisMessages {
        + messages MCPConfig[*]
        + lastID string
    }

    class MCPConfig

    RedisNotifier --> RedisClient : uses
    RedisNotifier --> MCPConfigChannel : returns
    RedisNotifier --> Context : observes cancellation
    RedisClient --> RedisMessages : returns
    MCPConfigChannel --> MCPConfig : carries
    RedisMessages --> MCPConfig : contains
Loading

File-Level Changes

Change Details Files
Redis notifier Watch now always starts consuming from the latest message ID instead of prefetching the current tail.
  • Removed pre-watch logic that queried Redis for the current stream tail using XRevRangeN and computed lastID based on the existing latest entry.
  • Initialized lastID inside the Watch goroutine and set it to "$" so that XREAD starts from new messages only.
  • Left the buffered channel creation and goroutine lifecycle (including deferred close on context cancellation) unchanged.
internal/mcp/storage/notifier/redis.go

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • Switching lastID to $ means any messages published before Watch starts will be skipped; if this is intentional, consider expanding the comment to explicitly describe that we only deliver new updates and intentionally ignore historical ones so future readers don’t reintroduce the previous behavior.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Switching `lastID` to `$` means any messages published before `Watch` starts will be skipped; if this is intentional, consider expanding the comment to explicitly describe that we only deliver *new* updates and intentionally ignore historical ones so future readers don’t reintroduce the previous behavior.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@iFurySt iFurySt merged commit 716d3bd into AmoyLab:main Apr 22, 2026
6 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.

2 participants