Skip to content

Fix: Add explicit error signalling to read() instead of silent default fallback (#390)#462

Merged
pradeeban merged 1 commit intoControlCore-Project:devfrom
GaneshPatil7517:fix/read-error-status
Mar 1, 2026
Merged

Fix: Add explicit error signalling to read() instead of silent default fallback (#390)#462
pradeeban merged 1 commit intoControlCore-Project:devfrom
GaneshPatil7517:fix/read-error-status

Conversation

@GaneshPatil7517
Copy link

@GaneshPatil7517 GaneshPatil7517 commented Feb 24, 2026

hello @pradeeban Sir

Problem

read() silently returned default values on all failure paths (file not found,
parse error, empty file, timeout, retry exhaustion, ZMQ failure), with no mechanism
for downstream nodes to detect whether they received real data or stale fallback values.
This is a safety concern in neuromodulation control loops.

Solution

read() now returns (data, success_flag) on every code path:

  • True → real data was successfully received
  • False → fallback/default value was used

Additionally, concore.last_read_status (and concore_base.last_read_status) is
set after each read to one of:
SUCCESS, FILE_NOT_FOUND, TIMEOUT, PARSE_ERROR, EMPTY_DATA, RETRIES_EXCEEDED

Example usage

val, ok = concore.read(1, "ym", init)
if not ok:
    print(f"Warning: stale data (status={concore.last_read_status})")

Backward Compatibility

Legacy callers can adapt with:
result = concore.read(...)
if isinstance(result, tuple):
    value, ok = result
else:
    value, ok = result, True

Files Changed

  • concore_base.py - Core read() implementation updated with status tracking and (data, flag) returns
  • concore.py - Wrapper updated; last_read_status exposed on module
  • concoredocker.py - Wrapper updated; last_read_status exposed on module
  • tests/test_read_status.py -15 new tests covering success, file-not-found, parse error, retries exceeded, ZMQ timeout, ZMQ error, and backward compatibility
  • test_concore.py -Updated existing roundtrip test for tuple return
  • test_concoredocker.py - Updated existing read tests for tuple return

Impact
Improves reliability and safety of control loops by allowing controllers to detect invalid reads.

read() now returns (data, success_flag) tuple and sets
concore.last_read_status / concore_base.last_read_status to one of:
SUCCESS, FILE_NOT_FOUND, TIMEOUT, PARSE_ERROR, EMPTY_DATA,
RETRIES_EXCEEDED.

- concore_base.read(): all return paths now yield (data, bool)
- concore.py: exposes last_read_status, syncs from concore_base
- concoredocker.py: same treatment
- Existing tests updated for tuple returns
- New test_read_status.py covers success, file-not-found, parse
  error, retries exceeded, ZMQ success/timeout/error, backward
  compatibility, and last_read_status exposure.

Backward compatible: callers can use isinstance(result, tuple) or
simply unpack with value, ok = concore.read(...).
@pradeeban pradeeban merged commit c083a97 into ControlCore-Project:dev Mar 1, 2026
6 checks passed
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.

2 participants