@@ -50,13 +50,6 @@ type Puller interface {
5050// PullerProvider is a function that returns a puller for the given task ID.
5151type PullerProvider func (ctx context.Context , taskID a2a.TaskID ) (Puller , error )
5252
53- // NewStaticPullerProvider returns a PullerProvider that always returns the same Puller.
54- func NewStaticPullerProvider (es Puller ) PullerProvider {
55- return func (ctx context.Context , taskID a2a.TaskID ) (Puller , error ) {
56- return es , nil
57- }
58- }
59-
6053// PullConfig configures the behavior of a pull-based event queue manager.
6154type PullConfig struct {
6255 // PollInterval is the interval at which the puller is polled for new events.
@@ -65,9 +58,6 @@ type PullConfig struct {
6558 // InactivityTimeout is the duration of inactivity after which the reader will time out.
6659 // Defaults to 5 minutes. Set to 0 to disable inactivity timeout.
6760 InactivityTimeout time.Duration
68- // AccessCheck is an optional callback executed before emitting the initial snapshot
69- // of a task to verify that the calling context has permission to access the task.
70- AccessCheck func (context.Context , * a2a.Task ) error
7161 // OnInactivity is an optional callback function that is called when a task has exceeded the
7262 // InactivityTimeout. It's only triggered from Reader.Read().
7363 // The returned task is used to update the snapshot.
@@ -124,12 +114,7 @@ func (m *pullQueueManager) CreateReader(ctx context.Context, taskID a2a.TaskID)
124114 return nil , fmt .Errorf ("failed to get puller: %w" , err )
125115 }
126116
127- snapshot , err := getSnapshot (ctx , puller , taskID )
128- if err != nil {
129- return nil , fmt .Errorf ("failed to get snapshot: %w" , err )
130- }
131-
132- return newPullReader (puller , taskID , m , snapshot ), nil
117+ return newPullReader (puller , taskID , m ), nil
133118}
134119
135120// CreateWriter implements Manager.CreateWriter. It delegates to the in-memory manager.
@@ -146,21 +131,17 @@ var _ Reader = (*pullReader)(nil)
146131
147132type pullReader struct {
148133 taskID a2a.TaskID
149- snapshot * Message
150134 puller Puller
151135 manager * pullQueueManager
152136 eventsChan chan * Message
153137 closed chan struct {}
154138 ctxCancel context.CancelFunc
155-
156- emittedSnapshot bool
157139}
158140
159- func newPullReader (p Puller , taskID a2a.TaskID , queueManager * pullQueueManager , snapshot * Message ) * pullReader {
141+ func newPullReader (p Puller , taskID a2a.TaskID , queueManager * pullQueueManager ) * pullReader {
160142 ctx , cancel := context .WithCancel (context .Background ())
161143 reader := & pullReader {
162144 taskID : taskID ,
163- snapshot : snapshot ,
164145 puller : p ,
165146 manager : queueManager ,
166147 eventsChan : make (chan * Message ),
@@ -215,10 +196,6 @@ func (r *pullReader) dispatchMessages(ctx context.Context, resp *PullResponse) s
215196 if msg == nil || msg .Event == nil {
216197 continue
217198 }
218- // Snapshot is emitted directly from r.snapshot by Read, so filter out to not send duplicate.
219- if _ , isTask := msg .Event .(* a2a.Task ); isTask {
220- continue
221- }
222199 select {
223200 case r .eventsChan <- msg :
224201 case <- ctx .Done ():
@@ -237,17 +214,6 @@ func (r *pullReader) dispatchMessages(ctx context.Context, resp *PullResponse) s
237214// If the inactivity timeout is reached, it will trigger the OnInactivity callback if configured,
238215// and return ErrInactivityTimeout.
239216func (r * pullReader ) Read (ctx context.Context ) (* Message , error ) {
240- if ! r .emittedSnapshot {
241- if err := r .accessCheck (ctx ); err != nil {
242- return nil , err
243- }
244- r .emittedSnapshot = true
245- return r .snapshot , nil
246- }
247- if taskupdate .IsFinal (r .snapshot .Event ) {
248- return nil , ErrQueueClosed
249- }
250-
251217 var timeout <- chan time.Time
252218 if r .manager .cfg .InactivityTimeout > 0 {
253219 timer := time .NewTimer (r .manager .cfg .InactivityTimeout )
@@ -269,8 +235,7 @@ func (r *pullReader) Read(ctx context.Context) (*Message, error) {
269235 return nil , fmt .Errorf ("%w: failed to call inactivity callback:%w" , ErrInactivityTimeout , err )
270236 }
271237 if task != nil {
272- r .snapshot = newMessage (task )
273- r .emittedSnapshot = false
238+ return newMessage (task ), nil
274239 }
275240 }
276241 return nil , fmt .Errorf ("%w after %v" , ErrInactivityTimeout , r .manager .cfg .InactivityTimeout )
@@ -284,52 +249,6 @@ func (r *pullReader) Close() error {
284249 return nil
285250}
286251
287- func (r * pullReader ) accessCheck (ctx context.Context ) error {
288- if r .manager .cfg .AccessCheck == nil {
289- return nil
290- }
291- task , ok := r .snapshot .Event .(* a2a.Task )
292- if ! ok {
293- return fmt .Errorf ("snapshot event is not a task: %T" , r .snapshot .Event )
294- }
295- return r .manager .cfg .AccessCheck (ctx , task )
296- }
297-
298- func getSnapshot (ctx context.Context , puller Puller , taskID a2a.TaskID ) (* Message , error ) {
299- resp , err := puller .Pull (ctx , taskID , nil )
300- if err != nil {
301- closePullerOnError (ctx , puller )
302- return nil , fmt .Errorf ("snapshot pull failed for task %v: %w" , taskID , err )
303- }
304- if resp == nil || len (resp .Messages ) == 0 {
305- closePullerOnError (ctx , puller )
306- return nil , fmt .Errorf ("puller returned no snapshot for task %v" , taskID )
307- }
308- snapshotMsg := resp .Messages [0 ]
309- if snapshotMsg == nil || snapshotMsg .Event == nil {
310- closePullerOnError (ctx , puller )
311- return nil , fmt .Errorf ("pull queue: puller returned nil snapshot message for task %q" , taskID )
312- }
313- task , ok := snapshotMsg .Event .(* a2a.Task )
314- if ! ok {
315- closePullerOnError (ctx , puller )
316- return nil , fmt .Errorf ("pull queue: puller's first message for task %q is %T, want *a2a.Task" ,
317- taskID , snapshotMsg .Event )
318- }
319- if task .ID != taskID {
320- closePullerOnError (ctx , puller )
321- return nil , fmt .Errorf ("pull queue: task ID mismatch in snapshot for task %q: got %q" ,
322- taskID , task .ID )
323- }
324- return snapshotMsg , nil
325- }
326-
327- func closePullerOnError (ctx context.Context , puller Puller ) {
328- if err := puller .Close (ctx ); err != nil {
329- log .Warn (ctx , "Error closing puller: %v" , err )
330- }
331- }
332-
333252func newMessage (task * a2a.Task ) * Message {
334253 return & Message {
335254 Event : task ,
0 commit comments