Claude harness: a long turn fails with "decode Claude event: unexpected end of JSON input" and the final reply is lost
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 22/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- go, kubernetes, postgresql
- Lĩnh vực
- ai-infra-agents, backend, databases
Hướng nghiên cứu
Start with the stdout reader in go/harness/claude/internal/driver/parser.go (readStamped, the 64-line channel, and the json.Unmarshal failure near line 349), then the artifact loop in go/harness/runtime/a2a/executor.go. Reproduce by adding a 50-100 ms sleep in taskStoreServer.UpdateTask and running a prompt with a long streamed answer. Done means a truncated stream no longer fails the task silently, either by draining stdout independently or by recovering the final reply from the transcript.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Summary
On the Claude harness, a long turn can end TASK_STATE_FAILED ("Harness runtime execution failed") with the runtime error decode Claude event: unexpected end of JSON input. The final report is cut mid-sentence. The Session is fine: a follow-up message in the same contextId runs and completes. The cause is a slow task store plus Claude Code exiting without draining stdout (anthropics/claude-code#101641).
Versions
kagent v1.0.0 (a08cde76), ateworker-gvisor v1.0.0, Claude CLI 2.1.285, k3s, controller limits 2 CPU / 512 MiB, Postgres 17 (1 GiB).
Timeline (2026-11-21, UTC)
- 13:56:54 session starts (Claude harness, one long turn, about 12k characters of final report).
- 13:56 to 14:11: 1,089
UpdateTaskcalls for the session. Latency climbs from about 29 ms to 90 ms as the task grows (controller-wide in the logs: p50 20-29 ms until 14:06, 64-78 ms from 14:08; p95 up to 150 ms; worst call 589 ms). The task ends with 207 text artifacts. - 14:11:39 task fails:
decode Claude event: unexpected end of JSON input. Stderr empty. - 14:12:22 Substrate checkpoint, 43 s later. This is the normal post-turn suspend after quiescence (
go/core/internal/database/session_tasks.go:218-256,session_quiescence.go:43-103), not the cause. - 14:22 a follow-up "send your final answer again" in the same context completes.
Not resources: controller CPU 0.28-0.34 cores, no CFS throttling, about 140 MiB; Postgres 0.23 cores.
Code path (v1.0.0)
go/harness/claude/internal/driver/process.go:116hardcodes--include-partial-messages, so every text delta is a stdout line.parser.go:288-306(readStamped) reads stdout into a 64-line channel (parser.go:278). When the consumer is slow the channel fills, reading stops and Claude Code's pipe fills. The line cap is 16 MiB (go/harness/claude/config/config.go:110), so size is not the issue.go/harness/runtime/a2a/executor.go:471-490: each text delta becomes one artifact event.go/adk/pkg/taskstore/store.go:114-150: each event is one serial unaryUpdateTaskcarrying the whole task.- Server side, per call (
go/core/internal/service/taskstore/service.go:93-118,go/core/internal/database/session_tasks.go:123-216,sessions.go:284-288): marshal and sha256 the whole request,SELECT ... FOR UPDATEthe session row, read the whole stored task, write it back. Cost grows with the task, so a turn is quadratic in its number of events. Tool results are persisted whole too, so a large tool result slows every later update. - Claude Code, in
-p --output-format stream-json, exits about 2 s after the turn without draining stdout (anthropics/claude-code#101641). A reader that has fallen behind gets a prefix: noresultline, and sometimes a last line cut mid-JSON. - That last line has no newline, reaches
json.Unmarshaland fails (parser.go:349); the loop returns at once (parser.go:252-262). The complete reply is in Claude's session transcript; only the delivery was lost.
Minimal reproduction idea
Either of these should show it without a long real turn:
- Add a sleep of 50-100 ms in
taskStoreServer.UpdateTask(or point the harness at a slow Postgres), then run a prompt that makes Claude stream a long answer (10k+ characters). The consumer falls behind the pipe and the tail is lost. - Or run the claude-code#101641 reproduction against the harness driver:
claude -p --output-format stream-json --verbose --include-partial-messages, a reader that pauses 40-60 s after the first 100 lines, then drains. Noresultline, last line cut mid-JSON, exit 0.
Proposed fixes
- Decouple reading from persistence. Drain stdout in its own goroutine into an unbounded or disk-spilled buffer, so a slow
UpdateTaskcan never fill Claude Code's pipe. - Coalesce text deltas before
UpdateTask(flush every N ms or N bytes), and send only the delta, not the whole task. - Recover from a truncated stream. If stdout ends without a
resultevent or the last line does not parse, read the final reply from the session's Claude transcript (~/.claude/projects/.../<session_id>.jsonl) instead of failing the task. At minimum, say in the error that the stream was truncated and the turn may have finished. - Optional: make
--include-partial-messagesconfigurable.
Workaround
Callers detect TASK_STATE_FAILED with "Harness runtime execution failed" or a status containing "decode Claude event", then send one follow-up in the same contextId asking for the final answer again. Keeping final messages short helps.
- Ngôn ngữ chính
- Go
- Star
- 4.5k
- Fork
- 937
- Merge trung bình
- 1 ngày 10 giờ
- Pull request đã merge (30 ngày)
- 150
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của kagent-dev/kagent
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
kagent-dev/kagent#3792 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
kagent-dev/kagent#3790 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 80/100
kagent-dev/kagent#3789 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
kagent-dev/kagent#3787 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[BUG] Python memory summarization fails for Gemini models: the request has no model nameCó thể đã có người làm @BahaaMattar đã nhận 6 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
kagent-dev/kagent#3710 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của kagent-dev/kagent
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
-
Screenshot missing in READMEĐang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 82/100
-
Add CybeDefendĐang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 66/100
slavakurilyak/awesome-ai-agents#1031 ·