Add cache TTL and max hits to zsh completion caching#360
Open
nat-n wants to merge 7 commits intodevelopmentfrom
Open
Add cache TTL and max hits to zsh completion caching#360nat-n wants to merge 7 commits intodevelopmentfrom
nat-n wants to merge 7 commits intodevelopmentfrom
Conversation
The in-memory cache (associative arrays _poe_mem_tasks/_poe_mem_args) had no TTL, causing it to serve stale data indefinitely within a shell session. When the disk cache expired after 1 hour, the code fell through to the in-memory fallback which had no expiration check, effectively making the cache permanent for the lifetime of the shell. Fix by tracking timestamps via $SECONDS alongside cached data and checking age against _POE_CACHE_TTL (3600s) on retrieval. This applies to all three cache consumers: task state, help_task state, and task args. https://claude.ai/code/session_017koSbdzwCoQ2evAwnRkpbN
…changes
The cache-policy was registered with zstyle using the literal
${curcontext} value. But _arguments -C modifies curcontext when entering
states (e.g. "poe" becomes "poe-args"), so when _cache_invalid later
looked up the policy with the modified context, it didn't match. Without
finding a policy, _cache_invalid only checks file existence — the disk
cache was never invalidated, even across new shell sessions.
Fix by using a wildcard pattern ":completion:*:${0#_}*:*" that matches
all poe-related contexts regardless of state suffix.
https://claude.ai/code/session_017koSbdzwCoQ2evAwnRkpbN
Test coverage for two bugs where the cache TTL wasn't working:
1. test_cache_policy_found_after_arguments_modifies_context: Verifies
the zstyle cache-policy pattern matches even after _arguments -C
modifies curcontext (e.g., poe -> poe-args). Fails with the old
":completion:${curcontext}:" pattern.
2. test_expired_in_memory_cache_triggers_fresh_fetch: Verifies that
in-memory task cache with expired TTL triggers a fresh fetch.
Fails without the SECONDS-based TTL check.
3. test_valid_in_memory_cache_is_used: Control test verifying
in-memory cache within TTL is used (passes with both old/new code).
4. test_expired_in_memory_args_cache_triggers_fresh_fetch: Verifies
task args in-memory cache also respects TTL. Fails without fix.
https://claude.ai/code/session_017koSbdzwCoQ2evAwnRkpbN
…hells In a long-running shell session, cached completion data could be served indefinitely if the disk cache TTL never expires (e.g., file mtime stays fresh due to other processes). This adds a per-key hit counter that forces a fresh fetch after every 10 cache hits, regardless of TTL status. Applies uniformly to both disk and in-memory caches for task lists, task args, and help_task completions. Counter resets to 0 on each fresh fetch. https://claude.ai/code/session_017koSbdzwCoQ2evAwnRkpbN
The task_state_handler and help_task_state_handler had identical 50-line cache blocks (disk -> in-memory -> hit counting -> fresh fetch -> store). Extract into a _poe_fetch_tasks() zsh helper function that both handlers call, returning results via the standard zsh reply array. Net -28 lines. Args handler left inline since its cache key structure (path|task) and data format differ enough to not warrant unification. https://claude.ai/code/session_017koSbdzwCoQ2evAwnRkpbN
Black 25.11.0 prefers expanded multiline argument formatting. The previous formatter commit (978d247) collapsed these, which was the opposite of what the current black version wants. https://claude.ai/code/session_017koSbdzwCoQ2evAwnRkpbN
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of changes
This PR enhances the zsh completion caching mechanism with two important features to prevent serving stale data:
1. In-Memory Cache TTL (Time-To-Live)
$SECONDSvariable in_poe_mem_tasks_timeand_poe_mem_args_timeassociative arrays2. Max Cache Hits Threshold
_poe_cache_hits_tasksand_poe_cache_hits_argsassociative arrays3. Cache Policy Pattern Fix
":completion:*:${0#_}*:*")_arguments -Cmodifiescurcontext_arguments -Cappended state suffixes (e.g.,poe→poe-args)4. Code Refactoring
_poe_fetch_tasks()helper functionTesting
All new features are covered by tests in
test_zsh_completion_harness.py.Pre-merge Checklist
https://claude.ai/code/session_017koSbdzwCoQ2evAwnRkpbN