Skip to content

fix(runtime): an open tab nobody uses lets its company's server go - #802

Merged
allisonmahmood merged 4 commits into
mainfrom
fix/800-idle-tabs-let-go
Oct 19, 2026
Merged

allisonmahmood merged 4 commits into
mainfrom
fix/800-idle-tabs-let-go

Conversation

@allisonmahmood

@allisonmahmood allisonmahmood commented Oct 19, 2026 •

Copy link
Copy Markdown
Owner

What changed

A tier 2 tab that stayed open held its company's server task, and its version's process, for as long as it was connected, whether anyone used it or not. In production one forgotten tab kept a company's task running for 36.5 hours, until a deploy ended it.

Now an open document holds the company task and keeps its version warm only while its viewer is active. After execution.document.idle (a new operating limit: 10 minutes by default, per company, overridable) without activity, it lets both go. The screen and the stream stay: the document stays ready, live updates still arrive, and its next call binds the company on demand.

  • Activity is the document's first stream, a change to its logical desired set (subscription ids, operations and canonical args, ignoring order, revisions and vectors), or an admitted server.call from its viewer for that version on this host. Reauthentication reconnects, reconciliation and re-runs for other people's writes don't count. Subscriptions.update now says whether an admitted request changed the logical set. It compares a generation's first set with the one the previous generation left, so the replace the shell sends after every reconnect only counts when it carries changes. Runtime tells the streams about each admitted server.call through a new called option. Activity lands on whichever generation of the document is connected when it runs, so a reauthentication that replaces the stream in between doesn't lose it; a document that disconnected meanwhile keeps none.
  • One warm-hold owner per document. RuntimeStream keeps an activity record per document across generations. The owner is one fiber holding ExecutionLifecycle.connect and ConnectedVersions.connect until the window passes or its generation ends. Expiry gives up ownership in the same step that decides it, and finalizers only clear their own owner. An old generation's expiry, acquisition or finalizer therefore never touches its replacement's holds. Reactivation re-holds in the background with warm: false and sends no frames; if it fails, the next activity retries.
  • Reconnects and readiness. An idle document's reconnect or resume opens dispatch, sends ready and reconciles, without connecting or warming. If the window outlasts a startup, the startup still ends in ready, so held calls always settle through ready, start_failed or closure. A document the host has no record of starts active.
  • Bounded records. Disconnected records wait in a cache of 4096, longest gone first, for at most an hour. Those defaults sit beside the cache, and tests lower them through a Context.Reference. Connected records are never evicted, and a record leaves the cache when it reattaches.
  • Wide events. The keepalive event gains endReason (idle or left). A tier 2 stream event beside the fleet counts idled and reactivated. Its limits carry execution.document.idle with the window, its configuration revision and, as peak, the longest stretch without activity.
  • Docs. Updated ADR-0010's readiness contract, ADR-0012 › Fleet controller and its idle-release decision, and OPERATIONS › Keeping open versions warm, which gains a tuning query. Also updated: the execution.company.idle description, the generated limits docs and server-skill table, the runtime stream description with docs/API.md, the analytics and runtime glossaries (a new Active entry) and docs/product.md.

Closes #800

Look at

1. A visible tab lets go, and comes back on use. This ran on the local instance with a second, local-fleet host, an 8 s window and a 5 s company idle. A real browser opened the starter tier 2 patch, left it visible for 20 s, added a note and stayed another 15 s. Below is the host's wide events, trimmed to the fields that matter, with seconds from the open:

{"type":"request","at":"0.2","operations":["server.call","tables.list"],"handler":"notes.list"}
{"type":"keepalive","at":"0.2","dur":"8.0","endReason":"idle","peakDocuments":1,"touches":{"absent":1},"warmups":{"loaded":1}}
{"type":"binding","at":"0.1","dur":"13.7","releaseCause":"idle"}
{"type":"request","at":"20.3","operations":["server.call","tables.insert"],"handler":"notes.create"}
{"type":"keepalive","at":"20.3","dur":"8.2","endReason":"idle","peakDocuments":1,"touches":{"absent":1},"warmups":{}}
{"type":"binding","at":"20.3","dur":"13.4","releaseCause":"idle"}
{"type":"stream","at":"0.1","dur":"35.5","idled":2,"reactivated":1,"closeReason":"disconnected",
 "limits":[…,{"limitId":"execution.document.idle","value":8000,"peak":20103,…}]}

The company's task was released 13.7 s after the open while the tab was still connected and visible. That is the window plus execution.company.idle. The note bound a fresh task on demand, the call made the document active again without a warmup, and the task was released again once the tab went quiet.

2. The browser test, red then green. starting.spec.ts › idle documents runs a real server and fleet, with an 8 s window and a 1 s company idle.

  • It checks that the visible tab's company is released.
  • Then the tab is hidden, suspends and resumes, and a call held while hidden must complete exactly once.
  • From before that call, it watches Postgres for the company's activity lock. Only an active document's hold takes that lock, never a call's own admission, so seeing it shows the call reached the document's stream. That doesn't depend on how fast the reply comes back.
  • The company must then be released again once the document's window passes, waited for with a deadline rather than a fixed sleep.

Each wiring point fails it on its own. With Runtime's call forwarding in RuntimeProduction.ts removed, or with Server.ts back to merging Runtime and the streams side by side:

Error: expect(received).toBe(expected)
Expected: true
Received: false      ← the company's lock never came back after the resumed call

With the window at 10 minutes, it fails at the first check, with no idle release in 30 s. As committed it passes in 20 s, along with the rest of the spec.

3. Activity across a reconnect. Two barrier tests construct a call's activity, or hold an admitted set change before its activity lands, then let reauthentication replace the generation. The replacement must take the company back. Before activity was forwarded to the current generation, both stalled waiting for that hold, and the replacement stayed idle.

How it was verified

  • New TestClock tests in RuntimeStream.test.ts cover the following. An active document holds both and lets both go after the window, the keepalive saying idle. A non-empty set whose revisions and vectors advance stays idle across 30 reconnects spanning two more windows. A set change re-holds and a repeat doesn't. A call re-holds the caller's connected documents, not a colleague's or a hidden one. Another viewer's write reaches an idle document through an on-demand admission. An unknown document starts active, and a startup the window outlasts ends in ready. A barrier-controlled race covers expiry against reactivation against generation replacement, with the old owner's lock finalizer landing after the new owner took over. Two more cover a call's and a set change's activity landing on the generation that replaced their document meanwhile, and not on one that left. The cache tests evict the longest-disconnected first, never a connected record, and never one that reattached.
  • Subscriptions.test.ts covers the logical set across order, revisions, vectors, stale, repeated and buffered deltas, and across generations. ConnectedVersions.test.ts covers endReason. InvocationAdmission.test.ts checks that only an admitted call reaches called. Fleet.test.ts now shows that an active holder alone, then an admitted invocation alone, on another host prevents release.
  • One locked pnpm verify passed on the review-fix commit: format, lint, typecheck, synth, test (1,965 offline tests), postgres-concurrency, cli-smoke, tier2-smoke and browser. The two later commits only change tests: the activity tests wait for background holds to settle, and the idle browser case watches for the company lock. pnpm check and the full browser suite (81 tests) passed on the last one.
  • Not checked here: multi-host behaviour beyond what sticky routing gives (fix(infra): the load balancer keeps a browser on one host #798), since activity records aren't replicated. The production window is a starting value to tune from the new stream fields.

Release impact

  • Breaking — requires action from anyone already running this

  • Not breaking — no action required. The stream wire and API shapes are unchanged; documents just let go sooner.

  • What does a revert leave behind? Nothing durable: activity lives in each host's memory, and the new limit is a registry entry with a default. If PATCHY_LIMITS_JSON names execution.document.idle by then, take it out first, because an older release refuses an unknown limit id at startup. A per-company override row for it is ignored.

  • Does the release before it still work with that? Yes. Open documents hold their company again for as long as they're connected.

Made by Claude Opus 5.5 via Claude Code; reviewed with GPT-6.1-Sol.

@github-actions github-actions Bot added area:server Touches the server area area:ci CI, shared testing infrastructure, development scripts and tooling area:docs Touches the docs area size:xl Over 1,000 changed lines; review in multiple passes labels Oct 19, 2026
allisonmahmood added a commit that referenced this pull request Oct 19, 2026
Address review of #802:

- A call's or set change's activity lands on the document's current
  connected generation, so a reauthentication replacing the stream
  between admission and activation no longer loses it; a document that
  disconnected meanwhile still keeps none. Barrier tests cover both
  handoffs.
- The idle browser case now shows the resumed call holds the company
  past execution.company.idle until the document's window passes, which
  fails without Runtime's call forwarding or the server's wiring.
- The disconnected-record bounds are module defaults (4096, one hour)
  that tests lower through a Context reference, not registry limits.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
allisonmahmood added a commit that referenced this pull request Oct 19, 2026
Address review of #802:

- A call's or set change's activity lands on the document's current
  connected generation, so a reauthentication replacing the stream
  between admission and activation no longer loses it; a document that
  disconnected meanwhile still keeps none. Barrier tests cover both
  handoffs.
- The idle browser case now shows the resumed call holds the company
  past execution.company.idle until the document's window passes, which
  fails without Runtime's call forwarding or the server's wiring.
- The disconnected-record bounds are module defaults (4096, one hour)
  that tests lower through a Context reference, not registry limits.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@allisonmahmood
allisonmahmood force-pushed the fix/800-idle-tabs-let-go branch from d8c4a34 to b57d1f5 Compare October 19, 2026 16:20
allisonmahmood added a commit that referenced this pull request Oct 19, 2026
Address review of #802:

- A call's or set change's activity lands on the document's current
  connected generation, so a reauthentication replacing the stream
  between admission and activation no longer loses it; a document that
  disconnected meanwhile still keeps none. Barrier tests cover both
  handoffs.
- The idle browser case now shows the resumed call holds the company
  past execution.company.idle until the document's window passes, which
  fails without Runtime's call forwarding or the server's wiring.
- The disconnected-record bounds are module defaults (4096, one hour)
  that tests lower through a Context reference, not registry limits.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@allisonmahmood
allisonmahmood force-pushed the fix/800-idle-tabs-let-go branch from bc3bc72 to 5683b26 Compare October 19, 2026 20:21
@allisonmahmood

Copy link
Copy Markdown
Owner Author

Acceptance: PASS with notes

Checked 5683b26ff3988b6d4c600933bd02016273fa3079 (base b5e43dbc4150803894cd2a664bdb6d2e1a7917e9) on fresh brightline and runtime browser fixtures, by GPT-6.1-Sol in the Codex harness through T3 Code. I did not write this change.

Done means

  • An inactive, connected tier 2 document releases its warm holds after the configured window, despite routine reconnects: passed. The TestClock cases release both company and version holds at the default ten-minute boundary, preserve inactivity across 30 reconnects with advancing revisions/vectors, and check keepalive endReason, stream transitions and the effective limit. The real-fleet browser case also passed with the shortened window.
  • Its screen stays usable, live updates arrive, and its next action runs without hanging or replay: passed. An independent browser check used a four-second document window and one-second company idle. Both visible streams remained connected after the first company release. A colleague's mutation appeared on the idle reader without reload. The company released again, then the reader's own mutation completed, with exactly two mutation requests and two rows across both writes. A third idle release followed. The PR's hide/resume case separately verified that a held call settled exactly once.
  • Hidden suspension and document limits keep their existing behavior: passed. The full browser suite passed hidden suspension/resume, draft preservation, the ninth-document refusal and reopening after a slot is freed.

Golden journeys

  • Use a tier 2 tool: passed. On fresh Brightline data, Jordan and Allison opened New Business with its sample deals. Jordan moved Saltwater Hotels from Lead to Discovery; Allison's already-open board updated live. Moving it back updated both boards. Spend refused Jordan approving a request Jordan submitted, displaying “You can't approve your own request.”
  • Find and open a tool: passed. Jordan's Home listed the tools; searching for Kudos found it and opened its frame.
  • Use a tier 1 tool live: passed. Jordan gave Priya kudos and it appeared on Priya's already-open page without reload.

Evidence

pnpm verify
PASS  format                 11s
PASS  lint                   24s
PASS  typecheck              55s
PASS  synth                  2s
PASS  test                   122s
PASS  postgres-concurrency   16s
PASS  cli-smoke              110s
PASS  tier2-smoke            85s
PASS  browser                274s
All passed.
2019 offline tests passed; 28 Postgres tests passed; 81 browser tests passed.

Independent idle-reader browser check: 1 passed.
Fresh Brightline golden-journey flow: passed.

All exact-head CI checks also passed, including clerk-live and the three Node test jobs. The ownership races, activity landing across generation replacement, bounded-record cache and cross-host hold/admission tests passed in the offline suite.

Mirrored surfaces checked: API descriptions/docs, the limit registry/generated docs/server skill, analytics fields, runtime vocabulary, product/ADRs and operations. Reactivation supplies the reverse state; no CLI wire shape, migrations, company-resource policy, served-page layout or package layout changed.

Rollback answers: They match the diff. There are no migrations, infrastructure changes, changed durable row shapes or wire-schema changes. Activity is host memory. The older release ignores an override row for the new limit; its configuration loader rejects an unknown environment-configured limit, so remove execution.document.idle from PATCHY_LIMITS_JSON before reverting, as the PR says. No missing one-way label found.

Not run

Notes

  • This PR will be rebased once more after fix(infra): the load balancer keeps a browser on one host #798 merges, and that rebase only resolves a conflict in the generated docs/API.md. This verdict names the head checked above.
  • The first golden-flow capture stopped on my incorrect Home locator (New Business instead of the displayed new-business). After correcting the test locator, the complete fresh flow passed. No product failure was found.
  • All instances started by this run were taken down; tracked files remain unchanged.

allisonmahmood and others added 4 commits October 19, 2026 22:50
A connected tier 2 document now holds its company task and keeps its
version warm only while its viewer is active: its first stream, a change
to its logical desired set, or an admitted server.call from its viewer.
After execution.document.idle (10 minutes, per company) without activity
it lets both go, stays ready, and binds on demand for its next call or
live update. One warm-hold owner per document is fenced across stream
generations, and disconnected activity records live in a bounded cache.

Closes #800

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Address review of #802:

- A call's or set change's activity lands on the document's current
  connected generation, so a reauthentication replacing the stream
  between admission and activation no longer loses it; a document that
  disconnected meanwhile still keeps none. Barrier tests cover both
  handoffs.
- The idle browser case now shows the resumed call holds the company
  past execution.company.idle until the document's window passes, which
  fails without Runtime's call forwarding or the server's wiring.
- The disconnected-record bounds are module defaults (4096, one hour)
  that tests lower through a Context reference, not registry limits.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The owner race asserted a released company lock right after advancing
the test clock, while the release could still be finishing behind a
limits read, and failed on CI's Node 22 run. Each test now waits for the
fleet to reach the counts it expects, and the owner race checks the
replacement's stream event for no second hold.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The idle case checked the company 3 s after the resumed call's reply,
but the document's window starts at admission, so a slow reply could use
it up first. It now watches, from before the call, for the company's
activity lock, which only an active document's hold takes, and waits for
the release with a deadline instead of a fixed sleep.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@allisonmahmood
allisonmahmood force-pushed the fix/800-idle-tabs-let-go branch from 5683b26 to 99ac540 Compare October 19, 2026 20:52
@allisonmahmood
allisonmahmood merged commit 9e4b0df into main Oct 19, 2026
14 checks passed
@allisonmahmood
allisonmahmood deleted the fix/800-idle-tabs-let-go branch October 19, 2026 21:01
allisonmahmood added a commit that referenced this pull request Oct 19, 2026
…connection (#814)

Release 15's What's new entry, written from `9e4b0df`. It covers
everything merged since release 14's `through` (`7694bab`), and sets the
`patchy` release to `0.15.0` (`packages/patchy/package.json` and
`CURRENT_RELEASE`).

| Change | PRs |
| --- | --- |
| New: Your agent can read a tool's log | #786 |
| Fixed: Tools with server code keep one steady connection | #798 |
| Behind the scenes: an unused open tool lets its server rest | #802 |

#783 is release 14's own entry, so it's left out. #795, #796, #797,
#799, #803, #804, #806 and #807 are agent docs, CI and dev tooling, with
no line.

None of the PRs in the range are `one-way`; #786 and #798 predate the
rollback questions, and their diffs leave nothing an older release can't
run with (a new read-only route and CLI command, and the load balancer's
stickiness setting, which the older commit restores).

If this release misbehaves, roll back to `03891e4` (release 14).

Made by Claude Opus 5.5 via Claude Code.

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:ci CI, shared testing infrastructure, development scripts and tooling area:docs Touches the docs area area:server Touches the server area size:xl Over 1,000 changed lines; review in multiple passes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

An open tab nobody uses keeps its company's server running

1 participant