Repository navigation
feat(workspace): an unread reply shows on the agent's row and in the tab title (ent#557) - #2648
Conversation
…tab title (ent#557) An agent replied while the operator was elsewhere and nothing indicated it. Most of the machinery already existed — the per-agent pill, the per-chat badge, the aggregate in the wordmark. Three things were missing. **1. A chat you have never opened could not be unread.** ent#359 defined unread relative to a read cursor and gave a cursorless thread a count of nothing, correctly: inventing a cursor at the beginning of time would have badged every historical conversation in every install on the day it shipped. What it could not foresee is ent#523, which made Main the landing place for everything an AGENT starts. A freshly minted Main has never been read by anyone, so the one case an unread badge exists for produced no badge anywhere. A cursorless thread now counts agent messages newer than the viewer's account baseline — "anything an agent has said to you since the first time you read anything here, in a chat you have never opened". The baseline is a STORED, write-once row, not a derived value, and that is the whole of the design. Both obvious derivations were tried and both fail the same test: * MAX(last_read_at) — "since you were last here" — advances every time the viewer reads anything, so an unread reply in a chat they have not opened is silently cleared by reading a DIFFERENT chat. * MIN(last_read_at) — "since the first time you read anything" — looks stable and is not: `mark_chat_read` UPDATES the row it advances, so a viewer with one chat has MIN == MAX and inherits the identical bug. MIN was implemented first and `test_reading_one_chat_does_not_silently_clear_ another` failed it, which is why the row exists. It lives in the chat-state table under a reserved kind, written on the first ever read and never moved; every read of that table excludes it, so it reaches neither the sidebar payload nor either row cap. A viewer with no baseline still counts nothing — ent#359's property preserved, and it falls out of SQL's NULL comparison rather than a second branch. **2. It only appeared when you did something.** `refreshThreads()` is event-driven — a send, a navigation, a turn finishing — so an agent-initiated reply reached the sidebar on the viewer's next action and not before, which is the same as never for someone in another tab. It now also runs on the ent#364 asks poll (20s, visibility-aware). Folded into that timer rather than given its own: the Workspace has no WebSocket a portal client is on, and since #2198 the thread half is ONE request for every agent, which is what makes it cheap enough to ride there. **3. The tab said nothing.** While anything is unread the title carries `(3) Trinity — Workspace`, returning to the plain title when everything is read and cleared when the Workspace unmounts. `utils/tabTitle.js` owns it because `document.title` now has two writers on independent schedules — the router's label and the count — and with both assigning directly the last to fire would erase the other's half. Neither assigns; both call in. The count is a PREFIX on whatever the router computed, which is what lets ent#556 change the label without touching any of this, and it leads rather than trails because browsers truncate a tab from the right. Reading clears it with no reload: `markRead` already cleared optimistically and re-decorated `threads`, so the total recomputes synchronously and the tab follows. Asks and unread stay separate (#2424) — this adds nothing that sums them. Tests: `test_ent557_unread_never_opened_chat.py` (12, against a real sqlite so the SQL is the code under test), `portalUnreadTabTitle.spec.js` (14, the format executed and the two-writer ordering), `portalUnreadLiveness.spec.js` (10). Backend portal slice 587 passed; frontend 114 files / 2539 tests; ratchets green; build clean. OSS-core, deliberately ungated, per the standing Workspace ruling restated in the issue. Related to Abilityai/trinity-enterprise#557 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01Bd71qsYbFodvofba8P69eP
|
merge-train 2026-09-09: not on this train. The feature does not reach the API — verified end to end.
The loop iterates Net effect: the reported case — an agent replies into a freshly minted Main the viewer has never opened — still produces no badge, no per-agent pill, no wordmark total, no tab-title marker. AC 1 and AC 2 are not delivered. The case the change does reach is starred but never opened, which is not the reported bug. The comment at Also worth fixing while it is open: no test crosses the db→service boundary (all 12 call The stored-baseline design, the SQL and the two-writer tab title are all sound — this is one layer short of working. Rides the next train once the service layer emits the cursorless sessions. |
…QL (ent#557) `count_unread_by_session` was widened to LEFT JOIN and count a never-opened thread against the account baseline — and `service.get_chat_state` then discarded every one of those rows. It built the payload by iterating the viewer's state ROWS and reading the unread map off them, so a thread with no cursor (the entire ent#557 case: an agent replies into a freshly minted Main nobody has opened) never appeared. No badge, no per-agent pill, no wordmark total, no tab title. AC 1 and AC 2 were undelivered; the only case the change did reach was "starred but never opened", which is not the reported bug. The service now runs a second pass over the unread map and emits the thread ids the row loop did not, de-duplicated against them so one chat cannot be counted twice in the wordmark total, and `starred: false` by construction. It is bounded by the same read — `count_unread_by_session` is scoped to the caller's own `enterprise_portal_messages`, so it cannot append a chat that is not theirs. The comment where the fallback used to be argued against restoring it by citing the INNER JOIN and the `last_read_at IS NOT NULL` filter — both of which this same PR removed. It read as protection that exists and would have stopped the next reader from putting the pass back (the ent#523 entry in `learnings.md`). Replaced with what is actually true now. Tests: five cases crossing the db→service boundary, which is the boundary all twelve existing tests skip by calling `client_portal.db` directly — which is why this was invisible. `test_the_api_reports_a_chat_that_has_no_state_row` fails against the pre-fix service and passes after. Related to Abilityai/trinity-enterprise#557 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01RSjVEjay9ztC1oDXXkh9uN
|
Fixed in
The comment at Tests now cross the db→service boundary. Five cases in a new section of
|
|
Re-review after the fix. No blockers. Two observations, both recorded rather than objected to. Re-read clean: the second pass in 1. The payload is no longer bounded by 2. Both are for a follow-up at most. The delivery half is correct now and the db→service tests are the right place to have put the proof. |
…y clear (ent#557) Found re-reviewing my own fix. Emitting cursorless threads was the right correction; it interacts badly with a cap I did not check. `service.mark_chat_read` silently no-ops when the row would be a NEW one and the viewer is at `MAX_CHAT_STATE_ROWS` (1000) — deliberately, on the stated ground that "a read marker is incidental to what the user asked for (opening a chat)". A cursorless thread is by definition a new row. So ent#557 made that no-op load-bearing. Before it, a cursorless thread produced no badge and the no-op was invisible, which is what made the justification true. After it, a capped viewer gets a badge on the wordmark total, the per-agent pill AND the browser tab title, and opening the chat cannot dismiss it — a permanent unread marker with no user action that clears it. The second pass is now gated on there being room. Not shown beats shown-and-stuck: a capped viewer degrades to exactly the ent#359 behaviour, which is the state they were in before this feature, rather than to a badge that never goes away. Three properties, each deliberate: * the gate applies to the CURSORLESS pass only. A thread that already has a row can always be marked read (`_would_create_row_past_cap` allows updating a row the caller already owns), so capping its badge would hide unread the viewer can perfectly well clear; * it fails OPEN — an unreadable count reports room, because refusing to show unread on a COUNT that could not be taken would hide real unread from every viewer on a transient DB error, and the write path is what enforces the cap; * the COUNT is paid only when the pass would emit something, i.e. never on the ordinary sidebar load where every thread already has a row. Asserted, so it stays true. Tests: the capped viewer (badge withheld, and the no-op demonstrated rather than assumed — `mark_chat_read` is called and the count does not move), the room-left case clearing to zero, a row-bearing thread still badging AT the cap, the fail-open path, and the no-COUNT-on-ordinary-load cost note. Removing the gate reds the first. 527 passed across portal / chat-state. Related to Abilityai/trinity-enterprise#557 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01RSjVEjay9ztC1oDXXkh9uN
|
Deeper self re-review — found a regression my own fix introduced. Fixed in Emitting the cursorless threads was the right correction. It interacts badly with a cap I did not check.
if _would_create_row_past_cap(email, kind, cid):
# Silently no-op rather than erroring: a read marker is incidental to
# what the user asked for (opening a chat) …
returnA cursorless thread is, by definition, a new row. So ent#557 made that no-op load-bearing. Before it, a cursorless thread produced no badge and the no-op was invisible — which is exactly what made its justification true. After it, a capped viewer gets a badge on the wordmark total, the per-agent pill and the browser tab title, and opening the chat cannot dismiss it. A permanent unread marker with no user action that clears it, which is a worse experience than the bug this PR fixes. Demonstrated rather than reasoned: the test calls The second pass is now gated on there being room. Not shown beats shown-and-stuck — a capped viewer degrades to exactly the ent#359 behaviour, which is the state they were in before this feature, rather than to a badge that never goes away. Three properties, each deliberate and each tested:
Removing the gate reds the capped-viewer case.
|
…2648) merge-train: mechanical, per the merge-train note on the PR. The two feature flows were updated but the requirements entry still stated the ent#359 rule this PR inverts for cursorless threads (RoE #1). Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
merge-train 2026-09-10 (evening run): riding. Both 09-09 findings re-verified by execution, not by the description: the cursorless thread reaches Two mechanical things pushed to your branch, both announced here so they are not a mystery commit:
The body's Non-blocking, for your judgement later: the tab total sums |
An agent replied while the operator was elsewhere and nothing indicated it.
Most of the machinery already existed — the per-agent pill, the per-chat badge, the aggregate in the wordmark. Three things were missing, and the first one is the interesting one.
1. A chat you have never opened could not be unread
ent#359 defined unread relative to a read cursor and gave a cursorless thread a count of nothing — correctly: inventing a cursor at the beginning of time would have badged every historical conversation in every install on the day it shipped.
What it could not foresee is ent#523, which made Main the landing place for everything an agent starts — agent-initiated messages, asks raised outside a chat, scheduled briefs all resolve to it. A freshly minted Main has never been read by anyone, so the one case an unread badge exists for produced no badge anywhere.
A cursorless thread now counts agent messages newer than the viewer's account baseline: anything an agent has said to you since the first time you read anything here, in a chat you have never opened.
The baseline is stored, not derived — and that is the whole design
Both obvious derivations were tried and both fail the same test, because both move:
MAX(last_read_at)MIN(last_read_at)mark_chat_readUPDATES the row it advances, so a viewer with one chat has MIN == MAX and inherits the identical bug.MIN was implemented first.
test_reading_one_chat_does_not_silently_clear_anotherfailed it — which is why the stored row exists, and why that test is the centre of this PR rather than a footnote. Trading "no badge" for "a badge that another chat can silently clear" would have been a worse bug than the one reported.The baseline is a row in the chat-state table under a reserved kind, written on the viewer's first ever
mark_chat_readand never moved. Every read of that table excludes it, so it reaches neither the sidebar payload (as a phantom chat) nor either row cap. A viewer with no baseline still counts nothing — ent#359's property preserved rather than traded away, and it falls out of SQL's NULL comparison rather than a second branch.2. It only appeared when you did something
refreshThreads()is event-driven — a send, a navigation, a turn finishing — so an agent-initiated reply reached the sidebar on the viewer's next action and not before, which is the same as never for someone in another tab. It now also runs on the ent#364 asks poll (20 s, visibility-aware).Folded into that timer rather than given its own: the Workspace has no WebSocket a portal client is on (
operator_queue_newis broadcast on the platform/ws), and a second cadence for one badge is a second thing to reason about. Since #2198 the thread half is one request for every agent rather than one per agent, which is what makes it cheap enough to ride there.3. The tab said nothing
While anything is unread the title carries a compact prefix, returning to the plain title once everything is read and cleared when the Workspace unmounts — a count that outlives the surface leaves a tab reading
(3)on a page with nothing to click.utils/tabTitle.jsowns the string becausedocument.titlenow has two writers on independent schedules — the router's label (#1418) and the count. With both assigning directly, the last to fire erases the other's half: a navigation drops the count, a count update drops the label. Neither assigns now; both call in and the module renders the whole string. The count is a prefix on whatever the router computed, which is what lets ent#556 change the label without touching any of this, and it leads rather than trails because browsers truncate a tab from the right — a suffix would be the first thing to disappear on the tab that most needs it.Acceptance criteria
markReadalready cleared optimistically and re-decoratedthreads, so the total recomputes synchronously and the tab follows with no reload.totalUnread(threads)the sidebar does, so every unit is a row the user can click;99+caps; zero renders nothing.The one AC I could not complete
AC 7 asks for screenshots of the sidebar row and the tab title in light and dark at 1 / several / 99+, reviewed against the design system. I have no browser and the local stack is down; rendering the Workspace needs a live backend plus a signed-in portal session with unread state. I have not faked it.
What I can give without a browser — the exact strings, from the shipped pure function:
The marker survives truncation at every count, which is the legibility half of that AC.
On the row half: this PR changes no sidebar markup at all. The badge, its cap and its token were already there (#2424 / ent#359); ent#557 only makes the number non-zero in a case where it was always zero. So "must not crowd the status chip or reflow it" is a property of markup already on
dev. Worth knowing while reviewing: #2641 touches that same row — it stops the always-reserved 72px availability slot charging every row, which gives the badges more room, not less. No conflict, but they are best looked at together.Verification
tests/unit/test_ent557_unread_never_opened_chat.py— 12 passed, against a throwaway sqlite carrying the real tables, so the SQL is the code under test rather than a mock: the agent-started Main case, a first-ever sign-in still counting nothing, a pre-baseline chat not retroactively unread, reading one chat not clearing another, the baseline frozen at the first read, the baseline row invisible to the sidebar and both caps, and cross-viewer isolation of the baseline subquery.portalUnreadTabTitle.spec.js— 14 passed. The format is executed (prefix, cap, zero, non-numeric input, empty base) and the two-writer ordering is driven through the module's own API.portalUnreadLiveness.spec.js— 10 passed.vite buildclean.Scope
OSS-core, deliberately ungated, per the standing Workspace ruling restated in the issue — so the code lands in the public repo with no
requires_entitlementand no gated Vue.Fixes abilityai/trinity-enterprise#557
🤖 Generated with Claude Code
https://claude.ai/code/session_01Bd71qsYbFodvofba8P69eP