Skip to content

Conversation

@samthanawalla
Copy link
Contributor

This CL utilizes the event store to write outgoing messages and removes the unbounded outgoing data structure.

For #190

@samthanawalla samthanawalla marked this pull request as ready for review August 20, 2025 15:47
@samthanawalla samthanawalla requested review from findleyr and jba August 20, 2025 15:47
Copy link
Contributor

@jba jba left a comment

Choose a reason for hiding this comment

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

Sorry that this PR is confusing me so much.
I think I need to see the algorithm as a whole, without diffs.
So if you think it is correct after addressing my comments that it is correct, I'll approve and then read it separately.

@samthanawalla
Copy link
Contributor Author

Sorry that this PR is confusing me so much. I think I need to see the algorithm as a whole, without diffs. So if you think it is correct after addressing my comments that it is correct, I'll approve and then read it separately.

Sorry I prematurely sent a new commit- not ready for review yet! (The flow is very confusing, I agree)

@samthanawalla samthanawalla marked this pull request as draft August 25, 2025 19:23
This CL utilizes the event store to write outgoing messages and removes
the unbounded outgoing data structure.

For modelcontextprotocol#190
@samthanawalla samthanawalla marked this pull request as ready for review August 27, 2025 14:19
@samthanawalla
Copy link
Contributor Author

samthanawalla commented Aug 27, 2025

Ready for review. The challenge is now with properly yielding the eventstore.After error.
Yielding this error immediately is not quite right since the eventstore.Append could happen after messages is called.

So we can either:

  1. skip streamid/session does not exist errors but yield other errors (PurgedError)
  2. skip yielding all eventstore errors and wait for an Append
  3. add some other synchronization methods such as eventstore.Start()

We can discuss IRL if that's better.

@samthanawalla samthanawalla requested review from findleyr and jba August 27, 2025 14:30
@findleyr
Copy link
Contributor

@jba and I were discussing yesterday, and he also suggested adding something like EventStore.Start. What should it be called though?

We could use this to allow customizing the stream id...
Here are a few options

  • the name could be NewStream, StartStream, OpenStream
  • The signature could be func(StreamID) (accept a stream id) or func() StreamID (return a stream id).

@samthanawalla
Copy link
Contributor Author

@jba and I were discussing yesterday, and he also suggested adding something like EventStore.Start. What should it be called though?

We could use this to allow customizing the stream id... Here are a few options

  • the name could be NewStream, StartStream, OpenStream
  • The signature could be func(StreamID) (accept a stream id) or func() StreamID (return a stream id).

Sounds good. Latest commit adds the EventStore.Open

// Open prepares the event store for a given session. It ensures that the
// underlying data structure for the sessionID is initialized, making it
// ready to store event streams.
Open(_ context.Context, sessionID string, streamID StreamID) error
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this need to be called once per session, or once per stream? If the latter, the doc is wrong.

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like once per stream.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we should call this OpenStream or StartStream to make that clearer? I'd be fine with either.

Copy link
Contributor

Choose a reason for hiding this comment

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

Everything is XXXStream. Append to stream, get messages from stream. The only session method has "Session" in the name. So "Open" is right.

Copy link
Contributor

Choose a reason for hiding this comment

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

I said that badly. I meant that EventStore.M is about streams unless M explicitly says otherwise.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, Open takes a stream ID, so of course it is opening a stream.

Copy link
Contributor

@findleyr findleyr left a comment

Choose a reason for hiding this comment

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

LGTM, just want to revisit the name 'Open'.

// Open prepares the event store for a given session. It ensures that the
// underlying data structure for the sessionID is initialized, making it
// ready to store event streams.
Open(_ context.Context, sessionID string, streamID StreamID) error
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we should call this OpenStream or StartStream to make that clearer? I'd be fine with either.

@jba
Copy link
Contributor

jba commented Aug 29, 2025

The challenge is now with properly yielding the eventstore.After error. Yielding this error immediately is not quite right since the eventstore.Append could happen after messages is called.

So we can either:

  1. skip streamid/session does not exist errors but yield other errors (PurgedError)
  2. skip yielding all eventstore errors and wait for an Append
  3. add some other synchronization methods such as eventstore.Start()

We can discuss IRL if that's better.

Not sure I understand. An error from After should mean that things are broken: the session or stream is unknown, the data you need is gone, the underlying storage has failed, etc. It's not an error to exhaust the available messages (even there are zero). The outer loop in messages takes care of Appends that come later. I think Open fixes the "unknown" case, right?

@samthanawalla
Copy link
Contributor Author

The challenge is now with properly yielding the eventstore.After error. Yielding this error immediately is not quite right since the eventstore.Append could happen after messages is called.
So we can either:

  1. skip streamid/session does not exist errors but yield other errors (PurgedError)
  2. skip yielding all eventstore errors and wait for an Append
  3. add some other synchronization methods such as eventstore.Start()

We can discuss IRL if that's better.

Not sure I understand. An error from After should mean that things are broken: the session or stream is unknown, the data you need is gone, the underlying storage has failed, etc. It's not an error to exhaust the available messages (even there are zero). The outer loop in messages takes care of Appends that come later. I think Open fixes the "unknown" case, right?

Yes Open fixes the unknown case now.

@samthanawalla samthanawalla enabled auto-merge (squash) August 29, 2025 15:33
@samthanawalla samthanawalla merged commit ddaf35e into modelcontextprotocol:main Aug 29, 2025
5 checks passed
@samthanawalla samthanawalla deleted the fixMemoryIssue branch September 11, 2025 18:17
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.

3 participants