Skip to content

⚡ Bolt: Optimize file staleness checks with native Zsh globbing - #495

Merged
kaovilai merged 3 commits into
mainfrom
bolt-zsh-globbing-cache-check-6081486736791090423
Jul 16, 2026
Merged

kaovilai merged 3 commits into
mainfrom
bolt-zsh-globbing-cache-check-6081486736791090423

Conversation

@kaovilai

@kaovilai kaovilai commented Jun 24, 2026 •

Copy link
Copy Markdown
Owner

💡 What: Replaced external stat and date subprocess calls with native Zsh extended globbing (#qN.ms+max_age) to calculate file staleness.
🎯 Why: Spawning subprocesses like stat and date is a significant bottleneck in shell scripts. By using Zsh native built-ins and glob qualifiers, we achieve the same functionality much faster and improve shell initialization.
📊 Impact: Eliminates expensive fork/exec overheads when checking if cache files are expired during shell startup and initialization, reducing startup latency.
🔬 Measurement: Verify cache expiration by manually editing a file's modification time (e.g. touch -d '2 days ago' ~/.zsh-command-cache/happy-update-check) and verifying that cache generation is triggered or cache functions report the correct TTL.


PR created automatically by Jules for task 6081486736791090423 started by @kaovilai

Summary by CodeRabbit

  • Bug Fixes
    • Improved background update checks to reliably detect missing or outdated cache files.
    • Improved compatibility across systems by removing reliance on platform-specific file timestamp commands.
    • Reduced unnecessary subprocess usage during cache expiration checks, improving efficiency.
  • Documentation
    • Expanded guidance for reliable Zsh glob evaluation and file-age checks.

Replaced external `stat` and `date` subprocess calls with native Zsh
extended globbing `(#qN.ms+max_age)` to calculate file age.

This eliminates costly fork/exec overhead during shell startup
and simplifies the logic for checking expired command caches
and happy CLI updates.

Also wraps the local options modification in `.zshrc` inside
an anonymous function to avoid leaking `extended_glob` to the
rest of the shell.

Co-authored-by: kaovilai <11228024+kaovilai@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@coderabbitai

coderabbitai Bot commented Jun 24, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 31917735-55ad-43b8-8d43-c32c2e2ad677

📥 Commits

Reviewing files that changed from the base of the PR and between 8768575 and 66bf76d.

📒 Files selected for processing (3)
  • .jules/bolt.md
  • .zshrc
  • zsh/command-cache.zsh

Walkthrough

Stamp-file expiration checks in .zshrc and zsh/command-cache.zsh now use Zsh extended glob qualifiers instead of stat and date. .jules/bolt.md documents the required local option scope and glob matching approach.

Changes

Zsh cache expiration

Layer / File(s) Summary
Native glob-based expiration checks
.zshrc, zsh/command-cache.zsh, .jules/bolt.md
Expiration logic uses locally scoped extended_glob qualifiers, match arrays, and the 86400-second threshold; guidance documents this pattern and its replacement of stat/date subprocesses.

Estimated code review effort: 2 (Simple) | ~10 minutes

Poem

I’m a rabbit with a glob in my ear,
Finding stale little stamps far and near.
No stat, no date, just a hop through the shell,
Extended patterns know expiration well.
Fresh files stay cozy; old ones ring the bell!

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bolt-zsh-globbing-cache-check-6081486736791090423

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request replaces subprocess-based file age checks (using stat and date) with native Zsh extended globbing ((#qN.ms+seconds)) in .zshrc and zsh/command-cache.zsh to optimize shell startup performance. It also adds a learning note documenting this optimization. Feedback suggests simplifying the logic in .zshrc by initializing the expired variable to 1 and writing the array check more concisely.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread .zshrc
Comment on lines +155 to 167
local expired=0
if [[ -f "$stamp" ]]; then
local mtime now
mtime=$(stat -f "%m" "$stamp" 2>/dev/null || stat -c "%Y" "$stamp" 2>/dev/null) || expired=0
now=$(date +%s)
(( now - mtime > 86400 )) && expired=0 || expired=1
() {
setopt local_options extended_glob
local -a expired_files
expired_files=("$stamp"(#qN.ms+86400))
if (( ${#expired_files} > 0 )); then
expired=1
fi
}
else
expired=0
expired=1
fi

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

We can simplify this logic and eliminate the else block by initializing expired=1 (expired by default). This also allows us to write the array initialization and the condition much more concisely and idiomatically in Zsh.

    local expired=1
    if [[ -f "$stamp" ]]; then
      () {
        setopt local_options extended_glob
        local -a expired_files=( "$stamp"(#qN.ms+86400) )
        (( $#expired_files )) || expired=0
      }
    fi

@github-actions

Copy link
Copy Markdown
Contributor

Code Review

The glob qualifier approach is correct and the logic inversion (fixing the confusing expired=0 semantics) is a good cleanup.

Two issues worth addressing:

1. .jules/bolt.md should not be committed

This is Jules AI's internal learning notes file. It's unrelated to dotfiles configuration and will accumulate with each Jules task. Add .jules/ to .gitignore to prevent future occurrences:

.jules/

2. Symlink edge case in cache-file-expired

The . qualifier in (#qN.ms+${max_age}) restricts matches to regular files only — symlinks are excluded. The original -f test followed symlinks, so:

  • Old behavior: a symlinked cache file is checked by age correctly
  • New behavior: a symlinked cache file never matches → expired_files is empty → function returns 1 (cache still valid) regardless of age

In practice, cache files in ~/.zsh-command-cache/ are unlikely to be symlinks, but it's a behavioral difference. Removing the . qualifier ((#qN.ms+${max_age}) → (#qNms+${max_age})) would match any file type and be more consistent with the original behavior.

Generated by Copilot Code Review for issue #495 · ● 5.4M · ◷

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR optimizes cache/staleness checks in the dotfiles’ Zsh startup logic by replacing external stat/date subprocess usage with native Zsh extended glob qualifiers ((#qN.ms+seconds)), reducing fork/exec overhead during shell initialization.

Changes:

  • Updated cache-file-expired to use extended glob qualifiers for age checks instead of computing epoch timestamps via subprocesses.
  • Updated the .zshrc “happy” update stamp TTL check to use the same native glob-qualifier approach.
  • Added a short Bolt learning note documenting the optimization pattern.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
zsh/command-cache.zsh Replaces stat/date-based expiry logic with Zsh native glob qualifiers in cache-file-expired.
.zshrc Replaces stat/date-based “happy-update-check” stamp staleness logic with Zsh native glob qualifiers.
.jules/bolt.md Documents the learning/action for using Zsh extended globbing to avoid subprocess overhead.
Comments suppressed due to low confidence (1)

zsh/command-cache.zsh:35

  • This allocates an array and counts elements just to test whether the glob matched. You can avoid the array entirely and do a direct non-empty check on the qualified path, which is simpler and avoids extra allocations in this hot path.
  local -a expired_files
  expired_files=("$file"(#qN.ms+${max_age}))

  if (( ${#expired_files} > 0 )); then
    return 0  # Cache expired
  else
    return 1  # Cache still valid
  fi

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

Comment thread .zshrc
Comment on lines +159 to +163
local -a expired_files
expired_files=("$stamp"(#qN.ms+86400))
if (( ${#expired_files} > 0 )); then
expired=1
fi
@kaovilai

Copy link
Copy Markdown
Owner Author

@jules this branch now has merge conflicts with main (main advanced significantly since this was opened). Please rebase/update this branch against the latest main and resolve any conflicts.

Note

Responses generated with Claude

@google-labs-jules

Copy link
Copy Markdown
Contributor

@jules this branch now has merge conflicts with main (main advanced significantly since this was opened). Please rebase/update this branch against the latest main and resolve any conflicts.

[!Note]
Responses generated with Claude

I have successfully fetched the latest main branch and resolved the merge conflicts in .jules/bolt.md.

google-labs-jules Bot and others added 2 commits July 16, 2026 15:10
Replaced external `stat` and `date` subprocess calls with native Zsh
extended globbing `(#qN.ms+max_age)` to calculate file age.

This eliminates costly fork/exec overhead during shell startup
and simplifies the logic for checking expired command caches
and happy CLI updates.

Also wraps the local options modification in `.zshrc` inside
an anonymous function to avoid leaking `extended_glob` to the
rest of the shell.

Co-authored-by: kaovilai <11228024+kaovilai@users.noreply.github.com>
Signed-off-by: Tiger Kaovilai <passawit.kaovilai@gmail.com>

# Conflicts:
#	.jules/bolt.md
@kaovilai
kaovilai merged commit 04a5677 into main Jul 16, 2026
3 of 4 checks passed
@github-actions github-actions Bot mentioned this pull request Jul 16, 2026
@kaovilai
kaovilai deleted the bolt-zsh-globbing-cache-check-6081486736791090423 branch October 9, 2026 16:47
kaovilai added a commit that referenced this pull request Oct 9, 2026
* ⚡ Bolt: Optimize file staleness checks with native Zsh globbing

Replaced external `stat` and `date` subprocess calls with native Zsh
extended globbing `(#qN.ms+max_age)` to calculate file age.

This eliminates costly fork/exec overhead during shell startup
and simplifies the logic for checking expired command caches
and happy CLI updates.

Also wraps the local options modification in `.zshrc` inside
an anonymous function to avoid leaking `extended_glob` to the
rest of the shell.

Co-authored-by: kaovilai <11228024+kaovilai@users.noreply.github.com>

* ⚡ Bolt: Optimize file staleness checks with native Zsh globbing

Replaced external `stat` and `date` subprocess calls with native Zsh
extended globbing `(#qN.ms+max_age)` to calculate file age.

This eliminates costly fork/exec overhead during shell startup
and simplifies the logic for checking expired command caches
and happy CLI updates.

Also wraps the local options modification in `.zshrc` inside
an anonymous function to avoid leaking `extended_glob` to the
rest of the shell.

Co-authored-by: kaovilai <11228024+kaovilai@users.noreply.github.com>

---------

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Co-authored-by: kaovilai <11228024+kaovilai@users.noreply.github.com>
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.

2 participants