Summary
flush_outbound_queue_to_relay in crates/clawdentity-core/src/runtime/relay.rs has #[allow(clippy::too_many_lines)] suppressed and handles multiple concerns inline: queue draining, payload deserialization, frame construction, WebSocket send, error recovery with re-enqueue, trusted receipt marking, and dead letter routing.
The HARNESS_ACTION_PLAN.md Phase 1 already identified this pattern as a quality issue.
Current State
The function:
- Loops up to
max_items times
- Checks relay connection state
- Takes oldest item from SQLite queue
- Deserializes JSON payload (handles malformed → dead letter)
- Constructs
ConnectorFrame::Enqueue
- Sends via
relay_sender
- On send failure: re-enqueues the item
- On success: marks trusted receipt
This is ~60 lines of mixed concerns with error handling interleaved.
Proposed Refactor
Split into:
// relay.rs
pub async fn flush_outbound_queue_to_relay(...) -> Result<FlushOutboundResult> {
// orchestration only: loop, take, delegate, aggregate
}
// relay_send.rs
fn prepare_outbound_frame(item: &OutboundQueueItem) -> Result<ConnectorFrame, OutboundPrepareError> {
// deserialize + construct frame
}
fn handle_send_failure(store: &SqliteStore, item: OutboundQueueItem) -> Result<()> {
// re-enqueue logic
}
fn handle_malformed_payload(store: &SqliteStore, item: &OutboundQueueItem, error: &serde_json::Error) -> Result<()> {
// dead letter logic
}
Files to Change
crates/clawdentity-core/src/runtime/relay.rs — extract helpers, remove #[allow(clippy::too_many_lines)]
- New file:
crates/clawdentity-core/src/runtime/relay_send.rs (or inline in relay.rs as private fns)
Acceptance Criteria
Summary
flush_outbound_queue_to_relayincrates/clawdentity-core/src/runtime/relay.rshas#[allow(clippy::too_many_lines)]suppressed and handles multiple concerns inline: queue draining, payload deserialization, frame construction, WebSocket send, error recovery with re-enqueue, trusted receipt marking, and dead letter routing.The HARNESS_ACTION_PLAN.md Phase 1 already identified this pattern as a quality issue.
Current State
The function:
max_itemstimesConnectorFrame::Enqueuerelay_senderThis is ~60 lines of mixed concerns with error handling interleaved.
Proposed Refactor
Split into:
Files to Change
crates/clawdentity-core/src/runtime/relay.rs— extract helpers, remove#[allow(clippy::too_many_lines)]crates/clawdentity-core/src/runtime/relay_send.rs(or inline in relay.rs as private fns)Acceptance Criteria
#[allow(clippy::too_many_lines)]removedclippy -D warningsclean