singularity-forge/packages/pi-coding-agent/src
Tom Boucher cdf42fe001 fix: prevent model config bleed between concurrent GSD instances (#650) (#652)
Two fixes for the model configuration bleeding between simultaneous
GSD instances that share the same global settings.json.

## Root Cause

1. `setDefaultModelAndProvider()` always persisted to `~/.gsd/agent/settings.json`
   (global), so when either instance's interactive mode changed models (via
   Ctrl+P or /model), it overwrote the other instance's saved default.

2. When auto-mode dispatched a new unit (after context wipe), if no
   per-unit-type model preference was configured, the session picked up
   the default from the now-contaminated global settings file.

## Fix 1: Project-scoped model persistence (settings-manager.ts)

`setDefaultModelAndProvider()`, `setDefaultModel()`, and `setDefaultProvider()`
now persist to project-level settings (`.pi/settings.json`) when a project
settings file exists, falling back to global only when no project context
is available. This prevents concurrent instances from overwriting each
other's model choice.

Added `hasProjectSettingsFile()` helper to detect project context.

## Fix 2: Auto-mode model capture (auto.ts)

Captures the session's model at auto-mode start (`autoModeStartModel`).
At each unit dispatch, if no model preference is configured for the unit
type, the captured model is re-applied with `persist: false`. This
ensures each auto-mode session maintains its own model regardless of
what other instances write to the shared settings file.

## Tests

3 new tests covering:
- Project settings file isolates model from global
- Two projects have independent model configs
- autoModeStartModel concept prevents model drift

All 448 existing tests pass.

Fixes #650
2026-03-16 10:59:12 -06:00
..
cli feat: dynamic model discovery & provider management UX (#581) 2026-03-16 06:23:18 -06:00
core fix: prevent model config bleed between concurrent GSD instances (#650) (#652) 2026-03-16 10:59:12 -06:00
modes feat: dynamic model discovery & provider management UX (#581) 2026-03-16 06:23:18 -06:00
resources/extensions/memory fix: replace better-sqlite3 with sql.js (WASM) to fix install on Node 25+ (#356) 2026-03-14 07:41:24 -06:00
utils feat: wire native Rust image module into image processing pipeline 2026-03-13 13:41:53 -06:00
cli.ts feat: vendor Pi source into workspace monorepo 2026-03-12 21:55:17 -06:00
config.ts perf: fix synchronous I/O in hot paths (#540) 2026-03-15 16:57:22 -06:00
index.ts feat: dynamic model discovery & provider management UX (#581) 2026-03-16 06:23:18 -06:00
main.ts feat: dynamic model discovery & provider management UX (#581) 2026-03-16 06:23:18 -06:00
migrations.ts feat: vendor Pi source into workspace monorepo 2026-03-12 21:55:17 -06:00