actionmcp 0.28.0 → 0.29.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 644f0795fca70107d86ba512e1c7083535f33269e4a53a488cc10d53d93ffd28
4
- data.tar.gz: 187ecb0de2249772b758177195b4c6006ff44e296cd518ba0c44f9ab83b58b19
3
+ metadata.gz: 0e4c587dbf08153dbc1b3c04a9a65be8accf56959e5f3c1e336c84950ca32936
4
+ data.tar.gz: c6fd2f8e495eaf00e30cd88a9022ab31cde81a24c90dda056cfc1ba9bc0e6526
5
5
  SHA512:
6
- metadata.gz: dee5271d34e57f3efb3b2459f1b258359a9b36040ca36e2567cf989435105322493cd344594a211a0cd4c426800153b5e9d21e7dd7c18a38183d79d593bedbb4
7
- data.tar.gz: c5c5ecb5398636afec82b781622f130da83aee55c04765eb9a04fd06b444cd10fd4c27b65d7485a9775d771e60605a85c5137323be10234ca9ebfcd0bebd480d
6
+ metadata.gz: d52f4037a16226d74929dc4bff5a6d5b3dbf5b9f4774b5521dc1dc2e107689e4de6271d3ba327ba124f114b7631f29f8d357f534954b55f996b31f281ae6bfbd
7
+ data.tar.gz: a08bda7ee781728e75477c1aa943728440ced72b42d71123d596fe6ff13f84893bbec8862071dde69b8452918735329adb4b97a95a55271f458fc578320ebd23
@@ -56,23 +56,40 @@ module ActionMCP
56
56
  return
57
57
  end
58
58
 
59
- # Schedule heartbeats using a proper timer
60
- heartbeat = Concurrent::TimerTask.new(
61
- execution_interval: HEARTBEAT_INTERVAL,
62
- timeout_interval: 5 # Timeout for heartbeat operation
63
- ) do
59
+ # Create a thread-safe flag to track if we should continue sending heartbeats
60
+ heartbeat_active = Concurrent::AtomicBoolean.new(true)
61
+
62
+ # Setup recurring heartbeat using ScheduledTask with proper cancellation
63
+ heartbeat_task = nil
64
+ heartbeat_sender = -> do
64
65
  if connection_active.true? && !response.stream.closed?
65
66
  begin
66
- sse.write({ ping: true })
67
+ # Try to send heartbeat with a controlled execution time
68
+ future = Concurrent::Promises.future do
69
+ sse.write({ ping: true })
70
+ end
71
+
72
+ # Wait for the heartbeat with timeout
73
+ result = future.value(5) # 5 second timeout
74
+
75
+ # Schedule the next heartbeat if this one succeeded
76
+ if heartbeat_active.true?
77
+ heartbeat_task = Concurrent::ScheduledTask.execute(HEARTBEAT_INTERVAL, &heartbeat_sender)
78
+ end
79
+ rescue Concurrent::TimeoutError
80
+ Rails.logger.warn "SSE: Heartbeat timed out, closing connection"
81
+ connection_active.make_false
67
82
  rescue StandardError => e
68
83
  Rails.logger.debug "SSE: Heartbeat error: #{e.message}"
69
84
  connection_active.make_false
70
85
  end
71
86
  else
72
- raise Concurrent::CancelledOperationError
87
+ heartbeat_active.make_false
73
88
  end
74
89
  end
75
- heartbeat.execute
90
+
91
+ # Start the first heartbeat
92
+ heartbeat_task = Concurrent::ScheduledTask.execute(HEARTBEAT_INTERVAL, &heartbeat_sender)
76
93
 
77
94
  # Wait for connection to be closed or cancelled
78
95
  while connection_active.true? && !response.stream.closed?
@@ -85,8 +102,10 @@ module ActionMCP
85
102
  ensure
86
103
  # Clean up resources
87
104
  timeout_task&.cancel
88
- heartbeat&.shutdown
105
+ heartbeat_active&.make_false # Signal to stop scheduling new heartbeats
106
+ heartbeat_task&.cancel # Cancel any pending heartbeat task
89
107
  listener&.stop
108
+ mcp_session.close! rescue nil
90
109
  response.stream.close rescue nil
91
110
 
92
111
  Rails.logger.debug "SSE: Connection cleaned up for session: #{session_id}"
@@ -203,4 +222,4 @@ module ActionMCP
203
222
  Rails.logger.debug "Unsubscribed from: #{session_key}"
204
223
  end
205
224
  end
206
- end
225
+ end
@@ -2,7 +2,7 @@
2
2
 
3
3
  require_relative "gem_version"
4
4
  module ActionMCP
5
- VERSION = "0.28.0"
5
+ VERSION = "0.29.0"
6
6
 
7
7
  class << self
8
8
  alias version gem_version
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: actionmcp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.28.0
4
+ version: 0.29.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Abdelkader Boudih