Skip to content

perf(bots): push bot and connector changes instead of polling - #458

Merged
nixuuu merged 1 commit into
perf/fetch-2-catalogsfrom
perf/fetch-3-bots-connectors
Nov 9, 2026
Merged

nixuuu merged 1 commit into
perf/fetch-2-catalogsfrom
perf/fetch-3-bots-connectors

Conversation

@nixuuu

@nixuuu nixuuu commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

Part 3 of 5. Bot summaries and connector/proxy changes are pushed instead of polled.

What changes

  • Gateway owner feed (core/owner-feeds.ts). It runs while anyone watches the overview. Every 2 s it reads the owner's bot journal clock (bot_view_clock, migration 0091; O(1) when idle), a signature of pending approval cards, and digests of connector accounts and proxies. Changes from the scheduler, agents, OAuth refreshes, configuration sync and other gateway instances are therefore seen too. Writes through the API nudge it at once (about 100 ms).
  • New additive OverviewUpdate cases: bot (824, the summary as ListBots returns it, changed bots only), bot_removed (825), connectors_changed (826), proxies_changed (827), feeds (828).
  • Negotiation through feeds. Each stream announces the domains it pushes completely. bots is listed only while every reachable linked computer pushes its bots too; a linked home's bot changes arrive with qualified ids. A client without a domain in feeds (older gateway or a dropped stream) keeps a bounded fallback: bot list every 15 s, Connectors every 30 s.
  • Web: the shared bot list applies pushed summaries (it polled every 5 s), and reads are fenced so an older list cannot overwrite a pushed bot. The Connectors page drops its 3 s ListConnectors + ListBots poll. Connector scopes and proxies are shared reads invalidated by these events.
  • Mobile: the shared bot list and connector reads follow the same events. Alerts keep their baseline semantics.

Where this differs from the audit. It suggested hooking every write path. Bot rows change from many places, including other gateway instances, so the feed uses the existing commit-ordered bot journal instead, plus a cheap card signature. That covers every source without new hooks or a migration. Full Bot upserts are sent only for changed bots, never per streaming token (bot messages are append-only). Splitting summary and configuration is left open.

Measurements

Scenario Method before after
S1: sidebar idle (127 s) ListBots (archived) 25 0
S2: Connectors open (126 s) ListConnectors 42 (450 KB) 1 (11 KB: a change pushed from another client)
ListBots 42 0
ListBots (archived) 25 0
Phone, 30 s foreground ListBots 8 1
Connector saved from another client while Connectors is open visible after ≤ 3 s poll ≤ 1.5 s, 1 read
Proxy saved from another client while Proxies is open visible after page reload pushed, 1 read

Gateway cost with 50 bots: one feed check (four queries) takes 0.35 ms and runs every 2 s while anyone watches. One ListBots takes 2.88 ms.

Tests: tests/integration/overview-feeds.test.ts (feeds announced; create, archive, a direct DB write and delete reach subscribers; connector and proxy writes reach every subscriber; an idle stream sends nothing), tests/integration/linked-reads.test.ts (a linked home's bot changes arrive with qualified ids).

How it was measured

  • Web (real browser, own stack). scripts/bench/client-stack.ts on private ports (dev BFF, server role, synthetic worker), base = dev at a423af85, after = top of this stack. Resource Timing counted /api/* requests per path in a visible tab. Scenarios: S1 sidebar idle 127 s; S2 Settings → Connectors open 126 s; S3 Settings → Workers open 127 s; S4 nine in-app Settings navigations in 27 s. The BFF routes are pass-throughs, so gateway call counts equal these.
  • Gateway and linked home. Two real desktop-role gateways linked over mTLS (tests/integration/support/linked-timeouts.ts), counting RPCs served by the linked home and linked reads started here.
  • Mobile. No device run: the phone's request sequence before and after was replayed from source against the linked test gateways. On-device profiling is still open (see the stack summary).
  • The stack is cumulative; each table lists only the methods this PR changes. Values for the top build apply to this PR because no later PR touches those methods.

Copy audit (docs/copy.md §8)

No UI text was added or changed. Existing messages ("Could not load bots.", "Could not load connectors.", "Could not load settings. Check the connection and retry.") moved to shared stores unchanged.

While anyone watches the overview, the gateway compares cheap revisions
every 2 s for its owner: the bot journal clock (0091), pending cards and
connector/proxy digests. Writes through the API nudge it at once. It
publishes changed bot summaries (OverviewUpdate.bot, bot_removed) and
connectors_changed / proxies_changed. Linked homes forward their bot
changes with qualified ids. Each stream announces the domains it pushes
(OverviewUpdate.feeds); bots count only while every reachable home
pushes them, so clients of older gateways keep a bounded fallback.

Web: the shared bot list applies pushed summaries (fallback 15 s instead
of 5 s), the Connectors page drops its 3 s ListConnectors+ListBots poll,
connector scopes and proxies are shared reads invalidated by events.
Mobile: the shared bot list and connector reads follow the same events.
@nixuuu
nixuuu added this pull request to stack #461 November 9, 2026 21:00
@nixuuu
nixuuu marked this pull request as ready for review November 9, 2026 21:01
@nixuuu
nixuuu merged commit ddab718 into dev Nov 9, 2026
10 checks passed
@nixuuu
nixuuu deleted the perf/fetch-3-bots-connectors branch November 9, 2026 21:45
nixuuu added a commit that referenced this pull request Nov 10, 2026
Linked bots can stay missing in web/desktop even when both computers
show connected. `ListBots` served only the in-memory peer-read cache
while a home was online, so a cold/evicted cache or an A gateway restart
returned no remote bots despite a committed bot mirror. The background
read eventually completed, but the web bot store ignored
`linkedReadCompleted("ListBots")`. Since #458 disabled polling when the
gateway advertises pushed bots, that incomplete list could persist until
another bot change or client reload.

Use the committed mirror while the online read cache is loading or
stale, and continue refreshing the authoritative home list in the
background. Bot mirror commits also mark the home's list cache due and
announce a list invalidation. The web bot store now handles that
invalidation. Mobile already handles it through `OverviewInvalidation`
in its shared query bus, so its implementation remains unchanged.
Existing dimmed/read-only rows and gateway rejection of offline writes
remain in place. Updating A restarts its gateway and client
subscription, restores the persisted mirror immediately and refreshes
from B automatically; no manual resync, database repair or re-pairing is
required.

The original cold-cache behavior comes from #348; #458 turned a
transient incomplete web list into persistent missing rows. History does
not implicate #502 (worker command delivery), #507 (connection
recovery), #500 (workspace/config sharing) or #475 (row badge
rendering). A plain warm-cache B restart did not fail in the baseline.
The cold-cache and A-restart cases reproduce a failure path matching the
report; the maintainer's live stack and databases were not inspected or
changed.

Extract the unchanged feed-negotiation helper from `routed-overview.ts`
to keep the file and watch function within the repository's size limits.
Update the Polish bot and linked-computer documentation.

## Verification

- RED, before the production fix: `TMPDIR=/var/tmp bun run check:tmp
tests/integration/linked-bots-resync.test.ts` — 2 failed, 2 passed. The
cold online-cache read and first list after A restarted omitted B's bots
despite their persisted mirror. Temp cleanup passed.
- GREEN: **30/30 sequential complete-file runs passed**, one test
process at a time using the same `check:tmp` command. Each final-file
run passed all five integration scenarios (150 scenario passes in total)
and left nothing in its private temp directory.
- Coverage: two real gateways, separate PostgreSQL databases and an
actual mTLS link; active and archived bots with last-message previews;
same-version B restart and restart with advertised app version changing
from nightly.119 to nightly.121; A's one ongoing overview watch and
fresh API reads; read-only/offline write rejection; A gateway restart
with its database retained; deletion, archive/unarchive and message
changes made while B was away, then convergence after a fresh B runtime.
Version coverage changes the handshake version on the current
implementation; it does not run historical release binaries. The client
is exercised at the public API/feed boundary; no UI test suite was
added.
- Related suites, run sequentially one file at a time through
`check:tmp`: `linked-reads` (4 passed), `linked-list-retention` (1
passed), `linked-agents` (16 passed). All three temp cleanup checks
passed.
- `bun install`, `bun run typecheck`, `bun run lint`, `bun run
format:check`: passed. Implementation and regression coverage received a
self-review. Full unfiltered tests, `gen:check`, a web build and
browser/device checks were not run locally under the workspace
verification limits; CI covers the broader automated checks.

Copy audit (`docs/copy.md` §8): no UI text added or changed.

Fixes: #458
Related: #348
nixuuu added a commit that referenced this pull request Nov 17, 2026
## Change

After deleting a provider, Settings → Proxies could retain its stale
“Used by” reference and keep Delete disabled. The proxy feed revision
now includes provider references, worker overrides and worker names, so
reference changes refresh the shared proxy list automatically.

Update the proxy documentation and add real gRPC/BFF regression coverage
for provider deletion, detaching and restoring worker overrides,
cascading assignment deletion, and subsequent proxy deletion.

## Verification

- Reproduced the failure before the fix: the gateway returned no
references while the BFF retained the deleted provider.
- Passed 14 integration tests through `bun run check:tmp
./tests/integration/bff-reads.test.ts
./tests/integration/overview-feeds.test.ts`; temporary directory clean.
- Re-ran both proxy-reference cases after the final assertion change;
both passed, with temporary directory clean.
- Edited-file lint and formatting passed; `git diff --check` passed.
- No UI markup or user-facing copy changed; a copy audit is not
required.
- Full repository checks, remaining tests and builds are left to CI.

Fixes: #458
nixuuu added a commit that referenced this pull request Nov 19, 2026
## Change

A cached pull request read could publish thread and overview updates for
every linked thread in its repository. Selecting another active thread
could also restart the shared overview twice and fetch two full
snapshots. A slow overview subscriber could then reach its 256-frame
limit while little data was queued.

- Scope PR updates to active links for that owner and PR. Repair stale
projections on cache hits. Re-read under the thread row lock so a
concurrent unlink cannot restore a removed link in the sidebar. Refresh
open lists when an older PR changes.
- Send changed bot summaries and preserve pending approvals and
execution state across partial bot replies. Limit the project updates
generated by worker status reports while keeping workspace origin and
scratch placement discovery.
- Keep the upstream overview open for a 500 ms renderer handover and
replay authorized head cursors to the new subscriber.
- Compact a slow overview queue only at its existing item or byte limit.
Keep ordering around state transitions and controls. An irreducible
queue still reports DataLoss and can recover from a new snapshot.

Migration 0177 initializes a per-link summary fingerprint for current
active links. It keeps concurrent readers of the same PR from increasing
a thread’s list revision repeatedly.

## Verification

An isolated repository with 439 linked threads, including five linked to
the measured PR, reproduced the fan-out. One warm GetPullRequest made
439 projection calls, read 439 thread rows and produced 878 hub
publications before the change. Each count fell to zero, with the same
PR returned and no GitHub HTTP request in either run. One local RPC took
247.7 ms before and 6.7 ms after.

On the original gateway a two-thread burst of 300 worker events
terminated the stalled overview with DataLoss. The fixed gateway
delivered both final states, persisted all 300 events in order and
replayed both completed responses from pre-burst checkpoints. Separate
cases exercise item and byte overflow with nonreplaceable frames, and
delivery to a healthy observer.

Five renderer handovers with the same subscriptions produced ten
additional snapshots before and zero after. Real PostgreSQL and gRPC
integration coverage exercises independent PRs in the same repository,
shared links, concurrent unlink, older PRs, cache repair, account
changes, bot feeds, disconnection, worker replay and lost
acknowledgements.

With five projects and 16 status reports, the original gateway published
80 project frames. The fixed gateway published zero, issued zero project
list queries and delivered all 16 worker updates. The same suite
verifies changed Git origins, retry after a failed read and a new
worker’s scratch placement.

Production renderer in Chromium, isolated gateway, BFF and PostgreSQL.
Seven bot conversation switches opened no additional overview SSE. A
pending approval survived navigation and reload and sent exactly one
worker response. Checked light and dark at desktop and phone widths.

Fixes: #501
Fixes: #847
Fixes: #458
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.

1 participant