Skip to content

fix(ops): restart ki-simulate on deploy to reload source + .env - #180

Merged
easingthemes merged 1 commit into
mainfrom
fix/ki-simulate-restart-on-deploy
Nov 21, 2026
Merged

easingthemes merged 1 commit into
mainfrom
fix/ki-simulate-restart-on-deploy

Conversation

@easingthemes

Copy link
Copy Markdown
Owner

Problem

The AfD party agent (the only party routed to xAI) was silently abstaining on every vote in production. The log showed:

[AI] agent:afd | xai/grok-4.3 | 0ms | PARSE_FAIL fallback=abstain-all

Root cause (diagnosed against the live prod box)

The production XAI_API_KEY was invalid — xAI rejected it with HTTP 400 "Incorrect API key provided: xa***2r". On the first failure, the engine latches the xAI provider as auth-failed in memory until process restart (client.ts), so every subsequent day short-circuited to empty text → PARSE_FAIL → abstain-all.

The reason a corrected key wouldn't have helped on its own: ki-simulate is a long-running tsx process. It loads source and its process.env at start, so neither a source deploy nor an .env change takes effect until it's restarted. update-env.yml only restarts ki-api, never ki-simulate — leaving the stale process running indefinitely. This same stale-process behavior previously caused the grok-3-mini incident.

Fix

Add a ki-simulate restart to scripts/post-deploy.sh (mirroring the existing ki-bot handling) so every deploy reloads its source and .env:

if pm2 describe ki-simulate >/dev/null 2>&1; then
  pm2 restart ki-simulate --update-env
fi

Verification (prod)

  • New valid key set → verify_http_code=200, grok-4.3 returned valid JSON.
  • ki-simulate restarted → auth flag cleared, .env reloaded.
  • AfD agent flipped from PARSE_FAIL fallback=abstain-all to OK in the live logs; aggregate fail rate back to ~1.2% normal.

Notes

  • The grok-4.3 slug fix (75f40af) was correct; this was purely an invalid-key + stale-process operational issue.
  • Scope limited to scripts/post-deploy.sh (1 file, +6 lines). Unrelated package-lock.json working-tree noise was deliberately left out.

ki-simulate (runner-auto.ts) is long-running and tsx loads source at
process start, so without a restart it keeps executing pre-deploy code
and its already-loaded process.env indefinitely. This masked the AfD/xAI
outage: an invalid XAI_API_KEY latched the xai provider as auth-failed
in memory (client.ts), and the stale process never picked up a corrected
key. Restart on deploy so source and .env are always current.
@easingthemes
easingthemes merged commit 53f5928 into main Nov 21, 2026
3 checks passed
easingthemes added a commit that referenced this pull request Nov 21, 2026
…deploy

fix(ops): restart ki-simulate on deploy to reload source + .env
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