[AUTOMATION] feat: clean up runtime host startup#256
Conversation
Greptile SummaryThis PR changes runtime host startup to fail when the default cwd cannot be resolved. The main changes are:
Confidence Score: 4/5This is close, but the daemon startup regression should be fixed before merging.
Important Files Changed
Reviews (1): Last reviewed commit: "fix: fail fast on runtimehost cwd lookup..." | Re-trigger Greptile |
| cwd := opts.CWD | ||
| if cwd == "" { | ||
| cwd, _ = os.Getwd() | ||
| cwd, err = currentWorkingDir() | ||
| if err != nil { | ||
| _ = host.Close(context.Background()) | ||
| return nil, fmt.Errorf("resolve current working directory: %w", err) | ||
| } | ||
| } |
There was a problem hiding this comment.
This resolves the current directory before checking SkipInitialSession, but the managed observe daemon calls runtimehost.Start with SkipInitialSession: true and no CWD. In that mode this cwd value is not used to open an initial session; daemon-observed sessions get their cwd later from hook events. If launchd starts the daemon from a deleted or unreadable working directory, currentWorkingDir() now fails and the daemon does not start at all, even though it does not need a startup cwd.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8afb84fd06
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| cwd, err = currentWorkingDir() | ||
| if err != nil { | ||
| _ = host.Close(context.Background()) | ||
| return nil, fmt.Errorf("resolve current working directory: %w", err) |
There was a problem hiding this comment.
Avoid resolving cwd when initial session is skipped
When opts.SkipInitialSession is true (as in internal/managedobserve/daemon.go, which starts the runtime host without passing CWD), the resolved cwd is never used because the OpenSession block is skipped, but this new lookup still runs and now fails if the process's working directory has been removed or is otherwise unreadable. That makes the managed observe daemon fail to start for an irrelevant cwd error; move the cwd resolution inside the !opts.SkipInitialSession branch or skip the error in that mode.
Useful? React with 👍 / 👎.

Summary
This cleans up runtime host startup by failing fast when the current working directory cannot be resolved.
Before this, internal/runtimehost/host.go ignored the os.Getwd error and opened the initial session with an empty cwd, which hid the real startup failure and made session state harder to trust.
Now runtimehost.Start resolves cwd through one testable helper and stops immediately if that lookup fails:
Why
This gives kontext-cli a cleaner maintenance path for local runtime startup:
runtimehost.Start
-> cwd resolution
-> explicit failure + cleanup
-> no empty session cwd
This PR does not broaden behavior beyond the cleanup scope.
What changed
Added a test seam for current working directory lookup
Removed the hidden fallback that continued with an empty cwd
Strengthened startup failure handling in runtimehost.Start
Updated tests for cwd resolution failure
Verification
go test ./internal/runtimehost -count=1
go test ./internal/managedobserve -count=1
git diff --check