Skip to content

fix: IPC mode port discovery, empty result handling, shell quoting, and debug support#6

Merged
Timmy6942025 merged 2 commits intomasterfrom
fix/ipc-mode-port-discovery-and-empty-results
Mar 27, 2026
Merged

fix: IPC mode port discovery, empty result handling, shell quoting, and debug support#6
Timmy6942025 merged 2 commits intomasterfrom
fix/ipc-mode-port-discovery-and-empty-results

Conversation

@Timmy6942025
Copy link
Copy Markdown
Owner

Summary

This PR fixes several issues with the live search and IPC mode functionality:

IPC Mode Port Discovery Fix

  • Prepends FPF_FZF_LISTEN_HOST=localhost:\$FZF_PORT to the IPC command so the subprocess correctly connects to fzf's listen port
  • Falls back to \$FZF_PORT environment variable if FPF_FZF_LISTEN_HOST is not set
  • Removes the hardcoded localhost:9812 fallback which was incorrect with --listen=0
  • Returns early with an error message to stderr when port cannot be determined

Empty Result Handling Fix

  • When buildDisplayRows() returns zero results, the code now calls emitFile(fallbackFile) instead of writeBuildDisplayRowsTSV(rows) to preserve the current fzf list rather than clearing it

Shell Quoting Improvement

  • Changed from "{q}" to '{q}' (single quotes) in both reload commands for safer shell handling across bash, dash, and zsh

Visual Manager Scope Indicator

  • Added Search (fast)> prompt when flatpak/npm are excluded from live search to signal to users that these managers are excluded and Ctrl+R will search all managers

Debug Support

  • Added FPF_DEBUG_RELOAD=1 environment variable support that logs to stderr: query received, managers being searched, result count, and any errors encountered

Tests Added

  • run_dynamic_reload_ipc_port_discovery_test() in smoke.sh to verify FPF_FZF_LISTEN_HOST appears in IPC command output
  • TestDebugReloadEnabled unit test for debug flag parsing

Documentation

  • Added Linux troubleshooting section to README.md explaining:
    • Why flatpak/npm are excluded from live search by default
    • How to use FPF_DYNAMIC_RELOAD_MANAGERS=all for full coverage
    • How to use Ctrl+R for full manager search
    • How to debug with FPF_DEBUG_RELOAD=1
    • IPC mode port discovery notes

…nd debug support

- Fix IPC subprocess connection to fzf's listen port by prepending
  FPF_FZF_LISTEN_HOST=localhost:$FZF_PORT in buildDynamicQueryNotifyIPCCommandGo()
- Fall back to checking $FZF_PORT in runIPCReload() if FPF_FZF_LISTEN_HOST is empty
- Remove hardcoded localhost:9812 fallback (incorrect with --listen=0)
- Return early with error to stderr when port cannot be determined

- Fix empty result handling: emit fallback file instead of clearing fzf list
  when buildDisplayRows() returns zero results

- Improve shell quoting: use single quotes for {q} placeholder to safely
  handle shell metacharacters across bash, dash, and zsh

- Add visual manager scope indicator: show 'Search (fast)> ' when flatpak/npm
  are excluded from live search

- Add FPF_DEBUG_RELOAD=1 support for debugging live search issues

- Add tests: IPC port discovery test, debug reload unit test

- Add Linux troubleshooting section to README.md
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 27, 2026

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Summary by CodeRabbit

  • Documentation

    • Added Linux Live Search Troubleshooting: typing-based search uses a fast manager subset by default; how to override scope via FPF_DYNAMIC_RELOAD_MANAGERS, use Ctrl+R for full reload, and enable debug output with FPF_DEBUG_RELOAD=1.
    • Documented IPC transport behavior, automatic port discovery from FZF_PORT, and minimum fzf/--listen requirements.
  • New Features

    • Typing prompt reflects fast-mode vs full reload (e.g., "Search (fast)>").
  • Bug Fixes

    • Improved IPC reload host/port discovery and clearer stderr debug output.

Walkthrough

Adds Linux live-search troubleshooting docs, debug logging for dynamic reload, IPC-based reload transport with port discovery from FZF_PORT, adjustments to fzf reload command quoting and prompt behavior, and corresponding test updates.

Changes

Cohort / File(s) Summary
Documentation
README.md
Added "Linux Live Search Troubleshooting" section documenting FPF_DYNAMIC_RELOAD_MANAGERS, FPF_DEBUG_RELOAD, FPF_DYNAMIC_RELOAD_TRANSPORT=ipc, FPF_FZF_LISTEN_HOST/FZF_PORT behavior, and debugging examples.
CLI Runtime & Tests
cmd/fpf/cli_runtime.go, cmd/fpf/cli_runtime_test.go, cmd/fpf/perf_trace_test.go
Added excludeSlowManagers bool parameter to runFuzzySelectorGo, adjust initial prompt text and restore it after reload (including IPC notify), switched {q} quoting to single quotes in reload commands, and updated test call sites.
Dynamic Reload Debugging
cmd/fpf/dynamic_reload.go, cmd/fpf/dynamic_reload_test.go
Added debugReloadEnabled() and conditional stderr debug logs at key decision points; added unit test covering FPF_DEBUG_RELOAD boolean interpretations.
IPC Actions
cmd/fpf/ipc_actions.go
runIPCReload now derives listen host from FZF_PORT when FPF_FZF_LISTEN_HOST is unset; errors out if no usable host/port is available.
Smoke Tests
tests/smoke.sh
Updated assertions to expect single-quoted '{q}' placeholders for --dynamic-reload/--ipc-query-notify, added IPC port discovery test asserting FPF_FZF_LISTEN_HOST=localhost:\$FZF_PORT.

Sequence Diagram(s)

sequenceDiagram
  participant User as User
  participant CLI as fpf CLI
  participant FZF as fzf (selector)
  participant Manager as Managers (detectors)
  participant IPC as IPC notify

  User->>CLI: type query (live search)
  CLI->>Manager: compute manager subset (dynamic reload)
  alt subset != all
    CLI->>FZF: start with "Search (fast)>" prompt
  else
    CLI->>FZF: start with "Search>" prompt
  end
  CLI->>Manager: buildDisplayRows(query, managers)
  Manager-->>CLI: rows
  CLI->>FZF: send rows (stdin)
  opt IPC transport enabled
    CLI->>IPC: send query notify (FPF_FZF_LISTEN_HOST/FZF_PORT)
    IPC->>FZF: result:change-prompt / reload trigger
  end
  FZF->>CLI: user selection / reload requests
  CLI->>Manager: on full reload -> use all managers
  Manager-->>CLI: updated rows
  CLI->>FZF: update prompt to original via result:change-prompt
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 With twitching nose I hop and peep,

I trace the reload when queries creep,
Single quotes snug, IPC finds its way,
Debug lights twinkle on stderr's display,
Hooray — live search hums throughout the day!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 7.41% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main changes: IPC port discovery fixes, empty result handling, shell quoting improvements, and debug support additions.
Description check ✅ Passed The description comprehensively explains the changeset with clear sections covering IPC mode fixes, empty result handling, shell quoting, visual indicators, debug support, tests, and documentation additions.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 fix/ipc-mode-port-discovery-and-empty-results

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

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
cmd/fpf/cli_runtime.go (1)

715-728: ⚠️ Potential issue | 🔴 Critical

Remove shell quotes around the {q} placeholder.

Wrapping {q} in quotes ('{q}') causes queries with apostrophes to break. When fzf substitutes {q} with a query like o'clock, it produces -- 'o'clock' where the shell quote from the placeholder surrounds an unescaped apostrophe in the query, breaking the command. fzf's documented reload examples pass {q} unquoted.

Suggested fix
 func buildDynamicReloadCommandGo(managerOverride, fallbackFile, managerListCSV string) string {
 	bypass := dynamicReloadBypassValueGo()
 	parts := []string{
 		"FPF_SKIP_INSTALLED_MARKERS=1",
 		"FPF_BYPASS_QUERY_CACHE=" + bypass,
 		"FPF_SKIP_QUERY_CACHE_WRITE=1",
 		"FPF_IPC_MANAGER_OVERRIDE=" + shellQuoteIfNeeded(managerOverride),
 		"FPF_IPC_MANAGER_LIST=" + shellQuoteIfNeeded(managerListCSV),
 		"FPF_IPC_FALLBACK_FILE=" + shellQuoteIfNeeded(fallbackFile),
 		shellQuote(os.Args[0]),
 		"--dynamic-reload",
 		"--",
-		"'{q}'",
+		"{q}",
 	}
 	return strings.Join(parts, " ")
 }
 
 func buildDynamicQueryNotifyIPCCommandGo(managerOverride, fallbackFile, managerListCSV string) string {
 	parts := []string{
 		"FPF_FZF_LISTEN_HOST=localhost:$FZF_PORT",
 		"FPF_IPC_MANAGER_OVERRIDE=" + shellQuoteIfNeeded(managerOverride),
 		"FPF_IPC_MANAGER_LIST=" + shellQuoteIfNeeded(managerListCSV),
 		"FPF_IPC_FALLBACK_FILE=" + shellQuoteIfNeeded(fallbackFile),
 		shellQuote(os.Args[0]),
 		"--ipc-query-notify",
 		"--",
-		"'{q}'",
+		"{q}",
 	}
 	return strings.Join(parts, " ")
 }

Also applies to: 732-742

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cmd/fpf/cli_runtime.go` around lines 715 - 728, In
buildDynamicReloadCommandGo, remove the surrounding shell single quotes around
the fzf query placeholder so queries with apostrophes don't break; locate the
parts entry that currently contains "'{q}'" and change it to "{q}" (and make the
same change for the other identical occurrence later in the function), ensuring
the placeholder is passed unquoted so fzf can substitute queries like o'clock
correctly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@cmd/fpf/cli_runtime.go`:
- Around line 214-216: The "(fast)" prompt is shown whenever the manager lists
differ (currently computed by comparing joined strings), which also flips for
reordered or custom subsets; change the logic that sets excludeSlowManagers
(used when calling runFuzzySelectorGo) to only be true when reloadCmd and
reloadFullCmd are set AND dynamicReloadManagers(managers) is a strict subset of
managers (every element of dynamic exists in managers and len(dynamic) <
len(managers)) instead of any inequality; also ensure the prompt-change bindings
(the result:change-prompt / change handlers that run after reload) do not
unconditionally overwrite the indicator—make those handlers consult the same
excludeSlowManagers flag (or accept it as a parameter) so the prompt remains
correct after the first reload.

In `@cmd/fpf/ipc_actions.go`:
- Around line 48-52: The fallback that sets fzfHost from os.Getenv("FZF_PORT")
should accept either a bare port or a precomposed host:port; change the logic
where fzfPort is read (variable fzfPort in cmd/fpf/ipc_actions.go, used to set
fzfHost) to check whether fzfPort contains ":" and if so assign fzfHost =
fzfPort directly, otherwise assign fzfHost = "localhost:"+fzfPort so you don't
produce addresses like "localhost:127.0.0.1:9999".

---

Outside diff comments:
In `@cmd/fpf/cli_runtime.go`:
- Around line 715-728: In buildDynamicReloadCommandGo, remove the surrounding
shell single quotes around the fzf query placeholder so queries with apostrophes
don't break; locate the parts entry that currently contains "'{q}'" and change
it to "{q}" (and make the same change for the other identical occurrence later
in the function), ensuring the placeholder is passed unquoted so fzf can
substitute queries like o'clock correctly.
🪄 Autofix (Beta)

✅ Autofix completed


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: f19e2a50-e60d-4472-b65b-025da5beb13a

📥 Commits

Reviewing files that changed from the base of the PR and between c2abbd2 and ee0c423.

📒 Files selected for processing (8)
  • README.md
  • cmd/fpf/cli_runtime.go
  • cmd/fpf/cli_runtime_test.go
  • cmd/fpf/dynamic_reload.go
  • cmd/fpf/dynamic_reload_test.go
  • cmd/fpf/ipc_actions.go
  • cmd/fpf/perf_trace_test.go
  • tests/smoke.sh
📜 Review details
🧰 Additional context used
🪛 GitHub Actions: test
tests/smoke.sh

[error] 1-1: fpf: missing packaged Go binary for linux/x86_64. Expected one of: /home/runner/work/fpf-cli/fpf-cli/bin/fpf-go-linux-amd64 or /home/runner/work/fpf-cli/fpf-cli/bin/fpf-go-linux-arm64. Run 'bash scripts/build-go-binaries.sh' to build local binaries.

Comment thread cmd/fpf/cli_runtime.go Outdated
Comment thread cmd/fpf/dynamic_reload.go
Comment thread cmd/fpf/ipc_actions.go
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 27, 2026

Note

Autofix is a beta feature. Expect some limitations and changes as we gather feedback and continue to improve it.

Fixes Applied Successfully

Fixed 3 file(s) based on 2 unresolved review comments.

Files modified:

  • cmd/fpf/cli_runtime.go
  • cmd/fpf/ipc_actions.go
  • fpf

Commit: 9a6e4061638f86b7187cf3f449cc741199512b44

The changes have been pushed to the fix/ipc-mode-port-discovery-and-empty-results branch.

Time taken: 2m 59s

Fixed 3 file(s) based on 2 unresolved review comments.

Co-authored-by: CodeRabbit <noreply@coderabbit.ai>
@Timmy6942025 Timmy6942025 merged commit 26b17cd into master Mar 27, 2026
0 of 2 checks passed
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.

1 participant