agent: surface ACK_FLASH_ERROR instead of returning empty bytes#101
Merged
Conversation
`FlashAgentClient.read_memory` previously broke its accumulator loop on any RSP_ACK and returned whatever the buffer held — `b""` when the agent rejected the address (e.g. a probe outside the V3+/V4+ I/O whitelist in `agent/main.c:addr_readable`). Callers couldn't tell a successful empty read from a rejection. Same shape in `FlashAgentClient.crc32`, where a clean RSP_ACK rejection was reported as a generic "CRC32 response invalid". Now both inspect the ACK status byte and raise a RuntimeError naming the status, the address, and the size — surfaced while probing eMMC controller MMIO at 0x10100000 on hi3516av300 returned empty bytes silently for ~30s. Also adds the missing `ACK_FLASH_ERROR = 0x02` to the Python protocol constants (already in agent/protocol.h) and updates the existing membw rejection test to use the constant instead of the 0x02 literal. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
FlashAgentClient.read_memory()previously broke its accumulator loop on anyRSP_ACKand returned the buffer as-is. When the agent rejected the address — e.g. a probe outside the V3+/V4+ I/O whitelist inagent/main.c:addr_readable— that meantb\"\"silently. Now it inspects the ACK status byte and raisesRuntimeError(\"Read rejected by agent: status=0x02 …; addr=… size=…\").FlashAgentClient.crc32()had the same shape — a cleanRSP_ACKrejection was reported as a generic "CRC32 response invalid". Now it explicitly detects the ACK and reports the status.ACK_FLASH_ERROR = 0x02tosrc/defib/agent/protocol.py(it already existed inagent/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..0x101FFFFFwhich isn't in the agent's V3+/V4+ whitelist; probing there silently returnedb\"\"for ~30s of wall time across multiple addresses, leading to wasted debugging.Test plan
uv run pytest tests/ -x --ignore=tests/fuzz— 496 passed, 2 skippeduv run ruff check src/defib/agent/ tests/test_agent_protocol.py— cleanuv run mypy src/defib/agent/ --ignore-missing-imports— clean0x10100000now reportsRead rejected by agent: status=0x02 (outside agent's readable whitelist or flash read failed); addr=0x10100000 size=64instead of returning empty bytes.🤖 Generated with Claude Code