Skip to content

fix(core): Handle invalid Redis stream IDs in SSE endpoint - #54

Open
sentry[bot] wants to merge 1 commit into
devfrom
seer/fix/redis-invalid-stream-id
Open

fix(core): Handle invalid Redis stream IDs in SSE endpoint#54
sentry[bot] wants to merge 1 commit into
devfrom
seer/fix/redis-invalid-stream-id

Conversation

@sentry

@sentry sentry Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

This PR addresses an issue where the /optimize/{job_id}/events SSE endpoint, when backed by Redis, would crash with a ResponseError: Invalid stream ID specified as stream command argument if the client provided a malformed Last-Event-ID header (e.g., 'invalid').

The root cause was that RedisJobStore.stream_events passed the client-controlled after_id (derived from Last-Event-ID) directly to Redis's xread command without validation. A truthy but malformed value would bypass the after_id or "0-0" fallback, leading to the Redis error.

The fix introduces a _normalize_stream_id helper function that validates the provided after_id. If after_id is None, empty, or does not conform to the expected Redis stream ID format (<ms>-<seq>), it now correctly defaults to "0-0". This ensures that streaming always starts from a valid point, preventing the ResponseError and mirroring the robust behavior already present in MemoryJobStore for invalid cursors.

Fixes NURSE-SCHEDULING-3D

@codecov

codecov Bot commented Jul 25, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 76.92308% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.62%. Comparing base (1c60cc8) to head (1ffb7ab).

Files with missing lines Patch % Lines
core/nurse_scheduling/server/stores/redis.py 76.92% 3 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##              dev      #54      +/-   ##
==========================================
- Coverage   92.65%   92.62%   -0.03%     
==========================================
  Files         100      100              
  Lines        8250     8262      +12     
  Branches      705      705              
==========================================
+ Hits         7644     7653       +9     
- Misses        460      463       +3     
  Partials      146      146              
Flag Coverage Δ
core 94.11% <76.92%> (-0.04%) ⬇️
core-macos 94.13% <76.92%> (-0.04%) ⬇️
core-windows 94.11% <76.92%> (-0.04%) ⬇️
web-frontend 88.84% <ø> (ø)
web-frontend-macos 88.84% <ø> (ø)
web-frontend-windows 88.84% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
core/nurse_scheduling/server/stores/redis.py 96.56% <76.92%> (-0.61%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

0 participants