Skip to content

tower: bound redelivery when echo verification never confirms (#1573 residual) #1578

Closed

Description

@waleedkadous

Problem

#1573 (PR #1577) made mailbox delivery hold a row when the message's header never appears on the receiving terminal, so a lost message is retried instead of being falsely reported delivered. That is the right direction of error — but nothing bounds the retrying.

If a harness is systematically unverifiable, every clean-gate pass writes the same message again, forever. The agent sees the instruction re-typed once per turn, and the row never resolves.

The known way to get there: a harness rendering on the alternate screen buffer (agy boots into it) has no scrollback, so a message longer than one viewport scrolls its own header out of reach and can never be confirmed. A second, narrower path compounds it: a very long write can evict the pre-write copy from the 1000-line mirror, so the occurrence count comes back equal rather than greater and a genuine delivery reads as unconfirmed.

#1573 assumed this would be loud rather than looping, because held rows escalate. Escalation is visibility only — markEscalated sets a flag and fires an SSE event; it does not stop the drainer from re-delivering. Two CMAP reviewers flagged the gap on PR #1577 and it is recorded there as a known residual.

Suggested fix

Bound the attempts. The obvious shapes, cheapest first:

  1. An in-process attempt counter in the delivery module (a Map keyed by row id, pruned with the held set). After N unconfirmed writes, stop rewriting and leave the row held + escalated, or mark it delivered with a loud log. No schema change; lost across a Tower restart, which is acceptable for a bound.
  2. An attempts column on the mailbox table — durable, but a migration.

Either way the choice to make explicitly is what happens at the bound: stop retrying and stay held (the agent may never get the message, but nothing is spammed) versus accept and mark delivered (at most N duplicates, then today's pre-#1573 behaviour, loudly logged). The sender is not misled either way — the afx send response already reports held on the first unconfirmed attempt.

Worth measuring agy's actual behaviour first: it was not measurable during #1573 (unauthenticated in that environment), so the headline trigger is inferred from its alternate-screen boot, not observed.

Refs #1573, PR #1577.

Activity

  1. added
    area/tower
    on Sep 1, 2026
  2. added a commit that references this issue on Sep 1, 2026
  3. waleedkadous commented on Sep 2, 2026

    @waleedkadous
    ContributorAuthor

    Superseded in urgency by #1583 (field loop at multiplicity 'dozens', trigger = any immediately-responding recipient, not just agy). The bound is being fixed as a hotfix in #1584 with the zero-re-write shape (option 'accept and mark delivered, loudly' at N=1 write). This issue stays open for the smarter-verification follow-up (scrolled-header tolerance, mirror eviction on long writes, agy alternate-screen measurement).

  4. added a commit that references this issue on Sep 2, 2026
  5. waleedkadous commented on Sep 2, 2026

    @waleedkadous
    ContributorAuthor

    Residuals recorded from PR #1585 (the #1584 hotfix — zero re-writes after a completed write), from its CMAP round-2 Claude review. All three are follow-up territory for this issue, not the hotfix:

    1. Unverified-delivery notices are un-deduplicated. The hotfix adds a per-message onUnverifiedDelivery notification (a delivered row is invisible to every held-scoped surface, so the escalated flag alone reaches nobody). On a harness that never echoes — the alternate-screen-buffer case this issue already tracks — that is one notification per message. Worth a per-agent/per-episode coalescer like the owner-starvation notice's.

    2. The double verify() window would be more honest as a timeout parameter. For the live watchEchoOnScreen binding, two sequential 600 ms windows against the same pre-write sample are equivalent to one 1.2 s window; "a second look" describes the intent but not the mechanism. A verify(timeoutMs) would say what it does.

    3. dropped and preempted still hold after bytes may have reached the wire. Neither is a completed write (dropped lost bytes mid-pace to a dead socket; preempted may have been cleared or truncated by an unserialized operator write), so re-holding them stays correct under the new contract — and unlike the echo residuals they are not self-sustaining, since both require an external event to recur. Recorded as a known residual rather than a bug.

    Smarter verification (scrolled-header tolerance, agy measurement) remains this issue's core scope.

  6. added 2 commits that reference this issue on Sep 9, 2026
  7. amrmelsayed commented on Sep 9, 2026

    @amrmelsayed
    Collaborator

    Verified: the defect this issue describes is structurally impossible in current code — closing with receipts

    Verification run 2026-09-10 against main (post-#1585/#1644/#1604), per the owner's word.

    The unbounded-rewrite loop is gone by architecture, not by tuning. The loop this issue asked to bound was: write completes → echo verification can't confirm → row re-held → every clean-gate pass writes the same message again, forever. Post-#1585, a completed write is the point of no return; and the current delivery path (mailbox-delivery.ts:1236) demotes echo verification to "pure REPORTING, downstream of a delivery that is already committed" — its own comment states false means "could not confirm", never a trigger. An unverified delivery is committed, flagged (markEscalatedDelivered), surfaced once via onUnverifiedDelivery, and "NOT re-written (Issue #1584)" — verbatim from the code. There is no code path from verification failure back to a write.

    The parked #1585-CMAP residuals are addressed. Un-deduplicated unverified notices: the escalation is computed once per delivery (raced-and-unechoed escalates exactly once, per the #1473 comment block) and fires one notification per row; rows never redeliver, so there is no repeat source.

    The systematically-unverifiable-harness premise also shrank. The verification needle now matches the header or a paste placard, and #1644 writes long frames as chunked bracketed pastes (≤512B pieces) — the alt-screen taller-than-viewport case at worst yields one flagged unverified delivery, never a loop. bugfix-1567-bracketed-paste-write.test.ts: 17/17 passing locally.

    Reopen trigger, should it ever fire: any observed second write of the same mailbox row id.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/tower

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions