fix(server,tools): surface live chat_run/mcp_server tasks (#472) + count shell.exec truncation in bytes (#441) - #482
Draft
TYRMars wants to merge 2 commits into
Draft
fix(server,tools): surface live chat_run/mcp_server tasks (#472) + count shell.exec truncation in bytes (#441)#482TYRMars wants to merge 2 commits into
TYRMars wants to merge 2 commits into
Conversation
…units `ShellExecTool.#accumulate` documented itself as counting "every observed byte" and capping the captured buffer at `#maxBytes` (default 64 KiB), but it measured JS string `.length` — UTF-16 code units, not bytes. For multibyte output (CJK ~3 bytes/char, most emoji 4 bytes / 2 code units) the cap was under-counted 2-4×, so the `[... truncated ...]` marker never fired and the reported "(N bytes)" was a code-unit count. A single line of 60k CJK chars (~180 KB) sailed under the 64 KiB cap and flooded the model context ~3× over the advertised bound with no truncation signal. Measure UTF-8 bytes via `Buffer.byteLength(line, "utf8")` for both the cap comparison and `total`, tracking a running `bufBytes` on `StreamBuf` to keep accumulation O(n). This matches the reported unit and the Rust origin (`line.len()` = UTF-8 byte length). Fixes #441 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GrTJW6ReXyCgkq4QnN7DAh
`collectTasks` skipped its `chat_run` and `mcp_server` sources on a stale "not on AppState yet" premise, but both fields have long existed and are populated: `AppState.chatRuns` (ChatRunRegistry, driven by the WS turn loop) and `AppState.mcpManager` (McpManager). As a result: - `GET /v1/tasks?conversation=<id>` returned `items: []` for an ordinary chat turn running right now — the background-tasks panel reported "nothing in flight" while the agent was mid-tool-call. The `taskMatchesConversation` `chat_run` branch (match by id) was unreachable because no chat_run entries were ever produced. - Stopped / unhealthy MCP servers were never surfaced. Implement both collectors against the live AppState fields, mirroring the Rust origin (`crates/harness-server/src/tasks_routes.rs::collect_tasks`): - Chat runs: `chatRuns.list(true)`, active-state guard, label "Chat · running <tool>" or "Chat turn", keyed by conversation id. - MCP servers: `mcpManager.list()`, skip running (idle infra), surface stopped/unhealthy with "MCP <prefix> · <status>", pinned to now(). Correct the stale file-header and `taskMatchesConversation` comments. Adds regression tests for both collectors and the chat_run filter path. Fixes #472 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GrTJW6ReXyCgkq4QnN7DAh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Auto-resolving open issues. This PR bundles two independent, self-contained bugfixes (each with regression tests). The branch is constrained to
claude/vibrant-dijkstra-u95inx, so both land here.Fixes #472 —
GET /v1/tasksnever surfaced chat runs or unhealthy MCP serverscollectTasksinpackages/server/src/tasks-routes.tsskipped itschat_runandmcp_serversources on a stale "not on AppState yet" premise. Both fields have long existed and are populated:AppState.chatRuns(ChatRunRegistry, driven by the WS turn loop) andAppState.mcpManager(McpManager).Consequences (user-visible):
GET /v1/tasks?conversation=<id>returneditems: []for an ordinary chat turn running right now — the background-tasks panel reported "nothing in flight" while the agent was mid-tool-call. ThetaskMatchesConversationchat_runbranch (match by id) was unreachable because nochat_runentries were ever produced.Fix: implement both collectors against the live
AppStatefields, mirroring the Rust origin (collect_tasks): chat runs viachatRuns.list(true)(labelChat · running <tool>/Chat turn, keyed by conversation id); MCP servers viamcpManager.list()(skip cleanly-running idle infra, surface stopped/unhealthy asMCP <prefix> · <status>). Corrected the stale doc comments; added regression tests for both collectors and thechat_runfilter path.Fixes #441 —
shell.exectruncation cap counted UTF-16 code units, not bytesShellExecTool.#accumulate(packages/tools/src/shell.ts) capped at#maxBytes(64 KiB) using JS string.length— UTF-16 code units, not bytes. For multibyte output (CJK ≈ 3 bytes/char, emoji 4 bytes / 2 code units) the cap was under-counted 2–4×, so the[... truncated ...]marker never fired and the reported(N bytes)was a code-unit count.Fix: measure UTF-8 bytes via
Buffer.byteLength(line, "utf8")for the cap andtotal, tracking a runningbufBytesto keep accumulation O(n) — matching the Rust origin (line.len()). Added a multibyte regression test.Testing
@jarvis/servertasks-routes: 14/14 pass (4 new).@jarvis/toolsshell: 15/15 (1 new); full tools suite 268/268.tsc --noEmitclean for both packages; eslint clean on changed files.@jarvis/servertests (server,ui,workspace-terminal-routes) fail to load in this environment only because thenode-ptynative module isn't built (postinstall skipped) — a pre-existing environment limitation unrelated to this change; CI builds it.🤖 Generated with Claude Code
https://claude.ai/code/session_01GrTJW6ReXyCgkq4QnN7DAh