Repository navigation
feat(qwen): report native context after root turns - #927
Conversation
8e72dca to
28409df
Compare
|
New failure in post-merge full tests: workflow Newly failing:
Please fix. See logs: |
|
Fixed in #930, approved and waiting for CI. Qwen's independent managed-memory extraction can overlap the context readback window. A fresh native reproduction captured that request; a no-context-query control still made the same memory calls. The test now disables memory extraction only in its isolated fixture, keeps zero calls during each query, and requires exactly three provider requests after all three root turns and process shutdown. Failure artifacts retain both sessions and provider bodies. Product behavior is unchanged.
|
<!-- stamp:review:v1 --> <sup><img src="https://api.raft.build/api/avatars/pixel/bXVn.svg" width="16" height="16" align="absmiddle" alt=""> <b>Cindy</b> from open-agent-runtime opened this pull request through Stamp</sup><br><sup><a href="https://stamp.build/review?receipt=prc_b8936a7a3676f7ba6a8c17eabd41e91f"><picture><source media="(prefers-color-scheme: dark)" srcset="https://stamp.build/assets/brand/stamp-glyph-dark.d907ffcadb44.svg"><img src="https://stamp.build/assets/brand/stamp-glyph-light.58a2c10ed108.svg" width="13" height="12" align="absmiddle" alt=""></picture> View in Stamp →</a></sup> --- <!-- /stamp:review:v1 --> Cursor and Qwen sessions now report how full the current context is, through `usage.context` and `Session.contextUsage()`, from each runtime's own count. ## Cursor: current context from the last model call (#926), feature Cursor SDK 1.4.1 reports each completed model call's full input count, cache included (`model-call-completed.usage.inputTokens`). OAR now projects that count into `usage.context.tokens`; each call replaces the previous reading rather than adding to it. The SDK reports no context window, so `contextWindow` and `percent` stay null. A completed native summary clears the reading until the next model call supplies one. Whole-turn spend is unchanged: in the retained native sample, the last call's input was 13,595 tokens while the turn spent 27,060. ## Qwen: current context after each turn (#927), feature After each non-aborted root turn, OAR asks Qwen for its own `get_context_usage` and records the last prompt's token count and the context window before `turn_ended` and before any queued input is sent. Counts Qwen marks as estimated stay unknown, including the zero it reports before the first prompt. OAR never derives occupancy from cumulative input. If the query fails, times out (1 second) or the runtime lacks it, the turn still ends normally and the last known reading stays, so the value can lag one turn. Native controls on Qwen 0.28.0 and the CI-pinned 0.27.4 measured 2 to 15 ms per query and no extra provider requests. Qoder's context stays unknown until retained native usage frames show what it reports. ## Also - The shared stream-json driver gains optional readbacks that run after a root result and before the turn is settled; replies stay consumable, and exit, disposal or timeout cannot leave a turn unsettled (#927). - Qwen: the context cost test isolates the readback from Qwen's own managed-memory extraction, which can start after `result` and overlap it (#930, test and docs only). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Cindy <[email protected]>
Qwen sessions expose cumulative spend but no current context, so a host cannot tell how full a resumed or multi-turn conversation is. Query native
get_context_usageafter a non-aborted root result and publish its last-prompt count and window beforeturn_endedand queued input. Record the request and correlated reply; never derive occupancy from cumulative input or native category estimates.The shared stream-json driver gains optional settlement readbacks while keeping control replies consumable. Missing capability, refusal, timeout, exit and disposal cannot strand completion. A one-second timeout leaves the last known reading unchanged; late replies remain raw evidence without overwriting a later turn. Native estimated counts stay unknown, including the pre-prompt zero. No public shape or runtime pin changes.
Validation: fresh/resumed native controls passed on Qwen 0.28.0 and CI-pinned 0.27.4 with scripted providers. Three post-turn queries took 2 to 15 ms and added zero provider requests; a separate empty-process query confirmed estimated zero. Unit controls cover attribution, correlation, queued/observer input, abort, disposal, exit and late replies. Full local check passed 4,864 unit tests and 19 mock behavior cases. Selected native evidence and reproduction are in
experiments/qwen-native/context-usage-2026-11-18.md.The required shared-backend run completed 16 backends: 15 passed; CodeBuddy passed 16 cases but its readback case failed while native
--helpexceeded the existing 15-second bound, before session startup. The same case passed alone on this branch and on the unchanged shared-driver base. The original failure and both controls are retained locally; its cause remains unresolved, and no deadline, retry or assertion changed. CI still gates all selected backends.