Skip to content

skill: cache preamble bash output within session to reduce duplication #1572

Closed as not planned

Description

@shizeqin

Problem

When executing a long plan that invokes 5–8 gstack-flavored skills sequentially (/investigate → /plan-eng-review → /codex → /review → /ship etc.), the SKILL.md "Preamble (run first)" bash block is re-injected and re-executed on every invocation. Each preamble is ~200 lines of bash producing 30+ echoed lines (PROACTIVE / PROACTIVE_PROMPTED / BRANCH / SKILL_PREFIX / REPO_MODE / LAKE_INTRO / TELEMETRY / TEL_PROMPTED / EXPLAIN_LEVEL / QUESTION_TUNING / LEARNINGS / HAS_ROUTING / ROUTING_DECLINED / VENDORED_GSTACK / MODEL_OVERLAY / CHECKPOINT_MODE / CHECKPOINT_PUSH / ARTIFACTS_SYNC / etc.).

Within a single session these values do not change. The repeated gstack-config get, find ~/.gstack/sessions, gstack-learnings-search, gstack-timeline-log calls add noise to the agent's context and slow the skill startup.

Measured impact

In a recent 10-task implementation plan (PR #309-like, schema migration + 5 route refactor + double review), the same preamble executed 8 times, ~1600+ lines of duplicated state echo consumed in agent context across the run.

Proposal

Session-scoped cache for preamble outputs:

  1. On first invoke per session: full preamble runs, output written to ~/.gstack/sessions/<ppid>/preamble.env (or similar)
  2. Subsequent invokes within the same session: skill checks the cache file age (mtime < 2 hours, same PPID), if valid → emit cached values, skip the bash block entirely
  3. One-shot invalidations (gstack-config set ..., telemetry toggle, etc.) write a marker to invalidate cache

Alternative lighter-weight: extract preamble into a single shared gstack-session-init helper that all skills source, which itself checks cache.

Repro

# In a Claude Code session, invoke several gstack skills in sequence:
/investigate
/plan-eng-review
/codex review
/review
# Each skill emits the full preamble block — values are identical across invocations.

Why now

PR-level plans now routinely chain 5+ skills (investigate → write-plans → execute → codex → kimi review → finishing-a-branch). Preamble overhead is no longer a one-time cost.

Activity

  1. time-attack commented on Jul 15, 2026

    @time-attack
    Contributor

    Thanks for this. The blocker is that caching the complete preamble would also cache mutable repository state and suppress required per-invocation side effects. Limit caching to an explicitly pure data subset and define durable session identity, invalidation, repository isolation, permissions, and concurrent access behavior.

  2. capy-ai commented on Oct 11, 2026

    @capy-ai
    Contributor

    Thanks @shizeqin for the idea. In the Oct 11 triage we grouped the open feature requests by theme so related asks get built together instead of one at a time. This one is part of the Prompt cost and skill shape theme in TODOS.md (https://github.com/garrytan/gstack/blob/50d020ad9/TODOS.md#L54-L69). Closing it here so the open list stays actionable; it isn't rejected, and the theme credits every linked reporter when it's picked up.

  3. added
    parked
    on Oct 25, 2026
  4. capy-ai commented on Oct 25, 2026

    @capy-ai
    Contributor

    Reopened under the parked label: this is tracked in the Prompt cost and skill shape theme in TODOS.md (https://github.com/garrytan/gstack/blob/main/TODOS.md#p3-feature-themes-from-the-wave-9-triage-filed-2026-10-11), and what fixes it is the shared-preamble trim (GSTA-96), which removes most of the duplicated preamble weight each skill run pays. Closed-but-tracked read as closed, so parked issues now stay open until they ship, are duplicates, or are declined (https://github.com/garrytan/gstack/blob/main/docs/triage.md).

  5. added
    S3
    enhancement
    on Oct 31, 2026
  6. capy-ai commented on Oct 31, 2026

    @capy-ai
    Contributor

    Thanks for the idea, @shizeqin. Caching the startup check would hide repo changes made in the middle of a session, and the shared startup text is already read only once. Closing as not planned.

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

    S3enhancementparked

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions