fix(config,repair,update,desktop): TOML-safe config writes, startup recovery, update reconciliation, session ownership and smart close
feat(config,repair,update,desktop): TOML-safe config writes, startup recovery, update reconciliation, session ownership and smart close
Four coordinated changes shipped in one PR (per the plan, they land in the same desktop preview candidate):
1. TOML-safe config writes with reversible repair
- encodeTOMLString/encodeTOMLKeyPart: single TOML 1.0 basic-string encoding entry point; never emits Go-only escapes (\a, \v, \xNN) the TOML parser rejects; invalid UTF-8 returns an error instead of silent replacement. All render.go value sites converted from %q/strconv.Quote.
- validateAndWriteConfigResolved: unified write pipeline used by SaveTo, SaveToScope, WriteFile, WritePermissionsAllow, project incremental merges and migrations: parse with the production parser, semantic round-trip via ConfigPersistenceSnapshot, delta-field verification for incremental merges, original-file state-ID re-check before the atomic replace; a renderer that silently drops or mangles a persisted field is caught by the intended-config-vs-decoded comparison (normalizePersistedConfig merges explicit values over built-in defaults, applies accessor normalization, injects implicit built-in providers with clean array-of-table decoding and clears legacy non-persisted fields).
- ScanTOMLPathEscapes/ApplyTOMLPathEscapes: TOML lexer diagnosing Windows absolute paths with unescaped backslashes (invalid-escape and silent semantic-escape classes), token-level high-confidence repair that preserves UNC prefixes, refusal on ambiguous/multi-line/non-path cases; fuzzed.
- Guard/macOS startup auto-repair of the global config with repair transaction, timestamped backup, undo, snapshot and last-known-good refresh; project reasonix.toml is preview-only and requires confirmation with bound state IDs; desktop recovery banner with undo/open/restore actions and a persistent damaged-config state.
2. Startup recovery and config fault isolation
- config.LoadUpdateNetworkConfig: minimal updater loader reading only update channel/proxy/network fields, falling back to the last-known-good snapshot and then env proxy defaults; the updater no longer depends on a full config.Load, so damaged configs never block update checks or installs.
- ConfigLoadError carries the failing file path and line; a broken project reasonix.toml only degrades its tab (file/line/fix-preview/apply/open actions), a broken global config boots tabs on the recovery configuration with external integrations disabled and a persistent banner.
3. Pending-update reconciliation
- InspectPendingUpdate derives the pending-update state (none | prepared | probationary | failed_install | restored | active_handoff | blocked) from the transaction, installed release-unit record, failure marker, running version and OS lock; the executor (repair.ReconcilePendingUpdate) cancels stale prepared transactions, rolls back failed installs exactly, preserves probationary transactions for the healthy-start commit and fails closed on damaged ones; active_handoff is never acted on and settled restored transactions end through the verified path. Guard launch, desktop startup, pre-check and pre-install all reconcile; UpdateInfo carries the recovery view and progress emits reconciling/rolling_back/recovered instead of the opaque "a pending update already exists" error.
4. Session ownership and smart close
- SessionRuntimeIssue extended with issueId, ownerKind and a non-null actions array; classification distinguishes current_tab, current_detached, same_instance_hidden, external_process, stale_reclaimed and unknown via the OS lease, its metadata and the process-local runtime registry. ResolveSessionRuntimeIssue re-validates the issue ID, runtime epoch binding and lease ownership and commits retry/read_only/copy in a single write-locked critical section; copy clones the authoritative transcript (checkpoint + event log under the cross-process file lock) to a reserved path and discards stale clones.
- Smart close (close_behavior=smart): idle quits without probing the tray, active work backgrounds with a notification and tray task count, and a missing restore path prevents the close and keeps the window visible. Config schema v6: new installs default to smart (version-gated accessor), upgraded configs without an explicit preference explicitly keep background, older binaries degrade smart to background. Settings gains the three-way selector; the frontend renders a classified session-issue card with actions.
Tests cover the encoding table and fuzz, path-fix fuzzing (including a two-process clone test with a child writer holding the cross-process lock), the write-pipeline state-ID and semantic-drift matrix, the update reconciliation state matrix and idempotence, session owner classification (external via a child process), smart-close decisions on every platform, and v6 migration with downgrade safety. Full root and desktop go test, targeted -race, vet, frontend tests and production build pass on the current main-v2.
Cache-impact: low — no model-facing prompt fields changed. The only
cache-sensitive path touched is internal/config/config.go (schema version 6,
close-behavior normalization and its version-gated accessor); none of these
feed the system prompt (the prompt builder reads agent/skills/tools config,
which this PR does not alter), and reasonix.example.toml / provider-visible
payloads are unchanged.
Cache-guard: scripts/cache-guard.sh passes (internal/agent
TestReleaseCacheHitGuard, which pins the release cache prefix, ran green
locally and in this PR's CI).
System-prompt-review: the system prompt is built by internal/agent from agent/skills/tools/permissions config — none of those files or values change in this PR. config.go only adds the smart-close schema default and keeps the rendered prompt output byte-identical for existing configs; please confirm on review that no prompt-affecting field sneaks through the config plumbing.