Skip to content

Bound WatchedField change queue to prevent memory growth #100

@zeevdr

Description

@zeevdr

Description

Both WatchedField._change_queue (sdk/src/opendecree/watcher.py:59) and AsyncWatchedField._change_queue (sdk/src/opendecree/async_watcher.py:59) use unbounded queue.Queue() / asyncio.Queue() with no maxsize. If a consumer of field.changes() falls behind while the server sends rapid updates, memory grows indefinitely.

The TypeScript SDK already handles this with DEFAULT_QUEUE_SIZE = 1024 and a drop-oldest strategy with _droppedChanges tracking (decree-typescript/src/watcher.ts:31,203-206). The Python SDK should adopt the same pattern.

Acceptance criteria

  • WatchedField and AsyncWatchedField accept a max_queue_size parameter (default 1024)
  • When the queue is full, the oldest entry is dropped (drop-oldest strategy)
  • A dropped_changes counter is exposed on the field object
  • Tests verify bounded behavior under rapid updates with a slow consumer
  • Behavior matches the TypeScript SDK's queue overflow semantics

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpriority: P1Current milestone worksize: SQuick win — a few hours or less

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions