Skip to content

fix: randomly select starting item on cache miss in round-robin workflows#30005

Merged
pelikhan merged 2 commits intomainfrom
copilot/investigate-agentic-workflows-cache-memory
May 3, 2026
Merged

fix: randomly select starting item on cache miss in round-robin workflows#30005
pelikhan merged 2 commits intomainfrom
copilot/investigate-agentic-workflows-cache-memory

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 3, 2026

Workflows using cache-memory for round-robin rotation always started from a fixed position on a cold start, causing repeated cache misses (after expiry or first run) to process the same items first every time.

Changes

  • daily-function-namer.md — Python snippet now returns -1 as a sentinel when the cache is absent/unreadable; after TOTAL is computed, -1 resolves to $(( RANDOM % TOTAL )). Added an early exit guard for TOTAL=0.

    # Before
    print(d.get('last_package_index', 0))  # always index 0 on miss
    
    # After
    print(d.get('last_package_index', -1))  # -1 = "pick randomly"
    # …then, after TOTAL is known:
    if [ "$LAST_INDEX" -eq -1 ]; then
      LAST_INDEX=$(( RANDOM % TOTAL ))
    fi
  • daily-caveman-optimizer.md — Updated instruction to use $(( RANDOM % TOTAL )) for the initial index on a cold start instead of hardcoding 0.

  • slide-deck-maintainer.md — Cold-start category selection now uses shuf -n1 -e source-code agentic-workflows documentation instead of always defaulting to documentation.

Copilot AI and others added 2 commits May 3, 2026 20:08
Update three workflows that use cache-memory with round-robin rotation
so that a cold start (absent or empty cache) selects a random position
in the list rather than always starting at the same fixed item:

- daily-function-namer: output -1 sentinel when cache is missing,
  then resolve to $(( RANDOM % TOTAL )) after package list is built
- daily-caveman-optimizer: instruct agent to use $(( RANDOM % total_files ))
  for the initial index on cold start
- slide-deck-maintainer: use shuf -n1 to randomly pick the first category
  instead of always beginning with 'documentation'

Agent-Logs-Url: https://github.com/github/gh-aw/sessions/e7394ac9-64c9-4b1b-beab-c53cab5e68ca

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
@pelikhan pelikhan marked this pull request as ready for review May 3, 2026 20:24
Copilot AI review requested due to automatic review settings May 3, 2026 20:24
@pelikhan pelikhan merged commit 1d69ddb into main May 3, 2026
10 of 20 checks passed
@pelikhan pelikhan deleted the copilot/investigate-agentic-workflows-cache-memory branch May 3, 2026 20:24
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adjusts round-robin cold-start behavior for workflows that rely on cache-memory so that cache misses don’t always start at a fixed position (reducing repeated cache-miss churn on the same initial items).

Changes:

  • Update daily-function-namer package selection script to treat cache miss/unreadable state as a sentinel and randomize the initial index (plus add a TOTAL=0 guard).
  • Update daily-caveman-optimizer instructions to randomize the initial index on cold start.
  • Update slide-deck-maintainer instructions to randomize the initial category on cold start.
Show a summary per file
File Description
.github/workflows/slide-deck-maintainer.md Documents randomized category selection on cold cache for round-robin scanning.
.github/workflows/daily-function-namer.md Implements cache-miss sentinel + random start index in the selection script and adds an empty-package guard.
.github/workflows/daily-caveman-optimizer.md Documents random start index selection for cold-cache runs.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 3/3 changed files
  • Comments generated: 3

# Load last_package_index from cache (default 0 if cache absent/empty)
# Load last_package_index from cache (-1 sentinel means cache is absent/empty — pick randomly later)
LAST_INDEX=$(python3 -c "
import sys, json, os
# On cache miss, start at a random position so repeated cold starts don't always hit the same package
if [ "$LAST_INDEX" -eq -1 ]; then
LAST_INDEX=$(( RANDOM % TOTAL ))
echo "cache_miss=true (random start at index ${LAST_INDEX})"

- If the file does not exist, start at index 0.
- If the queue in cache differs from the current file list (files added/removed), rebuild the queue from the current sorted list and reset index to 0.
- If the file does not exist, count the total number of files in the sorted list (`TOTAL=$(...)`) and pick a **random** starting index with `$(( RANDOM % TOTAL ))`. This avoids always processing the same files first when the cache is cold.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants