Skip to content

fix: capture output from quick-completing commands in screen isolation (issue #96)#97

Merged
konard merged 4 commits intomainfrom
issue-96-efde41b8c023
Mar 14, 2026
Merged

fix: capture output from quick-completing commands in screen isolation (issue #96)#97
konard merged 4 commits intomainfrom
issue-96-efde41b8c023

Conversation

@konard
Copy link
Member

@konard konard commented Mar 14, 2026

Summary

Fixes #96: agent --version (and other quick-completing commands) run through screen isolation produced no output, even though the command succeeded with exit code 0.

Root Cause

GNU Screen's -L log capture uses an internal FILE* buffer with a 10-second default flush interval (log_flush = 10). For commands that complete in milliseconds (like agent --version), the buffer is never flushed to the log file before the session terminates — so the output is silently lost.

From GNU Screen source (src/ansi.c):

static void WLogString(Window *win, char *buf, size_t len)
{
    logfwrite(win->w_log, buf, len);  // writes to FILE* buffer
    if (!log_flush)
        logfflush(win->w_log);        // only flushes if log_flush == 0 (default: 10s)
}

Fix

Native logging path (screen ≥ 4.5.1): Create a temporary screenrc with logfile flush 0 and pass it via screen -c. This sets log_flush = 0, forcing screen to flush after every write — eliminating the 10-second delay.

Tee fallback path (screen < 4.5.1, e.g. macOS bundled 4.0.3): Add a 50ms retry when the log file appears empty right after session completion, handling the TOCTOU race where tee may not have flushed to disk before screen -ls shows the session as gone.

Before (output missing)

$ --isolated screen -- agent --version
│ ...
$ agent --version


✓
│ exit      0

After (output captured)

$ --isolated screen -- agent --version
│ ...
$ agent --version

0.13.2

✓
│ exit      0

Changes

File Change
js/src/lib/isolation.js Create temp screenrc with logfile flush 0 for native logging; add retry for empty log; clean up both temp files
js/test/isolation.test.js Add regression test: node --version output must be captured in screen isolation (issue #96)
rust/src/lib/isolation.rs Equivalent fix for Rust implementation
rust/src/lib/isolation_tests.rs Add Rust regression test for version-flag commands (issue #96)
docs/case-studies/issue-96/ Deep-dive case study with timeline, root cause, and solutions evaluated
js/.changeset/fix-screen-log-flush-quick-commands.md Patch changeset
experiments/ Diagnostic scripts used to reproduce and verify the fix

Test Plan

  • All existing JS tests pass (67 pass, 0 fail)
  • New regression test: should capture output from version-flag commands (issue #96) passes — captures v20.20.1 from node --version
  • Rust compilation and tests pass (cargo check, cargo test, cargo fmt --check, cargo clippy)
  • ESLint and Prettier pass on changed files
  • Manual verification: node js/src/bin/cli.js --isolated screen -- agent --version shows version output

🤖 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
…n (issue #96)

Add `logfile flush 0` via a temporary screenrc to force GNU Screen to flush
its log buffer immediately after every write, preventing output loss for
commands like `agent --version` that complete faster than screen's default
10-second log flush interval.

Also add a 50ms retry for the tee fallback path (screen < 4.5.1) to handle
the TOCTOU race where the log file may be empty when first read immediately
after session completion.

Changes:
- js/src/lib/isolation.js: create temp screenrc with `logfile flush 0` for
  native logging path; add readAndDisplayOutput() with retry logic; clean up
  both log file and screenrc on completion
- js/test/isolation.test.js: add regression test for version-flag commands
  (issue #96)
- rust/src/lib/isolation.rs: equivalent fix for Rust implementation
- rust/src/lib/isolation_tests.rs: add Rust regression test for version-flag
  commands (issue #96)
- docs/case-studies/issue-96/: deep-dive case study with timeline, root
  cause analysis, and solutions evaluated
- js/.changeset/fix-screen-log-flush-quick-commands.md: patch changeset
- experiments/: scripts used to diagnose and verify the fix

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@konard konard changed the title [WIP] agent --version does not work in screen isolation fix: capture output from quick-completing commands in screen isolation (issue #96) Mar 14, 2026
@konard konard marked this pull request as ready for review March 14, 2026 12:53
@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: $5.235641
  • Calculated by Anthropic: $4.730235 USD
  • Difference: $-0.505406 (-9.65%)
    📎 Log file uploaded as Gist (2884KB)
    🔗 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

🔄 Auto-restart triggered (attempt 1)

Reason: CI failures detected

Starting new session to address the issues.


Auto-restart-until-mergeable mode is active. Will continue until PR becomes mergeable.

…-line limit

Both isolation.js (1016 lines) and isolation.rs (1048 lines) exceeded the
1000-line file size limit enforced by CI.

- Extract screen version detection and log capture logic from isolation.js
  into new js/src/lib/screen-isolation.js module
- Extract screen-related functions from isolation.rs into new
  rust/src/lib/isolation_screen.rs module
- Add rust/changelog.d/97.md changelog fragment for issue #96 fix

After refactoring:
- isolation.js: 758 lines (was 1016)
- isolation.rs: 851 lines (was 1048)
- screen-isolation.js: 309 lines (new)
- isolation_screen.rs: 215 lines (new)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@konard
Copy link
Member Author

konard commented Mar 14, 2026

🔄 Auto-restart-until-mergeable Log (iteration 1)

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

💰 Cost estimation:

  • Public pricing estimate: $1.668288
  • Calculated by Anthropic: $1.779365 USD
  • Difference: $0.111077 (+6.66%)
    📎 Log file uploaded as Gist (4262KB)
    🔗 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 f34db75 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