refactor(mothership): one re-queue policy and one send payload, and keep a Stop-failed send waiting for the user

Merged
WA
13d ago
+328-245

Summary

Second step of the chat send-queue consolidation (after #8738): one re-queue policy, one payload type, and the G3 fix.

  • One withdrawal reason. A send handed back to its caller now carries reason: 'withdrawn' | 'offline' | 'unreachable' | 'busy' | 'stop-failed', instead of five mutually exclusive booleans (unreachable, heldUntilOnline, busy, held, and the implied plain withdrawal).
  • One re-queue policy. A pure requeuedFields(reason, previousAttempts, chatlessSurface) in the new send-queue-policy.ts decides when, and on which surface, a re-queued message goes out. Both re-queue sites (sendMessage after a failed direct send, and the queue dispatch's restore) use it. A send that failed outright, with no withdrawal, is failed and waits for the user.
  • G3 fixed. The restore spread the dispatched entry back with whatever hold, retry and surface fields an earlier outcome had set. A message held for the network that the user then sent by hand over a running turn, whose Stop did not settle, came back waiting for the user but still marked heldUntilOnline. The browser coming online then released and sent it. The restore now strips those fields (withoutRequeueFields) before applying the policy for this outcome.
  • One payload type. SendPayload (content, attachments, contexts, mode, search settings) replaces the positional parameters of createQueuedMessage and sendMothershipMessage and about ten hand-spread copies. sendPayload() is the one place that drops the fields a send doesn't set. QueuedMessage extends it. Callers of sendMothershipMessage outside chat (log details, terminal, workflow block, search modal, console store) pass an object now.
  • Comment fix: the head re-queue comment now notes the one exception: a held send adopted from a dead mount while the POST was out can be older.

Type of Change

  • Bug fix
  • Improvement (refactor)

Testing

  • keeps a Send-now whose Stop failed waiting for the user when the browser comes online (DOM) fails on staging and passes here.
  • send-queue-policy.test.ts unit-tests the policy for each reason, the field stripping, and the payload normalizer.
  • The existing chat suites pass unchanged. The full gate and integration tests ran on the CI runner.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)