Skip to content

Deduplicate cold-load network requests - #2672

Merged
ymichael merged 6 commits into
mainfrom
bb/profile-network-with-dev-browser-thr_2fun4nxmap
Aug 31, 2026
Merged

ymichael merged 6 commits into
mainfrom
bb/profile-network-with-dev-browser-thr_2fun4nxmap

Conversation

@ymichael

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

Cold app loads had multiple owners for the same system-config and plugin-list resources, while pending-interaction query options accidentally overwrote the shared QueryClient freshness default with undefined. The plugin frontend loader also interpreted a failed shared query as an authoritative empty installation set, and overlapping initial-connection atom refreshes repeated local daemon discovery.

What changed

The app now has one shared QueryClient for React and non-React owners, with stable shared query options for system config and the installed-plugin list. Plugin frontend reconciliation reuses that query and preserves active frontends when inventory loading fails. Pending interactions inherit the app freshness default unless callers provide an override, while stale remounts still revalidate. The redundant local-daemon connection refresh was removed, cache writers use the raw installed-plugin array shape, and narrow regressions cover each ownership and failure boundary.

There are no wire, daemon protocol, CLI, guide, or public Plugin SDK changes.

Review requested from @slopcop.

How you verified

The regressions failed before the fixes and pass afterward. Browser verification used the copied production repro database and confirmed one cold request each for system config, plugins, thread include, interactions, daemon status, and workspace targets. Hosts and sidebar retain their intentional initial-connect race-closing revalidation.

  • pnpm exec turbo run test --filter=@bb/app --force: 443 files passed; 3,510 tests passed and 3 skipped
  • pnpm exec turbo run typecheck --filter=@bb/app --force: passed
  • pnpm exec turbo run build --filter=@bb/app --force: passed
  • pnpm exec turbo run lint --filter=@bb/app --force: 0 errors
  • Touched-file oxfmt --check and git diff --check: passed

Fixes: none

AGENT GENERATED

ymichael and others added 3 commits August 28, 2026 14:26
## What was wrong

PR #2616 removed the `host.list_branches` command from the host daemon
contract and its dispatch table, but one call to it stayed behind in
`host-branches-dispatch.test.ts`. `main` is red: `tsc` reports TS2820 for the
unknown command type, and the test itself throws
`onlineRpcHandlers[command.type] is not a function`.

## What changed

- `apps/host-daemon/test/command/host-branches-dispatch.test.ts` dispatches
  `host.inspect_git_source` with `remoteRefresh: "blocking"`, like the other
  tests in the same describe block. A blocking refresh keeps the promise
  pending until the fetch ends, which is what this test waits for.

## How you verified

- `pnpm exec turbo run typecheck test --filter=@bb/host-daemon` passes, 45
  test files. The repaired test runs instead of throwing.

> AGENT GENERATED

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

@bb-slop-cop bb-slop-cop Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🚨 SLOP COP 🚨 · review

I am reviewing this pull request now. I will check security, code quality, architecture, performance, and the main user path.

Comment thread apps/app/src/lib/system-config-atoms.ts Resolved
Comment thread apps/app/src/lib/plugin-frontend.ts Resolved

@bb-slop-cop bb-slop-cop Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🚨 SLOP COP 🚨 · review

This PR gives early app startup and React one shared QueryClient.

It joins matching system config and plugin inventory requests. It also fixes the pending-interaction freshness policy.

I found two event paths that still need work.

  1. A config-changed event can start two config requests. The second refresh cancels the first request.
  2. A persisted page restore can reuse the plugin inventory for 30 seconds. The page can miss plugin changes during the freeze.

I found no confirmed security defect. The product has no supported same-page server or user transition.

The focused app suite passed all 88 tests. All GitHub CI checks passed.

I could not complete browser QA. The checkout-specific dev server stayed in the plugin SDK type build for 20 minutes.

Please add one test for each event sequence. The inline comments give the exact cases.

@ymichael

ymichael commented Aug 31, 2026 •

Copy link
Copy Markdown
Collaborator Author

@slopcop ready for re-review at f69b465.

Addressed only the two demonstrated issues:

  • System config: preserves the in-flight fetch across either config-changed listener order; the real atom/query/realtime regression verifies one request and zero aborts.
  • Persisted plugin restore: marks the exact enabled inventory stale, then lets the existing reconcile fetch remain the sole request owner; the real fetchQuery regression verifies one request and application of changed server data.

Validation:

  • Focused regressions: 3 files, 31 tests passed.
  • Related cache/realtime/plugin suite: 6 files, 136 tests passed.
  • Full @bb/app suite: 446 files passed; 3,526 tests passed, 3 skipped.
  • Turbo app typecheck passed.
  • Prettier and git diff --check passed.

Complexity audit: runtime delta is +20/-2 lines. One cache-owner operation and one lifecycle dependency were introduced; no new cache, flag, retry manager, or global mutable state. No code comments were added. The reviewer-deferred residuals and side channels remain unchanged.

@bb-slop-cop bb-slop-cop Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🚨 SLOP COP 🚨 · review

I am the SlopCop. I am reviewing this pull request now.

I will check security, code quality, architecture, performance, and the main user flow.

Comment thread apps/app/src/lib/plugin-frontend.ts Resolved
Comment thread apps/app/src/lib/plugin-frontend.ts Resolved

@bb-slop-cop bb-slop-cop Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🚨 SLOP COP 🚨 · review

This pull request gives system configuration and plugin inventory one shared cache. This removes duplicate start requests from separate owners.

It also preserves active plugin frontends after an inventory failure. It restores the shared freshness default for pending interactions.

I found four issues that should be fixed before merge:

  • High: A plugins-changed event can join an older inventory request. The old result can clear invalidation and retain stale plugin code.
  • High: A failed inventory refresh can retain registrations, CSS, and content scripts after an authorization or revocation failure.
  • Medium: A later configuration event can join an older request. The app can then retain old settings or local helper ports.
  • Medium: A quick remount can miss a pending interaction because the new two-second freshness value prevents the baseline request.

The shared QueryClient is the correct architectural owner. I found no second production owner for either new shared query.

The old fetchPluginList wrapper now has no production caller. You can remove it as a small follow-up cleanup.

Three focused Turbo runs passed the changed query and cache tests. The largest run passed 58 tests.

The browser test loaded the shell once. Plugin rebuilds and a slow provider request prevented a stable end-to-end request-count result.

The final GPT-5.6 review gate confirmed the four defects and returned REQUEST CHANGES. I am posting a comment review, as required.

@ymichael

Copy link
Copy Markdown
Collaborator Author

Addressed the four latest review findings in 0d32f9e.

  • Plugin changes and persisted restores now refresh after any older inventory request settles.
  • Plugin-list 401/403 responses deactivate active frontends; transient transport failures preserve them.
  • Later config events queue one trailing shared-cache refresh and propagate changed helper-port data to Jotai consumers.
  • Pending interactions refresh after each zero-owner interval without losing concurrent cold-load deduplication.

Validation:

  • Focused matrix: 8 files, 165 tests passed.
  • Full app suite: 446 files passed; 3,531 tests passed, 3 skipped.
  • Turbo app typecheck passed.
  • Turbo app production build passed.
  • Prettier and git diff --check passed.

Complexity audit: runtime delta is +65 net lines across the four fixes. One cache-owner operation and one local query-cache subscription were added. There is no new global cache, retry manager, feature flag, or code comment.

@ymichael

Copy link
Copy Markdown
Collaborator Author

Simplified the plugin refresh path in 6c8a0c2.

The serialized frontend reconciliation module now owns the full refresh sequence: wait for the current boot/reconcile, mark the shared plugin inventory stale, then reconcile or reboot torn-down state. The lazy loader and page-lifecycle adapter only request reconciliation. The cache owner still joins an unrelated in-flight inventory query before invalidating, so the demonstrated stale-response race remains covered.

Complexity delta for this pass: 21 additions, 84 deletions; runtime code is 13 net lines smaller; the page-lifecycle interface shrank from four operations to two; no new helper, cache, flag, retry manager, or code comment.

Validation:

  • Focused plugin matrix: 3 files, 59 tests passed
  • Full app suite: 446 files, 3,530 tests passed, 3 skipped
  • Turbo app typecheck passed
  • Turbo app production build passed
  • Production cold browser probe: config, hosts, sidebar bootstrap, thread include, plugins, interactions, daemon status, and workspace targets each requested once
  • The known two-call thread-tabs side channel remains unchanged and outside this branch

@ymichael
ymichael merged commit 4d07564 into main Aug 31, 2026
15 checks passed
@ymichael
ymichael deleted the bb/profile-network-with-dev-browser-thr_2fun4nxmap branch August 31, 2026 23:09
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.

2 participants