Skip to content

fix(opencode): AND lsof selection terms on macOS for cwd lookup#121

Merged
graykode merged 1 commit into
graykode:mainfrom
tbouquet:fix/opencode-lsof-cwd-and-semantics
May 14, 2026
Merged

fix(opencode): AND lsof selection terms on macOS for cwd lookup#121
graykode merged 1 commit into
graykode:mainfrom
tbouquet:fix/opencode-lsof-cwd-and-semantics

Conversation

@tbouquet
Copy link
Copy Markdown
Contributor

@tbouquet tbouquet commented May 13, 2026

Credit @Alexander-He for the diagnosis in #120.

Adds -a to the lsof call in get_process_cwd so -p <pid> and -d cwd AND instead of OR. Without it, lsof returns cwd entries from unrelated processes too, and the parser grabs the first n... line it sees, which can belong to a different pid. The OpenCode session match against the DB directory column then fails and the session gets dropped.

Linux path (/proc/<pid>/cwd) is unaffected.

Refs #120

Without -a, lsof ORs the -p <pid> and -d cwd filters, so the output
mixes the target pid's open files with cwd entries from every other
process. The parser then grabs the first 'n...' line and can land
on a different process's cwd, breaking the match against the
OpenCode DB 'directory' column.

Refs graykode#120
@tbouquet tbouquet force-pushed the fix/opencode-lsof-cwd-and-semantics branch from e2c2467 to c4eb18c Compare May 13, 2026 23:24
Copy link
Copy Markdown
Owner

@graykode graykode left a comment

Choose a reason for hiding this comment

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

Looks good. I verified the macOS lsof behavior locally: without -a, cwd entries from unrelated processes can be returned first, and with -a the lookup is scoped to the target PID's cwd. CI is green, and I don't see any blocking issues.

@graykode graykode merged commit d28dc30 into graykode:main May 14, 2026
7 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.

2 participants