Skip to content

SessionStart: cache the injected context, the flattened config and the tool verdicts across starts, validated by mtime (Part of #660) #668

Closed

Description

@fdaviddpt

Part of #660. The structural lever behind #662-#666: most of what SessionStart computes is identical from one start to the next, and the plugin already runs a detached phase (save-session, consolidation) that could compute it ahead of time.

What is recomputed on every start today

  1. Injected memory context -- six memory files read, sized, headed and concatenated (session-start-hook.sh:1532-1549), rotated-slice listing and sizes (:1588-1631), history hint (:1465), handoff (:1322). Changes only when a memory file changes -- i.e. after a save or a consolidation, both of which run in the background already.
  2. Flattened config -- jq merge of up to three config.json files (lib-memory-dir.sh:313) plus a jq flatten into _RCFG_* (log.sh:206). Changes only when a config file changes.
  3. Tool verdicts -- python3 -V probe (detect-tools.sh:48-66), jq presence, cygpath presence. Change only when PATH changes.
  4. Slug and paths -- session_dir_slug via cygpath -w + sed (lib-slug.sh:177,348), claude_projects_dir via cygpath -u (:75). Change only when the project dir changes.

lib-env-cache.sh already publishes an env cache from SessionStart for later hooks in the same session (:107,124); this issue extends the idea across sessions.

Fix shape

  • Context cache: the detached phase (end of save-session.sh, end of run-consolidation.sh) writes $REMEMBER_DIR/tmp/start-context.cache = the exact bytes SessionStart would inject, plus a manifest of the source files' mtimes. SessionStart validates with bash -nt against each source (zero spawns), and on a hit does a single cat; on a miss falls back to today's path and rewrites the cache. Handoff and the promo line stay dynamic (they are small and cheap).
  • Config cache: _config_load writes the flattened _RCFG_* assignments as a sourceable file keyed by the config files' mtimes; steady state is source with zero jq.
  • Tool verdicts: cache $PYTHON/$JQ/$CYGPATH in the same sourceable file keyed by a hash of $PATH (bash ${PATH} compared as a string is enough).
  • Slug: cache the computed slug per project dir alongside.

Steady-state SessionStart then spawns: the stdin read, one source, one cat, the marker writes. Everything else has moved to the phase that already runs after the user is busy.

Guardrails

  • A stale cache must be impossible to serve silently: every source file in the manifest is -nt-checked, and a missing manifest entry is a miss, not a hit.
  • The cache lives under $REMEMBER_DIR/tmp and is world-invisible (umask 077), same as the promo marker.
  • Positive control: edit a memory file, start a session, the new bytes are injected (miss path); negative control: no edits, second start injects identical bytes with a spawn count pinned by a test in the shape of tests/test_session_start_promo_spawn_budget_660.py.
  • Windows band: -nt on MSYS compares mtimes correctly; note the 2s FAT/exFAT mtime granularity as a reason to treat equal mtimes as a miss.

[AI-generated]

Activity

  1. added
    priority:high
    filed-by-loop
    lane-capture
    on Sep 11, 2026
  2. self-assigned this
    on Sep 11, 2026
  3. added 2 commits that reference this issue on Sep 11, 2026
  4. removed their assignment
    on Sep 12, 2026
  5. added 3 commits that reference this issue on Sep 26, 2026
  6. added 3 commits that reference this issue on Oct 9, 2026
  7. added 4 commits that reference this issue on Nov 1, 2026
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

    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