This repository was archived by the owner on Nov 4, 2026. It is now read-only.
Repository navigation
fix(app-shell): Studio rails converge on an AI copilot apply without a page reload - #7376
Merged
Merged
Conversation
…a page reload The Studio copilot is the right dock of the SAME document as the workbench (ADR-0057 P3c) and `ChatPane` already announces every authoring turn on the assistant bus (`emitMetadataRefresh` — the pulse `usePendingDrafts` and `MetadataProvider` converge on). The four pillar rails never subscribed, so a just-applied object and its new `app.navigation` entry stayed invisible until the author reloaded the whole page. `useMetadataRefreshNonce` turns that pulse into a load dependency the rails can list beside `publishNonce` / `draftNonce`. Each refetch is exactly the package-scoped read that went stale — no polling, no remount, no reload. The Interfaces pillar HOLDS the pulse while the nav editor has unsaved or in-flight edits: its load rehydrates `appDraft`, which IS the nav edit buffer, so an unheld pulse would overwrite the author mid-drag. The hold defers rather than drops — autosave clears `navDirty` and the pulse lands then. That pillar also stops flapping `appStatus` back through `loading` on a re-read of the same package, which had blinked the nav toolbar once per copilot turn.
Contributor
✅ Console Performance Budget
The eager closure is every chunk the entry reaches through static imports — what the browser fetches and parses before the app renders. The entry chunk on its own is a small fraction of it. 📦 Bundle Size Report
Size Limits
|
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Fixes #7255
The bug
The Studio copilot is the RIGHT DOCK of the same document as the workbench (ADR-0057 P3c). When a copilot turn applied a new object and pushed a nav item into the app's
navigation, the tenant registry had both — the objectactive, the item present insys_metadata— and the workbench's left rail still showed the pre-apply tree. Only a full page reload surfaced it.The channel was already there.
ChatPaneannounces every authoring turn on the assistant bus (emitMetadataRefresh()—AiChatPage.tsx, both the "turn carried an authoring envelope" effect and the chat-card publish handler). What was missing was a subscriber: the four Studio pillar rails keyed their loads onpublishNonce/draftNonceonly, both of which are bumped by the workbench's OWN publish / draft-save buttons and by nothing the copilot does.The refresh channel, and why this one
The card requires a production-available channel and forbids a global poll. Of the three sanctioned options — same-page event, tool-result callback, existing query invalidation — this PR takes the existing invalidation mechanism, which happens to also be the same-page event:
/api/v1/dev/metadata-events, the dev-only SSE stream 生产姿态下 console 持续轮询 GET /api/v1/dev/metadata-events → 404,浏览器控制台被刷红 #7257 taught to stop retrying once it 404s in production posture — that stream watches metadata FILES on the server's disk and has no production equivalent, which is exactly why that card shipped no replacement and named this bug as needing its own fix.draftReview/replayOutcome) — an ordinary Q&A turn emits nothing. Each subscriber then re-reads exactly its own package-scoped queries (list('app', { packageId }),list('object', { packageId }),listDrafts({ packageId, type })). There is no timer anywhere in this diff.usePendingDraftsstates it in writing: "every successful publish path callsemitMetadataRefresh()— that pulse, plus this hook, is the whole unification mechanism."MetadataProvidersubscribes for the same reason. The rails were the outlier.A packageId payload on the pulse was considered and deliberately not added. It would only pay off when Studio is open on package A while a pulse concerns package B — but the Studio dock's copilot is always scoped to the open package (
editPackageId={packageId}), and the only cross-package producers (marketplace install, the full-page/aiconsole route) are not mounted alongside a Studio pillar. That is a declaration surface with no measured pull, against six call sites that could silently drift back to coarse. Contract-first cuts the other way here: the pulse is a producer-side fact ("the live registry changed"), and widening it to carry scope belongs in a card that has a consumer asking for the scope.The change
useMetadataRefreshNonce(hold?)turns the pulse into a load dependency the rails list besidepublishNonce/draftNonce. Wired into all four pillars — Interfaces (nav tree + the nav inspector's object picker), Data (objects rail), Automations (flows rail), Access (permission-set rail). The card's acceptance is the nav rail; the other three are the same one-line subscription against the same producer, and leaving them out would reproduce this exact bug on the next object / flow / permission set an author asks the copilot for.Two things the naive version gets wrong, both handled:
appDraft, which IS what the nav editor patches. An unheld pulse would overwrite an author mid-drag. The hook therefore takeshold— passed asnavDirty || !!navSaving— and defers rather than drops: the nonce advances the moment the hold lifts, so the rail still converges once autosave settles. Several pulses during one hold release as one refetch.appStatusback to'loading'on every run. With the pulse added, the nav toolbar (gated on'ready') would have blinked once per copilot turn. It now only shows loading when the package identity actually changed; a re-read of the same package refreshes in place. Rail selection was already preserved (setCurrent((cur) => cur ?? …)), and nothing here bumps akey=.Out of scope, filed instead: the missing icon
Requirement 2 of the card ("AI-generated nav items have no icon") is a producer defect, filed as objectstack-ai/cloud#1858 with no assignee. Both objectui consumers already have a default-icon convention —
resolveIconfalls back toFileTextin the runtime sidebar, and the StudioNavTreefalls back node icon → the object's own metadata icon → a type-generic glyph — so this is not "no icon renders", it is "a generic glyph next to two semantic ones". Picking a meaningful icon needs to know what the table is FOR, which only the blueprint / apply chain has; guessing from the label in the renderer would fossilize a second de-facto contract (Commandment #0.1). Not touched here.Verification
Ran at
c8534ddce(the final commit).Targeted tests —
pnpm exec vitest run packages/app-shell/src/views/studio-design/ packages/app-shell/src/assistant/→Test Files 48 passed (48) / Tests 257 passed (257). The wider first pass includingpackages/app-shell/src/preview/wasTest Files 60 passed (60) / Tests 353 passed (353).New coverage:
StudioDesignSurface.aiApplyRefresh.test.tsx— the card's scenario against a mutable server world: the Interfaces rail grows跟进记录and the Data rail grows the new object afteremitMetadataRefresh(), in the SAME mounted tree (the pre-existing entries are asserted to survive, so a remount-based "fix" would not pass).useMetadataRefreshNonce.test.tsx— the hold semantics, which no pillar test can see: pulses during a hold are deferred and coalesced, not dropped.Reverse verification (ablation). Committed first, then stripped
metadataRefreshNoncefrom the two dep arrays under test. Mutation confirmed on disk before measuring, not by an editor exit code: themetadataRefreshNonce]occurrence count went 5 → 2 and the file hash movedb2522f25→ba30689f. Predicted direction was RED, and that is what happened — both acceptance tests failed (Tests 2 failed | 3 passed), while the three hook unit tests stayed green, which is the correct split: they measure the adapter, not the wiring. No rebuild leg is claimed or needed — the test imports./StudioDesignSurfaceas a sibling source module, so the mutated bytes ARE what ran. Restore wasgit checkout HEAD -- <path>under an EXIT/INT/TERM trap with an absolute repo root, and is proven by state, not exit code:git diff HEADempty, working tree clean, on-disk hash back tob2522f25d375f1b7b3fc08309c3acd133a66e0c2= the HEAD blob, occurrence count back to 5. The suites above were then re-run on the restored tree.Type-check —
pnpm --filter @object-ui/app-shell type-check→ exit 0, after building the dependency closure (pnpm --filter '@object-ui/app-shell^...' build, exit 0); without it the run was 20+ phantomTS2307 Cannot find module '@object-ui/*'. Both new test files are genuinely covered rather than excluded:tsc -p tsconfig.test.json --listFilesnames them, and the first run actually caught a real widening error in the nav fixture.Lint — full repo
pnpm lint(eslint . --no-inline-config), not a narrowed run:Tasks: 47 successful, 47 total/Cached: 0 cached, 47 total,0 errors(2877 pre-existingno-explicit-anywarnings, none in this diff).Gates, each read from its own verdict line with the exit code captured before any pipe:
check:control-bytes—OK (scanned 6075 tracked text file(s); skipped 85 binary)check:i18n-keys— every in-scope call-site key resolves against the en pack; no new keys addedcheck:i18n-drift—0 en value(s) changedin this rangecheck:vi-mock-specifiers/check:vi-mock-inherit— OK (this diff addsvi.mockcall sites, so both apply)check:self-import,check:phantom-deps,check:side-effects-array,check:entry-guard,check:icon-record-names— OKcheck-changeset-presence—1 source file(s) of 1 released package(s) changed, and this change declares 1 changeset(s);check-changeset-no-major— OK (minor)check:eager-closure— NOT MEASURED locally: it needsapps/console/dist/eager-closure.json, which a local run has no build for; it reports itself as a broken gauge rather than a verdict. CI has the artifact.packages/i18nand the marketplace surfaces are untouched; the file surface is disjoint from #7372 and #7371.Generated by Claude Code