Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: preserve successful GitHub calls during graceful shutdown (#6992)

[._.]/ Adam Eivy0f9d9ab9a7dd
diff --git a/server/lib/importScoping.test.js b/server/lib/importScoping.test.js
index 3db1ed1fe9..efef14be86 100644
--- a/server/lib/importScoping.test.js
+++ b/server/lib/importScoping.test.js
@@ -408,7 +408,12 @@ describe('deferred imports stay deferred (#6156)', () => {
// ~30 modules). Measured against current main: 103,462 -> 101,702 (-1,760);
// suites whose closure reaches services/instances.js: 181 -> 33. Lower the
// ceiling to the new measured total plus the standard ~1.5k allowance.
-const MAX_STATIC_INSTANTIATIONS = 103202;
+// #6992 adds the existing hostShutdown latch to GitHub command completion and
+// branch reconciliation. Its dependencies were already in these callers'
+// closures; the measured baseline 103,190 -> 103,228 is the shutdown module
+// itself in 38 additional suite closures, not a new heavy subtree. Preserve
+// the existing headroom by accounting for exactly that additive lifecycle edge.
+const MAX_STATIC_INSTANTIATIONS = 103240;
const SKIP_DIRS = new Set(['node_modules', 'coverage', 'dist', 'data']);
diff --git a/server/services/github.js b/server/services/github.js
index edfa0379e7..21e629f2ba 100644
--- a/server/services/github.js
+++ b/server/services/github.js
@@ -162,7 +162,9 @@ export function execGh(args, timeoutMs = DEFAULT_EXEC_GH_TIMEOUT_MS, { cwd = nul
child.on('close', (code, signal) => {
if (timedOut || settled) return;
clearTimeout(timer);
- if (signal === 'SIGTERM' || isHostShuttingDown()) {
+ if (signal === 'SIGTERM' || (code !== 0 && isHostShuttingDown())) {
+ // PM2 may deliver SIGTERM to the child before the host latch is set.
+ // Other signals count as failures unless the host confirms shutdown.
// Cancellation says nothing about forge health; preserve prior backoff.
settle(null);
reject(Object.assign(new Error(signal ? `gh command cancelled by ${signal}` : 'gh command cancelled during host shutdown'), {
diff --git a/server/services/github.test.js b/server/services/github.test.js
index e58601daff..4671ebf975 100644
--- a/server/services/github.test.js
+++ b/server/services/github.test.js
@@ -228,6 +228,18 @@ describe('execGh backoffKey', () => {
expect(spawn).toHaveBeenCalledTimes(2);
});
+ it('preserves a successful result completed during graceful shutdown', async () => {
+ const child = makeChild();
+ spawn.mockReturnValue(child);
+ const pending = execGh(['pr', 'list'], 5000, { backoffKey: 'finishing-repo' });
+ child.stdout.emit('data', '[]');
+ markHostShuttingDown();
+ child.emit('close', 0, null);
+ resetHostShutdownFlagForTests();
+ await expect(pending).resolves.toBe('[]');
+ expect(vi.getTimerCount()).toBe(0);
+ });
+
it('keeps unexpected signal failures visible and subject to backoff', async () => {
const child = makeChild();
spawn.mockReturnValue(child);