Skip to content

SessionStart: ls|grep|wc counting pipelines, $(cat), $(dirname), ungated mkdir -p on every start (Part of #660) #666

Closed

Description

@fdaviddpt

Part of #660.

Observed

Around 20 spawns per start come from counting and listing that bash can do with globs and expansions:

  • :1659 staging count: $(ls | grep -v | grep -v | wc -l | tr -d) -- 5 forks + 5 execs, unconditional.
  • :1495 rotated slices: $(ls archive-*.md recent-*.md | sort) -- 2 + 2.
  • :808 capture-alive prune: ls -t | tail -n +201 | while -- runs even when there are fewer than 200 entries.
  • :657 previous_transcript: ls -t | while; :676 ls -t | tail | head.
  • :1270 $(cksum < f | tr); :776 $(cat capture-alive) and :846 $(cat capture-gap-reported) -- cat forks even when the file is missing.
  • :860 $(dirname "$REMEMBER_DIR").
  • :1163 mkdir -p "$REMEMBER_DIR/tmp" unconditional, not gated on -d.
  • :1015, :1399-1460 date +%s via _remember_date -- lib-clock refuses %s for the builtin, so these fall through to an external date.
  • bootstrap-dirs.sh:143 find "$REMEMBER_DIR/tmp" -mmin +30 -exec rm every start.

Cost

Estimated 0.5-1.5s per start on Windows/Git Bash (reasoned, not measured).

Fix shape

  • Staging count: for f in "$dir"/today-*.md with a case exclusion for today-$TODAY.md and *.done.md, counting in bash.
  • Rotated slices and transcripts: glob arrays; newest-first via a -nt loop.
  • Capture-alive prune: set -- "$dir"/*; [ $# -gt 200 ] || skip before any pipeline.
  • $(<file) for the two cat-into-variable reads (guarded by [[ -f ]]); ${REMEMBER_DIR%/*} for dirname.
  • [[ -d ]] || mkdir -p at :1163.
  • EPOCHSECONDS (bash 5) with a printf '%(%s)T' -1 fallback for epoch reads; teach lib-clock.sh to accept %s on bash >= 4.2 where %(%s)T is supported.
  • find -mmin sweep: run it in the detached phase, or only when the tmp dir has more than N entries.

Negative control: spawn-count test in the shape of tests/test_session_start_promo_spawn_budget_660.py for the whole foreground path; positive: the existing consolidation-trigger and recovery tests still fire.

[AI-generated]

Activity

  1. added
    priority:high
    filed-by-loop
    lane-capture
    on Sep 11, 2026
  2. self-assigned this
    on Sep 12, 2026
  3. added 2 commits that reference this issue on Sep 12, 2026
  4. added a commit that references this issue on Oct 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

filed-by-looplane-capturepriority:high

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions