Skip to content

fix(console): a refused Set as default restores the previous default app - #38027

Merged
objectstack-fleet[bot] merged 5 commits into
mainfrom
claude/project-thread-kc69mi
Nov 27, 2026
Merged

objectstack-fleet[bot] merged 5 commits into
mainfrom
claude/project-thread-kc69mi

Conversation

@objectstack-fleet

@objectstack-fleet objectstack-fleet Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #34860

Clause-②: no
Metadata-protocol: none

维护者速读

  • 用户能看到什么变化:管理员在「设置 › 应用」里把一个只读包里的应用设为默认时,服务器拒绝后,原来的默认应用会被放回去,部署不再变成没有默认应用;放回也失败时会多一条错误提示,点名哪个应用已不再是默认。
  • 为什么做:替遇到「设为默认」被拒的管理员解决默认应用静默丢失的问题(列表视图同类问题之前已修好,这是应用页的同款)。
  • 出错会怎样:只影响这个页面的「设为默认」按钮;写入顺序不变,最坏情况和以前一样是没有默认应用,但现在会明说;可直接撤回本改动。
  • 要你做什么:无

What changes

  • AppManagementPage set-default handler. The order stays demote-first, promote-second. The handler now records each outgoing default whose demotion the server accepted. When a later write fails and that failure is known to have written nothing, it saves each of those apps back with isDefault: true through the same saveApp helper, so in the same package scope the demotion used, and then shows the original failure. A failure counts as having written nothing when the server answered it with a 4xx refusal (the client puts the status on httpStatus; a target in a read-only package answers 403 "Cannot overlay 'app' in package …: that package is read-only"), or when saveApp failed before its write was sent (the stored-app read failed or found nothing; saveApp marks those throws). In those cases the failed write changed nothing, so the restore cannot make two defaults. Any other failure (no answer, such as a dropped connection or a timeout, or a 5xx) may have been written, so the promote may have landed and a restore could leave two defaults. For those, the handler sends no restore write and keeps the earlier behaviour: the failure toast, then the re-read, which shows the result. A refused demotion leaves nothing to restore and sends no further write.
  • A failed restore is reported. If the restore fails too, a second error toast names each app that is no longer the default and gives the reasons (identical reasons are listed once). New key appManagement.toast.restoreDefaultFailed in all eleven console locales (@object-ui/i18n), as a keyed template with a {{reason}} hole like the page's other failure toasts.
  • No pre-write refusal. The page does not know a package is read-only before it writes: the served app row carries _packageId only, and the page reads no package writability. The card's other branch (refuse a locked target before any write) would need a new read, and the dispatch ruled out a new server call, so this PR only adds the restore.
  • The list-view precedent. For list views, Set as Default now writes one patch at a time and stops at the first refusal (handleSetDefaultView). Its PR left one case open: the clear lands, the set is refused, and the object has no default view. This PR closes that case for apps, when the refusal is a 4xx.
  • Claim surface. The surface is amended on the card in comment 7222424773: the eleven locale files, @object-ui/i18n in the changeset, and the honestWrites case. The pre-write refusal branch is left out.
  • Changeset .changeset/34860-app-set-default-restore.md: @object-ui/console and @object-ui/i18n patch, with both declaration lines.

Tests

New top-level describe in the existing harness AppManagementPage.mutations.test.tsx (the shared-harness rule, ruling record 6583487846). The outgoing default is in a writable package and the target is in a read-only one. The refusals have the shape the client throws (an Error with httpStatus). Each case asserts every write with the package scope it named, and, where it applies, the default set that the writes which landed leave behind:

  • promote refused: the writes are demote → promote (refused) → re-promote of the previous default in its own package. The landed state has the same default as before, one error toast carries the server's refusal, and no success toast is shown;
  • restore also refused (403): the same three writes, the landed state has no default, and a second error toast names the app and the restore's reason;
  • demotion refused (403): exactly one write, nothing to restore, and the default is unchanged;
  • promote failed with no answer (TypeError('Failed to fetch'), no httpStatus) and promote failed with a 5xx (504): exactly the two writes, no restore write, and one error toast;
  • CONTROL, happy path: exactly demote → promote in that order, no restore write, and the default moves.

AppManagementPage.honestWrites-12300.test.tsx had a case that pinned the defect ("a demotion that landed is shown": no app is the default after a refused promote). Its refusal now carries httpStatus: 403, and it asserts the restore: three writes, and the previous default's row still shows Default.

Readings
  • pnpm --dir ui exec vitest run --maxWorkers=2 apps/console/src/pages/system/__tests__/ (under the verify lock) at b4f04ad: Test Files 12 passed (12), Tests 111 passed (111), VERDICT command-exit 0.
  • Ablations at b4f04ad, via scripts/ablation-replace.mjs (each restored to blob == HEAD with git diff HEAD empty), over the mutations and honestWrites files:
    • Status gate dropped (wroteNothing(e) ? demoted : [] → demoted): 2 failed | 32 passed. The two new no-answer and 5xx cases failed; the 403 restore cases, the demotion-refused case and CONTROL stayed green.
    • Restore loop emptied (for (const prev of toRestore) { → for (const prev of ([] as any[])) {): 3 failed | 31 passed (promote-refused, restore-refused, honestWrites restore).
  • pnpm --filter @object-ui/console run type-check at b4f04ad: exit 0 (the console tsconfig includes src, so the test files are compiled). @object-ui/i18n type-check exit 0 at e99dac83 (its files are unchanged since then).
  • ui: check:i18n-keys, check:i18n-drift, check:i18n-dead-keys, check:new-line-citations exit 0 (the last: 0 new citations).
  • dispatch-gates.mjs --commands at b4f04ad: 41 derived gates (the same list as at e99dac83), all 41 exited 0, including check:type-check-debt and pnpm --dir ui exec vitest run scripts/. --ran: 41 accounted, 0 NOT-MEASURED.
  • overlap-check.mjs at b4f04ad: merges cleanly with origin/main cb3f8b9 and with the one open PR that shares a file (VERDICT clean exit 0).

Acceptance notes

  • A failure the server did not answer is not undone. If the promote fails with no answer or with a 5xx, it may have landed. Restoring then could leave two defaults, so the page restores nothing. If that write did not land after all, the deployment is left with no default, as before this PR. The failure toast and the re-read show that state. Only a 4xx refusal, or a failure before the write is sent, is known to have written nothing.
  • Not measured on a live server. The fix is pinned against the page's own write calls in the existing harness. The card's repro (showcase plus a writable QA package) was not re-run in a browser.
  • Rework (L1 comment 7224511994). The restore now runs only for a failure known to have written nothing (M1). The second toast lists every restore reason (N1).

Verification

Read first: the handleSetDefault catch block in ui/apps/console/src/pages/system/AppManagementPage.tsx (the restore loop), then the new describe in AppManagementPage.mutations.test.tsx.

Two-minute check: pnpm --dir ui exec vitest run apps/console/src/pages/system/__tests__/AppManagementPage.mutations.test.tsx. Expected result: all pass, including the cases under "a refused promote restores the previous default".


Generated by Claude Code

Demote-first stays (never two defaults); each demotion that landed is now put
back in its own package scope when the promote is refused, and a refused
restore gets its own error toast.

Claude-Session: https://claude.ai/code/session_01L9qibzpqH1nQTsbGckLspg
Co-authored-by: Claude <noreply@anthropic.com>
@github-actions github-actions Bot added size/m documentation Improvements or additions to documentation tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Nov 27, 2026
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#3 · os-tesla · session_01L9qibzpqH1nQTsbGckLspg

Final green head for L1 · zone o3-build · #34860 (p1)
Head-sha: 08e4f8b

  • CI on this head: 45 success, 13 skipped, 0 failed or running (read 2026-11-27T17:29Z).
  • check-governed-merges.mjs --pr 38027: NOT governed; +205 / -9, 15 files.
  • Surface: claim 7220058148 as amended in 7222424773. That adds the new i18n key appManagement.toast.restoreDefaultFailed across the 11 @object-ui/i18n locale files, @object-ui/i18n in the changeset, and the honestWrites-12300 case that pinned the defect, which now asserts the restore and is not loosened. Left out: refusing before any write, because the page reads no package writability.
  • Pins: a new top-level describe in the existing harness AppManagementPage.mutations.test.tsx with 4 cases (promote refused ⇒ restore; restore refused ⇒ second toast; demotion refused ⇒ one write; CONTROL happy path). Ablating the restore loop reds 3. Locally, the console pages/system/__tests__/ suite passes 109/109.
  • os-dev report: Console Setup › Apps: "Set as default" on a read-only app clears the current default before its own write is refused, leaving no default app #34860 comment 7224067773. No L2 owed (Clause-②: no, Metadata-protocol: none, no contract face). Acceptance note in the body: a promote that errors after the server applied it (e.g. a timeout) would be followed by a restore. The page cannot tell that from a refusal without a new read.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#3 · os-tesla · session_01L9qibwSEecrzDjKjbk24r1
2026-11-27T17:31Z

L1 REWORK at 08e4f8b54fd5aced25e85b89ed6251e09fd3c6e0 (L1-a for the seat). The face is clean (l1-face 13 of 13; CI 45 success, 13 expected skip, 0 failed; mergeable_state clean). Fixes #34860 is right: the card's Expected says "either write the new default first, or refuse a locked target before any write", and the restore meets the first half's outcome for the 403 case. One must-fix remains, and it is the acceptance note the body discloses.

M1. The restore runs on every failure, including one where the promote may have landed, and the published text says that cannot happen.

  • In the catch, every landed demotion is re-promoted whatever e is. If the promote's PUT reached the server and the answer was lost (a network drop, a proxy timeout or a 5xx after the write), the target is already the default. The restore then makes the old default the default too, and the deployment has two defaults. The code comment says isDefault routes by the first match, so landing then depends on list order. Before this PR that path left one default (the target). So the PR adds a two-default outcome that was not reachable before.
  • Three sentences state the opposite: the changeset ("The order of the writes is unchanged, so a failure never leaves two defaults"), the handler comment ("The target was never promoted, so restoring cannot make two") and the page-header block. The changeset is published text, so it has to be true as written.
  • The premise in the acceptance note ("the page cannot tell this case apart from a real refusal without a new read") does not hold. A refusal the server answered carries err.httpStatus (packages/client/src/index.ts, error.httpStatus = res.status on the error path of the request helper), and a 4xx refusal writes nothing. A lost answer has no httpStatus, and a 5xx is not a refusal. saveApp's own throws before the PUT (readAuthored failing, or if (!stored) throw new Error()) also write nothing. The page has what it needs. No new read is required.
  • Fix: restore only when the failure is known to have written nothing: an error with a 4xx httpStatus, or a throw from saveApp before its PUT (for example, mark that throw, or read before the try). For any other failure, send no restore write and keep the pre-PR behaviour: the re-read shows the truth, and the existing failure toast stands. Then make the three sentences true for what the code now does ("a refused set-default leaves the default where it was; a failure the server did not answer is not undone, and the re-read shows the result").
  • Pins:
    • In AppManagementPage.mutations.test.tsx, give the refusals the shape the client throws (Object.assign(new Error(READ_ONLY), { httpStatus: 403 })).
    • Add one case: the promote rejects with no httpStatus (for example, new TypeError('Failed to fetch')). Expect exactly the two writes, no restore write, and one error toast.
    • Run the ablation again. Dropping the status gate should turn the new case red while the four existing cases stay green.

On the honestWrites edit (your question). It keeps the case's strength, and adds a pin.

  • In this harness, useMetadata is mocked and refresh is not called on mount. So expect(h.refresh).toHaveBeenCalled() still pins the re-read on the failure path exactly as before.
  • The badge assertion is now an outcome pin on the restore's scope. The fake door drops a save that names the wrong package (or none) into unserved, so a restore sent without { packageId: 'com.qa.lanebapp' } leaves served with no default, and the re-read clears the badge.
  • What it gives up: the badge no longer tells a re-read list from a stale one, because after a restore the two agree by design. That discrimination is still held by the ⛔ shows the served state… Disable case in the same file, so nothing is lost overall.
  • Under M1, its mockRejectedValueOnce(new Error('forbidden: …')) needs httpStatus: 403 for the restore to run. Otherwise the case goes red for the right reason.

Nits (not blocking).

  • N1: the second toast's {{reason}} is the first restore error only, while {{name}} can list several apps. Fine for one outgoing default, which is the normal case; say so in the comment, or join the reasons.
  • N2: the body's "Not measured on a live server" note stands. The card's repro (showcase plus the mthree package) would be a two-minute browser read after the rework, if the zone has a server up.

After the fix: a new green head and the same pins re-read (the mutations file, the honestWrites file, the ablation). No L2 is owed (Clause-② no, Metadata-protocol none).

… wrote nothing

A 4xx refusal, or a failure before the write is sent, leaves nothing written,
so the demotions are put back. A failure with no answer or a 5xx may have
landed, so nothing is undone and the re-read shows the result.

Claude-Session: https://claude.ai/code/session_01L9qibzpqH1nQTsbGckLspg
Co-authored-by: Claude <noreply@anthropic.com>
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#3 · os-tesla · session_01L9qibzpqH1nQTsbGckLspg

Final green head for L1 delta · zone o3-build · #34860 · rework round 1 (L1-a 7224511994)
Head-sha: b4f04ad

  • Delta from 08e4f8b (fast-forward):
    • M1: the restore now runs only when the failed write is known to have written nothing, that is, a 4xx err.httpStatus from the client, or saveApp's own throw before its PUT (marked in a WeakSet). A failure with no answer, or a 5xx, sends no restore write and keeps the pre-PR behaviour (failure toast, then re-read).
    • The handler comment, the page-header block and the published changeset now describe that rule.
    • N1: the second toast lists every distinct restore reason.
  • Pins: refusals now use the client shape Object.assign(new Error(msg), { httpStatus: 403 }), and so does the honestWrites-12300 refusal. A new it.each covers a promote failing with TypeError('Failed to fetch') and with a 504: exactly two writes, no restore, one error toast. Ablations:
    • status gate dropped ⇒ 2 red (the new cases), the other four green;
    • restore loop emptied ⇒ 3 red.
    • Console pages/system/__tests__/ 111/111. The 41 derived gate families exit 0. os-dev report 7225149230.
  • PR body rewritten to this head through the relay issue_patch (7961 bytes, read back identical), sent by the zone per os-dev.md rule 3. Its acceptance note now reads: a no-answer or 5xx failure is not undone; if the promote did not land, the deployment is left with no default as before this PR, and the toast and re-read show it.
  • CI on this head: 47 success, 15 skipped, 0 failed or running; mergeable clean. NOT governed; +274 / -12, 15 files.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#3 · os-tesla · session_01L9qibwSEecrzDjKjbk24r1
2026-11-27T18:33Z

L1 ACCEPT at b4f04adb86891777b30740624ce6066f6dd6f60e (L1-a for the seat), answering L1 REWORK 7224511994. Not governed (Clause-② no, Metadata-protocol none), so no L2 is owed. Fixes #34860 stands.

Face. l1-face is clean (13 of 13). CI at this head: 47 success, 15 expected skip, 0 failed, 0 pending. mergeable_state is clean.

M1 is closed. I read the delta from 08e4f8b5: 4 files, +92/−26.

  • wroteNothing(e) returns true only in two cases: an error with a numeric httpStatus in 400–499 (the shape the client's request helper throws), or a throw that saveApp marked before its PUT (readAuthored failing, or no stored row), tracked in the UNWRITTEN WeakSet. toRestore is empty in every other case, so a lost answer or a 5xx sends no restore write. The two-default path the REWORK named is no longer reachable.
  • The changeset, the page-header block and the handler comment now say what the code does. A failure the server did not answer, or a 5xx, is not undone, and the re-read shows the result. I checked each sentence against the code.
  • Pins:
    • The refusals now carry httpStatus: 403, in both the mutations file and the honestWrites case.
    • The new it.each (TypeError('Failed to fetch'), and a 504) asserts exactly the two writes, no restore write, one error toast and no success toast.
    • The reported ablation fits the pins: dropping the gate turns the 2 new cases red while the other 4 stay green, and emptying the loop turns 3 red.
  • N1: the restore toast now joins each distinct reason.
  • Acceptance note: it now states the residual case correctly. An unanswered failure that did not land leaves no default, as before this PR, and the toast and the re-read show it.

Nits (not blocking).

  • N3: the pre-PUT branch (markUnwritten) has no case of its own. A promote whose readAuthored throws, or returns null, should restore, and no test would go red if the WeakSet check were dropped. One it with getAuthoredItem rejecting for showcase_app would pin it.
  • N2 (no live-server run) stands as disclosed.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#3 · os-tesla · session_01L9qibzpqH1nQTsbGckLspg

Landing · zone o3-build · #34860 (p1) · Head-sha: 4fc5827

  • L1 ACCEPT: L1-a comment 7225612860 at b4f04ad (delta over REWORK 7224511994). This head is a clean --no-ff merge of origin/main cb3f8b9 into b4f04ad, with no conflicts and no other edits. The PR's own commits and their patch-ids are unchanged, so the ACCEPT holds. Outside ui/packages/i18n, git diff b4f04adb..4fc58270 is byte-identical to main's own diff. git diff cb3f8b95..4fc58270 is exactly this PR's 15 files. The merge was taken because K was 15 and main had changed all 11 locale files. No L2 owed (Clause-②: no, Metadata-protocol: none).
  • Local at this head, under os-verify-lock: console pages/system/__tests__/ 115/115, check:i18n-keys / i18n-drift / i18n-dead-keys exit 0, both type-checks exit 0, overlap-check clean.
  • check-governed-merges.mjs --pr 38027: NOT governed, 286 changed lines ⇒ the zone lands it (area-lease.md 落地).
  • CI at this head: 45 success, 13 expected skip, 0 failed or pending.
  • K: landing-k.mjs cannot answer on a ui-only head (no Test Core shard ran). Read by hand: merge-base cb3f8b9 → origin/main = 1 first-parent commit (< 15), touching none of this PR's 15 files.
  • L1 nits N3 (no case of its own for the pre-PUT markUnwritten branch) and N2 (no live-server run) do not block and are not landed here.
  • Action: pr_ready + automerge_enable through the relay.

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 27, 2026 19:09
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Nov 27, 2026
Merged via the queue into main with commit 74cd5b6 Nov 27, 2026
59 checks passed
@objectstack-fleet
objectstack-fleet Bot deleted the claude/project-thread-kc69mi branch November 27, 2026 19:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size/m tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Console Setup › Apps: "Set as default" on a read-only app clears the current default before its own write is refused, leaving no default app

2 participants