Skip to content

Comments

fix(gateway): prevent service process from detecting itself as duplicate#70

Merged
drpedapati merged 1 commit intomainfrom
fix/gateway-self-detection
Feb 23, 2026
Merged

fix(gateway): prevent service process from detecting itself as duplicate#70
drpedapati merged 1 commit intomainfrom
fix/gateway-self-detection

Conversation

@drpedapati
Copy link
Owner

Summary

  • Skip the foreground guard when XPC_SERVICE_NAME (launchd) or INVOCATION_ID (systemd) env vars are set, so the managed service process doesn't detect itself as a duplicate and crash-loop
  • Use hasNonZeroPID() in Status() instead of checking for any pid = substring — pid = 0 appears when the service is bootstrapped but not running, causing false positives

Test plan

  • Tested on data1: gateway starts correctly, Discord connects, sciclaw service status shows Running=yes
  • make build compiles cleanly
  • Fresh install: sciclaw service install && sciclaw service start — no crash loop

🤖 Generated with Claude Code

The foreground guard (dec0eee) checks launchctl print to prevent
double-running when the managed service is active. However, when
launchd spawns the gateway, launchctl print shows the live PID of
*that very process*, causing it to immediately exit with "Gateway is
already running" — producing a crash loop.

Two fixes:
1. Skip the foreground guard when XPC_SERVICE_NAME (launchd) or
   INVOCATION_ID (systemd) env vars are set, indicating the process
   IS the managed service.
2. Use hasNonZeroPID() in Status() instead of checking for any "pid ="
   substring — "pid = 0" appears when the service is bootstrapped but
   not actually running, causing false positives.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@drpedapati drpedapati merged commit e97dc7f into main Feb 23, 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