Commit 93bc795
fix(zsh): streaming placeholder not updated when async is enabled (#7443)
* fix: streaming placeholder not updated when async is enabled
When both async and streaming are configured on ZSH, the init command
becomes 'precmd() { source <script> }', which re-sources the script on
every prompt cycle. This unconditionally reset _omp_stream_fd=-1, causing
_omp_cleanup_stream to skip closing the previous cycle's stream fd.
The stale stream's EOF handler would later call _omp_cleanup_stream using
the global _omp_stream_fd (now pointing to the new stream's fd) and kill
the new stream before it could send any updates. The placeholder never
got replaced.
Three fixes:
1. init.go: Skip async sourcing when streaming is also active. Streaming
provides its own async update mechanism; re-sourcing on every precmd is
not needed and conflicts with the streaming fd lifecycle.
2. omp.zsh (_omp_stream_fd init): Use \ so a
re-source does not clobber an in-flight stream fd.
3. omp.zsh (_omp_async_handler): On EOF, close only the specific fd that
triggered the handler instead of calling _omp_cleanup_stream. This
prevents any stale handler from closing the current stream's fd even if
the global variable has diverged.
Fixes #7313
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* fix(zsh): streaming placeholder not updated when async is enabled
When both async and streaming are configured in ZSH, the omp.zsh script
is re-sourced before every prompt cycle via the async init mechanism
(precmd() { source <script> }). Top-level variable assignments in the
re-sourced script run unconditionally, so _omp_stream_fd was reset to -1
on every prompt cycle even while a live stream was in flight.
This caused two problems:
1. _omp_cleanup_stream skipped cleanup (fd -1 < 0) before starting the
new stream, leaking the old fd and its ZLE handler.
2. The stale EOF handler later fired, saw _omp_stream_fd pointing at the
NEW stream, and closed it so the placeholder was never replaced.
Fix 1: use _omp_stream_fd=\ (ZSH := modifier) so
the fd value survives a re-source, initialising to -1 only when the
variable is genuinely unset (first source at shell startup).
Fix 2: in _omp_async_handler, guard the EOF cleanup with
[[ \ -eq \ ]] so a stale handler from a previous
prompt cycle can never close the current stream's fd.
Reverts the init.go change from the previous commit changing the
async sourcing mechanism is unnecessary and caused a regression (exit
code 127) when streaming was enabled.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* fix(zsh): correct misleading comment on stream fd initialization
The comment referenced := (ZSH assign-if-unset) but the code uses :-
(use-default-if-unset). Update the comment to accurately describe
what the expansion does.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent dba37ed commit 93bc795
1 file changed
+5
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
110 | 111 | | |
111 | 112 | | |
112 | 113 | | |
113 | | - | |
114 | | - | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
115 | 117 | | |
116 | 118 | | |
117 | 119 | | |
| |||
0 commit comments