Skip to content

Claude adapter runtime resilience improvements - #137

Merged
Yeachan-Heo merged 1 commit into
mainfrom
claude-adapter-resilience
Apr 23, 2026
Merged

Claude adapter runtime resilience improvements#137
Yeachan-Heo merged 1 commit into
mainfrom
claude-adapter-resilience

Conversation

@minislively

Copy link
Copy Markdown
Owner

Summary

Defends the Claude adapter runtime against corrupt state, invalid events, and stale trust status rewrites.

Changes

  • Guard trust status read: readClaudeTrustStatus now gracefully handles malformed/corrupt trust.json files instead of crashing.
  • Guard trust status write: writeClaudeTrustStatus swallows filesystem write failures to avoid crashing the hook pipeline.
  • Avoid stale trust rewrites: ensureFreshClaudeContextForTarget no longer redundantly patches trust status when the target is already fresh.
  • Validate hook events: handleClaudeRuntimeHook rejects unrecognized event names with a clean noop decision.
  • Clean up empty directories: clearClaudeRuntimeSession removes empty parent directories after deleting session state files.

Tests

Added test/claude-adapter-resilience.test.mjs with 4 new tests:

  1. Corrupt trust status file defense
  2. Unrecognized event name no-op
  3. Session clear removes empty parent directories
  4. Non-stale path does not rewrite trust status

All 220 tests pass (216 existing + 4 new).

🤖 Generated with Claude Code

…and stale trust

- Guard JSON.parse/readFileSync in readClaudeTrustStatus against malformed trust.json
- Guard mkdirSync/writeFileSync in writeClaudeTrustStatus against filesystem errors
- Remove redundant patchClaudeTrustStatus call in ensureFreshClaudeContextForTarget non-stale path
- Add VALID_CLAUDE_HOOK_EVENTS guard in handleClaudeRuntimeHook to reject unrecognized events
- Clean up empty parent directories after clearing Claude runtime session state
- Add resilience tests for corrupt trust file, unrecognized events, directory cleanup, and non-stale trust preservation

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@Yeachan-Heo
Yeachan-Heo merged commit c814cca into main Apr 23, 2026
2 checks passed
@Yeachan-Heo
Yeachan-Heo deleted the claude-adapter-resilience branch April 23, 2026 05:17
minislively added a commit that referenced this pull request May 14, 2026
…and stale trust (#137)

- Guard JSON.parse/readFileSync in readClaudeTrustStatus against malformed trust.json
- Guard mkdirSync/writeFileSync in writeClaudeTrustStatus against filesystem errors
- Remove redundant patchClaudeTrustStatus call in ensureFreshClaudeContextForTarget non-stale path
- Add VALID_CLAUDE_HOOK_EVENTS guard in handleClaudeRuntimeHook to reject unrecognized events
- Clean up empty parent directories after clearing Claude runtime session state
- Add resilience tests for corrupt trust file, unrecognized events, directory cleanup, and non-stale trust preservation

Co-authored-by: minislively <minislively@users.noreply.github.com>
Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants