Skip to content

Commit 327eb9f

Browse files
sahrizviclaude
andauthored
feat(workspace): state the linked workspace every turn, and mean the Altimate one (#1330)
* feat(workspace): state the linked workspace every turn, and mean the Altimate one "Which workspace is this project linked to?" had one answer only when the workspace was routing something. #1278 put the binding into the routing directive in `awareness.ts`, which is silent by design whenever there is nothing to steer — so an unlinked project, an unverifiable link, and a workspace that materialised no integrations each rendered nothing, and the model answered with whichever "workspace" happened to be nearby in context: a Databricks workspace, an IDE workspace folder, or a guess. Identity now has one owner. `identity.ts` renders a short `## Altimate Workspace` section on every turn from the binding itself (`resolveBindingOutcome`), independent of routing: - bound: names the workspace (id kept even when the name sanitises to nothing) and says that a workspace-IDENTITY question resolves to it — never to another service's own "workspace". - unbound: says none is linked and how to link one. - unknown: asserts neither a workspace nor "unlinked"; says to retry. Each branch scopes its instruction to a genuine identity question ("this", "current", "active" or an unqualified "workspace" asking what THIS project is connected to). An earlier draft fired on any mention of the word and nagged about linking in the middle of unrelated Databricks conversations; the tests pin that it no longer does. Behind the pilot flag like the rest. `awareness.ts` goes back to routing only: `bindingSection`, `NAMES_BINDING` and the identity charge against `MAX_SECTION_CHARS` are gone, and the `nothing-materialised` state is byte-identical silence again (#1291's two tests that asserted the old line inside the routing section now assert silence). `prompt.ts` places the identity section right after the environment block, ahead of skills and routing. Two strings elsewhere used "workspace" for something else and are reworded so the word means one thing in the product: the Databricks auth prompt says `<databricks-workspace-host>`, and the nothing-built validator says "this project is configured to require artifacts". Tests: 1498 pass across the workspace, plugin, prompt and validator suites; typecheck clean. Rebased onto v0.12.0. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_012Q51zFUmPg1WwtS5CrGJE6 * fix(workspace): identity review — one owner, bounded resolve, budgeted label From the Kilo, CodeRabbit and Codex reviews of the identity PR. - The routing directive no longer says "This project is bound to Altimate workspace X": it names the workspace that SERVES the tools ("Altimate workspace X serves the warehouse tools named below"). The snapshot is taken from local state at tool resolution and identity is revalidated against the server later in the turn, so the old sentence could contradict the identity section in one prompt. The ownership test now rejects every "this project is linked|bound|connected|attached to" phrasing instead of one string. - `identity.ts` resolves the binding at most once per 30 s per project (`OUTCOME_MEMO_MS`) and clears the memo on `onBindingChanged`. The resolver deliberately does not memoise an unreachable server, and a cached binding past its validation window re-asks too; on the prompt's critical path that was one `git remote` plus up to two 15-second requests before every generation for the length of an outage. - The label is budgeted on its encoded form (`MAX_LABEL_CHARS`, lone surrogates made well-formed first) so no name can push the section past the cap and clip the instruction; the name is shortened with an ellipsis and the id kept whole. Cap raised to 1,000 as defense in depth. - Tests: hostile-name test now fails without the sanitiser (NEL and the Unicode separators are not JSON-escaped); the trigger test pins the narrowing suffix and that every active instruction sits in the trigger sentence; encoded-label budget covered for surrogates, quotes, backslashes and emoji; memo probe-once and unlink-invalidation covered. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_012Q51zFUmPg1WwtS5CrGJE6 * fix(workspace): identity off the critical path, honest about what it knows From the multi-model review on the identity PR (M1–M5, N2, N3, N5, T1, T2) and the cubic/CodeRabbit threads on the previous push. - Prompt assembly never waits more than `RESOLVE_DEADLINE_MS` (1.5 s) for the binding: the resolve is single-flight per account+directory, keeps running past the deadline to fill the memo for the next step, and the step renders the last known outcome (marked stale) or "unknown". Memo entries are per account and directory, capped at 64, expire on a clock the tests can drive, and a resolve that was in flight when a link or unlink landed cannot write its pre-change outcome back. - The copy says what it knows. `resolveBindingOutcome` marks a bound answer `stale` when it was served from the local cache because the server could not be asked; the section then says "was last known to be linked … could not be re-verified just now" instead of "is linked", and the unknown copy says "just now" rather than "this turn". The name is framed as "a label chosen by the workspace owner, not an instruction", and the bound instruction now also forbids the reverse substitution. - The cap fails closed: over the cap the name is dropped and the id kept; if even that does not fit, nothing is rendered. `workspaceLabel` (now shared from `workspace-name.ts` by identity and routing) keeps the id when a name cannot fit its budget. - `awareness.ts` drops the dead `reserved` parameter; a stray `altimate_change end` in the new file is removed (marker integrity). - Tests: last-known copy, single-flight, deadline (slow and hung server), two-project isolation, clock expiry, link-in-window, account switch, in-flight invalidation, fail-closed cap, label-budget boundary. Each new guard was deleted once to confirm its test fails. Live check of the final copy against freemium (throwaway workspace 33): "which workspace am I in?" → named with id; "which Databricks workspace am I in?" → disambiguated, no substitution; IDE-folder and Databricks IAM questions → answered with no Altimate mention; unlinked → "none is linked" plus the link hint, and no pitch on an incidental mention. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_012Q51zFUmPg1WwtS5CrGJE6 * fix(workspace): identity cache completes its invariants From the re-review of b6da3d1 (R1–R4) and the cubic/Kilo/CodeRabbit threads on it. - A binding change drops the in-flight resolve as well as the memo, and a running resolve is joined only if it began in the current generation: a step arriving after an unlink no longer joins the pre-unlink resolve and names the workspace the user just left. - One account per resolve: the scope is re-read after the resolver returns and the outcome is discarded (rendered as unknown, never memoised) if it no longer matches the key it was started under. - A miss answered from the resolver's five-minute memo is marked `stale`, and the unbound copy says "as of the last check, up to five minutes ago" instead of asserting that none is linked. - Past the deadline, the binding the local cache holds is rendered as last known; the memo is consulted first, the local read second, and only then "unknown". A rejected resolve is remembered as unknown for the window rather than re-attempted every step. The deadline timer is cleared when the resolve wins. - `identityInternals` is a test seam for the resolver (ESM bindings are read-only); production never reassigns it. - Tests: post-unlink join, account switch mid-resolve, stale miss wording, throwing resolver, local-cache fallback past the deadline; the deadline test polls for the memo fill instead of sleeping; the clock is restored in `afterEach`. Each new guard was deleted once to confirm its test fails. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_012Q51zFUmPg1WwtS5CrGJE6 * fix(workspace): identity fallback and stale-miss wording - The deadline fallback reads the local binding under the current credentials and uses it only if they still match the key the resolve started under, so an account switch during the wait cannot surface the other account's cached workspace. - The stale-miss branch instructs "none was linked as of the last check" rather than "none is linked yet", so the qualification survives into the answer. - The post-unlink join test waits on request-start signals instead of fixed delays and asserts two requests were made. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_012Q51zFUmPg1WwtS5CrGJE6 * fix(workspace): identity fallback checks the account before any last-known answer The expired memo entry was consulted before the scope check that the local-cache branch had; a switch landing while the resolve hung could render the previous account's remembered workspace. The check now precedes both branches. Test: expired bound memo, hung resolve, switch before the deadline — fails with the check removed. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_012Q51zFUmPg1WwtS5CrGJE6 * fix(workspace): identity deadline is a bound, failures expire sooner Non-blocking items from the approving review of e142bde. - The deadline branch's own work (a credentials read, at most a cache read) is raced against `FALLBACK_BUDGET_MS`, so a step waits at most `RESOLVE_DEADLINE_MS + FALLBACK_BUDGET_MS` even when those reads hang, rather than the deadline plus whatever the disk takes. - A rejected resolve is remembered for `FAILURE_MEMO_MS` (5 s), not the full window: one transient blip no longer silences identity for 30 s, while a persistently throwing resolver is still not retried every step. The `.catch` path applies the same account check as the settled path. - `lastKnown` documents why its local-cache read deliberately repeats a slice of the resolver's "serve as stale" rule. - Tests: bounded wait with hung fallback reads; failure TTL shorter than the outcome TTL. Both fail with the guard removed. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_012Q51zFUmPg1WwtS5CrGJE6 --------- Co-authored-by: Claude Opus 5 <[email protected]>
1 parent 5d6cab9 commit 327eb9f

10 files changed

Lines changed: 1337 additions & 193 deletions

File tree

‎packages/opencode/src/altimate/plugin/databricks.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export async function DatabricksAuthPlugin(_input: PluginInput): Promise<Hooks>
127127
authorize: async () => ({
128128
url: "https://accounts.cloud.databricks.com",
129129
instructions:
130-
"Enter your credentials as: <workspace-host>::<PAT-token>\n e.g. myworkspace.cloud.databricks.com::dapi1234567890abcdef\n Create a PAT in Databricks: Settings → Developer → Access Tokens → Generate New Token",
130+
"Enter your credentials as: <databricks-workspace-host>::<PAT-token>\n e.g. myworkspace.cloud.databricks.com::dapi1234567890abcdef\n Create a PAT in Databricks: Settings → Developer → Access Tokens → Generate New Token",
131131
method: "code" as const,
132132
callback: async (code: string) => {
133133
const parsed = parseDatabricksPAT(code)

‎packages/opencode/src/altimate/validators/dbt-nothing-built.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ export const DbtNothingBuiltValidator: Validator = {
428428
// agent to distrust the gate.
429429
`The task document at ${safeTaskFile} names required deliverables${namedText}, but this session built other deliverables and none of them matched those names. The named work was not done.`
430430
: `The task document at ${safeTaskFile} names required deliverables${namedText}, but this session wrote no project files and produced no fresh successful build artifact. Nothing was built, so the task is not done.`
431-
: `This session wrote no project files and produced no fresh successful build artifact, but the workspace is configured to require artifacts. Nothing was built, so the task is not done.`
431+
: `This session wrote no project files and produced no fresh successful build artifact, but this project is configured to require artifacts. Nothing was built, so the task is not done.`
432432

433433
return {
434434
ok: false,

‎packages/opencode/src/altimate/workspace/awareness.ts‎

Lines changed: 24 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import {
4949
servedExtensions,
5050
servedInventory,
5151
} from "./precedence"
52+
import { workspaceLabel } from "./workspace-name"
5253

5354
/** Hard ceiling on the rendered section. Deliberately independent of
5455
* `UNIFIED_INJECTION_BUDGET`: this is a routing directive, not knowledge, and must
@@ -59,8 +60,6 @@ export const MAX_SECTION_CHARS = 2_000
5960

6061
const HEADING = "## Workspace integrations"
6162

62-
const BINDING_HEADING = "## Workspace"
63-
6463
/** How each capability is named to the model. Keyed on the `Capability` union, so a
6564
* new capability is a compile error here rather than an unlabelled row. */
6665
const CAPABILITY_LABEL: Record<Capability, string> = {
@@ -128,51 +127,16 @@ const DISABLED_COPY: Record<NonNullable<Precedence["disabledReason"]>, string> =
128127
"nothing-materialised": "",
129128
}
130129

131-
/** Whether the workspace may be NAMED in this state. Separate from `DISABLED_COPY`
132-
* because identity and routing are different claims: the routing directive stays
133-
* silent unless there is something to steer, but "which workspace is this project
134-
* linked to" is a question the model is asked directly and could not previously
135-
* answer — nothing else puts the binding in the prompt, and no tool reports it.
136-
*
137-
* Keyed on the union so a new `disabledReason` is a compile error here rather than
138-
* silently naming — or silently failing to name — a workspace. `false` for the three
139-
* unverified states for the reason `UNVERIFIED_SECTION` gives: nothing has confirmed
140-
* the binding those states were derived from, and under `unattributed` the engine may
141-
* belong to a different workspace than the one the link names. `false` for the hatch
142-
* and `pilot-off` because neither carries a name to print (see `EMPTY` in
143-
* `precedence.ts`) — a bound project with the hatch on therefore stays unnamed, which
144-
* is a data limitation of that call site, not a decision made here.
145-
*
146-
* NOTE: this deliberately breaks the "byte-identical system prompt" property that
147-
* `DISABLED_COPY` claims for `nothing-materialised`. A project bound to a workspace
148-
* that materialised no integrations is exactly the case users hit — a freshly created
149-
* workspace — and it is the case where being told nothing is most confusing. */
150-
const NAMES_BINDING: Record<NonNullable<Precedence["disabledReason"]>, boolean> = {
151-
"pilot-off": false,
152-
"escape-hatch": false,
153-
unbound: false,
154-
"binding-unreadable": false,
155-
unattributed: false,
156-
"derive-failed": false,
157-
"nothing-materialised": true,
158-
}
159-
160-
/** The identity line: what this project is linked to, independent of whether anything
161-
* is being routed. Empty when the state may not name a binding, or when the snapshot
162-
* carries no name to print. */
163-
function bindingSection(precedence: Precedence): string {
164-
const nameable = precedence.enabled || (precedence.disabledReason ? NAMES_BINDING[precedence.disabledReason] : false)
165-
if (!nameable) return ""
166-
// A name that sanitises to nothing must not erase the identity when the id
167-
// is known: the line is the only place the binding is stated. Without an id
168-
// either there is nothing left to print.
169-
if (!inertWorkspaceName(precedence.workspaceName) && !precedence.workspaceId) return ""
170-
return [
171-
BINDING_HEADING,
172-
"",
173-
`This project is linked to Altimate workspace ${workspaceLabel(precedence.workspaceName, precedence.workspaceId)}.`,
174-
].join("\n")
175-
}
130+
// Identity — "which Altimate Workspace is this project linked to" — is NOT stated
131+
// here, and the workspace named in the routing intro is the one that SERVES the
132+
// tools (the snapshot's provenance), not a claim about the current link: a
133+
// snapshot is taken from local state at tool resolution, and the link can be
134+
// revalidated against the server later in the same turn. It lives in `identity.ts`, which renders it every turn from the binding
135+
// itself, independent of routing: a project can be linked and route nothing (a
136+
// workspace that materialised no integrations), or be unlinked, or be unverifiable
137+
// this turn, and each of those deserves a definite answer that a routing directive,
138+
// silent by design whenever there is nothing to steer, cannot give. One owner, so the
139+
// two can never disagree about what the project is linked to.
176140

177141
/**
178142
* Render the section, or "" when there is nothing to steer.
@@ -193,30 +157,22 @@ function bindingSection(precedence: Precedence): string {
193157
*/
194158
export function systemSection(precedence: Precedence | undefined): string {
195159
if (!precedence) return ""
196-
// Identity first, then routing. Either half can be empty; both empty renders "".
197-
// The identity line is charged against MAX_SECTION_CHARS rather than added on top:
198-
// the cap exists to bound what this module injects, so letting a new part sit
199-
// outside it would raise the real ceiling silently.
200-
const binding = bindingSection(precedence)
201-
const routing = routingSection(precedence, binding ? binding.length + SEPARATOR.length : 0)
202-
return [binding, routing].filter(Boolean).join(SEPARATOR)
160+
return routingSection(precedence)
203161
}
204162

205-
const SEPARATOR = "\n\n"
206-
207-
/** The routing directive. Unchanged contract: silent unless the workspace is really
208-
* routing, so the model is never steered toward tools it should not use. The one
209-
* addition is the extension tools a live IDE bridge serves, which ride along in
210-
* both shapes and are the only thing said in the extension-only shape. */
211-
function routingSection(precedence: Precedence, reserved = 0): string {
163+
/** The routing directive. Silent unless the workspace is really routing, so the
164+
* model is never steered toward tools it should not use. The one addition is the
165+
* extension tools a live IDE bridge serves, which ride along in both shapes and are
166+
* the only thing said in the extension-only shape. */
167+
function routingSection(precedence: Precedence): string {
212168
const extLines = servedExtensions(precedence).map(extensionLine)
213169
if (!precedence.enabled) {
214170
// The one disabled state that can carry served extension tools (see `derive`):
215171
// no warehouse capability is routed, but the bridge is serving, and silence
216172
// would leave the model unaware of tools it can see. Without them the table's
217173
// entry renders exactly as before.
218174
if (precedence.disabledReason === "nothing-materialised" && extLines.length > 0) {
219-
return assembleExtensionsOnly(precedence.workspaceName, precedence.workspaceId, extLines, reserved)
175+
return assembleExtensionsOnly(precedence.workspaceName, precedence.workspaceId, extLines)
220176
}
221177
return precedence.disabledReason ? DISABLED_COPY[precedence.disabledReason] : ""
222178
}
@@ -227,7 +183,7 @@ function routingSection(precedence: Precedence, reserved = 0): string {
227183
// do are still real and still callable, so they are said.
228184
if (served.length === 0) {
229185
return extLines.length > 0
230-
? assembleExtensionsOnly(precedence.workspaceName, precedence.workspaceId, extLines, reserved)
186+
? assembleExtensionsOnly(precedence.workspaceName, precedence.workspaceId, extLines)
231187
: ""
232188
}
233189

@@ -243,7 +199,7 @@ function routingSection(precedence: Precedence, reserved = 0): string {
243199
return `- ${type} — ${servedPart}${localPart}`
244200
})
245201

246-
return assemble(precedence.workspaceName, precedence.workspaceId, typeLines, extLines, reserved)
202+
return assemble(precedence.workspaceName, precedence.workspaceId, typeLines, extLines)
247203
}
248204

249205
/** One extension-type integration and every tool of it the caller can call. The
@@ -273,15 +229,14 @@ function assembleExtensionsOnly(
273229
workspaceName: string,
274230
workspaceId: string | undefined,
275231
extLines: string[],
276-
reserved = 0,
277232
): string {
278233
const label = workspaceLabel(workspaceName, workspaceId)
279234
const render = (ext: string[]) => {
280235
const omitted = extLines.length - ext.length
281236
return [
282237
HEADING,
283238
"",
284-
`This project is bound to Altimate workspace ${label}. No warehouse capability is routed through it in ` +
239+
`Altimate workspace ${label} serves the extension tools below. No warehouse capability is routed through it in ` +
285240
`this session: every connection uses the local tools (${ALL_LOCAL_TOOLS}).`,
286241
"",
287242
EXTENSION_INTRO,
@@ -292,7 +247,7 @@ function assembleExtensionsOnly(
292247
}
293248
let ext = extLines
294249
let out = render(ext)
295-
while (out.length + reserved > MAX_SECTION_CHARS && ext.length > 0) {
250+
while (out.length > MAX_SECTION_CHARS && ext.length > 0) {
296251
ext = ext.slice(0, -1)
297252
out = render(ext)
298253
}
@@ -305,11 +260,6 @@ function assembleExtensionsOnly(
305260
* well, so quotes cannot break out of the sentence, and the numeric id, when known,
306261
* is named alongside as the stable identifier. Re-applying the sanitiser costs
307262
* nothing and keeps this surface safe even for a snapshot built elsewhere. */
308-
function workspaceLabel(name: string, id: string | undefined): string {
309-
const bounded = inertWorkspaceName(name) || "(unnamed)"
310-
return id ? `${JSON.stringify(bounded)} (id ${id})` : JSON.stringify(bounded)
311-
}
312-
313263
/** Build the section from its type lines, enforcing the char cap by dropping trailing
314264
* types rather than truncating mid-sentence — down to none if a single line is
315265
* oversized, so the ceiling is a real one. The converse paragraph is never dropped:
@@ -325,7 +275,6 @@ function assemble(
325275
workspaceId: string | undefined,
326276
typeLines: string[],
327277
extLines: string[] = [],
328-
reserved = 0,
329278
): string {
330279
const label = workspaceLabel(workspaceName, workspaceId)
331280
const render = (lines: string[], ext: string[]) => {
@@ -340,7 +289,7 @@ function assemble(
340289
return [
341290
HEADING,
342291
"",
343-
`This project is bound to Altimate workspace ${label}. For each connection type below, the ` +
292+
`Altimate workspace ${label} serves the warehouse tools named below. For each connection type below, the ` +
344293
"local tool for a capability that names a workspace tool will NOT execute — it returns a " +
345294
"redirect. Call the named workspace tool directly; capabilities not named for a type stay on " +
346295
"the local tools:",
@@ -366,7 +315,7 @@ function assemble(
366315
// Extension lines are dropped first: they are awareness, while the type lines
367316
// are directives the guard will enforce, and a redirect the model was never
368317
// warned of is the worse failure. Type lines go only once none are left.
369-
while (out.length + reserved > MAX_SECTION_CHARS && (ext.length > 0 || lines.length > 0)) {
318+
while (out.length > MAX_SECTION_CHARS && (ext.length > 0 || lines.length > 0)) {
370319
if (ext.length > 0) ext = ext.slice(0, -1)
371320
else lines = lines.slice(0, -1)
372321
out = render(lines, ext)

0 commit comments

Comments
 (0)