Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

stop an early "Check delivery" click from disarming the send it was checking

[._.]/ Adam Eivy79dee6afcb51
diff --git a/server/services/beeperOutbox.js b/server/services/beeperOutbox.js
index d8ba7c80f0..56f0567b00 100644
--- a/server/services/beeperOutbox.js
+++ b/server/services/beeperOutbox.js
@@ -644,10 +644,17 @@ function releasePending(id) {
* `DELETE` unsends for everyone. It stays `awaiting-confirmation` with a
* recorded reason, which reads as "sent, unconfirmed" and offers no re-send.
*/
-async function resolveConfirmation(id, reason) {
+async function resolveConfirmation(id, reason, { terminal = false } = {}) {
const pending = pendingConfirmations.get(id);
if (!pending || localTransitions.has(id)) return null;
- if (reason === 'fallback-timeout' || reason === 'manual') pending.deadlineReached = true;
+ // A `manual` probe is terminal ONLY when the caller armed the row itself —
+ // a row stranded across a restart, whose real deadline elapsed long ago. When
+ // a live timer is already counting down, the send is seconds old and the user
+ // simply pressed "Check delivery" early: a null lookup there means "not yet",
+ // not "never". Treating it as the deadline would record a false 30s verdict
+ // AND release the pending entry, disarming the timer and the socket listener
+ // that were about to confirm it.
+ if (reason === 'fallback-timeout' || (reason === 'manual' && terminal)) pending.deadlineReached = true;
// The one-shot timer can fire during a socket lookup. Let that lookup own
// the deadline outcome rather than dropping the only fallback signal.
if (pending.resolving) return null;
@@ -757,7 +764,11 @@ async function reconcileEntry(id) {
}
const uncertainFailure = entry.state === 'failed' && [SEND_INTERRUPTED_CODE, DELIVERY_UNCONFIRMED_CODE, 'NETWORK_ERROR'].includes(entry.errorCode);
if (!['sending', 'awaiting-confirmation'].includes(entry.state) && !uncertainFailure) return entry;
- if (!pendingConfirmations.has(id)) {
+ // Armed here means the row had no live in-process timer — it was stranded by
+ // a restart, so its real deadline is long past and this lookup is its last
+ // word. A row that already had one is still inside its 30s window.
+ const stranded = !pendingConfirmations.has(id);
+ if (stranded) {
const unknown = entry.state === 'sending' || uncertainFailure || entry.errorCode === DELIVERY_UNCONFIRMED_CODE;
const requestedAt = persistedSendMoment(entry);
if (entry.state !== 'awaiting-confirmation') {
@@ -765,7 +776,7 @@ async function reconcileEntry(id) {
}
armConfirmation({ ...entry, requestedAt, deliveryOutcomeUnknown: unknown });
}
- await resolveConfirmation(id, 'manual');
+ await resolveConfirmation(id, 'manual', { terminal: stranded });
return recoveryView(await readEntry(id));
}
diff --git a/server/services/beeperOutbox.test.js b/server/services/beeperOutbox.test.js
index 1476c210ea..9135b1cd28 100644
--- a/server/services/beeperOutbox.test.js
+++ b/server/services/beeperOutbox.test.js
@@ -979,6 +979,31 @@ describe('local persistence recovery without another send', () => {
expect(sendMessage).toHaveBeenCalledTimes(1);
});
+ it('leaves the live confirmation armed when a human checks delivery early', async () => {
+ // "Check delivery" is offered the instant a row reaches awaiting-confirmation,
+ // so a user can press it seconds into the 30s window. A lookup that finds
+ // nothing THERE means "not propagated yet", not "deadline reached": recording
+ // the unresolved verdict would also release the pending entry, disarming the
+ // timer and socket listener that were about to confirm the send.
+ const entry = await createOutboxEntry({ conversationId: CONVERSATION_ID, body: 'hello there' });
+ await sendOutboxEntry(entry.id, { confirmFirstContact: true });
+ // Nothing has propagated yet: both lookups miss.
+ getMessage.mockRejectedValue(new BeeperApiError('not found', { status: 404, code: 'NOT_FOUND' }));
+ listMessagesPage.mockResolvedValue({ items: [] });
+
+ await reconcileOutboxEntry(entry.id);
+ expect(outbox.get(entry.id)).toMatchObject({ state: 'awaiting-confirmation', errorCode: null });
+ expect(getOutboxStatus().awaitingConfirmation).toBe(1);
+
+ // The message lands; the still-armed fallback confirms it.
+ getMessage.mockResolvedValue(sentMessage());
+ listMessagesPage.mockResolvedValue({ items: [sentMessage()] });
+ clock.runTimersWithDelay(CONFIRMATION_TIMEOUT_MS);
+ await flush();
+ expect(outbox.get(entry.id)).toMatchObject({ state: 'sent' });
+ expect(sendMessage).toHaveBeenCalledTimes(1);
+ });
+
it('manually reconciles a durable stranded sending row with lookup only', async () => {
const entry = await createOutboxEntry({ conversationId: CONVERSATION_ID, body: 'hello there' });
outbox.get(entry.id).state = 'sending';