Skip to content

Show the refusal of a database that requires an unsupported extension in the app (ADR-083 §2) - #3427

Merged
mstomar125 merged 5 commits into
mainfrom
issue-3413-refusal-view
Oct 1, 2026
Merged

mstomar125 merged 5 commits into
mainfrom
issue-3413-refusal-view

Conversation

@mstomar125

@mstomar125 mstomar125 commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Closes #3413

Slice S7 of #3413, the last one: the app's refusal view for a database that requires an extension core doesn't support (ADR-081 step 3, ADR-083 §2). It consumes the app-lib contract from S6 (#3426, merged).

Most of the change is TypeScript and Svelte. At the coordinator's request, one small Rust commit makes the app-lib token-stream retry loop stop probing a refused database (see "Token-stream retry loop" below). The branch is rebased onto main at 33ed106.

How the refusal reaches the view

S6's contract: a command routed to a refused database rejects with CommandError { code: 'REQUIRES_EXTENSION', requiresExtension: { unsupportedExtensions, message, downloadLabel, downloadUrl } }. list_databases marks the database requires_extension, but carries no text.

  • Why the store reads the database itself. The data stores swallow their own load errors. The sidebar's boot-time loads also go to the daemon default before routing is set. A central error hook therefore couldn't tell which database a REQUIRES_EXTENSION belonged to, and could mark the wrong one refused.
  • The read. The database store reads the database itself, with one cheap routed read: list_conflicts with limit: 1, the cheapest routed read that goes through status_to_command_error. get_stale_root_count would not do: it maps Unimplemented to 0 without touching the database.
  • A database the listing marks requires_extension is read after set_active_database and before the selection commits, under the same switch-sequence guards as the rest of load() and switchTo(). The refusal commits with the selection, so the workspace never mounts against it.
  • Any other database commits at once, as before. checkSelectedDatabase then reads it and records a refusal if one comes back (a listing older than the database file). A switch to a database that opens therefore never waits for its open; that wait would widen the window in which routing points at the new database while the old workspace is still editable.
  • databaseStore.activeRefusal is the payload, keyed to the active id. A check result for a database that is no longer selected is dropped.
  • Recovery. A listing that marks the selected database requires_extension, with no refusal recorded, reads it again. This covers a read that failed for another reason. It is skipped while a switch is in flight.
  • A payload the guard rejects leaves the workspace showing, and readRefusal logs a warning.
  • A refused activation:
    • It evicts the previous database's caches.
    • It still calls onDatabaseActivated at the same point, so hook timing and the 2.0 API are unchanged.
    • It reloads nothing.
    • The next switch or create replaces the refusal; both go through switchTo, which evicts and reloads.

Changes to existing behaviour

  • load() and switchTo() send one more command, list_conflicts with limit 1:
    • after pin_window_database for a database the listing does not mark;
    • between set_active_database and pin_window_database for one it marks refused.
    • The two tests that pin the command sequence are updated.
  • evictAndReloadActiveDatabase splits into evictDatabaseCaches and reloadDatabaseStores. The calls are the same, and each store's invalidation still precedes its load.
  • app-shell shows the view in place of the sidebar and panes. The app-shell-overlay slot stays mounted, so slot mount semantics are unchanged. While the database is refused:
    • the startup conflicts notice waits for the first database that opens;
    • the indexing-queue poll pauses (otherwise it logs an error every 5 s).
  • A refused database the user picks is remembered like any other selection, so the next launch shows the refusal again. This matches the tray, which keeps the entry selectable.
  • Settings → Databases shows a requires_extension row as "Needs an extension this app doesn't support" instead of "Unknown". The listing has no ids or text, so the row can't name the extension.

Token-stream retry loop (Rust, app-lib/src/commands/local_agent.rs)

The loop re-subscribed to the daemon's token stream every 2s after any failure. While the active database is refused, that meant probing forever and logging a warning each time.

  • What changes behaviour: only a status that nodespace_proto::requires_extension::unsupported_extensions recognises as the refusal. The task then waits for the active database to switch, or the shared channel to be rebuilt (subscribe_active_database), and resubscribes at once.
  • What doesn't: every other outcome keeps the 2s retry exactly.
  • Structure:
    • resubscribe_forever runs the loop. It takes the active-database receiver before each attempt, so a change during the attempt is not missed.
    • wait_to_resubscribe holds the wait decision. It falls back to the delay if the client is gone, so it never spins.
  • Tests (paused clock), each mutation-checked:
    • after a refusal, the loop resubscribes once the active database changes and not before;
    • a change during the refused attempt is not missed;
    • any other failure retries every 2s, with exactly 11 attempts in 20s;
    • the wait decision on its own, the client-gone fallback, and the classifier.

Acceptance (quoted from the slice) and where each is met

  1. App: "This database needs NodeSpace Pro" for pro, or "This database needs an extension this app doesn't support (‹id›)" otherwise. It shows a "Download NodeSpace Pro" link, a compile-time constant pointing at https://nodespace.ai until a direct link exists, and actions to switch to another registered database or create a new one. No contact link. It never offers to move or modify the file.
    • database-requires-extension.svelte renders payload.message as its heading. S6's extension_names renders both sentences.
    • Its download button is labelled payload.downloadLabel and opens payload.downloadUrl through openUrl. Both come from S6's constants, pinned by the_download_link_is_pinned.
    • Switching lists the other registered databases, leaving out any the listing marks refused. New database… opens the existing create flow (DatabaseNameDialog, then create and switchTo).
    • Tests show there is no contact link and no move, rename, reset, remove or start-fresh action.
  2. bun run test:changed passes, and the merge gate passes. Core's first release can be cut after this lands.
    • test:changed passed on the frontend and Chromium tiers; Rust, skill and scripts were skipped for a frontend-only diff. The merge gate is the coordinator's.
  3. ADR: render message, label and URL from the payload, so no TS source or test contains the product name or https://nodespace.ai.
    • git grep -nP 'NodeSpace Pro|https://nodespace\.ai' -- packages/desktop-app/src returns 0. The fixtures use "Fixture App" and https://example.test/….
  4. ADR: add RequiresExtensionCommandError (extends CommandError; code 'REQUIRES_EXTENSION'; requiresExtension payload) and its type guard in a NEW module, e.g. src/lib/types/requires-extension.ts, following VersionConflictCommandError's pattern. Do NOT edit src/lib/extension-api/*, plugins/ui-extensions.ts, plugins/ui-extensions.svelte.ts, or the DatabaseInfo / CommandError declarations: S4's 2.0 must stay the only version bump.
    • Added in src/lib/types/requires-extension.ts. The guard accepts only a well-formed payload: string ids, string message and label, and an https download URL.
    • git diff origin/main --stat over the extension API and ui-extensions files is empty. DatabaseInfo and CommandError are untouched.

Other #3413 items, delivered by earlier slices

Tests

Test File
A payload for an id with a display name, and one for an unknown id, both render their message and label verbatim (neutral fixtures) tests/components/database-requires-extension.test.ts
Download calls openUrl with payload.downloadUrl same
Switch calls databaseStore.switchTo with another registered id; neither the refused database nor another listed-refused one is offered same
Create opens the existing create dialog, then create + switchTo same
No mailto or contact link, and no move, rename, reset, remove or start-fresh action same
A store error is shown same
A REQUIRES_EXTENSION on the first read marks the restored database refused, evicts the boot-time loads and reloads nothing tests/stores/database.test.ts
A registry default refused at startup is marked refused; another error records no refusal same
Switching to a refused database records the refusal and loads nothing; switching to, or creating, a database that opens clears it same
A listing marks the selected database refused → read once; not while a switch is in flight; a read a switch overtook is discarded same
A tray switch landing during load()'s read wins; a superseded switch's read is discarded; the refusal belongs to its own id same
A switch to a database the listing does not mark doesn't wait for its open; its refusal is recorded after the commit, from load() and from switchTo() same
A refused activation still fires onDatabaseActivated once, after eviction, from load() and from switchTo() same
A malformed REQUIRES_EXTENSION payload records no refusal and warns same
AppShell shows the view instead of the workspace: on a refused first read, and for a registry default refused at startup tests/components/app-shell-database-refusal.test.ts
AppShell goes back to the workspace after a switch to a database that opens; shows no view for a database that opens same
While refused, AppShell holds the conflicts notice and pauses the poll same
The type guard accepts only a well-formed payload tests/types/requires-extension.test.ts
The settings row marker tests/components/settings/database-settings.test.ts

Rust mutation check. I applied 7 single-point mutations to the token-stream loop. All 7 were killed: the classifier forced true and forced false, resuming only after the delay, no client-gone fallback, every error waiting for a change, the loop ignoring the decision, and the receiver taken after the attempt.

TypeScript mutation check. I applied 45 single-point mutations, one at a time, each run against its test file. All 45 were killed. They covered:

  • every guard condition;
  • the view's message, label, URL, filters, switch, create and error display, and the absence of contact and move actions;
  • every store branch and race guard, including reading before the commit for every database, both post-commit checks, the warning, and hook gating;
  • the app-shell swap and both pauses;
  • the row marker.

Verify

  • git grep -nP 'NodeSpace Pro|https://nodespace\.ai' -- packages/desktop-app/src → 0
  • git grep -nP mailto -- packages/desktop-app/src/lib/components/database-requires-extension.svelte → 0
  • git diff origin/main --stat over lib/extension-api, plugins/ui-extensions.ts and plugins/ui-extensions.svelte.ts → empty
  • bun run --cwd packages/desktop-app test src/tests/extension-api → 46 passed (the snapshot is still 2.0, unchanged)
  • The new and changed test files → 98 passed
  • bun run scripts/check-pro-boundary.ts (the hard ban from Remove the multi-user skill guidance and make the Pro-boundary check a hard ban #3420) → passes, every marker 0
  • cargo clippy -p nodespace-app-lib --all-targets -- -D warnings is clean, and cargo fmt --check is clean.
  • local_agent tests → 7 passed
  • bun run test:changed on the final head (6a6af77) passed: frontend 88 s, scripts 23 s, Chromium 3 s, Rust workspace nextest 50 s.

Ratchet

No marker hit anywhere on the branch. It is rebased onto main at 33ed106, which includes #3420's hard ban and #3426's allowlisted display-name module.

Review

  • Pragmatic review: APPROVE, with 2 🟡, 4 🟢 and 2 nits.
  • Round-1 address-review: all 🟡 and 🟢 findings are addressed; both nits were skipped, with reasons. The details are in the PR comments.
  • Round 2: APPROVE, with two nits. One is addressed. The other was skipped, because it is practically unreachable.
  • Round 3 (the Rust commit): APPROVE, with one log-format nit, addressed in 6a6af77. It also raised an out-of-scope follow-up: the node watcher's capped 30 s backoff could also wait on db_changed after the refusal.
  • No re-review is needed.

Still needed before the release

  • A real-device smoke run of a refused database. Agents can't run it. Register a database whose settings node lists required_extensions: ["pro"], then launch the app. Check:
    • the message and the download button (it should open the website);
    • switching to another database;
    • creating a new one;
    • the Databases row marker.
  • app-shell.svelte and database-settings.svelte were already not Prettier-clean on main. I left them as they were.

DB reset: none for this slice. S6 requires one.

🤖 Generated with Claude Code

@mstomar125

Copy link
Copy Markdown
Contributor Author

Pragmatic code review: PR #3427 (S7, refusal view)

Review Type: Initial Review (medium depth). Head e0dcb30f. I read it against the slice spec, issue #3413 (the App bullet and the Gate), S6's contract on origin/issue-3413-requires-extension-guard, and ADR-081/082/083/084 on nodespace-docs origin/main.

What I ran:

  • The 5 new and changed test files: 92/92 pass.
  • quality:design-tokens: no new violations.
  • scripts/check-pro-boundary.ts: passes.
  • The slice's VERIFY greps (NodeSpace Pro|https://nodespace\.ai, mailto in the view, the diff over extension-api, ui-extensions and types/errors.ts): all return 0.

Contract check against S6:

  • set_active_database only rebuilds the routed clients and never fails, so the store reaches its refusal read.
  • list_conflicts goes through status_to_command_error, and its ListConflictsInput is camelCase {status, kind, limit}, which matches the call.
  • The serialized payload is {message, code: "REQUIRES_EXTENSION", details, requiresExtension: {unsupportedExtensions, message, downloadLabel, downloadUrl}}. That is exactly what isRequiresExtension accepts, and DOWNLOAD_URL is https, so it passes the guard.

Requirements Check

ACCEPTANCE

# Item Status Notes
1 App: message for pro or ‹id›, the "Download …" link from a compile-time constant, switch to another database or create one, no contact link, never move or modify the file ✅ The heading, button label and URL all come from the payload, and S6's extension_names renders both sentences and the constant. Switch lists the other registered databases and leaves out those the listing marks refused. Create reuses DatabaseNameDialog, then create, then switchTo. There is no mailto, contact, move, rename, reset or remove action.
2 bun run test:changed and the merge gate pass ✅ / ⏳ The author reports test:changed green, and the files I ran pass. The merge gate waits on the post-S6 rebase. The PR is correctly a draft until then.
3 Message, label and URL rendered from the payload; no TS source or test contains the product name or the URL ✅ The grep returns 0. Fixtures use "Fixture App" and https://example.test/…. The 'pro' id in one fixture is an extension id, not the product name, and the ratchet passes.
4 RequiresExtensionCommandError and its guard in a new module; no edits to extension-api, ui-extensions*, DatabaseInfo or CommandError ✅ Added in src/lib/types/requires-extension.ts on the VersionConflictCommandError pattern. The protected files have an empty diff, so 2.0 is still the only version bump.

TESTS

Bullet Status Notes
A pro-style payload and an unknown-id payload render the message verbatim (neutral fixtures) ✅ it.each over both payloads, checking the heading text and the button label.
Download calls openUrl with payload.downloadUrl ✅
Switch calls switchTo with another id; create opens the existing create flow ✅ Also checks that neither the refused database nor another listed-refused one is offered.
No mailto or contact link, no move, rename, reset or move-aside action ✅ Opens the create dialog too, so the dialog's buttons are covered.
Store: REQUIRES_EXTENSION on the first load marks the database refused and app-shell shows the view; a registry default refused at startup shows it too; switching to a database that opens clears it ✅ Covered in both stores/database.test.ts and app-shell-database-refusal.test.ts.
The type guard accepts only a well-formed payload ✅ Covers every field and the non-https schemes, including mailto: and javascript:.

OWNED FILES / DO NOT TOUCH: ✅. The diff is TS and Svelte only. It doesn't touch Rust, extension-api, ui-extensions*, labs-settings or check-pro-boundary.ts. The view has no mailto.


On the questions I was asked to scrutinise

1. The store reads the database itself instead of catching REQUIRES_EXTENSION centrally. The reasoning is sound.

  • The sidebar's boot-time loads go to the daemon default before routing is set, and every data store swallows its own errors. A central hook would therefore attribute a refusal to whichever database is selected when the error lands, which can be the wrong one.
  • A dedicated read sent right after set_active_database, under the same switchSeq guard, is attributable.
  • I traced every await the PR adds:
    • load() re-checks superseded() after the read.
    • switchTo() re-checks seq after the read.
    • recheckActiveDatabase() returns early while a switch is in flight, and drops a result that a newer switchSeq or a changed activeDatabaseId overtook.
  • activeRefusal is keyed on databaseId === activeDatabaseId, so a stale record can't be shown for another database. remove() setting activeDatabaseId = null also yields null.
  • The only remaining way for the payload to describe a different database is Tauri running two concurrent set_active_database invokes out of order. That race predates this PR and applies to all routing.
  • The refusal clears on every committed selection, because both load() and switchTo() reassign refusal alongside activeDatabaseId.
  • The approach has one cost on the normal path, which I raise in finding 1.

2. The evictDatabaseCaches / reloadDatabaseStores split.

  • No ordering dependency breaks. Each store is still invalidated before it loads.
  • The only reorder is that collectionsState.reset() now runs before loadCollections(), and that is harmless: it resets UI selection state, not the data store.
  • onDatabaseActivated still fires after the commit and the eviction on both paths, in commit order, which meets ADR-082's lifecycle timing. No test pins this on the refused path, though (finding 2).

3. app-shell.svelte.

  • The normal path is unchanged: the {:else} branch is the old markup, re-indented.
  • app-shell-overlay and app-shell-modal stay mounted. ChromeSlot and ReplaceableSlot declare only these two plus collaboration.entry, which lives inside the Settings tab, so no slot's mount semantics change.
  • The sidebar remounts after leaving the refusal, and its onMount re-runs databaseStore.load() and the four store loads. Those duplicate reloadDatabaseStores' loads against the same database. That is harmless, and it happens only after a switch has fully settled (the commit through finally runs synchronously after the last await).
  • The conflicts-notice gate and the poll pause are both correct and both tested.

4. The view.

  • Strings are rendered as text, with no {@html}.
  • It uses semantic tokens throughout, and <section aria-labelledby> points at the h1.
  • The aria-label="Open {name}" includes its visible text "Open", so it passes WCAG 2.5.3.
  • The error shows in role="alert".

5. The type guard. Accepting only https is right. It is stricter than openUrl, which also allows http: and mailto:, so a drifted payload can never turn the download button into a contact link.

6. Tests. They are well isolated and test what they claim. The routed-daemon fake (daemon(...)) is a good way to model attribution. Two gaps are noted below.


Code Review Findings

🟡 1. Every activation now waits for the target database to open before the selection commits

📁 packages/desktop-app/src/lib/stores/database.svelte.ts:237-240, 454-459

await invoke('set_active_database', { id });
if (seq !== this.switchSeq) return;
const refusal = await this.readRefusal();   // first routed request → waits on get_or_open
if (seq !== this.switchSeq) return;
this.activeDatabaseId = id;

Before this PR, the commit followed set_active_database directly. That command only rebuilds the routed clients, with no daemon round trip to the database. Now the commit waits on a routed read, and for a closed database that read includes the daemon's whole get_or_open: the guard probe, the WAL switch, the schema DDL, seeding and NodeService init.

This has two effects on the normal path, where nearly every switch lands:

  • The switcher and the tray pick give no feedback until the open completes. Neither the view's Open buttons nor the switcher show a busy state.
  • The window in which routing already points at the target, while the previous database's workspace is still mounted and editable, grows from one IPC hop to the open time. Edits typed in that window can be routed to the target database. That hazard already exists through the 500 ms save debounce, but this PR widens it.

The PR body lists "one more command" under its changes to existing behaviour, but not that the commit now blocks on the open.

Recommendation (not blocking): one of the following.

  • Gate the read on the listing. S6's list() already probes closed databases and reports requires_extension, and the view already trusts that status for its "Open" filter. Send readRefusal() only when the target's listing entry is requires_extension, to fetch the payload. load() has a listing fetched moments before. switchTo() can use this.databases, and the existing recheckActiveDatabase covers a stale entry.
  • Or keep the current design, and record the blocking-on-open trade-off in the PR body and in the readRefusal doc comment.

Principle: KISS/YAGNI on the hot path. Don't charge every switch for a rare case when a signal you already have can tell the cases apart.

🟡 2. No test pins onDatabaseActivated on a refused activation

📁 packages/desktop-app/src/tests/stores/database.test.ts:933+ (the refusal describe), and the lifecycle tests at :684-857

The PR states that a refused activation still calls onDatabaseActivated at the same point. ADR-082 §8 lists lifecycle timing as part of the versioned API. However:

  • The lifecycle tests only cover databases that open.
  • The refusal tests never assert the hook.

So the mutation if (refusal === null) notifyDatabaseActivated(id) survives in both load() and switchTo().

Recommendation: in the refusal describe, register the fixture lifecycle extension as the lifecycle block does. Then assert that the hook fires once with the refused id, after the commit and after clearAll, for both the load() path and the switchTo() path.

Principle: a versioned contract needs a test that fails when the contract changes.

🟢 3. readRefusal swallows every other error silently, including a malformed REQUIRES_EXTENSION

📁 packages/desktop-app/src/lib/stores/database.svelte.ts:289-296

} catch (err) {
  return isRequiresExtension(err) ? err.requiresExtension : null;
}

Suppose S6's wire shape drifts, for example by renaming a field. The guard then rejects the error, the refused database is committed as an open one, and the user gets a workspace where every read fails. recheckActiveDatabase uses the same guard, so it never recovers. Nothing is logged, which makes this hard to diagnose from a bug report.

Recommendation: when code === 'REQUIRES_EXTENSION' but the guard rejects the error, log.warn it. Log any other error at log.debug.

Principle: fail visibly at a trust boundary.

🟢 4. Recovery only runs on a later load(), so it waits for Settings → Databases

📁 packages/desktop-app/src/lib/stores/database.svelte.ts:262-267, 306-313

After boot, load() runs only when Settings → Databases mounts or on a registry mutation. The sidebar's onMount is the initial load. If the first read fails transiently on a database that the just-fetched listing already marks requires_extension, the user stays in a broken workspace until they open Settings.

Recommendation: in the initial branch, when the listing marks resolved as requires_extension and the read returned null, call recheckActiveDatabase() right after the commit. Or state the limitation in the doc comment.

🟢 5. "Evict" leaves the previous database's lists in place on a refused activation

📁 packages/desktop-app/src/lib/stores/database.svelte.ts:498-545

schemasData, savedQueriesData and aiChatsData.invalidateForDatabaseSwitch() only bump a generation, and collectionsData keeps its list. They rely on the reload to replace the list wholesale, as ai-chats.svelte.ts:181-183 says. On a refused activation there is no reload, so the previous database's collections, schemas, saved queries, chats and schema-plugin registrations stay in the stores while the refused id is active.

Nothing visible reads them today: the sidebar and panes are unmounted, and the host API only exposes reload(). But the doc comment "Evict every per-database cache" overstates what it does.

Recommendation: reset those lists on the refused path, or reword the comment so a future reader of these stores (for example an overlay contribution) isn't misled.

🟢 6. Each of the recheck's two post-read guards is individually untested

📁 packages/desktop-app/src/tests/stores/database.test.ts:1122

In "discards a listing re-read that a switch overtook", the switch has already committed b when the read returns. Both seq !== this.switchSeq and this.activeDatabaseId !== id are therefore true, and deleting either one alone still passes.

Recommendation: add a case where a switch has started but not committed when the read resolves: activeDatabaseId unchanged, switchSeq bumped. That pins the seq guard, which is the one that matters there.

🟢 Nits

  • Nit: createDatabase and the DatabaseNameDialog props in database-requires-extension.svelte:47-52, 118-126 copy database-settings.svelte's create flow verbatim. That is fine at this size; extract it if a third caller appears.
  • Nit: while the database is refused, the app menu's Settings… adds a settings tab that PaneManager isn't mounted to show, so it silently does nothing. The next switch's clearAllTabs() then drops that tab. This is acceptable for a gate screen; a one-line comment near the {#if activeRefusal} branch would save the next reader a puzzle.

Recommendation: APPROVE

This is a clean, well-scoped slice that does what it should:

  • It meets all four acceptance items and every TESTS bullet.
  • It keeps the 2.0 extension surface untouched.
  • It respects the product-name boundary.
  • Its attribution design is correct under every race I traced.

None of the findings blocks the merge. I'd fold 🟡2, the lifecycle-hook test, into the post-S6 rebase, since it is cheap and pins a versioned contract. I'd also make a deliberate call on 🟡1: either gate the read on the listing or document the trade-off. The real-device smoke run the PR lists is still needed before the release.

@mstomar125 mstomar125 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated pragmatic-code-review: APPROVE (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above.

@mstomar125
mstomar125 force-pushed the issue-3413-refusal-view branch from e0dcb30 to 9ecc3bf Compare October 1, 2026 11:50
@mstomar125

Copy link
Copy Markdown
Contributor Author

Address review (round 1)

The fixes are in commit 9ecc3bf. The branch is also rebased onto main at 1534f76, which carries the hard ban from #3420.

Addressed

  • 🟡 1: switches waited for the target to open. Fixed in database.svelte.ts.
    • A database the listing marks requires_extension is still read before its selection commits. The read supplies the refusal's text, and while it waits, any stray write to that database is refused anyway.
    • Any other database now commits at once. checkSelectedDatabase reads it right after the commit and records a refusal if one comes back. This covers a listing older than the database file, so the "error on the first data load" case still shows the view.
    • The new test does not hold a switch to a database the listing does not mark until it opens fails if the read is made blocking again.
  • 🟡 2: the hook timing was untested. Two tests now pin it:
    • load() restoring a refused database still fires the hook once, after the caches are evicted;
    • switchTo a refused database still fires the hook once, after clearAll and before clearAllTabs.
    • Gating either call on the refusal fails them (mutations L1 and L2).
  • 🟢 3: no log when a payload is malformed. readRefusal now warns when a REQUIRES_EXTENSION error carries a payload the guard rejects. Tested with a mailto: download URL.
  • 🟢 4: recovery depended on a later load(). The post-commit check covers it, and the listing recheck stays as a second path.
  • 🟢 5: the eviction doc overstated what is evicted. evictDatabaseCaches now says that the sidebar stores' lists stay until reloadDatabaseStores runs. It also says why a refused database doesn't need that reload.
  • 🟢 6: the guard test couldn't tell the two conditions apart. checkSelectedDatabase now has one guard: drop the result unless the database is still selected. The seq check was redundant, because the read is sent while routing points at id, so its result always describes id. drops a refusal read for a database that is no longer selected kills the guard's removal (mutation S11).

Skipped

  • Nit: the create flow duplicates database-settings.svelte. It is three lines. Sharing them would mean editing the settings page beyond the row marker this slice owns. Worth folding into a store method if a third caller appears.
  • Nit: the Settings menu does nothing while the database is refused. This is by design: the refusal view replaces the workspace and offers the two actions ADR-083 §2 names. Opening Settings over a refused database could be a follow-up if a real-device run shows users reaching for it.

Checks

  • Mutation check: 45 single-point mutations, each run against its test file. All 45 were killed; 9 of them are new for this round.
  • bun run test:changed passed on the frontend tier (89 s) and the Chromium tier.
  • bun run scripts/check-pro-boundary.ts passes the hard ban with every marker at 0.
  • quality:fix is clean.

Re-review decision

RE-REVIEW NEEDED. The selection flow in load() and switchTo() changed its logic.

@mstomar125

Copy link
Copy Markdown
Contributor Author

Pragmatic code re-review: PR #3427 (S7, refusal view)

Review Type: Re-Review (medium depth). Only the round-1 fix commit 9ecc3bf4 is in scope.

Base: the branch is rebased onto main @ 1534f761, which carries the #3420 hard ban. git range-diff confirms that 6bdfed72 is round-1's e0dcb30f with no content change (1: e0dcb30f = 1: 6bdfed72).

What I ran on head 9ecc3bf4:

  • The 5 PR test files: 98/98 pass, including 65/65 in stores/database.test.ts.
  • stores/database.test.ts and app-shell-database-refusal.test.ts re-run 3×: 71/71 every time, no flakes.
  • eslint on the two changed files: clean.
  • check-pro-boundary.ts: "No Pro marker in core (ADR-081 section 8 hard ban)."

S6 contract: I re-checked it on S6's current head 5188f78e. The RequiresExtensionPayload shape (camelCase), the requires_extension status string, and list_conflicts → status_to_command_error are all unchanged.


Previous Review Summary

Round 1 had 8 items: 2 🟡, 4 🟢 and 2 nits. Status now: 6 addressed (both 🟡 and all four 🟢) and 2 nits skipped, with reasons I accept.

Round-1 item Status Notes
🟡1 Every switch waited for the target database to open ✅ Addressed See the explanation after this table. The PR body's "Changes to existing behaviour" section is updated to match.
🟡2 No test of onDatabaseActivated on a refused activation ✅ Addressed Two lifecycle tests now cover the load() path and the switchTo() path. Each asserts the hook fires once, with the refused id, after the commit (activeAtHook) and after clearAll. The switchTo test also asserts it fires before clearAllTabs. Gating either call on the refusal now fails.
🟢3 readRefusal swallowed a malformed REQUIRES_EXTENSION silently ✅ Addressed A log.warn now fires when code === 'REQUIRES_EXTENSION' but the guard rejects the payload, tested with a mailto: download URL. A log.debug for other errors was optional and isn't added. That's fine.
🟢4 Recovery waited for a later load() ✅ Addressed The check after the commit gives a second attempt right away, and the listing re-check stays as a third.
🟢5 The evictDatabaseCaches doc said it evicted more than it does ✅ Addressed The doc now says the sidebar stores' lists stay until reloadDatabaseStores runs, and why a refused database doesn't need that reload. It is accurate.
🟢6 Each of the re-check's two guards was untested on its own ✅ Addressed The re-check now has one guard (activeDatabaseId !== id), and drops a refusal read for a database that is no longer selected pins it. I confirm below that the dropped seq guard was redundant.
Nit: the create flow duplicates database-settings.svelte Skipped, accepted Sharing it would mean editing the settings page beyond the row marker this slice owns.
Nit: the Settings menu does nothing while the database is refused Skipped, accepted By design: the refusal view is a gate offering the two actions ADR-083 §2 names.

How 🟡1 is fixed:

  • A database the listing marks requires_extension is still read before its selection commits, which it needs for the refusal's text.
  • Any other database commits at once and is checked afterwards (checkSelectedDatabase).
  • does not hold a switch to a database the listing does not mark until it opens pins this. Its read never resolves, and it races the switch against a 200 ms timer.

On the points raised for this round

1. Does routing point at id when the read after the commit is sent, and is the single guard enough?

Yes, given the same assumption all frontend routing already makes: Tauri handles set_active_database calls in the order they are sent. Taking each path in turn:

  • switchTo: void this.checkSelectedDatabase(id) runs synchronously in the tail after the last await (set_active_database), and readRefusal calls invoke before its first await. So the read goes out in the same macrotask as the commit.
    • A switch that started earlier has a lower seq. If it got past its seq check, it sent set_active_database before this switch bumped seq, which is before this switch's own send.
    • A switch that starts later can only send after its flushAllPendingSaves await, which is after this read went out.
  • load(): the same holds. A switch that starts during the await makes superseded() true, and load() returns before the commit. One that was already in flight is excluded by the switchesInFlight > 0 check before set_active_database.
  • The listing re-check:
    • switchesInFlight === 0 is evaluated synchronously right after the list_databases await, and the read is sent in the same tick, so there is no gap.
    • With no switch in flight and the initial branch excluded (activeDatabaseId !== null), routing points at the last committed selection.
    • One state escapes this. A switch is superseded after its set_active_database, and the switch that superseded it then fails before sending its own. That leaves routing and the selection out of step, but it predates this PR, and the old seq capture wouldn't have caught it either: seq doesn't change during the re-check.
  • The result: the read always describes id. A database's refusal doesn't flip between reads, so a refusal recorded for id is never wrong, and the only stale case is "no longer selected", which the remaining guard drops.

2. Switch A's check resolving after switch B started but before B commits.

This is acceptable. The result describes A, because it was sent while routing pointed at A, and A really is refused. So the store records a true fact about the database still selected. B's commit then reassigns refusal, the same way any other commit replaces it.

The visible effect is that the refusal view can appear for A while B is in flight, if B is pre-read because the listing marks it refused. The view then gives way to B's own outcome. No test covers exactly this interleaving. I don't think one is needed, because both halves are each pinned: the "no longer selected" drop and "the commit reassigns refusal".

3. The warn branch and the doc. Both are correct. See the nit below for one small tidy-up.

4. Are the new tests brittle? No.

  • The 200 ms race: it is deterministic. With the mocks, switchTo only chains microtasks (flushAllPendingSaves and invoke both resolve immediately, and b is registered, so refreshDatabaseList never runs). Microtasks always drain before any timer callback, however loaded the machine is. Under the mutation, switchTo never settles and the timer wins. The never-resolving read left behind on the unmutated path is harmless.
  • The checks via vi.waitFor: these have bounded polls, with the default 1 s timeout.
  • logWarn: it is cleared by the existing vi.clearAllMocks() in beforeEach, so not.toHaveBeenCalled can't pick up an earlier test's warning. I ran the file 3× with identical results.
  • Command order: the sequence tests assert the read as the last command for an unmarked database, and between routing and pin for a marked one. Both are deterministic, because the read goes out synchronously before switchTo and load() return.

Code Review Findings (new in this round)

🟢 Nit: one condition in the warn branch

📁 packages/desktop-app/src/lib/stores/database.svelte.ts (readRefusal's catch)

if (typeof err === 'object' && err !== null && 'code' in err) {
  if (err.code === 'REQUIRES_EXTENSION') {

Nit: the two nested ifs can be one condition. It is purely cosmetic.

🟢 Nit: a database that is refused but not marked in the listing loses the startup conflicts notice

📁 packages/desktop-app/src/lib/components/layout/app-shell.svelte (the conflicts-notice $effect), together with the check after the commit

When the restored database is refused but the listing doesn't mark it, the selection commits with activeRefusal === null. The startup conflicts effect then fires at once and sets conflictsNoticeStarted before the check after the commit records the refusal. A later switch to a database that opens therefore never shows the one-time nudge. The workspace also flashes before the refusal view replaces it.

This is practically unreachable: at boot the listing was fetched moments before, and S6's list() probes closed databases with the same guard the open runs. I note it only so the trade-off is on record. No change needed.


Recommendation: APPROVE

Every round-1 finding is addressed, and the redesign is a clear improvement:

  • A database that opens never waits for its open.
  • A database the listing marks refused still never mounts the workspace.
  • The single guard is sound for the reasons above.

The tests pin the new behaviour without timing fragility.

Still outstanding before merge and release, as before:

@mstomar125 mstomar125 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated pragmatic-code-review (re-review): APPROVE (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above.

@mstomar125
mstomar125 force-pushed the issue-3413-refusal-view branch from 9ecc3bf to 661bcf4 Compare October 1, 2026 12:04
@mstomar125

Copy link
Copy Markdown
Contributor Author

Address review (round 2)

The branch is rebased onto main at 33ed106, which includes #3426.

Re-review nits

  • 🟢 One condition in the warn branch: addressed in 5ce1dc5, a single condition.
  • 🟢 The startup conflicts notice is lost for a refused database the listing didn't mark: skipped, as the reviewer suggested. At boot the listing is fetched moments before, and list() probes closed databases with the same guard the open runs, so this is practically unreachable.

No logic changed in this round's TS, so these alone need no re-review.

New since round 2, at the coordinator's request: 661bcf4 (Rust)

The token-stream task in app-lib/src/commands/local_agent.rs re-subscribed every 2s after any failure. While the active database is refused, that meant probing forever and logging a warning each time.

  • Now:
    • Only a status that nodespace_proto::requires_extension::unsupported_extensions recognises as the refusal changes the behaviour. The task then waits for the active database to switch, or the channel to be rebuilt, and resubscribes at once.
    • Every other outcome keeps the 2s retry exactly.
  • Structure:
    • The loop is resubscribe_forever. It takes an active-database receiver before each attempt, so a change during the attempt is not missed.
    • The wait decision is wait_to_resubscribe.
  • Tests (paused clock): 7 in total.
    • The loop waits out a refusal and resubscribes once the generation changes.
    • It doesn't miss a change during the refused attempt.
    • It retries any other failure every 2s, with exactly 11 attempts in 20s.
    • The wait decision on its own.
    • The client-gone fallback.
    • The classifier.
  • Mutation check: 7 of 7 mutations killed, covering the classifier forced true and forced false, resuming only after the delay, no fallback, every error waiting, the loop ignoring the decision, and the receiver taken after the attempt.
  • Checks: clippy -D warnings and fmt are clean on app-lib, and the hard ban passes.

Re-review decision

RE-REVIEW NEEDED for 661bcf4, since it is new Rust logic.

@mstomar125

Copy link
Copy Markdown
Contributor Author

Pragmatic code re-review, round 3: PR #3427

Review Type: Re-Review (medium depth). In scope: 661bcf4a (Rust, app-lib/src/commands/local_agent.rs) and 5ce1dc57 (the TS nit). Head 661bcf4a, base main @ 33ed106a, which includes S6 #3426.

Rebase check: git range-diff shows that 24cccab5 and 2597adac match round 2's 6bdfed72 and 9ecc3bf4 with no content change.

How I checked it:

  • I reviewed the Rust by reading only, with no cargo build or test.
  • stores/database.test.ts on the new head: 65/65.
  • check-pro-boundary.ts: "No Pro marker in core (ADR-081 section 8 hard ban)."
  • I confirmed against the sources:
    • tonic is 0.12.3 (Cargo.lock), and I read its Display for Status.
    • The daemon's subscribe_token_stream goes through route_or_self → routed_database_services, so a refused active database does reach this loop as the S6 refusal status.
    • GrpcClient bumps db_generation in both set_active_database (grpc_client.rs:442) and reconnect (:555).
    • requires_extension::unsupported_extensions returns Some only for FAILED_PRECONDITION carrying the x-requires-extension-bin payload with reason == requires_extension.

Previous Review Summary

Round 2 had 2 items, both 🟢 nits: 1 addressed and 1 skipped, as I suggested. Every round-1 item stays addressed, since those commits are unchanged.

Round-2 item Status Notes
🟢 Nit: one condition in readRefusal's warn branch ✅ Addressed (5ce1dc57) It is now a single condition with identical behaviour.
🟢 Nit: a refused database the listing didn't mark loses the startup conflicts notice Skipped, accepted It is practically unreachable, as noted in round 2. No change was needed.

Round 3: the token-stream retry loop (661bcf4a)

The coordinator's three conditions:

Condition Status Notes
(1) Only a status that unsupported_extensions recognises changes the behaviour; every other error keeps the 2s retry exactly ✅ is_database_refusal is exactly unsupported_extensions(status).is_some(). wait_to_resubscribe skips the sleep only when that holds and changed() returns Ok. A plain failed_precondition("model not ready") and unavailable are both pinned as not refusals.
(2) After a refusal, the loop resumes once the active database changes ✅ the_loop_waits_out_a_refusal_and_resubscribes_once_the_active_database_changes runs the real resubscribe_forever. It makes 1 attempt across 20s of paused time, then 2 within 1 ms of a generation bump. Production passes `
(3) Crate-scoped build, test and test:changed ⏳ This is the author's run, which I didn't repeat on the shared slot. The PR summary reports clippy -D warnings and fmt as clean, and 7 of 7 mutations killed.

On the points to scrutinise:

(a) Behaviour for Ok and for errors other than the refusal. It is preserved.

  • Ok(()), meaning the stream ended or a database change interrupted it, gives the same info line and then sleep(2s).
  • Any other Err gives the same warn text and then sleep(2s).
  • The one observable difference is the warn line's error field: see the nit below.
  • Swapping the error type from String to tonic::Status doesn't change control flow. Both ? sites forward the same statuses that used to be stringified.

(b) The receiver taken before the attempt, and the clone given to the attempt. There is no double wake and no missed wake.

  • Receiver::clone copies the seen-version. So the attempt's clone and the outer receiver both start at the current generation, and each tracks changes on its own.
  • Ok path: the clone sees the change inside try_subscribe's select! and returns Ok. wait_to_resubscribe never polls the outer receiver on Ok, so the next iteration's fresh receiver discards the pending change. There is a single 2s sleep, as before.
  • Refusal path: the refusal comes from the initial RPC, before the select! ever runs. A change made between taking the receiver and the refusal is therefore still unseen on the outer receiver, and changed() returns at once. the_loop_does_not_miss_a_change_during_the_refused_attempt pins this.
  • Ordering against set_active_database: it rebuilds the routed clients under the write lock and bumps the generation after releasing it. If the receiver was taken after the bump, the attempt necessarily got the new client. If it was taken before, the bump is seen. Either way no change is lost, and at worst one extra attempt goes to the same new database.

(c) Falling back to the delay when the sender is gone.

  • This is correct. changed() returns Err once the sender is closed, which falls through to sleep(delay), so there is no spin. a_refusal_falls_back_to_the_delay_once_the_client_is_gone pins it.
  • In production the sender is Arc<watch::Sender> inside GrpcClient, which this task owns, so the fallback is defensive only.

(d) Closure lifetimes.

  • Both closures capture app and grpc by shared reference from the spawned async move block, which owns them for the task's life.
  • The future that try_subscribe(&app, &grpc, …) returns borrows through those shared captures, which is sound for FnMut because shared references are Copy.
  • The two closures share their borrows without conflict.
  • The spawned future stays 'static + Send, since it owns its captures.

(e) The paused-clock tests.

  • They are deterministic. With start_paused, tokio advances time only when every task is idle. So after send_modify, the woken loop task runs before the test's 1 ms timer can fire.
  • The exact elapsed() assertions (ZERO and RESUBSCRIBE_DELAY) hold because auto-advance jumps straight to timer deadlines.
  • "11 attempts in 20 s + 1 ms" is exact, at t = 0, 2, …, 20.
  • Each loop test abort()s its task.
  • They prove condition (2) at the loop level, as described above.

(f) Log levels.

  • The refusal logs at info, once per attempt, and attempts now happen only on a database change or channel rebuild. So it is once per change, instead of a warn every 2s.
  • Other failures stay at warn, and Ok stays at info.

(g) Product-name wording. It is clean. The text is "requires an extension this build does not support", and the hard ban passes.


Code Review Findings (new in this round)

🟢 Nit: the warn line now prints the whole tonic::Status, not just its message

📁 packages/desktop-app/app-lib/src/commands/local_agent.rs (resubscribe_forever, the Err(e) arm)

tracing::warn!(error = %e, "Token stream subscription failed; reconnecting in 2s")

e used to be the String from e.message(). It is now tonic::Status, and tonic 0.12.3's Display writes status: {code:?}, message: {msg:?}, details: {bytes:?}, metadata: {MetadataMap:?}. So while the daemon is unreachable, every 2s warn line carries the full metadata map and the details bytes, where before it carried only the message.

Recommendation: use tracing::warn!(code = ?e.code(), error = %e.message(), …) to keep the old, compact line. This is optional.

🟢 Follow-up (out of scope for this PR): the node watcher has the same pattern, already bounded

📁 packages/desktop-app/app-lib/src/watcher.rs (run)

WatchNodes is routed, so with a refused active database stream_once fails with the same refusal. It then logs warn! and retries on its exponential backoff, capped at BACKOFF_MAX = 30s. The backoff select! already wakes on db_changed, so a switch recovers at once, and the noise is bounded to one warn every 30s or less.

A one-line follow-up would bring the two loops into line. On is_database_refusal, skip the sleep arm and wait only on db_changed or cancellation, and log at info. This is not needed for this PR.


Recommendation: APPROVE

661bcf4a meets the coordinator's conditions (1) and (2) exactly. It keeps every non-refusal path identical apart from the log formatting nit. Its race handling around the generation receiver is correct, and its tests are deterministic.

The TS nit commit is a no-op refactor. The rebased round-1 and round-2 commits are unchanged.

Before merge:

  • the author's crate-scoped Rust run and test:changed (condition 3);
  • the merge gate;
  • the real-device smoke run of a refused database before the release.

@mstomar125 mstomar125 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated pragmatic-code-review (re-review, round 3): APPROVE (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above.

@mstomar125

Copy link
Copy Markdown
Contributor Author

Address review (round 3)

The head is now 6a6af77, on main at 33ed106.

Round-3 findings

  • 🟢 The warn line printed the whole tonic::Status: addressed in 6a6af77. It now logs code = ?e.code(), error = %e.message(), which restores the old compact line. The change is log-only, and clippy -D warnings, fmt and the 7 local_agent tests all pass.
  • 🟢 Follow-up, out of scope here: the node watcher (watcher.rs).
    • It retries a refused database on its exponential backoff, capped at 30s, and already wakes on db_changed, so the noise is bounded.
    • Bringing it into line with the token-stream loop would be a one-line change: on the refusal, wait only on db_changed or cancellation, and log at info.
    • It is left for the coordinator to file.

Checks on the final head

  • bun run test:changed passed:
    • frontend: 88 s
    • scripts: 23 s
    • Chromium: 3 s
    • Rust workspace nextest: 50 s
  • bun run scripts/check-pro-boundary.ts passes the hard ban.
  • The VERIFY greps all come back clean: no product name or URL in src, no mailto in the view, and no diff in the extension API or ui-extensions files.
  • The extension-api tests pass, 46 of them, and the snapshot is unchanged at 2.0.

Re-review decision

NO RE-REVIEW NEEDED. The only change since the round-3 APPROVE is the log formatting.

@mstomar125
mstomar125 marked this pull request as ready for review October 1, 2026 12:12
mstomar125 and others added 5 commits October 1, 2026 14:22
… in place of the workspace (ADR-083 §2)

- types/requires-extension.ts: RequiresExtensionCommandError (code
  REQUIRES_EXTENSION, requiresExtension payload) and its guard, which accepts
  only a well-formed payload with an https download link.
- database store: after routing to a database it is about to select, read it
  once (list_conflicts, one record) and record the REQUIRES_EXTENSION payload
  as the selection's refusal, before the selection commits. A listing that
  marks the selected database requires_extension with no refusal recorded
  reads it again. A refused activation evicts the previous database's caches
  and reloads nothing; the next switch or create replaces the refusal.
  evictAndReloadActiveDatabase splits into evictDatabaseCaches and
  reloadDatabaseStores.
- database-requires-extension.svelte: renders the payload's message, download
  label and URL verbatim (openUrl), and offers a switch to another registered
  database or the existing create flow. No contact link, and nothing that
  moves, renames or resets the file.
- app-shell: shows the view in place of the sidebar and panes while the
  active database is refused, leaving the overlay slot mounted; holds the
  startup conflicts notice and pauses the indexing-queue poll meanwhile.
- Databases settings: a requires_extension row reads "Needs an extension this
  app doesn't support" instead of "Unknown".

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…database refused

- A database the listing marks requires_extension is still read before its
  selection commits (it needs the refusal's text, and writes to it are
  refused anyway). Any other database commits at once, and
  checkSelectedDatabase reads it right after, so a switch to a database that
  opens no longer waits for its open while routing already points at it.
  The same check runs when a later listing marks the selected database with
  no refusal recorded, and drops a result for a database no longer selected.
- readRefusal warns when a REQUIRES_EXTENSION error carries a payload the
  guard rejects.
- evictDatabaseCaches' comment says what it evicts and that the sidebar
  stores' lists wait for reloadDatabaseStores.
- Tests: a refused activation still fires onDatabaseActivated after eviction,
  from load() and from switchTo(); a switch to an unmarked database does not
  wait for its open; refusals found after the commit; the malformed-payload
  warning; the command-sequence tests follow the read's new place.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… 2s while the active database is refused

The token-stream task re-subscribed every 2s after any failure, so while the
daemon refused the active database (it requires an extension this build does
not support, ADR-083 §2) it asked again forever, logging a warning each time.

- resubscribe_forever runs the loop over an active-database generation
  receiver, taken before each attempt so a change during it is not missed,
  and an attempt that gets a clone of it.
- wait_to_resubscribe: after the refusal (recognised only by
  nodespace_proto::requires_extension::unsupported_extensions), wait for the
  active database to switch or the channel to be rebuilt, then resubscribe at
  once; if the client is gone, fall back to the delay. Every other outcome
  keeps the 2s retry.
- try_subscribe returns the tonic::Status, so the loop can tell the refusal
  apart.
- Tests (paused clock): the loop waits out a refusal and resubscribes once
  the generation changes, does not miss a change during the refused attempt,
  and retries any other failure every 2s; the wait decision on its own; the
  classifier.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…and message, not the whole status

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@mstomar125
mstomar125 force-pushed the issue-3413-refusal-view branch from 6a6af77 to 27fe9e4 Compare October 1, 2026 12:22
@mstomar125
mstomar125 merged commit ab9961e into main Oct 1, 2026
@mstomar125
mstomar125 deleted the issue-3413-refusal-view branch October 1, 2026 12:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Core release blocker] Refuse Pro databases on every surface and add the contact entry point (ADR-081 step 3)

1 participant