Skip to content

Harden Claude stale-session recovery#32

Merged
dimavrem22 merged 1 commit into
inkbox-ai:mainfrom
shreyaskommuri:agent/harden-claude-turn-recovery
Jul 9, 2026
Merged

Harden Claude stale-session recovery#32
dimavrem22 merged 1 commit into
inkbox-ai:mainfrom
shreyaskommuri:agent/harden-claude-turn-recovery

Conversation

@shreyaskommuri

Copy link
Copy Markdown
Contributor

Summary

  • Retry the stale Claude resume-session recovery when the missing-session error happens during turn submission/response handling, not only during client startup.
  • Move stale-resume cleanup into one helper that clears the resume id, persisted state, live client, and conversation-scoped tool grants.
  • Keep generic Claude turn failures on the existing actionable /health or /clear notice path while closing the broken client.

Fixes #31

Why

PR #29 fixed the exact failure we hit through real Inkbox iMessage testing: Claude Code could not find an old saved conversation id, and the bridge now clears that stale id when the failure happens during startup.

This follow-up tightens the adjacent edge cases. The same missing-session error can surface after the client has connected, while the bridge submits the turn or starts reading the response. That is still the same recoverable stale-resume problem, so it should use the same one-time fresh retry instead of falling through to an error notice.

The cleanup also now drops conversation-scoped always-allowed tool grants when abandoning the old Claude conversation, so the fresh session does not inherit grants from stale context.

Validation

  • .venv/bin/python -m pytest tests/test_sessions.py -q
  • .venv/bin/python -m pytest -q

Notes

  • The retry is still intentionally limited to the known No conversation found with session ID case.
  • This does not try to recover every Claude process, login, permission, or SDK failure.
  • Live iMessage delivery with a real mid-query stale resume error was not reproduced; this is covered with targeted regression tests.

Claude resume recovery should handle the same missing-session failure even when it appears after client startup, without turning arbitrary runtime failures into retry loops.

Constraint: PR inkbox-ai#29 only recovered the missing-resume path around client startup; SDK failures can also surface while submitting or reading a turn.

Rejected: Retry every Claude turn failure | that could hide real login, permission, or process failures and create confusing loops.

Confidence: high

Scope-risk: narrow

Directive: Keep retries limited to the known missing-resume signature and preserve actionable notices for all other turn failures.

Tested: .venv/bin/python -m pytest tests/test_sessions.py -q; .venv/bin/python -m pytest -q

Not-tested: Live iMessage turn with a mid-query missing resume from the real SDK.
@shreyaskommuri shreyaskommuri marked this pull request as ready for review July 9, 2026 20:29
@dimavrem22 dimavrem22 merged commit af168dc into inkbox-ai:main Jul 9, 2026
8 checks passed
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.

Handle stale Claude resume failures later in a turn

2 participants