[GH-ISSUE #7583] [Bug] Zsh completion setup omits the required compinit initialization order #4517

Closed
opened 2026-10-31 00:50:26 +00:00 by bsakaguchi · 0 comments
Owner

Originally created by @coygeek on GitHub (Oct 27, 2026).
Original GitHub issue: https://github.com/morluto/rea/issues/7583

Before submitting

  • I searched the open and closed issues for a related report.
  • I removed credentials, tokens, private paths, and sensitive target data.

Area

CLI

Observed behavior

node scripts/rea.mjs completions --help gives this zsh Setup instruction:

eval "$(rea completions zsh)"   # add to ~/.zshrc

When that is the only startup instruction in an isolated interactive macOS system zsh, startup emits (eval):12: command not found: compdef. The generated function exists, but REA is absent from the completion association table: association=0 function=1.

Reproduction

Use a built checkout at the revision below with Node v24.22.1 on PATH. All shell configuration below is disposable; the real startup files are untouched.

  1. From the checkout root, create an isolated HOME/XDG/ZDOTDIR and a launcher for this checkout:
verify_root="$PWD"
verify_node="$(command -v node)"
verify_dir=$(mktemp -d)
export REA_VERIFY_ROOT="$verify_root" REA_VERIFY_NODE="$verify_node"
export HOME="$verify_dir/home" ZDOTDIR="$verify_dir/zdot"
export XDG_CONFIG_HOME="$verify_dir/config" XDG_CACHE_HOME="$verify_dir/cache"
export XDG_DATA_HOME="$verify_dir/data" XDG_STATE_HOME="$verify_dir/state"
export XDG_RUNTIME_DIR="$verify_dir/runtime"
mkdir -p "$HOME" "$ZDOTDIR" "$XDG_CONFIG_HOME" "$XDG_CACHE_HOME" \
  "$XDG_DATA_HOME" "$XDG_STATE_HOME" "$XDG_RUNTIME_DIR" "$verify_dir/bin"
printf '%s\n' '#!/bin/sh' \
  'exec "$REA_VERIFY_NODE" "$REA_VERIFY_ROOT/scripts/rea.mjs" "$@"' > "$verify_dir/bin/rea"
chmod +x "$verify_dir/bin/rea"
export PATH="$verify_dir/bin:$PATH"
printf '%s\n' 'eval "$(rea completions zsh)"' > "$ZDOTDIR/.zshrc"
  1. Inspect the advertised setup, then start three fresh interactive shells:
node scripts/rea.mjs --version
node scripts/rea.mjs completions --help
for attempt in 1 2 3; do
  /bin/zsh -i -c 'print -r -- "association=${+_comps[rea]} function=${+functions[_incur_complete_rea]}"'
done

Each run prints the compdef diagnostic on stderr and association=0 function=1 on stdout. This reproduced in all three runs.

  1. Initialize zsh completion before the same hook as a control:
/bin/zsh -f -c 'autoload -Uz compinit; compinit -i -d "$XDG_CACHE_HOME/zcompdump"; eval "$(rea completions zsh)"; print -r -- "association=${+_comps[rea]} function=${+functions[_incur_complete_rea]}"'

The control prints association=1 function=1 with empty stderr. The shell checks end with a successful print command, so their exit status alone does not reveal the failed registration.

Expected behavior

The advertised zsh Setup instructions should explain that compinit must run before the supplied eval line, or otherwise provide setup that successfully registers completion in a fresh zsh. The CLI guide directs users to this help output for shell setup. Neither that guide nor the help output mentions the prerequisite or ordering requirement. Applicability to a fresh shell is inferred from the unqualified Setup instruction; there is no explicit fresh-shell guarantee.

Impact and scope

P2: a bounded functional setup failure with a demonstrated workaround. On the tested fresh zsh configuration, loading the advertised hook reports an error and does not register REA completion. Initializing compinit first restores registration. Shells that already initialize completion before this hook are outside the demonstrated failure. Other shells, completion candidate behavior, and other zsh versions were not tested. No analysis target or data was involved.

REA version

Exact stdout of node scripts/rea.mjs --version:

6.8.0

Source commit: 65f1c447344a423fa2785847dbcea1e9a9e2454a.

Runtime and platform

Node v24.22.1; macOS 27.0.1, build 26A434; arm64; macOS system /bin/zsh, version zsh 5.9 (arm64-apple-darwin26.0). No analysis provider was launched.

Target and artifact context

Generated zsh completion hook; no analysis target.

Interface

CLI

Earliest failure stage

Setup or provider admission

Relevant output or evidence

The failing startup checks above each produced:

stderr: (eval):12: command not found: compdef
stdout: association=0 function=1

The compinit-first control produced:

stdout: association=1 function=1
stderr: empty

The documentation locator is docs/cli.md:149-177: it directs users to completion help and then documents Bash setup specifically. Zsh registration is selected through src/cli/completions.ts:83-86. In pinned Incur 0.6.1, node_modules/incur/src/Completions.ts:306-319 generates the zsh hook and node_modules/incur/src/internal/command.ts:392-408 supplies the setup hint. These locators explain the observed public output; no checkout changes were made.

Analysis or suspected cause

Source-derived explanation supported by the control: the generated hook calls compdef immediately, assuming the caller has already initialized zsh completion. The supplied setup instruction leaves that prerequisite unstated. This report does not require automatic shell initialization; documenting the prerequisite and ordering would address the demonstrated setup omission.

Additional context

Related closed reports cover different defects: #5527 concerns Bash registration with unsupported nosort; #5526 concerns missing global candidates; #5528 concerns MCP completion scope. #5481 requested completion generally, and #6250/#5533 document Bash setup. Their bodies and comments do not describe this compinit prerequisite. No last-known-good release was established, so this is not claimed as a regression.

Originally created by @coygeek on GitHub (Oct 27, 2026). Original GitHub issue: https://github.com/morluto/rea/issues/7583 ### Before submitting - [x] I searched the open and closed issues for a related report. - [x] I removed credentials, tokens, private paths, and sensitive target data. ### Area CLI ### Observed behavior `node scripts/rea.mjs completions --help` gives this zsh Setup instruction: ```sh eval "$(rea completions zsh)" # add to ~/.zshrc ``` When that is the only startup instruction in an isolated interactive macOS system zsh, startup emits `(eval):12: command not found: compdef`. The generated function exists, but REA is absent from the completion association table: `association=0 function=1`. ### Reproduction Use a built checkout at the revision below with Node v24.22.1 on PATH. All shell configuration below is disposable; the real startup files are untouched. 1. From the checkout root, create an isolated HOME/XDG/ZDOTDIR and a launcher for this checkout: ```sh verify_root="$PWD" verify_node="$(command -v node)" verify_dir=$(mktemp -d) export REA_VERIFY_ROOT="$verify_root" REA_VERIFY_NODE="$verify_node" export HOME="$verify_dir/home" ZDOTDIR="$verify_dir/zdot" export XDG_CONFIG_HOME="$verify_dir/config" XDG_CACHE_HOME="$verify_dir/cache" export XDG_DATA_HOME="$verify_dir/data" XDG_STATE_HOME="$verify_dir/state" export XDG_RUNTIME_DIR="$verify_dir/runtime" mkdir -p "$HOME" "$ZDOTDIR" "$XDG_CONFIG_HOME" "$XDG_CACHE_HOME" \ "$XDG_DATA_HOME" "$XDG_STATE_HOME" "$XDG_RUNTIME_DIR" "$verify_dir/bin" printf '%s\n' '#!/bin/sh' \ 'exec "$REA_VERIFY_NODE" "$REA_VERIFY_ROOT/scripts/rea.mjs" "$@"' > "$verify_dir/bin/rea" chmod +x "$verify_dir/bin/rea" export PATH="$verify_dir/bin:$PATH" printf '%s\n' 'eval "$(rea completions zsh)"' > "$ZDOTDIR/.zshrc" ``` 2. Inspect the advertised setup, then start three fresh interactive shells: ```sh node scripts/rea.mjs --version node scripts/rea.mjs completions --help for attempt in 1 2 3; do /bin/zsh -i -c 'print -r -- "association=${+_comps[rea]} function=${+functions[_incur_complete_rea]}"' done ``` Each run prints the compdef diagnostic on stderr and `association=0 function=1` on stdout. This reproduced in all three runs. 3. Initialize zsh completion before the same hook as a control: ```sh /bin/zsh -f -c 'autoload -Uz compinit; compinit -i -d "$XDG_CACHE_HOME/zcompdump"; eval "$(rea completions zsh)"; print -r -- "association=${+_comps[rea]} function=${+functions[_incur_complete_rea]}"' ``` The control prints `association=1 function=1` with empty stderr. The shell checks end with a successful print command, so their exit status alone does not reveal the failed registration. ### Expected behavior The advertised zsh Setup instructions should explain that `compinit` must run before the supplied eval line, or otherwise provide setup that successfully registers completion in a fresh zsh. The CLI guide directs users to this help output for shell setup. Neither that guide nor the help output mentions the prerequisite or ordering requirement. Applicability to a fresh shell is inferred from the unqualified Setup instruction; there is no explicit fresh-shell guarantee. ### Impact and scope P2: a bounded functional setup failure with a demonstrated workaround. On the tested fresh zsh configuration, loading the advertised hook reports an error and does not register REA completion. Initializing compinit first restores registration. Shells that already initialize completion before this hook are outside the demonstrated failure. Other shells, completion candidate behavior, and other zsh versions were not tested. No analysis target or data was involved. ### REA version Exact stdout of `node scripts/rea.mjs --version`: ```text 6.8.0 ``` Source commit: `65f1c447344a423fa2785847dbcea1e9a9e2454a`. ### Runtime and platform Node v24.22.1; macOS 27.0.1, build 26A434; arm64; macOS system `/bin/zsh`, version `zsh 5.9 (arm64-apple-darwin26.0)`. No analysis provider was launched. ### Target and artifact context Generated zsh completion hook; no analysis target. ### Interface CLI ### Earliest failure stage Setup or provider admission ### Relevant output or evidence The failing startup checks above each produced: ```text stderr: (eval):12: command not found: compdef stdout: association=0 function=1 ``` The compinit-first control produced: ```text stdout: association=1 function=1 stderr: empty ``` The documentation locator is `docs/cli.md:149-177`: it directs users to completion help and then documents Bash setup specifically. Zsh registration is selected through `src/cli/completions.ts:83-86`. In pinned Incur 0.6.1, `node_modules/incur/src/Completions.ts:306-319` generates the zsh hook and `node_modules/incur/src/internal/command.ts:392-408` supplies the setup hint. These locators explain the observed public output; no checkout changes were made. ### Analysis or suspected cause Source-derived explanation supported by the control: the generated hook calls compdef immediately, assuming the caller has already initialized zsh completion. The supplied setup instruction leaves that prerequisite unstated. This report does not require automatic shell initialization; documenting the prerequisite and ordering would address the demonstrated setup omission. ### Additional context Related closed reports cover different defects: #5527 concerns Bash registration with unsupported nosort; #5526 concerns missing global candidates; #5528 concerns MCP completion scope. #5481 requested completion generally, and #6250/#5533 document Bash setup. Their bodies and comments do not describe this compinit prerequisite. No last-known-good release was established, so this is not claimed as a regression.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
morluto/rea#4517
No description provided.