Skip to content

tests: save-session harness failures print an empty stderr, because the script redirects stderr to hook-errors.log #210

Closed

Description

@fdaviddpt

The problem

scripts/bootstrap-dirs.sh:112 does:

exec 2>> "$REMEMBER_DIR/logs/hook-errors.log"

Every byte written to stderr after that point in save-session.sh goes to that file. So for any test that drives the script as a subprocess, result.stderr is structurally always empty — and the common assertion idiom in this suite is:

assert result.returncode == 0, result.stderr

which prints nothing on failure. The failure message is guaranteed to be blank exactly when you need it.

What it cost

This is not hypothetical — it cost about an hour on #208 today. Two tests failed on all four Ubuntu legs with:

assert 127 == 0
 +  where 127 = CompletedProcess(args=[...], returncode=127, stdout='', stderr='')

An empty stderr alongside a 127 reads as "the command was never found and the shell said nothing", which sends you looking at PATH and the harness. Two plausible hypotheses were built and killed against that reading before anyone thought to look in hook-errors.log — where the actual message had been sitting the whole time:

<stub>/tail: 10: exec: command: not found

That one line names the root cause outright (Debian dash cannot exec a builtin). With it in the assertion output, the diagnosis is two minutes instead of several CI rounds.

Proposed fix

A small helper that appends the log to the failure message — roughly:

def _failure_detail(result, project):
    log = project / ".remember" / "logs" / "hook-errors.log"
    tail = log.read_text(encoding="utf-8")[-2000:] if log.exists() else "(no hook-errors.log)"
    return f"rc={result.returncode}\nstdout={result.stdout!r}\nhook-errors.log:\n{tail}"

used as assert result.returncode == 0, _failure_detail(result, project) in the harnesses that drive save-session.sh (test_save_session_gates.py, test_ndc_truncate_race.py, test_ndc_tail_failure_no_truncate.py, and any sibling using the same _run).

Two details worth getting right:

  • It must not fail when the log is absent or unreadable — a helper that throws inside an assertion message turns one clear failure into a confusing one.
  • Truncate from the end. The log accumulates across the whole run, and the relevant lines are the last ones.

Why bother

The suite is otherwise good at this — it pins post-conditions and its failure messages usually say what went wrong. This is the one place where the harness is guaranteed to withhold the evidence it has, and it will do it again to the next person, in a CI-only failure they cannot reproduce locally.

Surfaced by the agent that diagnosed #208, which flagged it rather than quietly adding it — correctly, since it was outside that PR's scope.

Activity

  1. fdaviddpt commented on Jul 28, 2026

    @fdaviddpt
    ContributorAuthor

    Addendum from the #206 work: on the save-session.sh --dry path, .remember/logs/hook-errors.log does not exist at all — so there is no diagnostic anywhere, not merely one that is hard to find. Whatever helper closes this should say "no hook-errors.log" explicitly rather than printing an empty string, since the absence is itself informative (the redirect in bootstrap-dirs.sh:112 had not been reached yet).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions