fix(warehouse, debug): address the review findings left on #1395 and #1409

Merged
SA
2mo ago
+1290-204

Issue for this PR

Follow-up to #1395 and #1409. Both were merged with bot review threads that had not been triaged. Each finding was checked against main; this PR fixes the valid ones. The remaining threads get a reply on the original PR, with the reason where nothing was changed.

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Snowflake reconnect (#1395)

  • Sequences are not resent: SELECT seq.NEXTVAL, GETNEXTVAL and SYSTEM$ calls are no longer treated as safe to resend after a closed session. A resend would consume a second value.
  • Session settings are replayed: USE, ALTER SESSION and SET are replayed onto a reopened session before anything runs on it. Every caller waiting on that reconnect gets them. A USE interrupted by the close is applied and remembered.
  • Unrestorable state is reported: temporary objects and an open transaction cannot be restored, so statements issued before the reopen report it instead of running. This is tracked by connection generation, so a late error from the old session can no longer clear it.

Credentials (#1395)

  • Removed after the write: secrets an earlier config stored are removed only after the new connections.json is written. A failed write no longer leaves the old config without its secrets.
  • Failed deletes are reported: a secret the store refuses to delete is reported as a warning on add and remove, instead of silently surviving and coming back after a restart.
  • Own-property check: "still defined" uses an own-property check, so a connection named constructor is cleaned up.
  • Read errors logged: keychain read errors are logged instead of looking like a missing password.
  • Test isolation: the registry's home follows Global.Path.home. Bun caches os.homedir(), so the suite was writing the developer's real ~/.altimate-code/connections.json; it now uses the test home.
  • Design note: credentials stay keyed by connection name. Only add stores them, for the saved connection. The docs now say that a project file which defines a connection of the same name without its own password was using the saved connection's password.

Sign-in and terminal (#1395)

  • Routing: sign-in notices are routed per account, and a reused connector that reconnects records its caller too.
  • Failure toast: a failed sign-in replaces the two-minute "Waiting for sign-in" toast.
  • Start event: warehouse_connect_started is flushed immediately and always carries a warehouse type.
  • SIGTERM: it takes the TUI's own shutdown, as SIGHUP does, so finalizers run. A 3 s fallback still exits with 143 and restores the terminal.
  • Raw mode: an unclean exit also takes stdin out of raw mode.
  • SSO link kept: the toast keeps the full SSO link. It is what the user opens when no tab appeared, the event stream is local, and the log already strips the query.

Debug bundle (#1409)

  • No network: --network=false keeps telemetry off, as --no-network does.
  • Log safety: tool error text is redacted before it is written to opencode.log, and that log is made owner-only.
  • Report file: the report goes to a new owner-only file that is renamed into place, never into an existing file or through a symlink.
  • Stall log: it runs with telemetry off.
  • Debug mode: "on, but no tool calls" is reported as such, not as debug mode off.
  • App starts: counted once per process. Neither the TUI worker nor each project load counts separately.
  • Call ids: a repeated call id no longer overwrites a running call.
  • Hosts:
    • Snowflake hosts must end in .snowflakecomputing.com.
    • DNS uses the hostname without the port.
    • The Databricks serverHostname alias is read.
  • Credentials: matched to the warehouse type, so a Postgres config with credentials_path is still flagged.
  • MCP servers: read from the config loader's sources in its order (ancestors, OPENCODE_CONFIG*, .altimate-code before .opencode). Entries are merged per field, and mcpServers is read too.
  • No census: connection names are read without queueing the warehouse census.
  • Log level: the shim log level follows debug mode.
  • Docs: redaction is described as pattern-based, so users are told to read the report before sending it.

How did you verify your code works?

  • New tests: a test for every fix. Each was mutation-checked: removing the fix fails its test (20 mutations across driver, credentials and debug code).
  • Real config: the credential tests now leave ~/.altimate-code/connections.json byte-for-byte unchanged (checked with cmp before and after the run).
  • --network=false: confirmed the CLI middleware sees it as network === false for both --no-network and --network=false.
  • Checks: typecheck passes on all 13 packages, and the marker guard is clean.
  • Full suites: drivers 353/353, TUI 346/346, opencode 16,549 pass with 6 failures, all six the MCP tests that read the developer's real ~/.claude.json (#1386).

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

🤖 Generated with Claude Code

https://claude.ai/code/session_018fJ3X7pcGT4R9yzjsJnqsV


Summary by cubic

Addresses the remaining review findings from #1395 and #1409. Snowflake reconnects now preserve only safely restorable state, while credential cleanup, terminal shutdown, and debug collection handle failures more reliably and securely.

Warehouse and terminal

  • Only effect-free single-session settings are replayed from a snapshot; sequence calls, SYSTEM$ calls, multi-statement settings, and other unrecoverable state are not retried.
  • Reconnect tracking separates temporary objects from transactions, clears transactions on COMMIT or ROLLBACK, prevents late errors from an old connection from clearing current state, and drops any result that predates an explicit connect().
  • Settings that finish during a reconnect are applied to the current session, the snapshot is replayed until a pass ends with it unchanged, repeated settings are recorded once, each new connection starts fresh tracking, a setting that does not fit the replay list marks the session as not restorable, and a reconnect whose settings never settle after five passes fails instead of installing a partial session.
  • Credential deletion still runs when reads fail, while failed or unconfirmed deletions are reported by warehouse_remove.
  • Sign-in notices remain scoped to their account, and failed sign-ins replace the waiting toast without claiming a specific cause.
  • SIGTERM uses the TUI shutdown path, repeated signals arm a single fallback that clean teardown cancels, and cooked input is restored even when stdout is not a TTY.

Debug bundle

  • The log is re-restricted after rotation or replacement, and reports use unique owner-only temporary files, opened exclusively, before an atomic rename.
  • MCP discovery follows documented ALTIMATE_CLI_* sources, project-config disabling, ancestor ordering, JSONC precedence, and normalized per-field merges.
  • Run-less project loads are reported separately rather than as app starts; repeated tool call IDs remain distinct, and debug mode without tool calls is reported separately.
  • Redaction values are collected independently, and --network=false disables telemetry and network probes.
  • The stall watcher starts with default settings even without telemetry; explicit settings keep unspecified options and replace a watcher only when the result differs.

Summary by CodeRabbit

  • Bug Fixes

    • Snowflake reconnects restore eligible session settings. Operations that change data, use sequence values, or rely on unrecoverable session state aren’t retried.
    • Connection removal warns when credentials could not be deleted and preserves credentials still referenced by configuration. Saving a replacement removes credentials it no longer uses.
    • Sign-in failures show an error notification, and terminal shutdown restores input more reliably.
    • Debug reports better distinguish activity and process starts, redact sensitive details, and collect connection and configuration information more accurately.
    • Debug mode enables debug logging when no log level is specified.
  • Security

    • Debug reports and log files use owner-only permissions where supported.
  • Documentation

    • Clarified credential setup, Snowflake reconnect behavior, and debug-bundle options and privacy details. Raw logs are documented as saved to a file rather than printed in the terminal.