You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 90699c1
Browse filesBrowse the repository at this point in the historyBrowse files
fix(*): keep the context window breakdown across a resume (#1340)
## Summary
The context card's breakdown (the system prompt, tools, session, files,
memory and skills shares of the window) was measured on every model call
and sent on the live `message.complete`, but never stored. A page that
resumed a conversation therefore drew the fill and said the breakdown
would appear after the next turn. A gateway restart forces exactly that
reload, so the analysis disappeared until another turn finished.
The measured parts now ride with the window reading on the reply that
produced it: `_context_parts` is stamped on the same row as
`_context_used`, renamed to `context_parts` on save, and read back by
`session.resume` from the newest reading-carrying row. `SessionUsage`
and `SessionUsageResult` declare the field as optional, and both
generated clients were regenerated. The web client needed no change: it
already passed `usage.context_parts` through to the card.
Key decisions:
- The breakdown is only taken from the row whose reading was accepted;
an older breakdown is never paired with a newer fill.
- Stored counts are sanitized on read: only the six known parts, only
non-negative integers a context window can hold. The session file is
editable, and a bad value must not reach the card.
- The field is optional end to end. Conversations written before this
change have no breakdown to return; they keep the existing hint until
one new turn records one. There is no honest way to reconstruct it from
the stored log, which is not the prompt the model was sent.
- A failed or cancelled turn files its newest breakdown on the closing
marker, next to the reading it already carried.
## Type
- [x] Fix
- [ ] Feature
- [ ] Docs
- [ ] CI / tooling
- [ ] Refactor
- [ ] Other
## Verification
- [x] Relevant tests pass locally
- [x] Relevant lint / type checks pass locally
- [ ] User-facing docs or screenshots are updated when needed
```
uv run --frozen --all-extras pytest -q tests/test_rpc_session.py tests/test_agent_loop_usage_sink.py -> 281 passed
uv run --frozen --all-extras pytest -q tests/test_agent_loop_*.py tests/test_session_*.py -> 1812 passed
uv run --frozen --all-extras pytest -q tests/test_rpc_schema_match.py tests/test_rpc_registration.py tests/test_rpc_session.py -> 789 passed
uv run --frozen --all-extras pytest -q tests/test_agent_loop_empty_recovery.py tests/test_agent_loop_stream.py tests/test_agent_loop_usage_sink.py tests/test_rpc_session.py -> 811 passed
ruff check, ruff format --check and ty check on the changed Python modules -> pass
npm run gen:check --prefix ui-web and npm run lint:rpc --prefix ui-tui -> both generated clients match the contract
npm run type-check in ui-web and ui-tui -> pass
npm run lint in ui-web and ui-tui -> 0 errors (pre-existing warnings only)
scripts/check_source_language.py and scripts/check_large_files.py over the change -> pass
npm test -- scripts/gates/fixture-shape.test.mjs (ui-web) -> 5 passed
```
No user-facing docs or screenshots change: the card's labels and its
empty-state sentence are untouched. The full ui-web suite was also run
under concurrent load; 31-40 tests in unrelated files timed out, none
referencing this field, and the same files pass 62/62 when rerun in
isolation.
## Risk
- [x] Security impact considered
- [x] Backward compatibility considered
- [x] Rollback path is clear for risky changes
Stored breakdowns come from an editable session file, so the resume
reader keeps only the six known parts with non-negative integer values
that fit in a window. Old transcripts have no breakdown and show the
existing hint until a new turn records one. Reverting the change leaves
the extra JSONL key inert to the prior reader and the optional wire
field unused.
## Related Issues
N/A
Copy file name to clipboardExpand all lines: rpc-schema/openrpc.json
+20Lines changed: 20 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -8576,6 +8576,16 @@
8576
8576
"context_estimated": {
8577
8577
"type": "boolean",
8578
8578
"description": "True when context_used is a tiktoken estimate."
8579
+
},
8580
+
"context_parts": {
8581
+
"type": [
8582
+
"object",
8583
+
"null"
8584
+
],
8585
+
"additionalProperties": {
8586
+
"type": "integer"
8587
+
},
8588
+
"description": "The window divided: tokens by part, keyed system / tools / conversation / files / memory / skills, as the last measured turn recorded them. Absent when that turn measured none, or the conversation predates the record."
8579
8589
}
8580
8590
}
8581
8591
}
@@ -13248,6 +13258,16 @@
13248
13258
"context_estimated": {
13249
13259
"type": "boolean",
13250
13260
"description": "True when context_used is a tiktoken estimate of a resumed transcript, not a measurement."
13261
+
},
13262
+
"context_parts": {
13263
+
"type": [
13264
+
"object",
13265
+
"null"
13266
+
],
13267
+
"additionalProperties": {
13268
+
"type": "integer"
13269
+
},
13270
+
"description": "The window divided: tokens by part, keyed system / tools / conversation / files / memory / skills, as the last measured turn recorded them. Absent when that turn measured none, or the conversation predates the record."
0 commit comments