#1176·honcho

`tokens` does not bound the representation in `get_context`, and the summary is starved as a result

Author: milojarowCreated Sep 14, 2026Updated Sep 22, 2026
Labelsqualityhonchomaintainer-approved

Summary

The tokens parameter on GET /v3/workspaces/{ws}/sessions/{id}/context does not bound the peer representation at all, and requesting a representation suppresses the session summary entirely. Two experiments below, each isolating one variable.

Measured on one self-hosted deployment (v3.1.1, 5d992bc) from two independent clients on separate machines. Both clients target the same API instance; what is independent is the client side — different hosts, different harnesses, different corpora.

Experiment 1 — tokens has no effect on the representation

Scope general, one session, measured 07:36:59Z. Same peer_target throughout. The only thing that changes is tokens:

tokens representation sha256
100 13,807 chars 07dcb89c6b8d
500 13,807 07dcb89c6b8d
1500 13,807 07dcb89c6b8d
5000 13,807 07dcb89c6b8d
20000 13,807 07dcb89c6b8d
omitted 13,807 07dcb89c6b8d

Six values spanning two orders of magnitude, plus omitting the parameter: byte-identical every time. The other client ran the same sweep on its own machine and got the same result — one constant across all six.

The control that makes this meaningful is that the endpoint does respond to a parameter — just not this one, same scope, same minute:

representation sha256
max_conclusions=25 4,162 chars 0497e79c6894
max_conclusions=100 13,807 07dcb89c6b8d

So this is not a harness sending the same request six times. tokens is inert for this block; max_conclusions (Query default None, coalescing to 100) is what bounds it.

Experiment 2 — asking for a representation removes the summary

Pick a session that has a stored summary (see the threshold note below — most do not). Same request twice, changing only peer_target:

GET .../sessions/{id}/context?tokens=1500
    -> summary present (1,570–2,498 chars), no representation

GET .../sessions/{id}/context?tokens=1500&peer_target={peer}&scope={scope}
    -> summary null, representation 11,199–12,425 chars

Eight sessions, eight for eight, four from each client on two machines. The summary is not missing and it is not too large: it is dropped as soon as a representation is requested.

peer_target is required to see this. Without it the handler takes a different path, no representation is fetched, and tokens behaves as documented — which is why the bare URL does not reproduce.

What the parameter promises

src/routers/sessions.py:695:

"Number of tokens to use for the context. Includes summary if set to true. Includes representation and peer card if they are included in the response."

The line that ties the two together

src/routers/sessions.py:981:

python
adjusted_limit = (
    token_limit - estimate_tokens(str(representation)) - estimate_tokens(card)
)

The representation is fetched first — unbounded by token_limit, per experiment 1 — and then subtracted whole. What remains is the budget for the summary and the conversational messages: the summary may take up to 40% of it, and the messages take whatever is left. When the remainder is ≤ 0, _select_summary_for_context returns no summary and a message budget of zero, so both come back empty. That is experiment 2.

We are not claiming that allocation is wrong. We are claiming that the one block which consumes the budget is the one block exempt from it, and that this contradicts the parameter's own description.

What the representation size does track

Nine scopes, sampled 06:36Z within ~two minutes of each other. A and B are the two clients.

scope client representation
miraflores-api B 17,184 chars
jungla-inmobiliaria B 15,900
Honcho B 14,346
host infrastructure B 13,681
muebleria-miraflores A 13,622
abp-ingenieria-beltran A 12,917
clinic-beauty-spa A and B 12,836
general A and B 11,635
hos-truck-app A 727

miraflores-api and muebleria-miraflores are two distinct scopes of the same customer, measured from different clients — not a duplicate row. clinic-beauty-spa and general are single objects visible to both clients; read from the two machines 47 seconds apart, both returned sha256-identical text, which is how we know the two measurement paths agree.

Size tracks how many conclusions the scope holds, against that cap of 100 — hos-truck-app is nearly empty and returns 727 chars. It also moves on its own: general measured 12,670 → 12,599 → 12,423 → 11,635 → 11,980 → 12,579 → 12,816 → 13,807 chars over one morning with no config change. The row in the table above is the 06:36Z reading; experiment 1 is the same scope an hour later, which is why the two differ. On one active session the 100-conclusion window covered just 37 minutes of history. None of this is reachable through tokens.

The production effect, and its limit as evidence

Across 1,206 context injections recorded by client A and 1,374 by client B — 2,580 in total — the summary block appeared 0 times.

That count is weaker than it looks and we would rather say so than have it found. Honcho only generates a short summary once a session reaches MESSAGES_PER_SHORT_SUMMARY (default 20). Across both clients, 783 of 828 sessions never reached it. The split is exact and we checked it separately on each machine: every session with a stored summary has ≥ 20 messages, every session without has ≤ 19, no overlap on either side. Most of those injections had nothing to summarise in the first place. The count is the effect we live with; the evidence is experiment 2.

Why it matters to clients

A caller cannot ask for a bounded context. Whatever tokens is set to, the representation arrives at whatever size the scope has reached, and the summary is gone. Our client re-bounds the assembled block at 6,000 characters — that truncation is ours, not the API's, and it costs us the later sections of the merged markdown. We are not claiming the API returns stale rows: created_at.desc() means it already keeps the newest.

What would fix it, in our reading

Apply the budget to the representation itself — cap max_conclusions against token_limit, or truncate the representation to the remaining budget — rather than subtracting its full size afterwards. Either makes tokens mean what its description already says, and the summary starts fitting on its own.

Happy to supply the raw measurements or test against a patch.