Repository navigation
fix(ui): show only what the server confirmed, and say when the worker is down - #623
Open
privatejoel wants to merge 2 commits into
Open
privatejoel wants to merge 2 commits into
privatejoel wants to merge 2 commits into
Conversation
… is down Plan C-5 (R-U6). Each step below reported a success that did not happen. Teams outbound: the shared send core answered a Teams row with ok: true and status 202, so the row was marked sent and nothing left. A Teams row is now failed with a not_configured reason, before the config lookup, so it never falls through to the email providers with a Teams address. The copilot confirm result carries sent and the reason, and Ask Anvil says "not sent" instead of "Done". WhatsApp: with no Twilio or Meta provider the endpoint answered ok: true. It now answers sent: false, code not_configured, with the reason. The row is stored on the whatsapp channel (it defaulted to email with a phone number as the address) and as failed, so the queued-comms reaper never picks it up. Quote email: quotes/send queued the email and the drawer said "sent". It now sends in the same request through the shared send core, as invoices/send does. The quote moves to SENT, learns customer part numbers and arms its goals only when a provider accepted the email. Otherwise the quote keeps its status (Send stays on offer), the drawer shows the reason, and the email row is marked failed, not left queued, so the reaper cannot send a stale quote later or send it twice after a retry. Alert emails: logistics and inventory alerts were queued with no recipient, so the reaper could only fail them. Recipients now come from the bell's roles through resolveInternalRecipients. When nobody resolves, no row is written and the exception records email_skipped: no_recipients. Bell: an operator's mark-read (and mark-all-read) is refused by the server's admin gate, and the error was swallowed. The refusal is now shown. Who may mark read is unchanged. Communications list: it read the audit log with a bare fetch (no session) and action names nothing writes, so it was always empty. It now reads GET /api/communications through the API client and shows each row's stored status. Sent shows only sent and replied rows. Email Triage: Promote made a blank DRAFT and Attach sent a field the orders endpoint drops, both with a success toast. No server path takes one chosen email to an order, so both are disabled with the reason on screen. Nav visibility is unchanged. Extraction watch: it now says when the background worker last ran, from cron_health through the existing public /api/health probe, and says when that run is late. The daily sweep now writes one admin bell row per tenant through notifyAdmins when cron/tick is stale. No email is sent for it. Tests (behavioural, through the handlers and screens): api-comms-send-teams, api-whatsapp-send-no-provider, api-quotes-send-status, api-alert-email-recipients, api-heartbeat-stale-bell, plus new cases in the Ask Anvil, QuoteDetailDrawer, Shell, comms, email and BackgroundExtractionWatch tests. 25 mutations, one per fix, each make a new test fail. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Alert email volume. Addressed alert emails now have a cap: a logistics
digest stamps each exception email_skipped "digested", and a new
alert-email-budget caps logistics_alert and inventory_alert emails per run
(default 10, deferred to the next run) and per tenant per day (default 30,
stamped email_skipped "daily_cap"; the bell still rings).
Quote send. The SENT update after a real send is retried once; if it
still fails the response is sent: true with a warning and a
quote_send_status_update_failed audit row, goals are not armed, and a
later send of the same quote is refused with 409 QUOTE_ALREADY_EMAILED.
The accept token of an attempt that was not sent is revoked. The drawer
shows the warning. History names quote_send_failed and the new action.
Copilot confirm marks a not-sent queued row failed (shared failUnsentRow,
also used by quote send), so the reaper cannot deliver a message the
user was told did not go.
notSentReason reports a provider that threw (sendCommunication now
returns lastError) instead of "no provider is configured".
comms_sent and the other issued counts exclude failed attempts.
bellStaleTick also rings when cron/tick has no row while cron/daily has
one ("no record of the 5-minute worker running").
Tests cover each fix, plus the three mutation gaps the review found
(margin override only after a real send, inventory To plus CC, the
stale-bell key carries the day). 21 mutations, all killed.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This was referenced Oct 20, 2026
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Several steps told the operator that something happened when the server had not done it. Line numbers are on main before this PR.
ok: truewith status 202 and sent nothing (src/api/_lib/comms-send.js:80). The copilot confirm path could reach it (src/api/copilot/confirm.js:52), and Ask Anvil said "Done".ok: true(src/api/whatsapp/send.js:121). The row defaulted to the email channel with a phone number as the address.queuedand flipped the quote to SENT, while the drawer said "Quote sent to customer" (src/api/quotes/send.js:455,:530). Queued email drains only through the agents/run reaper, so it left days late or never.src/api/_lib/logistics/notifications.js:192,src/api/_lib/inventory/notifications.js:113).src/v3-app/components/Shell.tsx:135).src/v3-app/screens/comms.tsx:84).src/v3-app/screens/email.tsx:128,:144).src/v3-app/components/BackgroundExtractionWatch.tsx:155). A stale tick wrote only aconsole.warn(src/api/_lib/heartbeat-check.js:97).Why
docs/SO_EXECUTION_COHESION.md, plan PR C-5, recommendation R-U6 ("Show only what the server confirmed"). When a screen reports a success that did not happen, people re-check every step by hand. C-5 is one of the decision-free Phase 0 PRs.How
Commit 1 (
0ca8299c, the build):sendViaChatfails a Teams row withnot_configuredbefore the config lookup, so the row never falls through to email. Copilot confirm returnssentplussend_error(newnotSentReason). Ask Anvil says "Draft saved, but the message was not sent: reason".ok: false,sent: falseand codenot_configuredorprovider_error. The row haschannel: "whatsapp"and is storedfailed, so the email reaper never takes it.sendCommunication, asinvoices/senddoes. The quote moves to SENT, learns customer parts and arms its goals only when a provider accepted the email. Otherwise the quote keeps its status and the row isfailed, not queued. The drawer says "sent" only onsent: true.alertRecipientsForRoles(_lib/internal-recipients.js) goes throughresolveInternalRecipients. Recipients are the bell's audience: the rule'sescalate_rolesfor logistics, and admin for inventory. To is the first address and CC is the rest. Recipients are resolved once per run. When nobody resolves, the dispatcher writes no row and stampsemail_skipped: "no_recipients".notifyWarn.AnvilBackend.communications.list(GET/api/communications) and shows each row's stored status. It does not use thecomm_draftandcomm_sendaudit names:comm_sendis also written for failed sends.cron_healthrows that the public/api/healthprobe already returns, and says when the run is late. The newbellStaleTick, called fromcron/daily, writes one admin bell row per tenant whencron/tickis stale.Commit 2 (
80f9435e, the review fixes):email_atwithemail_skipped: "digested". New_lib/alert-email-budget.jscaps thelogistics_alertandinventory_alertemails. The per-run cap defaults to 10, and an email past it waits for the next run. The per-day cap defaults to 30 per tenant, counted from today's rows of that template. An exception past it is stampedemail_skipped: "daily_cap"; its bell still rings and the screen still lists it. Env overrides:LOGISTICS_MAX_ALERT_EMAILS_PER_RUN/_PER_DAYandINVENTORY_MAX_ALERT_EMAILS_PER_RUN/_PER_DAY.sent: truewith awarning, writes aquote_send_status_update_failedaudit row, and does not arm goals. A guard at the top refuses a later send of the same quote with 409QUOTE_ALREADY_EMAILEDwhen asentorrepliedquote_emailrow already exists. The drawer shows the warning next to the success.queuedthat Ask Anvil reported as not sent is now markedfailedwithnot_sent_reason, so the reaper cannot deliver it later. The shared helperfailUnsentRowincomms-send.jsis used by quote send too. If that update fails, the message says the row is still queued and may be sent later.sendCommunicationnow returnslastError.notSentReasonreports a provider that threw (for example an Outlook token refresh) as "The send failed: ...", and no longer says "No provider is configured".revoked_at), andportal_urlis null in the response.quote_send_failed"Send failed" (bad) andquote_send_status_update_failed"Sent, status not updated" (warn).isIssuedin_lib/metrics/catalog.jsnow excludesfailed, so a failed attempt followed by a successful retry counts once. Failed rows still count incomms_delivery_rate.bellStaleTickalso rings whencron_healthhas nocron/tickrow but has acron/dailyrow. The wording is "There is no record of the 5-minute worker (cron/tick) running". When thecron/dailyrow is missing too, it does not ring, because nothing is recording heartbeats.Behaviour change for review: when no mail provider is configured, a quote now stays DRAFT, as invoice send already does. Before, it became SENT with an email that never left.
No migrations. No new
requireActionnames.Tests
New or extended (all behavioural: they call the handler or the function through the existing in-memory mocks):
src/v3-app/api-comms-send-teams.test.js. A Teams row is failed withnot_configuredand is never emailed. Copilot confirm returnssent: falsefor Teams and for email with no provider, and the row isfailedwithnot_sent_reason, with nothing left queued. Confirm returnssent: truewhen a provider accepts.src/v3-app/api-whatsapp-send-no-provider.test.js. No provider returnsnot_configured, with channel whatsapp and status failed. A refusal returnsprovider_error. An accepted send returnssent: true.src/v3-app/api-quotes-send-status.test.jssent: truewith a warning, then 409 on a retry with no second email.src/v3-app/api-alert-email-recipients.test.jsescalate_roles.daily_capand counts only this tenant's rows of this template.src/v3-app/api-heartbeat-stale-bell.test.js(through thecron/dailyhandler)src/v3-app/api-metric-catalog.test.js.comms_sentexcludes failed attempts. New: a failed quote email plus its retry counts as one, and still shows in the delivery rate.src/v3-app/components/QuoteDetailDrawer.test.tsx.sent: falseshows "Quote not sent: reason" with no success.sent: truetoasts sent. New: awarningis shown withnotifyWarn.src/v3-app/components/QuoteHistoryTab.test.tsx. New: "Send failed" (bad) and "Sent, status not updated" (warn).src/v3-app/components/Shell.test.tsx,screens/ask-anvil.test.tsx,screens/comms.test.tsx,screens/email.test.tsx,components/BackgroundExtractionWatch.test.tsx. These cover the bell refusal, the not-sent copilot message, the list read and the status tabs, the disabled triage actions, and the worker-last-ran line, including the late wording.Mutation checks. Each check broke the fix, saw a named test fail, and restored the file byte for byte.
ok: true; Teams falls through to email; confirm alwayssent: true.sentis forced; the row is left queued;sendCommunicationis skipped; the drawer ignoressent.cron/dailyskips the bell; the bell rings for any stale worker.email_skipped.notSentReasonignoreslastError.isIssuedcounts failed rows again.cc_addrs.lastErroris not returned.Gates
On head
80f9435e, with local Node 25.8.1 and npm 11.11.0.npm ciran from the existing lockfile, and the lockfile is unchanged.npm run check: pass. This includes tsc and the cold import ofapi/dispatch.js.npm run lint: 0 errors and 511 warnings, the same count as before the review fixes.npm run build: pass. Build output is not committed.npm run verify: pass.docs/RBAC_AUDIT.mdanddocs/WRITE_PATH_AUDIT.mdwere reverted after the run.npm run eval:golden: pass, with an average score of 1.000.NODE_OPTIONS=--no-experimental-webstorage npx vitest run: 624 of 624 files and 7313 of 7313 tests passed. The known flake did not fire.Main has moved since the branch was cut (C-4 #612 and docs). The branch was not rebased.
Left out
Declined review findings:
src/v3-app/lib/nav-settings.ts, Admin > Navigation). A default "hidden for pilot roles" is the pilot nav preset that plan PR C-8 builds (nav-visibility.pilot-preset.test.ts). The user-facing defect, a false success, is fixed here: Promote and Attach are disabled and the screen says why. An admin can hide the item today through Admin > Navigation. For that reason the plan'semail-triage.hidden.test.tsxis not in this PR.screens/email.test.tsxcovers the disabled actions instead.Deferred items:
logistics_monitor_enabledorinventory_planning_enabledis switched on: the C-8 lane-readiness card should check the alert email caps and the backlog size (review 1). The caps here bound the volume. They do not decide whether a backlog of wrong criticals should exist.src/api/invoices/send.js) still leaves a not-sent invoice emailqueuedwhen no provider is configured. If the operator retries after a provider is set up, the reaper could send it twice. The fix is onefailUnsentRowcall, but the change is outside the C-5 list.cron/dailyis the only path that Vercel guarantees. As instructed, no email is sent for it. The plan's "emails admins" part is not built.QUOTE_ALREADY_EMAILEDdoes not heal the status. After a double SENT failure, the operator marks the quote SENT through the status transition. That path does not savepayload_hash.portal/accept_quoteneeds only SENT and records a null hash.route-deadlinksand column-drift CI gates are not in this PR.🤖 Generated with Claude Code