Skip to content

fix: add -L flag for screen log capture on macOS 4.00.03 (issue #96)#98

Merged
konard merged 10 commits intomainfrom
issue-96-829d21ddabc4
Mar 14, 2026
Merged

fix: add -L flag for screen log capture on macOS 4.00.03 (issue #96)#98
konard merged 10 commits intomainfrom
issue-96-829d21ddabc4

Conversation

@konard
Copy link
Member

@konard konard commented Mar 14, 2026

Summary

Fixes #96agent --version produces no output when run through $ --isolated screen -- agent --version on macOS with screen 4.00.03.

Root Cause

The previous fix (v0.24.9/PR #97) used deflog on in screenrc to enable logging. However, deflog on only applies to windows created AFTER screenrc is processed. In screen -dmS mode, the default window is created BEFORE screenrc processing — so the initial window (where the command runs) never had logging enabled. This caused all output to be silently lost.

Fix

  • Add -L flag to screen invocation: screen -dmS session -L -c screenrc ...
    • -L explicitly enables logging for the initial window at creation time
    • -L is available on ALL screen versions (including macOS 4.00.03)
    • Combined with logfile <path> in screenrc, -L logs to our custom path
  • Add --verbose flag support to args parser — sets START_VERBOSE=1 so screen-isolation debug output is visible when troubleshooting
  • Lazy DEBUG evaluationisDebug() function instead of constant, so env vars set by --verbose flag are respected at runtime
  • Exit code capture via sidecar file (echo $? > exitfile)
  • Enhanced retry logic — 3 retries with increasing delays (50/100/200ms)
  • Screenrc logging configlogfile <path>, logfile flush 0, deflog on for immediate flush and additional window coverage

Changes

File Change
js/src/lib/screen-isolation.js Add -L flag, lazy isDebug(), screenrc logging
rust/src/lib/isolation_screen.rs Add -L flag, matching Rust implementation
js/src/lib/args-parser.js Add --verbose flag support
js/test/screen-integration.test.js Integration tests for screen output capture
js/package.json Version unchanged (CI handles versioning)
docs/case-studies/issue-96/ Updated root cause analysis with deflog on timing issue

Key Insight

From the GNU Screen manual: deflog on sets "the default log state for all new windows." The word "new" is critical — the initial window in -dmS mode is not "new" from the screenrc's perspective. The -L flag bridges this gap by enabling logging at window creation time.

Test plan

  • All 10 screen integration tests pass (Linux)
  • All 60 isolation tests pass
  • All Rust tests pass
  • ESLint + Prettier pass
  • Cargo clippy + fmt pass
  • Experiment script verifies -L + screenrc approach works
  • Manual verification on macOS screen 4.00.03 (user testing needed)

🤖 Generated with Claude Code

Adding .gitkeep for PR creation (default mode).
This file will be removed when the task is complete.

Issue: #96
@konard konard self-assigned this Mar 14, 2026
konard and others added 5 commits March 14, 2026 13:37
Replace the version-dependent approach (native -Logfile for screen >= 4.5.1,
tee fallback for older versions) with a unified screenrc-based approach that
works on ALL screen versions including macOS bundled 4.00.03.

The screenrc uses three directives:
- `logfile <path>` sets the log file path (available since early screen)
- `logfile flush 0` forces immediate buffer flush (no 10-second delay)
- `deflog on` enables logging for all windows by default

This eliminates the tee fallback which had reliability issues on macOS:
- tee's write buffers may not be flushed before the session ends
- TOCTOU race between session detection and file read was hard to mitigate

Additional improvements:
- Exit code capture via sidecar file ($? saved after command completes)
- Enhanced retry logic with 3 retries and increasing delays (50/100/200ms)
- Debug output responds to both START_DEBUG and START_VERBOSE env vars
- Descriptive [screen-isolation] prefix on all debug messages

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…sue #96)

New test cases in both JS and Rust:
- Verify exit code capture from failed commands (nonexistent command → 127)
- Verify stderr output is captured via screen logging
- Verify multi-line output with correct exit code (JS only)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Update case study to document the complete fix history:
- v0.24.9 partial fix (logfile flush 0 + tee retry) that failed on macOS
- v0.25.0 complete fix (unified screenrc-based logging) that works on all versions
- Root cause analysis of tee fallback reliability issues
- Discovery of deflog on + logfile screenrc approach
- Exit code capture bug documentation

Add experiment scripts used in investigation:
- test-screen-capture-issue96.js: Both native and tee path testing
- test-screen-tee-forced.js: Force tee fallback path testing
- test-screen-screenrc-logging.js: Screenrc-based logging validation
- test-screen-dash-L-screenrc.sh: Shell-level screenrc + -L testing

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Bump JS package version from 0.24.9 to 0.25.0 (minor: new behavior)
- Add changeset for the screen isolation fix
- Add Rust changelog entry for PR #98
- Fix Rust formatting (cargo fmt) and clippy warning

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Move screen integration tests from isolation.test.js to
screen-integration.test.js to keep isolation.test.js under
the 1000-line limit (1070 → 804 lines).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@konard konard changed the title [WIP] agent --version does not work in screen isolation fix: use screenrc-based logging for all screen versions (issue #96) Mar 14, 2026
konard and others added 2 commits March 14, 2026 13:57
…issue #96)

Root cause: `deflog on` in screenrc only applies to windows created AFTER
screenrc processing. In `screen -dmS` mode, the default window is created
BEFORE screenrc is processed. The initial window never had logging enabled,
causing all output to be silently lost on macOS screen 4.00.03.

Fix: Add `-L` flag to screen invocation to explicitly enable logging for the
initial window at creation time. Combined with `logfile <path>` in screenrc,
`-L` logs to our custom path. The `-L` flag is available on ALL screen
versions including macOS 4.00.03.

Additional fixes:
- Add --verbose flag support to args parser (sets START_VERBOSE=1)
- Make DEBUG evaluation lazy so --verbose flag works at runtime
- Fix prettier formatting issues flagged by CI
- Revert manual version change in package.json (CI doesn't allow it)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…sue #96)

Documents the discovery that `deflog on` only applies to NEW windows, not the
initial window in `-dmS` mode. This was the root cause of the v0.25.0 failure
on macOS screen 4.00.03.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@konard konard changed the title fix: use screenrc-based logging for all screen versions (issue #96) fix: add -L flag for screen log capture on macOS 4.00.03 (issue #96) Mar 14, 2026
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@konard konard marked this pull request as ready for review March 14, 2026 14:07
@konard
Copy link
Member Author

konard commented Mar 14, 2026

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $23.361622
  • Calculated by Anthropic: $16.494764 USD
  • Difference: $-6.866859 (-29.39%)
    📎 Log file uploaded as Gist (5436KB)
    🔗 View complete solution draft log

Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard
Copy link
Member Author

konard commented Mar 14, 2026

✅ Ready to merge

This pull request is now ready to be merged:

  • All CI checks have passed
  • No merge conflicts
  • No pending changes

Monitored by hive-mind with --auto-restart-until-mergeable flag

@konard konard merged commit 07e9775 into main Mar 14, 2026
23 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.

agent --version does not work in screen isolation

1 participant