Open
Conversation
…ary-continuation
Root cause: query() had no maxTurns, letting sessions run until the model's
context window was exhausted — killing the session before a Slack reply was sent.
Changes:
session.ts
- DEFAULT_MAX_TURNS = 200 (configurable via CLAUDE_MAX_TURNS env var)
- maxTurns: DEFAULT_MAX_TURNS in sharedOptions — applies to every session
- summarizeSession(): resumes a timed-out session with maxTurns: 5 and a prompt
asking Claude for a concise summary of what was done and what remains
response.ts
- ClaudeResponse.subtype — SDK result subtype ('error_max_turns', etc.)
- ClaudeResponse.didAutoCompact — set to true when a compact_boundary message
is seen; this is the SDK's token-based trigger (fires when context fills up),
so this is more accurate than a turn-count check
- consumeResponse() tracks compact_boundary events in the stream
files.ts
- uploadContentAsFile(): writes a string to a temp file and uploads it to Slack
events.ts
- handleMessage(): if didAutoCompact, posts an informational notice so the user
knows the session auto-compacted during their request
- callClaudeWithRetry(): on error_max_turns:
1. Resumes the session (still has full recent context) to generate a summary.
Claude writes this from the full history including the recent "second half"
that auto-compaction hadn't touched.
2. Uploads the summary as session-summary.txt (file, not inline text, since
it can be long).
3. Starts a fresh continuation session with the summary as context so the
task can resume without the bloated history that caused the limit.
If any step fails, falls back to the raw error. The continuation deliberately
does not re-enter the recovery path to avoid infinite loops.
tools.ts
- slackSendMessage: disable link/media unfurling
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add vitest-based unit test suite covering all major ClaudeX subsystems: - Slack integration: messages, tools, events, client, files (6 files, 103 tests) - Claude SDK: response parsing, session management, crash scenarios (3 files, 38 tests) - Data store: session persistence, atomic writes, corruption handling (1 file, 10 tests) - Utilities: path resolution, file detection (2 files, 22 tests) - Crash prevention: 38 dedicated tests for error paths that cause "process exited with code 1" All tests are fully mocked (no real Slack API calls, no Claude sessions, no filesystem side effects). One test is marked as expected-fail to document a known bug in resolveUserName (missing try/catch in events.ts). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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
it.fails()to document a known bug: missing try/catch inresolveUserName(events.tsline 354-368)Test Coverage
messages,tools,events,client,filesevents-crashes,response-crashesresponse,sessionpaths,file-detectsessionsRun with
Test plan
npm testpasses: 180 passing, 1 expected fail🤖 Generated with Claude Code