Skip to content

fix: rewrite port file when session ID becomes available#142

Merged
four-bytes-robby merged 1 commit into
mainfrom
fix/set-session-port-file
Jun 14, 2026
Merged

fix: rewrite port file when session ID becomes available#142
four-bytes-robby merged 1 commit into
mainfrom
fix/set-session-port-file

Conversation

@four-bytes-robby

@four-bytes-robby four-bytes-robby commented Jun 14, 2026

Copy link
Copy Markdown
Member

Port file now updated with session-scoped hash when setSessionId is called.


Summary by cubic

Rewrite the status port file when a session ID is set, scoping it per session so clients reliably discover the correct port and avoid collisions. We hash the session ID to generate status-port-.json under ~/.cache/opencode/brain, write { port } only if a port is set, and create the directory if missing.

Written for commit d636098. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • Chores
    • Improved session management infrastructure with enhanced discovery mechanisms.

@coderabbitai

coderabbitai Bot commented Jun 14, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

Pull request was closed or merged during review

Walkthrough

Walkthrough

In setSessionId, after updating _sessionId and _channel, a new block checks whether _port is already assigned. If so, it hashes the session id with SHA-256, derives a cache file path (status-port-<hash>.json), creates the cache directory, and writes { port: _port } to that file, ignoring any errors.

Changes

Session-scoped port discovery file persistence

Layer / File(s) Summary
Port persistence inside setSessionId
src/status.ts
Adds a conditional block that, when _port > 0 at the time setSessionId is called, hashes the session id, ensures the cache directory exists, and writes { port: _port } to a session-scoped JSON discovery file; errors are swallowed.

Estimated code review effort

3 (Moderate) | ~15 minutes

Possibly related PRs

  • four-bytes/four-opencode-brain#141: Directly modifies src/status.ts with the same session-scoped status-port-<hash>.json discovery file mechanism, including the hash derivation and cache path logic that this PR's setSessionId change depends on.
Pre-merge checks | ✅ 3 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description lacks required template sections including Related Issue, version bump confirmation, HISTORY.md update status, and build/test verification checkboxes specified in the repository template. Complete all required checklist items from the template: confirm conventional commit format, add Related Issue reference, verify bun test and build pass, confirm version and HISTORY.md updates, and check for personal paths.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: rewriting a port file when the session ID becomes available, which directly aligns with the changeset that adds session-scoped port file persistence in setSessionId.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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/set-session-port-file
Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch fix/set-session-port-file

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

@four-bytes-robby four-bytes-robby merged commit 844f5b9 into main Jun 14, 2026
5 of 6 checks passed
@four-bytes-robby four-bytes-robby deleted the fix/set-session-port-file branch June 14, 2026 12:07
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