singularity-forge/packages/pi-coding-agent/src/core
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
..
compaction feat: vendor Pi source into workspace monorepo 2026-03-12 21:55:17 -06:00
export-html fix: add missing export-html vendor files 2026-03-13 10:38:13 +01:00
extensions feat: add yaml support, run-hook command, and path sanitization (#637) 2026-03-16 09:22:23 -06:00
lsp feat(lsp): activate LSP by default, add call hierarchy/format/signature, sync edits (#639) 2026-03-16 09:22:52 -06:00
tools feat(lsp): activate LSP by default, add call hierarchy/format/signature, sync edits (#639) 2026-03-16 09:22:52 -06:00
agent-session.ts fix(session): rebuild tools when cwd changes in newSession (#633) (#638) 2026-03-16 09:23:19 -06:00
artifact-manager.ts feat: TTSR + blob/artifact storage (ported from oh-my-pi) 2026-03-13 08:43:56 -06:00
auth-storage.test.ts fix: prevent credential backoff on transport errors and handle quota exhaustion gracefully (#353) 2026-03-14 07:15:00 -06:00
auth-storage.ts feat: add cross-provider fallback when rate/quota limits are hit (#125) 2026-03-14 15:45:44 -05:00
bash-executor.ts feat: native Rust bash stream processor for single-pass chunk processing (#271) 2026-03-13 16:34:17 -06:00
blob-store.ts feat: TTSR + blob/artifact storage (ported from oh-my-pi) 2026-03-13 08:43:56 -06:00
defaults.ts feat: vendor Pi source into workspace monorepo 2026-03-12 21:55:17 -06:00
diagnostics.ts feat: vendor Pi source into workspace monorepo 2026-03-12 21:55:17 -06:00
discovery-cache.test.ts feat: dynamic model discovery & provider management UX (#581) 2026-03-16 06:23:18 -06:00
discovery-cache.ts feat: dynamic model discovery & provider management UX (#581) 2026-03-16 06:23:18 -06:00
event-bus.ts feat: vendor Pi source into workspace monorepo 2026-03-12 21:55:17 -06:00
exec.ts feat: vendor Pi source into workspace monorepo 2026-03-12 21:55:17 -06:00
fallback-resolver.test.ts feat: add cross-provider fallback when rate/quota limits are hit (#125) 2026-03-14 15:45:44 -05:00
fallback-resolver.ts feat: add cross-provider fallback when rate/quota limits are hit (#125) 2026-03-14 15:45:44 -05:00
footer-data-provider.ts feat: vendor Pi source into workspace monorepo 2026-03-12 21:55:17 -06:00
index.ts feat: add cross-provider fallback when rate/quota limits are hit (#125) 2026-03-14 15:45:44 -05:00
keybindings.ts feat: vendor Pi source into workspace monorepo 2026-03-12 21:55:17 -06:00
messages.ts feat: vendor Pi source into workspace monorepo 2026-03-12 21:55:17 -06:00
model-discovery.test.ts feat: dynamic model discovery & provider management UX (#581) 2026-03-16 06:23:18 -06:00
model-discovery.ts feat: dynamic model discovery & provider management UX (#581) 2026-03-16 06:23:18 -06:00
model-registry-discovery.test.ts feat: dynamic model discovery & provider management UX (#581) 2026-03-16 06:23:18 -06:00
model-registry.ts feat: dynamic model discovery & provider management UX (#581) 2026-03-16 06:23:18 -06:00
model-resolver.ts feat: default to Opus 4.6 1M context variant (#565) 2026-03-15 18:57:46 -06:00
models-json-writer.test.ts feat: dynamic model discovery & provider management UX (#581) 2026-03-16 06:23:18 -06:00
models-json-writer.ts feat: dynamic model discovery & provider management UX (#581) 2026-03-16 06:23:18 -06:00
package-manager.ts feat: vendor Pi source into workspace monorepo 2026-03-12 21:55:17 -06:00
prompt-templates.ts feat: vendor Pi source into workspace monorepo 2026-03-12 21:55:17 -06:00
resolve-config-value.ts feat: vendor Pi source into workspace monorepo 2026-03-12 21:55:17 -06:00
resource-loader.ts feat: vendor Pi source into workspace monorepo 2026-03-12 21:55:17 -06:00
sdk.ts chore(M003/S04): auto-commit after reassess-roadmap 2026-03-15 08:33:13 -06:00
session-manager.test.ts perf: optimize discovery and interactive hot paths 2026-03-14 16:03:44 -05:00
session-manager.ts perf: optimize discovery and interactive hot paths 2026-03-14 16:03:44 -05:00
settings-manager.ts fix: prevent model config bleed between concurrent GSD instances (#650) (#652) 2026-03-16 10:59:12 -06:00
skills.ts feat: vendor Pi source into workspace monorepo 2026-03-12 21:55:17 -06:00
slash-commands.ts feat: dynamic model discovery & provider management UX (#581) 2026-03-16 06:23:18 -06:00
system-prompt.ts feat(lsp): activate LSP by default, add call hierarchy/format/signature, sync edits (#639) 2026-03-16 09:22:52 -06:00
timings.ts feat: vendor Pi source into workspace monorepo 2026-03-12 21:55:17 -06:00