Skip to content

LLM skills and durable sessions - #13778

Merged
vito merged 21 commits into
mainfrom
llm-workspace-llm-sessions
Aug 5, 2026
Merged

vito merged 21 commits into
mainfrom
llm-workspace-llm-sessions

Conversation

@vito

@vito vito commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

Skills and durable sessions for LLM, on top of the workspace binding (#13635).

Skills. The model discovers and reads skills through ListSkills/ReadSkill: engine-embedded skills, directories installed with the new LLM.withSkills, and any directory in the bound workspace's tree with a SKILL.md carrying name/description frontmatter. Engine-embedded skills come first and cannot be shadowed; installed skills take precedence over workspace-discovered ones.

Durable sessions. Saved sessions recorded workspace edits as operation chains rooted at live reads: once the checkout drifted, loads either failed (withReplaced no longer found its search text) or silently re-applied edits already on disk. Edits are now normalized to git patches at the session boundary and recorded as withPatch(patch, onConflict: LEAVE_CONFLICT_MARKERS), so a drifted hunk degrades to conflict markers the agent can resolve.

LLM.portableID returns an ID fit to persist. Binding a workspace is a pure setter — only the tip-most withWorkspace on the recipe spine matters — so the recipe is flattened structurally: superseded bindings (each mutating tool call records one) are not emitted, and the current binding is carried verbatim, pending un-exported edits included. Saving after an export stops replaying edits that are already on disk.

Stale host reads. Host reads are cached per client for the client's lifetime, so a file read before an export kept returning its pre-export snapshot. Workspace.export now bumps the client's workspace read epoch, and a new Workspace.reloaded invalidates cached reads without exporting. These are the ctrl+s and ctrl+u directions of the CLI's session controls (#13780).

Replay (dagql). Loading a recipe-form ID serves each recorded call from cache before its inputs load, and implicit inputs replay verbatim — right for pure data, wrong for the two impure things a saved ID can reach. Query.currentWorkspace and Host.directory are marked NotReplayable and re-execute on replay. Previously a resumed session failed with "failed to retrieve session main client", or replayed a pending edit against the saving session's frozen snapshot and clobbered out-of-band host changes.

Tests. core/integration/llm_resume_test.go covers save/resume in one engine, with the file edited on disk in between, and across an engine restart — each over both session-teardown orders (teardown releasing the recorded currentWorkspace was masking the dead-client bug) and through the tools-derivation path the CLI takes on the first prompt after a resume. A TODO lists what's still owed: a tool's Service running at save time, a module function returning a bound LLM, and other session-owned state (secrets, sockets, tunnels).

@vito
vito force-pushed the llm-workspace-llm-sessions branch from ee1d96c to cf340cd Compare August 5, 2026 01:54
Base automatically changed from llm-workspace-llm-binding to main August 5, 2026 04:21
@vito
vito force-pushed the llm-workspace-llm-sessions branch from cf340cd to 55bae76 Compare August 5, 2026 04:21
vito added 10 commits August 5, 2026 09:32
Replace the "glob **/SKILL.md via dang_eval" convention with two read-only
builtins that give the model progressive disclosure of task-specific skills:

- list_skills returns each skill's name and one-line description, parsed from
  its SKILL.md frontmatter.
- read_skill returns a skill's SKILL.md, or a reference file it routes to
  (read_skill(name, file)).

The model cannot read a Dang-teaching skill through a Dang eval it does not yet
know how to write, so discovery and reading must live outside dang_eval.

Skills come from ordered sources behind a skillSource interface. The only source
today is engine-embedded: the dang-language skill in dang's .agents/skills
embed, reached by bumping the dang/v2 pin. An allowlist keeps the compiler-
contributor skills (builtin-dsl, dang-internals, editor-syntaxes, testing) out
of the model's view. Workspace-shipped SKILL.md files will plug in as a second
source.

The dang prompt now points at list_skills/read_skill and nudges reading the
dang-language skill before writing non-trivial scripts.

(cherry picked from commit 743a684)
Signed-off-by: Alex Suraci <[email protected]>
Saved sessions recorded workspace edits as operation chains rooted at live
reads, so once the checkout drifted the load either failed outright or
silently re-applied edits that were already on disk.

Normalize the edits to git patches at the session boundary and record them as
withPatch(patch, onConflict: LEAVE_CONFLICT_MARKERS), so a drifted hunk
degrades into labeled conflict markers the agent can resolve instead of
breaking the load. Add withResetWorkspace, which re-emits the session as a
flat, data-only recipe after an export, so a resumed session continues from
the workspace's on-disk state rather than replaying edits already applied.

Signed-off-by: Alex Suraci <[email protected]>
Skills previously came from two fixed sources: the engine-embedded dang
skills and SKILL.md files discovered in the bound workspace.
LLM.withSkills(directory) adds a third: explicitly installed skill
directories, using the same **/SKILL.md discovery convention. Sources
are consulted in engine, installed, workspace order, so installed
skills win name collisions with ambient workspace skills but cannot
shadow the engine's built-ins.

The model's skill index is now also introspectable as LLM.skills (an
LLMSkill name/description list served verbatim from list_skills),
giving tests and dagger shell a direct view of what the model sees.
Installed directories are re-emitted by withResetWorkspace and attached
as dependency results so they survive session persistence and cache
lifetimes. Integration tests cover discovery across all three sources,
precedence, the reset/portableID round trip, and the live
list_skills/read_skill tool path via a canned replay conversation.

(cherry picked from commit 6a5bec5)
Signed-off-by: Alex Suraci <[email protected]>
withResetWorkspace rebound the LLM without actually clearing the accumulated
overlay, so the reset session still carried its edits. Clear it properly, and
bump the client's workspace read epoch on reset: host reads are cached per
client for the client's whole lifetime, so within one conversation a file read
before the export kept returning its pre-export snapshot.

Signed-off-by: Alex Suraci <[email protected]>
The reset-family tests relied on the ambient binding llm() no longer
performs. Give them a real git workspace and bind currentWorkspace on
construction; where they inspect workspace state after a reset, rebind
the live workspace first, mirroring what the CLI does after ctrl+s and
ctrl+u. The recipe-shape assertions still run against the un-rebound
reset, which stays flat.

Also correct WithResetWorkspace's doc: a bare currentWorkspace base is
dropped because its recorded call is per-invocation, not because it was
NewLLM's imperative default — NewLLM no longer captures one.

Signed-off-by: Alex Suraci <[email protected]>
Three integration tests for resuming a saved LLM session in a session
other than the one that saved it: a plain save/exit/resume on one
engine, the same with the file edited on disk in between, and the same
across an engine restart through the persistence cache.

They are skipped. They were written to pin down the zombie-client class
of resume failures — a saved recipe records the currentWorkspace call
that bound the workspace, and on resume that call can replay against the
cache and hit a value pinned to the saving session's dead client. As
written all three pass: the plain path re-resolves correctly without the
per-client workspace session-resource handle that was dropped here.

Keep them as the skeleton for the coverage that is actually owed, with a
TODO listing the situations that plausibly do break — pending overlay
edits (exported or not), a tool's Service still running at save time, a
module function returning a bound LLM — to be filled in and unskipped as
each is made to work.

Signed-off-by: Alex Suraci <[email protected]>
Regenerate this layer's docs and Go SDK against its own schema. The
generated files were carried down from higher layers during the original
split, so they described API that does not exist yet at this point in
the stack.

Signed-off-by: Alex Suraci <[email protected]>
Loading a recipe-form ID serves each recorded call from the dagql cache
before its inputs are loaded, so a hit short-circuits the whole subtree
beneath it. The recorded digest is reproducible across sessions because
implicit inputs are replayed verbatim rather than re-resolved, which is
correct for pure data but wrong for the two impure things a saved ID can
reach: a client-bound workspace and a host read. Their digest is a stable
key for a value that means nothing outside the session that produced it.

Resuming a saved LLM session hit both. The recorded currentWorkspace call
came back carrying the saving session's client ID, which never resolves in
another session, so deriving tools or reading files failed with "failed to
retrieve session main client". The recorded overlay came back rooted at
that session's frozen snapshot of the tree, so replaying a pending edit
overwrote out-of-band host changes instead of merging, and the conflict
markers withPatch records LEAVE_CONFLICT_MARKERS for never arose.

Add FieldSpec.NotReplayable so a field can declare its result unsafe to
serve to a replayed call, and taint every recorded call that depends on
one — the taint has to propagate upward or an ancestor hit would skip past
the marked node. Gate it on the recorded cachePerSession stamp differing
from the loading session: replaying a host read inside the session that
made it is fine, and same-session recipe loads are not rare. Dockerfile
support is built on them, synthesizing a call chain rooted at the build
context and loading it, so tainting those unconditionally would cost cache
hits on every build from a host directory.

Mark Query.currentWorkspace and Host.directory. The workspace read APIs
are deliberately left alone: a git-backed or synthetic workspace replays
reproducibly, and the client-local case already routes through
Host.directory.

Signed-off-by: Alex Suraci <[email protected]>
The earlier sketch passed for the wrong reason. Every scenario closed the
saving session before resuming, and session teardown collects the recorded
currentWorkspace result once nothing owns it, so the offending value was
garbage-collected and re-resolved live. Keeping any session alive that
still owns it — most naturally the saving session, which is what autosave
then resume in another terminal looks like — is what makes the replay hit
the cached value.

Run every scenario over both arrangements so that teardown order is a
named variable rather than a hidden property of the harness, and add the
tools derivation path, which is what the CLI actually takes on the first
prompt after a resume and where the dead-client failure surfaces.

Cover pending overlay edits by emulating the editor write() and edit()
tools through the same normalization MCP.applyChangeset performs, so the
recorded shape matches what a real tool call produces rather than a
shortcut no agent takes. Assert conflict markers through the same search
the CLI runs to build the model's restore-time cue, since markers no
search surfaces are markers the agent never learns about.

Give each scenario distinctive file contents. Directories are content
addressed, so byte-identical trees are shared across separate temp
workdirs, and an identical-content neighbour can mask or manufacture a
failure.

Signed-off-by: Alex Suraci <[email protected]>
Loading a saved ID is not the same as making the calls it records, and the
difference is not obvious from either side of it: implicit inputs are
replayed verbatim rather than re-resolved, and the digest lookup precedes
input loading, so a cached ancestor can hide an impure call underneath it.

Write down why some recorded calls must be re-executed, why the taint has
to propagate upward, and why the rule is scoped to crossing a session
boundary rather than applied to every replay — Dockerfile builds load a
synthesized recipe rooted at the build context, so an unscoped rule would
cost cache hits on every build from a host directory.

Sits next to session_resources.md and explains how the two relate: that
rule gates values through dependency edges, this one gates recorded calls
through recipe structure, and neither subsumes the other.

Signed-off-by: Alex Suraci <[email protected]>
@vito
vito force-pushed the llm-workspace-llm-sessions branch from 55bae76 to be20a31 Compare August 5, 2026 13:36
vito added 2 commits August 5, 2026 10:04
Signed-off-by: Alex Suraci <[email protected]>
dagger agent's ctrl+s and ctrl+u failed with "no workspace is bound to
this LLM". withResetWorkspace deliberately emitted an unbound recipe when
the workspace's base was the ambient currentWorkspace, on the contract
that whoever continues the session rebinds explicitly - and the CLI never
held up its end, so the Changes preview right after a reset blew up.

Rather than paper over it with a rebind, remove the operation. Binding a
workspace is a pure setter, so only the tip-most withWorkspace on the
recipe spine matters and MCP.WithTools already keeps at most one binding
per object type, which makes the flattening structural: portableID now
returns the flattened recipe itself and every superseded binding step
simply isn't emitted. The current binding is carried verbatim, overlay
derivations and all, so pending un-exported edits still survive a
save/resume round trip while already-exported ones stop being replayed.

withResetWorkspace also carried an unrelated second job, bumping the
client's workspace read epoch. Rehome it to where the staleness
originates: export bumps it, and a new Workspace.reloaded covers the
ctrl+u direction where nothing was exported but the agent must still
re-read the live host.

Signed-off-by: Alex Suraci <[email protected]>
@vito
vito force-pushed the llm-workspace-llm-sessions branch from c7c01ee to 06fd68e Compare August 5, 2026 15:30
vito added 9 commits August 5, 2026 13:02
Signed-off-by: Alex Suraci <[email protected]>
recipeSelectors emitted the root llm() call with only the model, so a
session created with an explicit provider — the llm(provider:) case for
fine-tune model names that match no inference pattern — resumed with
provider inference alone and routed to the wrong provider. Emit the
final provider on the root selector alongside the model. Internal
Selects run under the empty view, which AfterVersion filters treat as
contained, so the v1-gated provider arg is accepted regardless of the
calling client's view.

Signed-off-by: Alex Suraci <[email protected]>
Workspace.reloaded bumped the read epoch under the caller's client
context, but withWorkspaceHostReadContext resolves the epoch after
switching into the workspace owner's client — the same context export
bumps in. When the caller is not the owner (a module handed the
workspace), the bump landed on the wrong client's epoch and the
invalidation was a silent no-op. Switch into the owning client before
bumping, and skip the bump for value workspaces, which have no owning
client and no host reads to invalidate.

Signed-off-by: Alex Suraci <[email protected]>
listSkills only surfaces a source error when no source lists at all,
and the engine-embedded source essentially always lists — so a broken
workspace enumeration silently hid that workspace's skills with no
signal anywhere. Keep the graceful degradation but log the skipped
source and its error, so the disappearance is diagnosable.

Signed-off-by: Alex Suraci <[email protected]>
Git patches carry file content only, so normalizeChangesetToPatch
silently dropped empty directories: a tool changeset creating an empty
directory beside a file edit produced a non-empty patch, and the
normalized changeset — which replaces the original on the live
workspace binding, not just the saved form — lost the directory with no
warning. Reconcile the patched tree against the changeset's real After:
the residue can only be directories (the patch fully covers files, and
any file-level residue now aborts normalization into the existing
raw-changeset fallback), so restore added directories with
withNewDirectory and drop removed ones with withoutDirectory. Both are
recorded as selectors on the overlay chain, keeping the recorded
overlay pure data that replays tolerantly. A cheap gate on the
changeset's own (already-memoized) paths skips the residue diff when no
directories changed at all.

The integration test drives the real tool path through a canned replay
conversation and asserts three things: the file edit lands, the empty
directory survives, and — since the directory would also survive if
normalization silently fell back to the raw changeset — the recorded
overlay actually contains withPatch plus the restoring
withNewDirectory.

Signed-off-by: Alex Suraci <[email protected]>
parseSkillFrontmatter closed the YAML block at the first "\n---"
occurrence, so any line merely starting with three dashes — a ----
rule, or a --- prefix inside a scalar — truncated the frontmatter
mid-block and leaked the remainder into the parse. Scan line by line
and close only on a line that is exactly --- (modulo a trailing CR),
matching how the opening fence is already checked.

Signed-off-by: Alex Suraci <[email protected]>
llm() with no model recorded an unpinned call and resolved the
configured default lazily at endpoint time, so a saved session resumed
against whatever default the resuming environment configured — silently
switching a transcript to a different model. Make llm() a NodeFunc that
resolves the default route and re-calls itself with the model and its
provider as explicit arguments, the way Container.from re-calls itself
with the digested ref; portableID then re-emits the pinned pair from
final state. Route resolution failures fall back to the old unpinned
behavior (surfacing at first use), and the legacy maxAPICalls knob is
applied to the outer call's result since no single schema view carries
both it (pre-v1) and provider (v1+). The test drives the CLI in a
container so the client environment the router reads is controlled, and
asserts the recorded root llm() call names both the model and provider.

Signed-off-by: Alex Suraci <[email protected]>
The provisional-false entry notReplayable plants to guard against
cycles is only safe against concurrent readers because the root vertex
computes its full taint closure synchronously, before loadRecipeVertex
fans out concurrent input loads — so other goroutines only ever consult
finalized entries. The invariant was load-bearing but implicit; state
it where the memo is maintained.

Signed-off-by: Alex Suraci <[email protected]>
Unit-test the taint at the dagql layer, next to the other implicit
input tests: a marked+stamped call replayed from a saved recipe stays
on the cache inside its recording session, and re-executes — along
with the pure ancestor above it — when loaded by another session.

The no-stamp test pins down something the integration tests could not
see: taint only skips the recipe loader's own lookups, and a marked
field without PerSessionInput re-issues a call whose ordinary digest is
identical in every session, so the regular call path serves the
recorded value and the resolver never re-runs. recipe_replay.md claimed
that fallback was "safe but silently costs cache hits"; correct it to
say the PerSessionInput pairing is load-bearing, with the test as the
pin.

Signed-off-by: Alex Suraci <[email protected]>

@grouville grouville left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM ✅

(fun fact, I did found 2 small bugs that you fixed as part of the followup commits. Too fast 😎 )

@vito
vito merged commit 87a07af into main Aug 5, 2026
88 checks passed
@vito
vito deleted the llm-workspace-llm-sessions branch August 5, 2026 19:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants