fix(ops): a requested stop is not a failure, and a dead NWC URI is not an error (#910)

* fix(ops): a requested stop is not a failure, and a dead NWC URI is not an error

Two loose ends from the sweep.

1. systemd recorded every deploy as a failure.
   A deploy stops the unit with SIGTERM and Next exits 143. With no
   SuccessExitStatus, systemd logged
     orangecat-app.service: Failed with result 'exit-code'
   and fired OnFailure= on every ordinary deploy.

   CORRECTION to what I reported earlier: this was NOT causing false pages.
   notify-failure.sh is recovery-aware — it waits 8s, sees the unit active
   again and logs "failed but recovered (restart/transient) — not paging".
   38 such suppressions in the last 7 days across the box. I claimed it paged
   without checking the notifier; it does not.

   It is a DIAGNOSIS bug, which is worth fixing on its own. In this unit's
   journal a routine deploy is indistinguishable from a crash: three "Failed
   with result 'exit-code'" lines in one afternoon read as a crash loop and
   cost real time to rule out while chasing an unrelated report. Telling
   systemd that a requested stop is success makes the journal mean what it
   says, and stops spawning a notifier per deploy to conclude nothing happened.

   Safe because SIGTERM here is always a requested stop — the OOM killer uses
   SIGKILL, which still counts as a failure and still pages.

   Applied to the box and verified by an actual restart: "Deactivated
   successfully", Result=success, no OnFailure, health 200.

2. A permanently undecryptable NWC URI logged at error on every resolution.
   Diagnosed on the box: the key is present and well-formed (32-byte hex,
   single unquoted line) and the ciphertext is intact (213 bytes), but GCM
   authentication fails — so it was encrypted under a DIFFERENT key. The
   plaintext is gone; this is real data loss, not a config outage.

   That is a permanent, per-wallet, OWNER-fixable state, and the product
   already handles it correctly: receiveStatus.ts flags the wallet and
   WalletCard renders "This connection can't be used by OrangeCat ... Edit it
   and paste the connection string again." So the log line is a breadcrumb,
   not an incident — but at error level, firing on every payment resolution
   and never able to self-resolve, one dead test wallet produced 21 of the 25
   error-level lines this app emitted in three days. Enough to bury a real one.

   Now warn, with the remedy in the payload. Deliberately NOT clearing the
   stored ciphertext: findUnusableConnections keys on it being non-null, so
   deleting it would remove the very signal that tells the owner to reconnect
   and leave the wallet looking merely empty.

241 payments/wallets tests pass; type-check and lint clean.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019ns25hxd1ExZsmCJz9nNhe

* fix(payments): keep the NWC note inside the file size gate

CI caught walletResolutionService at 516 lines against a 500 limit — the
explanatory comment I added pushed it over. The file sits at 496 on main, so
there were only 4 lines of headroom and I had not re-run check:sizes after
that edit.

Condensed to fit exactly, rather than adding a size exception (that list only
shrinks) or splitting a 500-line payment-resolution service as a side effect
of a log-level change. The full reasoning lives in the commit below it and in
PR #910, which is where someone asking "why warn?" will look.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019ns25hxd1ExZsmCJz9nNhe

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
CatoandClaude Opus 5 authored and GitHub committed 2026-09-07 10:40:09 +00:00
1 parent 4fda83518e
commit 817bdf6019
3 files changed
+30 -3

No files matched your search

+19
View File
@@ -19,6 +19,25 @@ EnvironmentFile=/opt/orangecat/app/.env
ExecStart=/opt/orangecat/app/launch.sh
Restart=on-failure
RestartSec=3
# A deploy stops this unit with SIGTERM, and Next exits 143. Without this,
# systemd records every ordinary deploy as
# orangecat-app.service: Failed with result 'exit-code'
# and fires OnFailure= (the notify-failure@ drop-in on the box).
#
# That is not a paging bug — notify-failure.sh is recovery-aware: it waits 8s,
# sees the unit active again, and logs "failed but recovered (restart/transient)
# — not paging". 38 such suppressions in the last 7 days across the box.
#
# It IS a diagnosis bug. Reading this unit's journal, a routine deploy is
# indistinguishable from a crash: three "Failed with result 'exit-code'" lines
# in one afternoon read as a crash loop, and cost real time to rule out
# (2026-09-07, while chasing an unrelated report). Telling systemd that a
# requested stop is a success makes the journal mean what it says, and stops
# spawning a notifier per deploy to conclude nothing happened.
#
# Safe because SIGTERM here is always a requested stop: OOM kills with SIGKILL
# (9), which still counts as a failure and still pages.
SuccessExitStatus=143 SIGTERM
StandardOutput=journal
StandardError=journal
+5 -1
View File
@@ -55,8 +55,12 @@ export async function checkNWCPaymentStatus(paymentIntent: PaymentIntent): Promi
try {
nwcUri = decrypt(wallet.nwc_connection_uri);
} catch {
logger.error('Failed to decrypt NWC URI for status check', {
// warn, not error — a permanent, owner-fixable state (the stored URI
// predates the current PAYMENT_ENCRYPTION_KEY), already disclosed on the
// owner's wallet card. See walletResolutionService for the full note.
logger.warn('NWC URI could not be decrypted for status check; treating as unpaid', {
sellerId: paymentIntent.seller_id,
remedy: 'owner must reconnect the wallet',
});
return false;
}
@@ -258,7 +258,10 @@ function pickMethodFromWallet(wallet: WalletRow): ResolvedWallet | null {
try {
return { method: 'nwc', wallet_id: wallet.id, nwc_uri: decrypt(wallet.nwc_connection_uri) };
} catch (e) {
logger.error('Failed to decrypt NWC URI', { walletId: wallet.id, error: e });
// warn, not error: permanent, per-wallet, OWNER-fixable (the key was
// rotated; plaintext is gone), and the wallet card already says to
// reconnect. At error it buried real ones — see PR #910.
logger.warn('NWC URI undecryptable; wallet skipped', { walletId: wallet.id, error: e });
// Fall through to next method
}
}
@@ -388,7 +391,8 @@ export async function resolveUserWallet(
nwc_uri: decryptedUri,
};
} catch (e) {
logger.error('Failed to decrypt NWC URI', { walletId: nwcWallet.id, error: e });
// Same owner-fixable state as pickMethodFromWallet above.
logger.warn('NWC URI undecryptable; wallet skipped', { walletId: nwcWallet.id, error: e });
// Fall through to next method
}
}