Skip to content

cache-memory: GH_AW_WORKFLOW_ID_SANITIZED not defined in update_cache_memory job, causing cache key mismatch #17243

@joperezr

Description

@joperezr

Summary

When using the cache-memory: tool, data saved by one workflow run is never found by the next run. This means features that depend on cross-run persistence (like accumulating daily snapshots for a burndown chart) don't work — every run starts fresh as if no previous data exists.

Root Cause

The compiled .lock.yml workflow has two jobs that interact with the GitHub Actions cache:

  1. agent job — restores cached data at the start of the run
  2. update_cache_memory job — saves cached data at the end of the run

Both jobs use a cache key that includes the environment variable GH_AW_WORKFLOW_ID_SANITIZED (e.g., dailyrepostatus). The intended key format is:

memory-<workflow_id>-<run_id>
  e.g. memory-dailyrepostatus-22233547030

The problem: GH_AW_WORKFLOW_ID_SANITIZED is defined in the agent job's env: block, but not in the update_cache_memory job. Since GitHub Actions jobs run in isolated environments, environment variables from one job are not available in another. So update_cache_memory sees an empty value and saves with the wrong key:

Job Operation Expected Key Actual Key
agent restore (prefix match) memory-dailyrepostatus- memory-dailyrepostatus-
update_cache_memory save memory-dailyrepostatus-<run_id> memory--<run_id>

On the next run, the agent job searches for keys starting with memory-dailyrepostatus-, but the saved key is memory--<run_id> (note the missing workflow ID between the two hyphens). The prefix doesn't match, so the cache is never found.

How to Reproduce

  1. Create a workflow that uses cache-memory::
    tools:
      cache-memory:
    
  2. Compile with gh aw compile
  3. Run the workflow twice
  4. On the second run, observe in the logs:
    • The restore step reports "Cache not found"
    • Any data the agent saved to /tmp/gh-aw/cache-memory/ in the first run is gone

Suggested Fix

Add GH_AW_WORKFLOW_ID_SANITIZED to the update_cache_memory job's env: block in the compiled lock file, so it matches the value used by the agent job. Alternatively, define the variable at the workflow level so all jobs inherit it automatically.

Here's roughly what needs to change in the compiled output:

update_cache_memory:
    needs: [agent, detection]
    runs-on: ubuntu-latest
+   env:
+     GH_AW_WORKFLOW_ID_SANITIZED: dailyrepostatus
    steps:
      # ...
      - name: Save cache-memory to cache
        uses: actions/cache/save@...
        with:
          key: memory-${{ env.GH_AW_WORKFLOW_ID_SANITIZED }}-${{ github.run_id }}

Evidence from Logs

Agent job (restore — correct prefix):

key: memory-dailyrepostatus-22233547030
restore-keys: memory-dailyrepostatus-
Cache not found for input keys: memory-dailyrepostatus-22233547030, memory-dailyrepostatus-

update_cache_memory job (save — missing workflow ID):

key: memory--22189346349
Cache saved with key: memory--22189346349

Version

  • gh aw v0.47.3 (also reproduced on v0.45.5)

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions