Skip to content

fix: terminal clear, detach, log replay, self-attach, and umask bugs#29

Open
s85io wants to merge 2 commits intomobydeck:mainfrom
s85io:fix/clear-without-terminal-reset
Open

fix: terminal clear, detach, log replay, self-attach, and umask bugs#29
s85io wants to merge 2 commits intomobydeck:mainfrom
s85io:fix/clear-without-terminal-reset

Conversation

@s85io
Copy link

@s85io s85io commented Mar 17, 2026

Summary

Collection of bug fixes for attach/detach lifecycle and master socket creation:

  • Replace RIS with explicit clear sequences — avoid leaking terminal state (bold, colors, charset) when clearing screen on attach/detach. Uses \033[999H\r\n (move-to-bottom) instead of full terminal reset.
  • Send MSG_DETACH on detach keypress — the client now notifies the master process before exiting, so the master can properly clean up the client entry.
  • Limit log replay to last SCROLLBACK_SIZE bytes — large session logs were read from the start, causing slow replays. Now seeks to the tail when the log exceeds SCROLLBACK_SIZE.
  • Move connect_socket before self-attach check — a stale SESSION_ENVVAR from a dead session would block new attaches. Now we connect first and only then check for loops. Also closes the socket on self-attach detection.
  • Separate ENOENT from replay path — "session does not exist" is now shown directly instead of falling through to the log replay code path, giving clearer error messages.
  • Restore umask on all error paths in create_socketumask(omask) was only called on the success path; failures in bind/listen/setnonblocking/chmod left the process umask changed to 077.

Test plan

  • Build and install (make clean && make && sudo cp atch /usr/bin/atch)
  • Verify session create, list, list -a
  • Attach to session, press detach key, verify clean disconnect
  • Kill a session, verify list -a shows it as exited, re-attach replays log tail
  • Verify no self-attach from within a session
  • Run long-lived session with large output, verify replay is fast

🤖 Generated with Claude Code

Bastedru and others added 2 commits March 17, 2026 19:13
…nal state leak

ESC c (RIS) resets the entire terminal state (fonts, colors, modes),
which leaks host terminal settings into the attached session.
Use CSI H + CSI 2J + CSI 3J instead to clear screen and scrollback
without resetting terminal configuration.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Send MSG_DETACH packet to master before exiting on detach keypress
- Seek to last SCROLLBACK_SIZE bytes when replaying large session logs
- Move connect_socket before self-attach check so stale env vars from
  dead sessions don't block new attaches
- Handle ENOENT separately from replay path for clearer error messages
- Restore umask on every error path in create_socket, not just success

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@s85io s85io changed the title fix(attach): replace RIS with explicit clear sequences fix: terminal clear, detach, log replay, self-attach, and umask bugs Mar 18, 2026
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