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

fix: surface failed subscription saves and keep the typed price (#12962) (#13083)

[._.]/7862c11ac71e
diff --git a/client/src/components/models/SubscriptionsTab.jsx b/client/src/components/models/SubscriptionsTab.jsx
index 4b6c5c699e..bdae4e9f32 100644
--- a/client/src/components/models/SubscriptionsTab.jsx
+++ b/client/src/components/models/SubscriptionsTab.jsx
@@ -253,12 +253,20 @@ export default function SubscriptionsTab() {
// One row saves at a time — each row's own controls are disabled while it is
// in flight, so a single slot says everything a set would.
+ // try/finally: a throw from the inner callback must not leave the row stuck
+ // busy with its controls disabled.
const withBusy = async (family, fn) => {
setBusyFamily(family);
- await fn();
- setBusyFamily(null);
+ try {
+ await fn();
+ } finally {
+ setBusyFamily(null);
+ }
};
+ // The failed request is toasted once by `request()` (no `silent`, since this
+ // catch adds no toast of its own), and the draft stays so the typed value
+ // survives for a retry.
const onSave = (row, patch) => withBusy(row.family, async () => {
// One request for both maps, and its response IS the refreshed row set —
// no follow-up GET. Only a PRICE moves the savings figures, so a tier-only
@@ -266,8 +274,9 @@ export default function SubscriptionsTab() {
const body = {};
if (patch.cost !== undefined) body.costs = { [row.family]: patch.cost };
if (patch.tier !== undefined) body.tiers = { [row.family]: patch.tier };
- const result = await api.updateSubscriptions(body, { silent: true }).catch(() => null);
- if (result?.families) setRows(result.families);
+ const result = await api.updateSubscriptions(body).catch(() => null);
+ if (!result?.families) return;
+ setRows(result.families);
if (patch.cost !== undefined) await loadSavings();
// Cleared only after the new rows land: dropping the draft first would
// flash the pre-save value back onto the row in between.
@@ -281,7 +290,6 @@ export default function SubscriptionsTab() {
const onToggle = (row) => withBusy(row.family, async () => {
const result = await api.setSubscriptionEnabled(
{ family: row.family, enabled: !row.enabled },
- { silent: true },
).catch(() => null);
if (!result?.families) return;
// The handler's own re-read, not a local patch: enablement is DERIVED from
diff --git a/client/src/components/models/SubscriptionsTab.test.jsx b/client/src/components/models/SubscriptionsTab.test.jsx
index 26437ed3d3..60fe2ce83d 100644
--- a/client/src/components/models/SubscriptionsTab.test.jsx
+++ b/client/src/components/models/SubscriptionsTab.test.jsx
@@ -143,7 +143,6 @@ describe('SubscriptionsTab', () => {
fireEvent.click(screen.getByLabelText('Enable the Codex subscription'));
await waitFor(() => expect(api.setSubscriptionEnabled).toHaveBeenCalledWith(
{ family: 'codex', enabled: true },
- expect.anything(),
));
// The handler's own rows are applied, so no follow-up GET is needed to
// learn the state it just computed.
@@ -173,7 +172,6 @@ describe('SubscriptionsTab', () => {
fireEvent.click(screen.getByRole('button', { name: 'Save the Claude Code plan' }));
await waitFor(() => expect(api.updateSubscriptions).toHaveBeenCalledWith(
{ costs: { claude: 100 }, tiers: { claude: 'Max 20x' } },
- expect.anything(),
));
expect(api.updateSubscriptions).toHaveBeenCalledTimes(1);
});
@@ -213,6 +211,31 @@ describe('SubscriptionsTab', () => {
expect(screen.getByLabelText('Enable the Grok subscription')).toBeDisabled();
});
+ // A failed save must keep the typed price on screen so the user can retry;
+ // clearing the draft unconditionally is what made the value silently revert.
+ it('keeps the typed price when the save is rejected', async () => {
+ api.updateSubscriptions.mockRejectedValue(new Error('server error'));
+ renderTab();
+ await screen.findByText('Claude Code');
+ fireEvent.change(screen.getByLabelText('Monthly cost for Claude Code'), { target: { value: '100' } });
+ fireEvent.click(screen.getByRole('button', { name: 'Save the Claude Code plan' }));
+ await waitFor(() => expect(api.updateSubscriptions).toHaveBeenCalled());
+ await act(async () => {});
+ expect(screen.getByLabelText('Monthly cost for Claude Code')).toHaveValue(100);
+ });
+
+ // The switch is controlled by the server's rows, so a rejected toggle must
+ // leave it on the stored state rather than flipping it optimistically.
+ it('leaves the switch on the server state when the toggle is rejected', async () => {
+ api.setSubscriptionEnabled.mockRejectedValue(new Error('server error'));
+ renderTab();
+ await screen.findByText('Codex');
+ fireEvent.click(screen.getByLabelText('Enable the Codex subscription'));
+ await waitFor(() => expect(api.setSubscriptionEnabled).toHaveBeenCalled());
+ await act(async () => {});
+ expect(screen.getByLabelText('Enable the Codex subscription')).toHaveAttribute('aria-checked', 'false');
+ });
+
it('says so when there is nothing to manage', async () => {
api.getSubscriptions.mockResolvedValue({ families: [], costs: {}, tiers: {} });
renderTab();