cccc icon indicating copy to clipboard operation
cccc copied to clipboard

Send-mode deliveries re-deliver forever after the actor has answered

Open chriscoveries opened this issue 3 weeks ago • 1 comments

Observed behaviour

A send-mode chat.message stays pending until its latest runtime delivery state is accepted, ambiguous, or withdrawn. When a non-native (headless) actor's submit attempt fails after the brief was already spliced into the live session, the source never reaches a terminal state: it keeps cycling through claim and retry indefinitely. Each retry hands the same brief to the session again as a fresh user message, so the actor answers the same brief a second (and third, ...) time.

The replay is produced entirely inside the daemon's delivery retry — the sender emits the brief once, and the duplicate injections come from the daemon re-offering the still-pending source.

Ledger timeline (one replayed brief)

Source event c44f4f8f189a460c804ad28826bc9700:

ts (UTC) ledger event
11-09 11:08:50 chat.message sender → recipient actor, message_mode=send
11-09 11:08:50 runtime.delivery claimed
11-09 11:28:51 runtime.delivery failed
11-09 13:03–19:05 claimed → failed cycles repeat (13:03, 18:08, 19:05)
11-10 03:00 / 03:17 claimed → failed (claim 03:00:43 → failed 03:16:51)
11-10 04:02:40 delivery submits again → brief spliced into the live session
11-10 04:09:21 recipient actor re-answers the brief
11-10 04:09:44 runtime.delivery accepted — pending state finally ends

A second send (f6e579f1a6d4, sent 11-09 21:23Z) shows the identical pattern, accepted at 04:11:19Z and 04:12:18Z, matching the actor's re-answers at 04:11Z/04:12Z.

Why the claims failed: the ACP submit could not confirm acceptance in ~20 minutes, so the state never became accepted until a later pass succeeded. Whether the text actually reached the session on the failed passes is uncertain — exactly the ambiguous case the code comments warn about ("calling it undelivered would invite a second copy").

Where it lives (v0.4.53, commit 8f5b6a79)

  • crates/cccc-daemon/src/ops/runtime_delivery.rs
    • pending_sources (~l. 404) → inbox::pending_deliveries; a send/request_reply event stays pending unless its latest delivery state is accepted, ambiguous or withdrawn (~l. 502–503). For a non-native actor (external_session_id empty), even a failed state still counts as pending (state != "failed" || actor.external_session_id.is_empty() || retryable).
    • is_stale_mail_notice (~l. 372–393) withdraws a mail notice once its underlying Mail was read, answered, or delivered. There is no equivalent for send-mode messages — a brief the actor already answered keeps re-delivering.
    • Stranded-claim settlement (~l. 199–214): claims without an outcome at restart resolve as failed/ambiguous on the next pass, then dispatch_unread re-offers everything pending.
  • crates/cccc-daemon/src/ops/actor_delivery.rs — dispatch_unread (~l. 590).
  • crates/cccc-core/src/inbox/deliveries.rs — source classification (~l. 68–72) and pending logic (~l. 182–216).

Proposed fix

Extend the stale-withdrawal safety net to send-mode deliveries, mirroring is_stale_mail_notice: before each delivery attempt (retries included), a send chat.message whose actor has since produced any later chat.message — i.e. the actor has answered — is recorded withdrawn with a stable reason and leaves the pending set for good. Reusing the existing ledger projection for reply/reference tracking keeps this a narrow change with no new persistent state.

As with the mail-notice check, a failed ledger read keeps the delivery: a redundant copy is safer than a lost one. mail and request_reply deliveries are unaffected.

Test env: observed on a Linux host running v0.4.53; the code path is unchanged in v0.4.54. A fix is in a PR that links this issue.

chriscoveries avatar Nov 11 '26 04:11 chriscoveries

Thank you. bedb4bc94 ("Stop replaying exhausted deliveries and check message arguments", v0.4.55) records an exhausted delivery as not retryable, which ends the unbounded loop described here. I confirmed the change in the v0.4.58 source and have not yet re-run the original case. If a repeat still shows up after we upgrade, I will open a new issue with a fresh capture. Closing.

chriscoveries avatar Nov 16 '26 21:11 chriscoveries