Skip to content

fix: /context-save session_duration_s empty on Linux (GNU date -jf) - #2704

Open
exGeni wants to merge 1 commit into
garrytan:mainfrom
exGeni:fix/context-save-linux-session-duration
Open

fix: /context-save session_duration_s empty on Linux (GNU date -jf)#2704
exGeni wants to merge 1 commit into
garrytan:mainfrom
exGeni:fix/context-save-linux-session-duration

Conversation

@exGeni

@exGeni exGeni commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Implementation: Claude Code (Sonnet 5). Independent technical review: Codex — findings from both the plan review and the diff review are folded into this PR (see Live evidence).

Why (in your own words)

/context-save's session_duration_s is always empty on Linux — GNU/uutils date
rejects the BSD-only date -jf "%c" flags used in the Step 3 duration
fallback, so START_EPOCH silently ends up empty on every Linux user's
machine. Separately, the fallback measured the wrong thing on any platform:
ps -o lstart -p $PPID reports how long the parent process has been
alive, not how long this specific /context-save invocation ran.

Live evidence

Before (the actual failure, this machine, GNU/uutils coreutils 0.8.0):

$ date -jf "%c" "Thu Aug 27 03:56:58 2026" "+%s"
error: unexpected argument '-j' found
exit code: 1
(full `date --help` usage dump omitted here for length)

After (the fix's actual mechanism — read the existing session-marker file's
mtime instead of parsing ps output at all):

$ ls -la ~/.gstack/sessions/"$PPID"
-rw-rw-r-- 1 exgenius exgenius 0 Aug 27 16:52 /home/exgenius/.gstack/sessions/3427913
$ date -r ~/.gstack/sessions/"$PPID" +%s
1787842375
exit code: 0

End-to-end: ran the actual (unmodified) Step 3 bash from context-save/SKILL.md
as its own subprocess, separate from its preamble:

SESSION_DURATION_S=28

(Step 3's code doesn't reference anything from the sibling telemetry fix in
the other PR — this number comes entirely from this PR's own diff. It was
captured on a local-only branch that also had the other PR's commits merged
in for realistic end-to-end testing; the isolation just described is why
that's safe to cite here.)

Scope

  • Changed: context-save/SKILL.md.tmpl (Step 3 duration fallback) +
    regenerated context-save/SKILL.md
  • Verified live by: the commands above, run directly on this Linux
    machine
  • Did NOT test: the Darwin branch on real macOS hardware (no Mac
    available) — the existing BSD date -jf path is preserved byte-for-byte,
    only defensively prefixed with LC_TIME=C in case macOS ps/strptime
    are locale-sensitive the same way Linux's are; would appreciate a
    maintainer/community check on real hardware

Liveness proof (required)

изображение

Checklist

  • Liveness screenshot attached: GSTACK PR typed live into a real surface
  • This is not a generated-file-only diff (edited the .tmpl source, regenerated)
  • No ETHOS.md edits, no voice/founder-perspective/YC changes
  • N/A — not a new public command/service/host adapter
  • Linked issue or reproduction: reproduction above (no existing issue found)

The Step 3 duration fallback shelled out to `ps -o lstart= -p $PPID | date
-jf "%c" ...`. `-j`/`-f` are BSD/macOS-only date flags; GNU date on Linux
rejects them outright, so START_EPOCH silently ends up empty and
session_duration_s is omitted from every checkpoint frontmatter on Linux.
Even fixed, `ps -o lstart=` is locale-dependent (non-English month/day
names break any date parser downstream).

Also: the fallback was measuring the wrong thing regardless of platform —
`ps -o lstart -p $PPID` reports how long the *parent* (host) process has
been alive, not how long this specific /context-save invocation has been
running.

Fix: reuse the existing `~/.gstack/sessions/"$PPID"` session-marker file
(already touched by every skill's preamble) as the start-time source,
reading its mtime portably (`date -r` on Linux, `stat -f %m` on Darwin)
instead of parsing `ps` output at all. Drops the ps/date-flag/locale
problem entirely rather than patching around it.

Live evidence (this machine, GNU/uutils coreutils 0.8.0):
  $ date -jf "%c" "Thu Aug 27 03:56:58 2026" "+%s"
  error: unexpected argument '-j' found        # confirms the Linux failure
  $ date -r ~/.gstack/sessions/"$PPID" +%s
  1787842375                                    # new path works, real marker file

Verified: bun run gen:skill-docs --host all clean, bun run skill:check
freshness clean (context-save/SKILL.md now in sync with the .tmpl for the
first time - a prior hand-patch had been applied directly to the generated
file and would have been silently destroyed by the next regen). The
skill:check "claude/SKILL.md missing" line and the 53 test failures in
test/gstack-repo-mode.test.ts and friends are pre-existing on a clean
origin/main checkout (verified via git stash), unrelated to this change.
@trunk-io

trunk-io Bot commented Aug 27, 2026

Copy link
Copy Markdown

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

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.

1 participant