Skip to content

Promote dev to stable: socket transport diagnostics - #2478

Merged
namastex888 merged 5 commits into
mainfrom
dev
May 22, 2026
Merged

namastex888 merged 5 commits into
mainfrom
dev

Conversation

@namastex888

@namastex888 namastex888 commented May 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary\n- report pgserve Unix socket transport in update diagnostics\n- include pgserve socketDir while keeping port only as legacy metadata\n- make serve status use resolvePgserveTransport() instead of stale active-port state\n- includes prior pgserve runtime.port diagnostics fix\n\n## Verification\n- GENIE_TEST_SKIP_PGSERVE=1 bun test src/genie-commands/tests/update.test.ts\n- bun run typecheck\n- bun run lint\n- bun run dead-code\n- bun run skills:lint\n- bun run wishes:lint\n- bun run lint:emit

Summary by CodeRabbit

  • New Features

    • Improved pgserve diagnostics with unified transport detection (socket vs TCP) and richer connection metadata extraction.
    • Enhanced service status reporting for the brain, including standalone discovery and direct CLI probing when available.
  • Chores

    • Version bump to 4.260522.16

Review Change Stack

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@coderabbitai

coderabbitai Bot commented May 22, 2026 •

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 57a0fe2c-f3cf-4446-9771-a3e57752773f

📥 Commits

Reviewing files that changed from the base of the PR and between 3c3aed5 and fb86633.

📒 Files selected for processing (2)
  • src/term-commands/brain.ts
  • src/term-commands/serve.ts

📝 Walkthrough

Walkthrough

Parses runtime socketDir/port from pgserve status --json, computes pgserve transport for diagnostics, updates serve/health reporting to use the unified resolver, adds standalone brain CLI detection and probing, extends tests, and bumps package/plugin versions.

Changes

Metadata version bumps

Layer / File(s) Summary
Version fields updated
.claude-plugin/marketplace.json, package.json, plugins/genie/.claude-plugin/plugin.json, plugins/genie/package.json
Updated manifest/package version strings from 4.260522.14 → 4.260522.16.

Pgserve transport, health reporting, and brain CLI handling

Layer / File(s) Summary
Socket/port extraction and diagnostics
src/genie-commands/update.ts, src/term-commands/serve.ts
Adds extractPgserveSocketDirFromStatus, expands port extraction to consider runtime.port, derives pgserveTransport (unix-socket/tcp/null) in diagnostics collection, and updates printPgserveHealth() to use resolvePgserveTransport for the "where" value.
Standalone brain CLI detection & status probing
src/term-commands/brain.ts, src/term-commands/serve.ts
Adds safe shell-quoting and detection helpers to run a local brain CLI when the @khal-os/brain module is missing; implements reading ~/.brain/config.json + PID/port validation and probing http://127.0.0.1:<port>/healthz for standalone brain status, returning early when handled.
Test coverage and regression locks
src/genie-commands/__tests__/update.test.ts
Extends diagnostics tests with live runtime status cases verifying socketDir extraction and runtime port preference; adds a regression assertion that printPgserveHealth uses the unified transport resolver.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • automagik-dev/genie#2477: Modifies src/genie-commands/update.ts and tests around extracting pgserve connection details from pgserve status --json, overlapping with runtime port/diagnostics changes.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: promoting pgserve socket transport diagnostics from dev to stable by updating version numbers and implementing socket directory reporting.
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 dev

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request updates the project version to 4.260522.16 and enhances pgserve diagnostic reporting by adding support for Unix socket transport detection. Key changes include the introduction of extractPgserveSocketDirFromStatus, updates to extractPgservePortFromStatus for better runtime status parsing, and a refactor of the health check logic in serve.ts to use a unified transport resolver. Review feedback suggests refining the transport detection logic to handle the '0' port sentinel and incrementing the diagnostic schema version to reflect the additive changes to the report structure.

const pgserveStatusJson = (await runCommandSilent('pgserve', ['status', '--json'], undefined, 2000)).output.trim();
const pgserveSocketDir = extractPgserveSocketDirFromStatus(pgserveStatusJson);
const pgservePort = pgservePortFromFile ?? extractPgservePortFromStatus(pgserveStatusJson);
const pgserveTransport = pgserveSocketDir ? 'unix-socket' : pgservePort ? 'tcp' : null;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The transport detection logic should account for the SOCKET_PORT_SENTINEL (value "0"), which indicates a Unix socket transport even if the socketDir wasn't explicitly extracted from the status JSON. Additionally, since pgservePort might contain trailing whitespace if read from the legacy port file, it's safer to trim it during the check.

Suggested change
const pgserveTransport = pgserveSocketDir ? 'unix-socket' : pgservePort ? 'tcp' : null;
const pgserveTransport = pgserveSocketDir || pgservePort?.trim() === '0' ? 'unix-socket' : pgservePort?.trim() ? 'tcp' : null;
References
  1. It is acceptable to use hardcoded numeric limits or sentinel values in non-critical fallback logic to prevent performance issues or handle specific states.

Comment on lines +1350 to +1351
pgserveTransport,
pgserveSocketDir,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

This change introduces new fields (pgserveTransport, pgserveSocketDir) to the diagnostics report. According to the internal guidelines, UPDATE_DIAGNOSTIC_SCHEMA_VERSION should be incremented for any additive change to the schema to allow consumers to correctly identify the available metadata.

References
  1. Increment schema versioning for additive changes to diagnostic reports. (link)

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@package.json`:
- Line 3: The release bump updated "version" without updating the pinned binary
hashes, causing SHA drift; update the "binarySha256" entries in package.json to
match the current release assets (or revert the asset set to match existing
pins) so CI integrity checks pass—locate the binarySha256 fields in
package.json, fetch the correct SHA256 for each referenced release asset, and
replace the stale values with the new hashes before merging.

In `@src/genie-commands/__tests__/update.test.ts`:
- Around line 909-918: Add a test asserting that when both top-level port and
runtime.port are present but different, runtime.port takes precedence: create a
JSON string with installed: true, status: 'online', port: '1234' (or number),
and runtime: { port: 8432, live: true } and call extractPgservePortFromStatus to
expect '8432'. Place this new case alongside the existing diagnostics tests
(same suite that contains the current live-status test) so the behavior of
extractPgservePortFromStatus is verified for the conflict-case.

In `@src/genie-commands/update.ts`:
- Around line 1269-1271: The port-selection logic currently uses parsed.port /
parsed.instance?.port before live data, causing stale values to be chosen;
update the fallback order so parsed.runtime?.port is preferred over legacy
fields by computing rawPort from parsed.runtime?.port ?? parsed.port ??
parsed.instance?.port (keep the same type checks that follow: allow finite
number -> String(...) and non-empty trimmed string), and ensure you reference
the same variable name rawPort so subsequent checks (Number.isFinite and trim)
still apply.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 41ead3fc-5184-4766-af73-49a1d430624b

📥 Commits

Reviewing files that changed from the base of the PR and between 64d54aa and 3c3aed5.

📒 Files selected for processing (7)
  • .claude-plugin/marketplace.json
  • package.json
  • plugins/genie/.claude-plugin/plugin.json
  • plugins/genie/package.json
  • src/genie-commands/__tests__/update.test.ts
  • src/genie-commands/update.ts
  • src/term-commands/serve.ts

Comment thread package.json
{
"name": "@automagik/genie",
"version": "4.260522.14",
"version": "4.260522.16",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Update binarySha256 pins before merge.

CI is failing with SHA drift, which means the pinned hashes in package.json no longer match downloaded release assets. This release/version bump should include refreshed binarySha256 entries (or the asset set must be reverted to match current pins), otherwise release integrity checks stay red.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@package.json` at line 3, The release bump updated "version" without updating
the pinned binary hashes, causing SHA drift; update the "binarySha256" entries
in package.json to match the current release assets (or revert the asset set to
match existing pins) so CI integrity checks pass—locate the binarySha256 fields
in package.json, fetch the correct SHA256 for each referenced release asset, and
replace the stale values with the new hashes before merging.

Comment on lines +909 to +918
test('diagnostics derives pgserve port from live pgserve runtime status json', () => {
const liveStatus = JSON.stringify({
installed: true,
status: 'online',
port: null,
runtime: { port: 8432, live: true },
});

expect(extractPgservePortFromStatus(liveStatus)).toBe('8432');
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Add a conflict-case test for runtime.port precedence.

Current coverage only checks runtime fallback when top-level port is null. Add a case where both are present but different, and assert runtime wins.

Suggested test addition
+  test('diagnostics prefers runtime.port over stale top-level port when both are present', () => {
+    const liveStatus = JSON.stringify({
+      port: 15432,
+      runtime: { port: 8432, live: true },
+    });
+    expect(extractPgservePortFromStatus(liveStatus)).toBe('8432');
+  });

As per coding guidelines: "Test edge cases and boundaries of every command, flag, and plugin contract".

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
test('diagnostics derives pgserve port from live pgserve runtime status json', () => {
const liveStatus = JSON.stringify({
installed: true,
status: 'online',
port: null,
runtime: { port: 8432, live: true },
});
expect(extractPgservePortFromStatus(liveStatus)).toBe('8432');
});
test('diagnostics derives pgserve port from live pgserve runtime status json', () => {
const liveStatus = JSON.stringify({
installed: true,
status: 'online',
port: null,
runtime: { port: 8432, live: true },
});
expect(extractPgservePortFromStatus(liveStatus)).toBe('8432');
});
test('diagnostics prefers runtime.port over stale top-level port when both are present', () => {
const liveStatus = JSON.stringify({
port: 15432,
runtime: { port: 8432, live: true },
});
expect(extractPgservePortFromStatus(liveStatus)).toBe('8432');
});
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/genie-commands/__tests__/update.test.ts` around lines 909 - 918, Add a
test asserting that when both top-level port and runtime.port are present but
different, runtime.port takes precedence: create a JSON string with installed:
true, status: 'online', port: '1234' (or number), and runtime: { port: 8432,
live: true } and call extractPgservePortFromStatus to expect '8432'. Place this
new case alongside the existing diagnostics tests (same suite that contains the
current live-status test) so the behavior of extractPgservePortFromStatus is
verified for the conflict-case.

Comment on lines +1269 to 1271
const rawPort = parsed.port ?? parsed.instance?.port ?? parsed.runtime?.port;
if (typeof rawPort === 'number' && Number.isFinite(rawPort)) return String(rawPort);
if (typeof rawPort === 'string' && rawPort.trim()) return rawPort.trim();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Prefer runtime.port over legacy status fields for live diagnostics.

Line 1269 currently prioritizes port/instance.port before runtime.port, which can report stale metadata even when live runtime data exists. This conflicts with the live-runtime diagnostics intent.

Suggested fix
-    const rawPort = parsed.port ?? parsed.instance?.port ?? parsed.runtime?.port;
+    const rawPort = parsed.runtime?.port ?? parsed.port ?? parsed.instance?.port;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const rawPort = parsed.port ?? parsed.instance?.port ?? parsed.runtime?.port;
if (typeof rawPort === 'number' && Number.isFinite(rawPort)) return String(rawPort);
if (typeof rawPort === 'string' && rawPort.trim()) return rawPort.trim();
const rawPort = parsed.runtime?.port ?? parsed.port ?? parsed.instance?.port;
if (typeof rawPort === 'number' && Number.isFinite(rawPort)) return String(rawPort);
if (typeof rawPort === 'string' && rawPort.trim()) return rawPort.trim();
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/genie-commands/update.ts` around lines 1269 - 1271, The port-selection
logic currently uses parsed.port / parsed.instance?.port before live data,
causing stale values to be chosen; update the fallback order so
parsed.runtime?.port is preferred over legacy fields by computing rawPort from
parsed.runtime?.port ?? parsed.port ?? parsed.instance?.port (keep the same type
checks that follow: allow finite number -> String(...) and non-empty trimmed
string), and ensure you reference the same variable name rawPort so subsequent
checks (Number.isFinite and trim) still apply.

@namastex888
namastex888 merged commit d991ece into main May 22, 2026
24 of 27 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