Fix shell execution degradation and session lock corruption in long conversations#468
Open
ayourk wants to merge 1 commit intoop7418:mainfrom
Open
Fix shell execution degradation and session lock corruption in long conversations#468ayourk wants to merge 1 commit intoop7418:mainfrom
ayourk wants to merge 1 commit intoop7418:mainfrom
Conversation
Long conversations cause context window overflow, making the model output tool calls as text instead of using the tool API. This adds token-aware context limiting, output streaming, fake tool call sanitization, and improved context pruning to prevent the feedback loop. Session locks left behind by crashes leave sessions permanently stuck in "running" state. This adds automatic stale lock cleanup on startup and a force-release endpoint for the UI. Shell execution: - Validate working directory before spawning (bash.ts) - Stream tool output via SSE as it arrives (bash.ts) - Reduce message history when context exceeds 75% of window (agent-loop.ts) - Fix doom loop detection with proper counting (agent-loop.ts) - Keep 16 recent turns instead of 6, preserve tool excerpts (context-pruner.ts) - Sanitize fake tool call patterns from compacted history (message-builder.ts) - Merge consecutive assistant messages instead of dropping (message-builder.ts) - Distinguish real summaries from hallucinated calls (message-normalizer.ts) - Harden fallback context instruction (claude-client.ts) Session lock recovery: - Clean up expired locks and reset stuck sessions on startup (db.ts) - Force-release lock endpoint for UI recovery (sessions/[id]/route.ts) - Validate working directory before starting session (chat/route.ts)
|
@ayourk is attempting to deploy a commit to the op7418's projects Team on Vercel. A member of the Team first needs to authorize it. |
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.
Summary
Steps to reproduce
Shell execution degradation
(used Bash: {"command":"..."})as literal text instead of making tool API callsSession lock corruption
Changes
Shell execution reliability
bash.ts: Validate working directory exists before spawning, stream output to client via SSE as it arrives, clean up kill timers properly on process exitagent-loop.ts: Token-aware context limiting — estimates token count and reduces message history if it exceeds 75% of the context window. Fixes doom loop detection with proper counting instead of broken heuristiccontext-pruner.ts: Keep 16 recent turns instead of 6 (~8 full exchanges), preserve tool name + 200-char excerpt in pruned results instead of a generic[truncated]markerclaude-client.ts: Explicit instruction in fallback context to never output[Tool call: ...]as text. TypeScript type fixes for tool result content array parsingmessage-builder.ts: Detect and clean fake tool call syntax ((used Bash: {...})) from compacted conversation history. Merge consecutive assistant messages preserving all content parts instead of dropping the earlier messagemessage-normalizer.ts: Change tool_use summary format from(used Name: ...)to[Tool call: Name — ...]so the sanitizer can distinguish real summaries from model-hallucinated fake callsSession lock recovery
db.ts:cleanupStaleLocks()deletes expired locks and resets stuck sessions to idle on startup.forceReleaseSessionLock()lets the UI break a stuck session regardless of lock ownershipchat/route.ts: CallcleanupStaleLocks()on first API request. Validate working directory exists before starting a session — return a 400 withINVALID_CWDinstead of crashingsessions/[id]/route.ts: Acceptforce_unlockin PATCH body to triggerforceReleaseSessionLock()You can edit the patches as needed before the merge.