fix(bin): gstack-codex-session-import — empty sessions dir exits 0 on Linux

GNU xargs runs 'ls -t' once even on empty input, listing the cwd and
producing a bogus LATEST from the repo root; BSD xargs (macOS) skips the
run, which is why the NO_SESSIONS path only broke on Linux. xargs -r pins
the BSD behavior on both platforms.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Garry Tan 2026-08-15 08:40:12 -07:00
parent c8bf0474b1
commit 45bc02952d
No known key found for this signature in database
GPG Key ID: C1F69E85C74EFE1D
1 changed files with 4 additions and 1 deletions

View File

@ -64,8 +64,11 @@ case "$MODE" in
echo "NO_SESSIONS: $CODEX_SESSIONS_ROOT does not exist"
exit 0
fi
# xargs -r: GNU xargs runs `ls -t` once even on EMPTY input (listing the
# cwd and producing a bogus LATEST); BSD xargs skips it. -r pins the
# BSD behavior on both.
LATEST=$(find "$CODEX_SESSIONS_ROOT" -type f -name "rollout-*.jsonl" -print 2>/dev/null \
| xargs ls -t 2>/dev/null | head -1 || true)
| xargs -r ls -t 2>/dev/null | head -1 || true)
if [ -z "$LATEST" ]; then
echo "NO_SESSIONS: no rollout-*.jsonl files under $CODEX_SESSIONS_ROOT"
exit 0