Dashboard and service memory: implementation plan

Branch jack_20261126_dashboard_memory. Plan for subagent-driven development: one implementer and one reviewer per task, in order.

Goal

A dashboard tab that stays open for a week keeps the memory of a fresh tab. A broadcast with no change does no DOM work. One tab holds one WebSocket. Large analytics answers do not stop the event loop. The service can report where its memory goes, to loopback callers only.

Evidence (measured 2026-11-26)

Global constraints

Review focus

  1. A real change (a new session, an ended session, a resurrected session, an account added or removed, a usage update, a credential scope change) still reaches an open page with no reload.
  2. A session that passes the page's own staleness setting leaves the view at that time, with no server message and no poll.
  3. The open account menu, an expanded account, the OAuth banner and typed text survive every update path.
  4. A page that loses its socket and gets it back holds exactly one socket, and the server count of clients matches the number of tabs.
  5. Each page looks the same after the Tailwind move, in both themes, at desktop and mobile size, with menus, modals and banners open, including classes that JS builds at run time.
  6. A socket that hangs while it connects, or that stays open on a dead path, is replaced; the page never freezes on an open but silent socket.

Task 1: one live WebSocket per page

Files: modify jacked/data/web/js/websocket.js; test tests/unit/test_web_js_websocket_single_socket.py.

Task 2: the server sends sessions_changed for each visible change, and not on a timer

Files: modify jacked/api/watchers.py (session_accounts_watch_loop and the sweeper's broadcast); create jacked/api/session_diff.py (a pure diff function); test tests/unit/test_session_watcher_broadcast.py.

Task 3: each value the page shows has a push event, and the poll runs only while the socket is closed

Files: modify jacked/api/watchers.py, jacked/api/main.py (start the new loops), jacked/api/routes/settings_remote.py, the identity watcher, jacked/data/web/js/websocket.js, jacked/data/web/js/app.js; test tests/unit/test_dashboard_push_events.py, tests/unit/test_web_js_push_inventory.py.

The inventory. Each row is one value the poll at app.js:378 catches today. The implementer confirms each writer by reading the code and adds any row it finds.

ValueWritersEventPage action
Sessionshooks, the sweeper, reassignsessions_changed (Task 2)refetch session states
Accounts list and fieldsroutes, the CLI, other jacked processesnew accounts_changed from an accounts-table data_version watcher (same pattern as logs_watch_loop)refetch accounts
Usageusage loopsusage_updated (exists)patch the card in place (exists)
Active credential identityClaude Code /login, the CLI, other processescredentials_changed sent by the identity watcher or the active poll loop when the identity changes; the client handler at websocket.js:216 exists and no server code sends it todayrefetch the active credential
Remote-access scope and allow_credential_activationPUT /remote-access (settings_remote.py:129-139)new remote_access_changed; it carries no value, because the answer depends on each client's addressrefetch /api/auth/active-credential
Swap historythe swap write pathname the event that the write sends, or add onereload the swap log only, no view rebuild
Decision logthe decision writerdecision_log_entry (exists)re-render the log (exists)

Task 4: the Accounts view does DOM work only when what it shows changes

Files: modify jacked/data/web/js/app.js, jacked/data/web/js/components/accounts.js, sessions.js, usage.js, account-actions.js; test tests/unit/test_web_js_accounts_rerender_gate.py.

Task 5: prebuilt Tailwind CSS replaces the Play runtime

Files: create scripts/build_css.sh, jacked/data/web/tailwind.config.js, jacked/data/web/css/tailwind.css (generated, committed); modify jacked/data/web/index.html, jacked/data/web/js/vendor/LICENSES.md, tests/unit/test_web_vendor_scripts.py; delete jacked/data/web/js/vendor/tailwindcss-3.4.17.js; test tests/unit/test_web_tailwind_build.py.

Task 6: large JSON answers are encoded off the event loop

Files: create jacked/api/threaded_json.py; modify jacked/api/routes/analytics.py and each other route whose answer grows with stored data, sync and async (the sweep includes logs.py:15, auth.py:1076, the session states and the swap log); test tests/unit/test_threaded_json.py.

Task 7: moved to the stacked pull request

Ruling (2026-11-28, split). Task 7 (the memory report, the loop switches and the one local-request rule) and Task 7b (the raw TCP forward lock) are now the branch jack_20261128_local_request_rule. That branch is stacked on this one. Five fix rounds of Task 7b each found new defects that the branch introduced, so by the owner's review rule the work leaves this pull request. The cut is before Task 7, because the Task 7 debug routes (with the loop-switch writes) are safe only with the raw TCP forward lock beside them.

Task 7a: the test environment scrub

Files: create tests/secret_env.py and tests/unit/test_secret_env.py; modify conftest.py and tests/conftest.py.

Task 7c: the JavaScript module size ratchet

Files: modify tests/unit/test_module_size_ratchet.py (or a sibling test that reuses its helpers); split the JavaScript files that this branch grew past 500 lines.

Task 7d: no new table header leaks a media query

Root cause (measured 2026-11-28). Chrome 158's user-agent stylesheet has thead, tfoot { break-inside: if(media(overflow-block: paged): avoid;) }. For each new <thead> or <tfoot>, the style engine keeps one more functional media-query set in a strongly keyed map, and never removes it. The page makes a new <thead> each time it rebuilds a table, for example the decision log on each decision_log_entry. Each kept set is a few small Blink heap objects. With the other render work in between, each set holds a heap page that is otherwise empty, and the Blink heap does not compact those pages. The soak shows 1,265 kept sets and about 22 KB of heap per simulated minute. A soak without the decision log drops to 4.7 KB per minute. microsoft/vscode #337444i shows the same pattern, tracked upstream as Chromium issue 578309740.

Files: modify jacked/data/web/css/style.css; test in a tests/unit/test_web_*.py file of its concern.

Task 7e: the decision log does DOM work only when what it shows changes

Measured (2026-11-28). The A/B soak proves that the Task 7d rule stops the Blink heap growth (fix arm flat after cycle 500, frozen and varied). But renderDecisionLog (js/components/auto-swap.js:494-518) still rewrites the whole container on each decision_log_entry: about 6,000 identical rewrites of about 50 KB of markup per simulated week, because most entries are checks that the default "swaps only" view does not show. Each rewrite also closes a detail row that the user opened, so an open row closes within a minute while nothing on the screen changed.

Files: modify jacked/data/web/js/components/auto-swap.js; test in a tests/unit/test_web_js_*.py file of its concern, in node.

Task 8: live proof, gate, review, PR


Generated with the jacked HTML artifact template. Edit freely.