Commit 45da1d6
agent: surface ACK_FLASH_ERROR instead of returning empty bytes (#101)
## Summary
- `FlashAgentClient.read_memory()` previously broke its accumulator loop
on **any** `RSP_ACK` and returned the buffer as-is. When the agent
rejected the address — e.g. a probe outside the V3+/V4+ I/O whitelist in
`agent/main.c:addr_readable` — that meant `b\"\"` silently. Now it
inspects the ACK status byte and raises `RuntimeError(\"Read rejected by
agent: status=0x02 …; addr=… size=…\")`.
- `FlashAgentClient.crc32()` had the same shape — a clean `RSP_ACK`
rejection was reported as a generic \"CRC32 response invalid\". Now it
explicitly detects the ACK and reports the status.
- Adds the missing `ACK_FLASH_ERROR = 0x02` to
`src/defib/agent/protocol.py` (it already existed in
`agent/protocol.h`). Updates the existing membw rejection test to
reference the constant.
## Context
Surfaced while studying flash on an eMMC-based hi3516av300 over the
running agent. The eMMC controller MMIO lives at
`0x10100000..0x101FFFFF` which isn't in the agent's V3+/V4+ whitelist;
probing there silently returned `b\"\"` for ~30s of wall time across
multiple addresses, leading to wasted debugging.
## Test plan
- [x] `uv run pytest tests/ -x --ignore=tests/fuzz` — 496 passed, 2
skipped
- [x] `uv run ruff check src/defib/agent/ tests/test_agent_protocol.py`
— clean
- [x] `uv run mypy src/defib/agent/ --ignore-missing-imports` — clean
- [x] Verified on real hardware (hi3516av300, eMMC D9D16): probing
`0x10100000` now reports `Read rejected by agent: status=0x02 (outside
agent's readable whitelist or flash read failed); addr=0x10100000
size=64` instead of returning empty bytes.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: Dmitry Ilyin <widgetii@users.noreply.github.com>
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 5d90121 commit 45da1d6
3 files changed
Lines changed: 55 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
320 | 321 | | |
321 | 322 | | |
322 | 323 | | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
323 | 331 | | |
324 | 332 | | |
325 | 333 | | |
| |||
627 | 635 | | |
628 | 636 | | |
629 | 637 | | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
630 | 645 | | |
631 | 646 | | |
632 | 647 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
65 | | - | |
| 65 | + | |
66 | 66 | | |
67 | 67 | | |
| 68 | + | |
68 | 69 | | |
69 | 70 | | |
70 | 71 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
831 | 832 | | |
832 | 833 | | |
833 | 834 | | |
834 | | - | |
| 835 | + | |
835 | 836 | | |
836 | 837 | | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
0 commit comments