Skip to content

Commit 92b3e8e

Browse files
authored
Merge branch 'main' into factory/altimate_code/run-38294090273-1
2 parents 2d589ac + b093196 commit 92b3e8e

16 files changed

Lines changed: 838 additions & 16 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,33 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.12.7] - 2026-10-13
9+
10+
**Workspace skills and knowledge come first.** In a linked project the agent prefers the workspace's own skills over lookalikes in the repo or your home folder, and checks the workspace's knowledge base for best practices without being asked. Linking now ends with a starter that says what the workspace provides and suggests prompts. Also in this release: opt-in automatic promotion for `learn`, session traces for the IDE extension, and Snowflake reconnects written to `opencode.log`.
11+
12+
**Heads-up for support:**
13+
- **The start-screen workspace box is back.** 0.12.6 removed it because it stopped every keybinding once it loaded. The cause is fixed, and Ctrl+C, Ctrl+P and Esc were checked on the start screen of the release build, linked, unlinked and with the workspace service unreachable. If a signed-in user still reports dead keys, `ALTIMATE_DISABLE_WORKSPACE=1` remains the stopgap.
14+
- **The skill list changes for everyone, not only workspace users.** Each skill the agent sees now carries its source (`workspace`, `project`, `built-in`, `personal` or `other`), and the agent is told to prefer them in that order. So a skill in the repository now outranks a personal one with a similar purpose. It is guidance to the agent, not a filter: every skill is still listed and can be asked for by name.
15+
- **The agent may search the workspace knowledge base on its own.** When the linked workspace has knowledge, the agent consults it for best practices and team conventions without the user asking. Unlinking the project, or turning knowledge off for the workspace, stops it.
16+
- **`serve` has new read-only routes for the IDE extension** (see Added). Traces hold prompts and tool output, including SQL and query results. Like every `serve` route, they need no password unless `OPENCODE_SERVER_PASSWORD` is set, so set one on a shared machine.
17+
18+
### Changed
19+
20+
- **Workspace skills and knowledge are preferred.** Every skill in the agent's list is labelled with where altimate-code found it, and one rule tells the agent to load the highest source that fits instead of asking which team's skill to follow. A project skill with exactly the same name as a workspace skill still replaces it. Listings stay in name order, so built-in skills are not pushed out of the skill tool's list. With knowledge on, the workspace section also tells the agent to check the knowledge base before answering best-practice questions. (#1435)
21+
22+
### Added
23+
24+
- **A starter after linking.** `altimate-code link` ends with what the workspace provides (skills, knowledge, integrations, memory setting) and up to three prompts to try; the TUI shows the same after a link and from `/workspace` → **Get started**, where picking a prompt fills the input without sending it. It makes no model call, and anything not yet known is left out rather than shown as "none". `GET /altimate/workspace/starter` serves it to the IDE extension. (#1435)
25+
- **`learn` can promote lessons without a person, if you opt in.** `learn enable --auto-promote` (or `learn.auto_promote: true`, or `ALTIMATE_LEARN_AUTO_PROMOTE=1`) promotes a lesson an automatic reflection staged when every check passes: it came from a correction, review or CI signal; it is exactly what was staged; it validates like a manual promote; it does not weaken a verification step; it does not edit or remove a lesson a person approved or pinned; and it stays within 3 changes per promotion and 5 per day (`learn.auto_promote_max_changes`, `learn.auto_promote_daily`). Otherwise the candidate stays staged and `learn status` says why. Off by default, needs capture and automatic reflection on, and `learn rollback` undoes a promotion. (#1418)
26+
- **Session traces for the IDE extension.** `serve` adds `GET /altimate/trace` (a page of traces, newest first) and `GET /altimate/trace/<session>/view` (the trace viewer, without Copy Link), so the extension's `/traces` can list and open them. Browser-originated requests are refused, as for the workspace routes. (#1415)
27+
28+
### Fixed
29+
30+
- **The TUI's keybindings keep working with the start-screen workspace box.** The box rendered nothing until the project's link was resolved; each time its lines arrived, the start screen remounted it empty, and it resolved again without end, which held up every keybinding. It now keeps a root element from its first render. (#1435)
31+
- **Snowflake reconnects are in `opencode.log`.** When Snowflake closes a session and the driver reopens it, the log gains `reconnecting`, then `reconnected` (with the reason, how long it took, how many session settings were restored, and whether temporary tables or a transaction may have been lost) or `reconnect failed` (a warning with the masked error). The lines name the account, and the connection when only one uses it; they never contain SQL. Before, a session that kept dropping left no trace. (#1427)
32+
- **A trace containing `<!--<script` no longer opens as an empty page.** The viewer embeds the trace in an inline script, and that text in tool output (a fetched web page, say) stopped the script from running. Affected the TUI's `/traces` too. Found in this release's testing.
33+
- **The trace viewer page cannot call the server's API.** Served from `serve` for the IDE, the page now carries a content security policy that allows its own script but no requests or form posts, so script injected through trace content cannot reach other routes. Found in this release's review.
34+
835
## [0.12.6] - 2026-10-06
936

1037
Hotfix for 0.12.5. **Heads-up for support:** anyone on 0.12.5 who is signed in to Altimate gets a TUI where keybindings do nothing and Ctrl+C does not quit; they have to close the terminal. Upgrading fixes it, and so does `ALTIMATE_DISABLE_WORKSPACE=1` as a stopgap.

‎docs/docs/configure/warehouses.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Each warehouse has a key (the connection name) and a config object:
5353
| `database` | No | Database name |
5454
| `schema` | No | Schema name |
5555
| `role` | No | User role |
56-
| `client_session_keep_alive` | No | Keep the session alive while Altimate Code is running (default `true`). A connection Snowflake closes anyway is reopened automatically. `USE`, `ALTER SESSION` and `SET` settings are applied again to the reopened session. A single read-only query interrupted by the close is run again; a statement that changes data, or calls a sequence, is not, because it may already have run, and the error says so. Temporary tables and an open transaction cannot be restored: statements issued before the reopen report that instead of running. |
56+
| `client_session_keep_alive` | No | Keep the session alive while Altimate Code is running (default `true`). A connection Snowflake closes anyway is reopened automatically. `USE`, `ALTER SESSION` and `SET` settings are applied again to the reopened session. A single read-only query interrupted by the close is run again; a statement that changes data, or calls a sequence, is not, because it may already have run, and the error says so. Temporary tables and an open transaction cannot be restored: statements issued before the reopen report that instead of running. Each reopen is written to `opencode.log` under `warehouse-connect` as `reconnecting`, then `reconnected` (with `reason`, `duration_ms`, `settings_restored` and `session_state_lost`) or `reconnect failed` (a warning with the masked error). The lines name the account, and the connection when only one uses that account; they never contain SQL. |
5757

5858
### Key-pair authentication
5959

‎docs/docs/usage/cli.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ With workspaces on:
6565
- When the linked workspace has knowledge, the agent is told to check it for best practices and team conventions before answering, without you having to mention the knowledge base.
6666
- In an ordinary session the agent is told every turn which workspace the project is linked to — or that none is, or that the link could not be verified just now. In an extension-pinned session it is told the pinned workspace instead, and that it differs from the project's own link. Either way "which workspace am I in?" has an answer, and the agent is told not to confuse it with a Databricks workspace or an IDE workspace folder.
6767
- When `altimate-code serve` is launched by the VS Code / Cursor extension, the workspace selected in the extension's panel governs that session's skills, memory and (unless `--integrations local` is set) warehouse tool routing, taking priority over whatever the project is linked to on the backend, and is scoped to the folder it was launched for. A pin is fixed for the life of the `serve` process, so the extension relaunches `serve` when the selection changes; nothing updates a running one.
68+
- `serve` also gives the IDE extension what the TUI shows: `GET /altimate/workspace/starter` (the starter message after a link) and `GET /altimate/trace` with `GET /altimate/trace/<session>/view` (the trace list and viewer behind `/traces`). Traces hold prompts and tool output, including SQL and query results. Like every `serve` route, these need no password unless `OPENCODE_SERVER_PASSWORD` is set, so set one on a shared machine.
6869

6970
## Global Flags
7071

‎packages/drivers/src/index.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ export { normalizeConfig, sanitizeConnectionString } from "./normalize"
88
export { onBrowserSignIn, redactSignInUrl } from "./sign-in"
99
export type { BrowserSignInNotice } from "./sign-in"
1010

11+
// Re-export reconnect events (a closed session reopened by the driver)
12+
export { onReconnect } from "./reconnect-events"
13+
export type { ReconnectEvent } from "./reconnect-events"
14+
1115
// Re-export file-backed store guards
1216
export { allowsCreate, assertStoreExists, isLocalFilePath, requireStorePath } from "./file-store"
1317

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
* A driver replacing a connection the warehouse closed (today: Snowflake after an idle
3+
* timeout, a network drop or laptop sleep). The reopen is silent to the caller, which is
4+
* the point, but without these events it was also missing from the log: a session that
5+
* kept dropping looked exactly like one that never did.
6+
*/
7+
export interface ReconnectEvent {
8+
warehouse: string
9+
/** Identifies which account the connection belongs to, e.g. the Snowflake account locator. */
10+
account?: string
11+
phase: "started" | "reconnected" | "failed"
12+
/** How the closed session showed: the SDK reported it down before a statement, or a statement failed because
13+
* the session had closed. The second does not say the statement did not run: a write may already have. */
14+
reason: "connection-down" | "closed-during-statement"
15+
/** From the start of the reconnect. On `reconnected` and `failed`. */
16+
durationMs?: number
17+
/** Session settings (USE, SET, ALTER SESSION…) restored on the new session. On `reconnected`. */
18+
settingsRestored?: number
19+
/** Temporary objects or an open transaction went with the old session, or a statement that could create them
20+
* was still running on it, so whether they did is not known yet. On `reconnected`. */
21+
sessionStateLost?: boolean
22+
/** On `failed`. Never carries the session's statements (a replayed setting can hold anything the user ran). */
23+
error?: string
24+
}
25+
26+
type Listener = (event: ReconnectEvent) => void | Promise<void>
27+
28+
// Process-global, for the same reason as the sign-in notices: the driver and its
29+
// subscriber can be loaded through different module graphs.
30+
const LISTENERS_KEY = Symbol.for("altimate.drivers.reconnectListeners")
31+
const listeners: Set<Listener> = ((globalThis as Record<symbol, unknown>)[LISTENERS_KEY] as Set<Listener>) ??
32+
((globalThis as Record<symbol, unknown>)[LISTENERS_KEY] = new Set<Listener>())
33+
34+
/** Subscribe to reconnect events from every driver. Returns the unsubscribe. */
35+
export function onReconnect(listener: Listener): () => void {
36+
listeners.add(listener)
37+
return () => listeners.delete(listener)
38+
}
39+
40+
export function emitReconnect(event: ReconnectEvent): void {
41+
for (const listener of listeners) {
42+
// A broken listener, sync or async, must not fail the reconnect or leave an unhandled rejection.
43+
try {
44+
void Promise.resolve(listener(event)).catch(() => {})
45+
} catch {
46+
// as above
47+
}
48+
}
49+
}

‎packages/drivers/src/snowflake.ts‎

Lines changed: 76 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import * as fs from "fs"
66
import type { ConnectionConfig, Connector, ConnectorResult, ExecuteOptions, SchemaColumn } from "./types"
77
import { loadOptionalDriver } from "./resolve"
88
import { emitBrowserSignIn, openInBrowser } from "./sign-in"
9+
import { emitReconnect, type ReconnectEvent } from "./reconnect-events"
910

1011
/**
1112
* Run `fn` with stdout/stderr writes swallowed for the (synchronous) duration of
@@ -214,6 +215,10 @@ export async function connect(
214215
/** The generation at which that state was lost: statements that started before it are not run, because they
215216
* may depend on it; statements issued after it run on the new session. Never cleared by a late error. */
216217
let stateLostAt: number | undefined
218+
/** Statements that may create temporary objects or open a transaction, by the generation of the session they were
219+
* sent to, while they run: one that finishes after a reconnect is reported to its caller then, so the reconnect
220+
* cannot yet say the replaced session lost nothing. */
221+
const stateStatementsRunning = new Map<number, number>()
217222

218223
function openConnection(): Promise<any> {
219224
const account = connectOptions?.account
@@ -290,9 +295,13 @@ export async function connect(
290295
}
291296

292297
/** Replace a connection Snowflake has closed. Concurrent callers share one reconnect. */
293-
function reconnect(): Promise<void> {
298+
function reconnect(reason: ReconnectEvent["reason"]): Promise<void> {
294299
if (!reconnecting) {
295300
const previous = connection
301+
const account = String(connectOptions?.account ?? "")
302+
const startedAt = Date.now()
303+
let settingsRestored = 0
304+
emitReconnect({ warehouse: "snowflake", account, phase: "started", reason })
296305
reconnecting = openConnection()
297306
.then(async (conn) => {
298307
const discard = () => {
@@ -314,13 +323,29 @@ export async function connect(
314323
await runQuery(conn, setting)
315324
} catch (err) {
316325
discard()
317-
throw new Error(
318-
`Snowflake closed the session and its settings could not be restored on a new one (${setting}): ${(err as Error)?.message ?? err}`,
326+
// The caller ran this setting and is told which; the reconnect event, which any subscriber in the
327+
// process receives, gets the message without it.
328+
// The SDK's message can quote the setting (a schema or value it names), so the event carries only its
329+
// error code.
330+
const cause = (err as Error)?.message ?? err
331+
const code = (err as { code?: unknown })?.code
332+
throw Object.assign(
333+
new Error(
334+
`Snowflake closed the session and its settings could not be restored on a new one (${setting}): ${cause}`,
335+
),
336+
{
337+
eventMessage:
338+
"Snowflake closed the session and its settings could not be restored on a new one" +
339+
(code !== undefined ? ` (Snowflake error ${String(code)})` : ""),
340+
},
319341
)
320342
}
321343
}
322344
const unchanged = snapshot.length === sessionSettings.length && snapshot.every((v, i) => v === sessionSettings[i])
323-
if (unchanged) break
345+
if (unchanged) {
346+
settingsRestored = snapshot.length
347+
break
348+
}
324349
if (pass + 1 >= MAX_REPLAY_PASSES) {
325350
// Settings keep arriving: a connection installed now would run later queries with some of them missing.
326351
discard()
@@ -333,6 +358,8 @@ export async function connect(
333358
discard()
334359
throw new Error("Snowflake connection was closed while reconnecting")
335360
}
361+
// Read before the generation moves on: statements still running on the session being replaced.
362+
const stateStillRunning = (stateStatementsRunning.get(generation) ?? 0) > 0
336363
generation++
337364
if (tempIn !== undefined || txnIn !== undefined) {
338365
stateLostAt = generation
@@ -346,6 +373,26 @@ export async function connect(
346373
} catch {
347374
// already terminated — nothing to release
348375
}
376+
emitReconnect({
377+
warehouse: "snowflake",
378+
account,
379+
phase: "reconnected",
380+
reason,
381+
durationMs: Date.now() - startedAt,
382+
settingsRestored,
383+
sessionStateLost: stateLostAt === generation || stateStillRunning,
384+
})
385+
})
386+
.catch((err) => {
387+
emitReconnect({
388+
warehouse: "snowflake",
389+
account,
390+
phase: "failed",
391+
reason,
392+
durationMs: Date.now() - startedAt,
393+
error: String((err as { eventMessage?: string })?.eventMessage ?? (err as Error)?.message ?? err),
394+
})
395+
throw err
349396
})
350397
.finally(() => {
351398
reconnecting = undefined
@@ -372,7 +419,7 @@ export async function connect(
372419
async function ensureLive(): Promise<void> {
373420
if (reconnecting) return reconnecting
374421
if (connection && connectOptions && typeof connection.isUp === "function" && !connection.isUp()) {
375-
await reconnect()
422+
await reconnect("connection-down")
376423
}
377424
}
378425

@@ -429,14 +476,14 @@ export async function connect(
429476
const used = connection
430477
const ranIn = generation
431478
try {
432-
const result = await runQuery(used, sql, binds)
479+
const result = await runTracked(used, sql, binds, ranIn)
433480
await noteSession(sql, binds, ranIn, startedInEpoch)
434481
return result
435482
} catch (err) {
436483
if (!connectOptions || !isClosedConnectionError(err)) throw err
437484
// Reopen only if the failed connection is still the current one: a late error from a connection
438485
// another statement already replaced must not tear down its replacement.
439-
if (connection === used) await reconnect()
486+
if (connection === used) await reconnect("closed-during-statement")
440487
else if (reconnecting) await reconnecting
441488
const cause = String((err as Error)?.message ?? err)
442489
if (lostFor(started)) throw sessionLostError(cause)
@@ -448,12 +495,33 @@ export async function connect(
448495
)
449496
}
450497
const ranAgainIn = generation
451-
const result = await runQuery(connection, sql, binds)
498+
const result = await runTracked(connection, sql, binds, ranAgainIn)
452499
await noteSession(sql, binds, ranAgainIn, startedInEpoch)
453500
return result
454501
}
455502
}
456503

504+
/** Whether a statement may create temporary objects or open a transaction: the same test `noteSession` applies
505+
* when it finishes, so a statement it would report as lost is also counted while it runs. */
506+
function mayHoldState(sql: string, binds?: any[]): boolean {
507+
const replayable = isSessionSetting(sql) && !(binds && binds.length)
508+
return opensTransaction(sql) || holdsSessionState(sql) || (looksLikeSessionChange(sql) && !replayable)
509+
}
510+
511+
/** `runQuery`, counting a statement that may hold session state against the session it was sent to (`ran`) for
512+
* as long as it runs. Counted only once sent: one still waiting on a reconnect will run on the new session. */
513+
async function runTracked(conn: any, sql: string, binds: any[] | undefined, ran: number) {
514+
if (!mayHoldState(sql, binds)) return runQuery(conn, sql, binds)
515+
stateStatementsRunning.set(ran, (stateStatementsRunning.get(ran) ?? 0) + 1)
516+
try {
517+
return await runQuery(conn, sql, binds)
518+
} finally {
519+
const left = (stateStatementsRunning.get(ran) ?? 1) - 1
520+
if (left > 0) stateStatementsRunning.set(ran, left)
521+
else stateStatementsRunning.delete(ran)
522+
}
523+
}
524+
457525
function runQuery(conn: any, sql: string, binds?: any[]): Promise<{ columns: string[]; rows: any[][] }> {
458526
return new Promise((resolve, reject) => {
459527
const options: Record<string, any> = {

0 commit comments

Comments
 (0)