Skip to content

Chunk 59: a small bug-fix chunk after 0.50.0 (MCP sessions held, turn cost counted, transcript window, session list order, logout hand-over, gateway fields checked) - #1269

Merged
misterjohannesson merged 21 commits into
mainfrom
development-2026-11-28-2
Nov 28, 2026

Conversation

@misterjohannesson

Copy link
Copy Markdown
Contributor

What this chunk is. A small bug-fix chunk after 0.50.0: four entries from the known-defects issues, one performance item, and one defect the chunk's own code research found. One pull request per issue into this branch, each verified in its own body.

What changed.

  • A TUI's hand-over in flight during troupe logout no longer leaves the daemon holding the token (The daemon holds no plane token for a person who signed out while a hand-over was in flight #1259 closes A TUI's plane token hand-over in flight during troupe logout leaves the daemon holding the token #1245): the hand-over reads the sign-in again once the daemon has answered identity.link and, finding it gone, sends identity.sign_out itself, so whichever of the two ends last, the daemon holds no token for a person who signed out. The logout's wording is true in both orders. A test parks a hand-over at the token store and at its identity.get, runs the logout, lets it go, and sees the daemon's token nil; failing before. Left: a daemon-side refusal of a link after a sign-out would hold for every client but needs the daemon to remember signed-out tokens; named in the PR.
  • An MCP session is held for as long as its caller needs it and ended when it is done (The daemon keeps one MCP session per connection for mcp.tools and mcp.call, a stop waits once, and a person's renewed token drops their older session #1262 closes An MCP session is held for as long as its caller needs it and ended when it is done #1046; Decision 1126 narrowing 746 and 757): the daemon's mcp.tools and mcp.call keep one Troupe.MCP.Sessions per connection and workspace under a new Troupe.Gateway.MCPSessions, started on the first call and ended with its DELETEs when the connection closes or the server entry goes (mcp.add, mcp.remove, a hand edit caught on the next call); a stateless server and a call with no connection behave as before; the sensitive-session marking and refusal stay where they were. Ending a caller's sessions is one bounded wait, every DELETE sent at once and 1.5 s for them all instead of 3 s each eight at a time; a DELETE runs in a process killed when the wait is up, since Finch put a connection whose request timed out back in its pool still waiting on that answer and the next request lent it waited too (measured on the old code: 6.0 s to stop nine slow sessions, 3.0 s for the next request; now bounded, tests failing before). On a pod, a person-mode call carries whose credential it is (Troupe.MCP.Server.owner) and the session it opens drops the same person's older one from the table; the pod holds no credential to end it at the server, so the server's expiry does that, named in the decision. Filed A timed-out MCP request leaves its pooled connection waiting for the next request #1260 for the same pooled-connection shape on a tools/list or tools/call that runs past timeout_ms.
  • A turn's cost counts every call it made and its prompt prefix stays cacheable (A turn's cost counts every call it made, the plane's row follows it, and compacting stops when it no longer helps #1265 closes A turn's cost counts every call it made and its prompt prefix stays cacheable #1050): a summary that fails (refused, timed out, crashed) is written as the new event compaction_failed with reason, error, model, prompt_bytes and stopped, and everything that counts cost reads it (the agent's replay, Spend.of, Log.Fold, the ledger, the index's dormant totals, the live bench, Session.Summary, the TUI and the GUI client), so a session summary's totals agree with the listing; a new event rather than llm_error with a field, since the desktop and A2A read llm_error as the turn ending and this turn goes on. The worker's manager reports a plane row's cost when a turn's cost is folded, for any agent, coalesced to one report in five seconds (a subagent's calls reach the row while the root waits; failing before). compacted carries thinking_resent, thinking_dropped and prefix_mismatch for Bench.Prefix.count/1; a prompt still over the threshold right after a compaction holds compacting until a prompt is under it, told once as a config_note with key compaction, instead of compacting before every call forever; prompt_bytes.brief is the brief's size under the stable prompt. Schema regenerated (230 documents), PROTOCOL.md says what each carries. Decision 793 unchanged: on the fake, tools_changed is true once a turn at call 11 on a model that does not bind its thinking and never on one that does; the recordings show one change in 33 requests; the PR carries a proposal (offer the todo tools from call 1 on every model and refuse an early todo_write in the tool) for a later decision. Left and noted: Session.Checkpoint facts count no stopped spend; a normal turn's llm_error after a stream that reported usage is still not counted.
  • Anthropic's cache, output and beta fields reach the model through an Anthropic-speaking gateway (The Anthropic provider sends a gateway what it sends Anthropic, and the docs say what LiteLLM needs to pass it on #1263 closes Anthropic's cache, output and beta fields reach the model through an Anthropic-speaking gateway #1048): checked, nothing dropped on our side. A new core test points the provider at a stand-in gateway on a loopback socket in LiteLLM's two shapes (/v1/messages with a bearer key, /anthropic pass-through with x-api-key) and asserts the cache_control marks, output_config with adaptive thinking and block_binding, the signed thinking block and the anthropic-beta header reach the wire as the provider sends them to Anthropic; emptying the beta header made two of the four fail. Read from LiteLLM's source at its current main (lines quoted with permalinks in the PR): the pass-through forwards body and headers unchanged; /v1/messages copies anthropic-version and anthropic-beta to Anthropic, Bedrock and Vertex; Bedrock filters betas through its allow-list and puts the survivors in the body as anthropic_beta, the thinking-binding beta since v1.103.0; cache_control and output_config pass; metadata is not passed on, so the owner's user id never reaches Anthropic through a proxy. docs/admin/integrations.md §5 and the providers page say so, with the minimum LiteLLM version. No behaviour changed, no decision.
  • The desktop's transcript draws the turns near the reader (The desktop's transcript draws only the turns near the reader, so a long session that never compacted opens with some 660 elements, not 21,000 #1266 closes The desktop's transcript windows its entries, so a long session that never compacted does not draw 21,000 elements at once #1192; Decision 1125 narrowing 1095): a hand-written window over turns (window.ts, useTurnWindow): the last 30 turns before layout, then the turns within one screen above and below plus five each side, re-checked on scroll, resize and change; undrawn turns keep their room as two blocks sized by measured or average height so the scrollbar stays true; holdPlace looks inside a turn and skips the blocks; a line that arrives while the reader is far up draws the tail and scrolls to the foot; aria-live moved to a box holding the newest turn and the part under way. Measured on the 10,000-event fake session: 21,004 elements to 664 at open and 224 settled, longest main-thread block 1.47 s to 0.25 s, click to the last answer 2.0 s to 0.9 s; content-visibility: auto alone still built every element (1.0 s longest block), which is why the window. Four tests failing before; from-checkpoint and session-chat read through the window with new @troupe/test-support helpers (layOut, readThrough). Left: a very large turn is drawn whole; things opened inside a turn close when it leaves the window or stops being the newest; the console's shorter list stays whole; the desktop has no deep link to an entry and no find, so neither was tested.
  • The worker's proposal-run test installs the pod's whole artifact host first (The worker's proposal-run test sets up the pod's whole artifacts host, so its deny run always reaches the approval gate #1268): found by this branch's own root mix check (360/361): the test installed only a publish function, and in the umbrella's run the gateway suite ahead of it left a daemon's about in the VM, which called a Gateway.Plane that does not run in the worker suite, so the publish crashed before any decision was written; test only, 20 of 20 under load with the leak injected. Not the product's event order, and not A turn's cost counts every call it made, the plane's row follows it, and compacting stops when it no longer helps #1265.
  • The session listing is ordered by recency on the wire and a page's roles cost a constant number of queries (The session listing comes back most recently active first, and its roles are computed for the page at once #1264 closes The session listing is ordered by id, not by recency, and computes each row's role with its own queries #1261, found by this chunk's code research): visible_to/2 said distinct: s.id with order_by: [desc: s.last_active_at], which Ecto emits as DISTINCT ON (s.id) … ORDER BY s.id, so rows came back in id order and a limit kept the wrong page (the desktop re-sorts, which hid it); the ACL is now an exists subquery and the order is last_active_at descending with never-active last, then newest made, then id. Sessions.roles_for/2 computes a page's roles in one ACL query plus the memberships already fetched, the rules those of role_for/2 (a test asserts they agree across owner, team, invitation and hidden), used by session_rows/2 and so by every method that answers a row: a listing of 10 team sessions went from 57 queries to 16, of 2 from 17 to 16. No default limit: no client passes one; a page size is a visible rule for a later decision, named in the PR.

Verified on this branch's head (d711e6c, before #1268's one-file test change): root mix check (protocol 325, operator 193, plane 1609, core 2029/2041 with the known 12 rg-shim failures, gateway 441, worker 360/361 whole, the one being the proposal-run test's host leak that #1268 fixes, 361 after; daemon 32, a2a 53; credo 21559 no issues, format, boundaries ok), clients/tui mix check 988/998 whole (the 3 known bench and doctor --bench shim tests, and AgentsManagerTest and NewSessionScreenTest under load, 27/27 alone; credo 6463 no issues, format, xref, CLI reference current), GUI client 527 / console 409 / desktop 556 with 2 skipped, with build, tokens, icons and lines; decisions 649 in shape; schema 230 documents unchanged after regeneration; admin reference current; 58 files changed since origin/main and none adds a decision number to code; doc-size 766; doc-links 1171; locks agree 24; licences 931; mix hex.audit clean at root and TUI. Every pull request's own walk is in its body.

Before you upgrade a plane: no migration, no CRD change. Schema: one new event, compaction_failed; compacted gains thinking_resent, thinking_dropped, prefix_mismatch; config_note gains key: compaction. A client of the last release shows a failed compaction as nothing and counts its cost from the listing only. Behind a LiteLLM proxy older than v1.103.0, keep thinking_binding at default (the docs say so). Decisions 1125 and 1126 taken; markers unchanged.

Closes #1245, closes #1046, closes #1050, closes #1048, closes #1192, closes #1261.

  • Every commit is signed off (git commit -s, the DCO); the dco check fails otherwise.
  • The gate for what changed passes, and generated files are regenerated.
  • Dependencies changed: none.

misterjohannesson and others added 21 commits November 28, 2026 17:37
…on, and a stop waits once

Signed-off-by: Martin Johannesson <martin.johannesson@it-minds.dk>
…and-over was in flight

A TUI's hand-over reads the sign-in, then asks the daemon who it is and links it. A troupe logout that ran between those steps took the token back, and the link then gave it again. The hand-over now reads the sign-in once the daemon has the token and, finding it gone, sends identity.sign_out itself, so whichever ends last, the daemon holds none. Fixes #1245.

Signed-off-by: Martin Johannesson <martin.johannesson@it-minds.dk>
The daemon holds no plane token for a person who signed out while a hand-over was in flight
…connection is left waiting; Decision 1126

Signed-off-by: Martin Johannesson <martin.johannesson@it-minds.dk>
…ix/1046-mcp-sessions

Signed-off-by: Martin Johannesson <martin.johannesson@it-minds.dk>
The daemon keeps one MCP session per connection for mcp.tools and mcp.call, a stop waits once, and a person's renewed token drops their older session
…hropic

A loopback stand-in for LiteLLM's /v1/messages and /anthropic routes
asserts that the cache_control marks, adaptive thinking's output_config
and the thinking-binding anthropic-beta header reach the gateway as the
provider sends them direct. Nothing was dropped on Troupe's side.

The admin page says what LiteLLM does with them: the pass-through
forwards body and headers unchanged; /v1/messages carries the beta to
Bedrock as anthropic_beta, the thinking-binding beta from LiteLLM
v1.103.0, so an older proxy needs thinking_binding left at default; and
drop_params can drop output_config for a model it lists without effort.

Signed-off-by: Martin Johannesson <martin.johannesson@it-minds.dk>
Signed-off-by: Martin Johannesson <martin.johannesson@it-minds.dk>
… no longer helps

A summary that fails (refused, timed out, its stream crashed) is written as
compaction_failed, with the call as stopped, so a replay, the listing, the
ledger and the session's summary count it; Session.Summary.fold counts the
summariser's call on compacted and a stopped call on llm_error, cancelled and
compaction_failed, so its totals agree with the listing.

A pod reports what a session has cost as calls are folded, at most once every
five seconds, so the plane's row says a subagent's calls while its root waits.

compacted carries thinking_resent, thinking_dropped and prefix_mismatch, which
Bench.Prefix counts. A compaction that leaves the prompt over the threshold
holds compacting until a prompt is under it again, said in a
config_note when it starts to, rather than compacting before every call. prompt_bytes.brief is
the brief's size under a stable system prompt too, where it is part of the
conversation.

Refs #1050

Signed-off-by: Martin Johannesson <martin.johannesson@it-minds.dk>
The Anthropic provider sends a gateway what it sends Anthropic, and the docs say what LiteLLM needs to pass it on
…ome in one pass

visible_to/2 joined the ACL and needed distinct on the id, which Postgres sorts by before last_active_at: rows came back in id order and a limit kept the lowest ids. The ACL is now asked with exists, the order is last activity descending (never-active last, then newest made), and a limit keeps the most recent rows.

sessions.list computed each row's role with role_for/2, up to three queries a session. Sessions.roles_for/2 answers a page with one ACL query, the memberships once and the page's teams once, by role_for/2's rules; harness.ex's session_rows/2 uses it. A listing of 2 or 10 visible sessions now costs 16 queries either way (17 and 57 before).

Signed-off-by: Martin Johannesson <martin.johannesson@it-minds.dk>
…UI formats

Signed-off-by: Martin Johannesson <martin.johannesson@it-minds.dk>
…ix/1050-turn-cost

Signed-off-by: Martin Johannesson <martin.johannesson@it-minds.dk>
Credo's nesting depth: the owner, team and invited cases of roles_for/2 are function heads.

Signed-off-by: Martin Johannesson <martin.johannesson@it-minds.dk>
The session listing comes back most recently active first, and its roles are computed for the page at once
A session that never compacted, or one paged all the way back, drew every
turn in one render: about 21,000 elements for 10,000 events. The transcript
now draws the turns within a screen above and below what is on it, five
more either side, and keeps the room of the rest as a block above and one
below, so the scrollbar stays the whole session's. holdPlace keeps the
reader's place whenever the drawn turns change, and looks into a turn's
children now that a turn is a box-less .turn-group. New content draws the
tail again and scrolls there. aria-live moves to a box holding the newest
turn, what is under way and what is queued, so turns drawn by scrolling
are not read out.

@troupe/test-support gains layOut and readThrough: jsdom lays nothing out,
so a test that reads a whole transcript scrolls through a laid-out screen.

Decision 1125 narrows 1095. Closes #1192.

Signed-off-by: Martin Johannesson <martin.johannesson@it-minds.dk>
Signed-off-by: Martin Johannesson <martin.johannesson@it-minds.dk>
A turn's cost counts every call it made, the plane's row follows it, and compacting stops when it no longer helps
The desktop's transcript draws only the turns near the reader, so a long session that never compacted opens with some 660 elements, not 21,000
Its setup installed only the publish function, so the gate's question to the host about a new version went to whatever host the VM held. In the umbrella's run that was the daemon's, left by the gateway suite, whose about/2 calls Troupe.Gateway.Plane; no such process runs in the worker suite, so the publish call's task crashed before it reached the approval gate, and the deny test saw a turn_ended with no approval_decided. The setup now installs the pod's host first and lays the test's publish over it.

Signed-off-by: Martin Johannesson <martin.johannesson@it-minds.dk>
The worker's proposal-run test sets up the pod's whole artifacts host, so its deny run always reaches the approval gate
@misterjohannesson misterjohannesson mentioned this pull request Nov 28, 2026
2 of 3 tasks
@misterjohannesson
misterjohannesson added this pull request to the merge queue Nov 28, 2026
Merged via the queue into main with commit 8377ffe Nov 28, 2026
43 checks passed
@misterjohannesson
misterjohannesson deleted the development-2026-11-28-2 branch November 28, 2026 19:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment