ARTICLE · INTELLIGENCE

战地情报 · 详情页

来自尧图项目组的一线实战观察与深度解析

Dagger v0.18.9 发布解读:新增 gc.sweepSize 引擎配置与 Host.directory 的 noCache 参数

Dagger v0.18.9 发布解读:新增 gc.sweepSize 引擎配置与 Host.directory 的 noCache 参数 Dagger v0.18.9 发布解读新增 gc.sweepSize 引擎配置与 Host.directory 的 noCache 参数【免费下载链接】daggerAutomation engine to build, test and ship any codebase. Runs locally, in CI, or directly in the cloud项目地址: https://gitcode.com/GitHub_Trending/da/daggerDagger v0.18.92025-05-27是一个以更精细的缓存与垃圾回收控制为主题的维护版本。本次更新引入了engine.json中全新的gc.sweepSize配置项允许用户控制单次 GC 清扫的数据量同时为Host.directory等宿主资源访问 API 增加了noCache参数使持久化 shell/prompt 会话能够自动重新加载上下文目录。读完本文你将理解这两项能力的设计动机、配置写法与源码级实现位置并能针对长时间运行的 AI prompt 会话和高缓存占用场景做出合理的引擎调优。版本概览按照 .changes/v0.18.9.md 的记录v0.18.9 共包含四类变更Addedengine.json新增gc.sweepSize设置用于控制单次 GC 清扫sweep释放的数据量ChangedHost.directory增加noCache参数用于在持久化的 shell/prompt 会话中自动重载上下文目录该参数实际同时覆盖Host.file等宿主资源访问Fixedshell修复_前缀未被保留给解释器内建命令的问题shell修复解析对象列表list of objects参数的问题。其中前两项直接影响用户的引擎运维与模块开发行为是本文展开的重点shell 修复项则面向 shell 风格的 API 描述与参数序列化下面简要说明。新增gc.sweepSize —— 控制单次 GC 清扫量配置语义gc.sweepSize的作用在源码注释中有明确定义。在 engine/config/config.go 中GCSpace结构体新增了SweepSize字段type GCSpace struct { // ReservedSpace is the minimum amount of disk space this policy is guaranteed to retain. ReservedSpace DiskSpace json:reservedSpace,omitempty // MaxUsedSpace is the maximum amount of disk space this policy is allowed to use. MaxUsedSpace DiskSpace json:maxUsedSpace,omitempty // MinFreeSpace is the target amount of free disk space the garbage collector will attempt to leave. MinFreeSpace DiskSpace json:minFreeSpace,omitempty // SweepSize is the minimum amount of space to sweep during a single gc pass. // Either an absolute number of bytes, or a percentage of the allowed // space between reserved and max. SweepSize DiskSpace json:sweepSize,omitempty }可以把它理解为每次垃圾回收清扫时至少要腾出这么多空间。当引擎缓存占用超过策略允许上限、触发一次 GC sweep 时回收器不会只象征性地清理一点而是以sweepSize作为单次清扫的下界保证一轮回收有实际效果、避免挤牙膏式的碎片回收。取值格式gc.sweepSize复用 Dagger 引擎配置中统一的DiskSpace类型。从 engine/config/config.go 中的 JSON Schema 定义可以看到合法写法有三种绝对字节数直接写一个整数例如512000000带单位的字节字符串如512MB遵循正则^[0-9][0-9.]*([kKmMgGtTpP][iI]?)?[bB]?$支持 k/M/G/T/P 及二进制 iB 变体百分比字符串如10%表示 reserved 与 max 之间允许空间的百分比。在 engine.json 中的位置引擎配置的顶层结构是 engine/config/config.go 中的Config其中GC字段承载垃圾回收设置type Config struct { // LogLevel defines the engines logging level. LogLevel LogLevel json:logLevel,omitempty // GC configures the engines garbage collector. GC GCConfig json:gc,omitempty ... } type GCConfig struct { // Enabled controls whether the garbage collector is enabled - it is // switched on by default (and generally shouldnt be turned off, except // for very short-lived dagger instances). Enabled *bool json:enabled,omitempty // DagqlCache configures structural memory pruning for the in-memory DAGQL // cache independently of physical cache disk usage. DagqlCache DagqlCacheGCConfig json:dagqlCache,omitempty // GCSpace is the amount of space to allow for the entire dagger engine, // only used in computing the default Policies. GCSpace // Policies are a list of manually configured policies - if not specified, // an automatic default will be generated from the top-level disk space // parameters. Policies []GCPolicy json:policies,omitempty }从源码结构看GCSpace含新增的sweepSize既可以直接放在gc顶层——此时它参与计算默认策略——也可以内嵌到gc.policies中每条GCPolicy内对特定容器d 过滤策略filters、keepDuration等单独约束清扫粒度。一个典型的engine.json片段形如{ gc: { enabled: true, reservedSpace: 1GB, maxUsedSpace: 10GB, minFreeSpace: 1GB, sweepSize: 2GB } }配置结构的设计约定同样写在 engine/config/config.go 顶部注释中保持顶层键简洁、优先新增键而非改动既有键的语义、为不再支持的键给出显式错误提示。这说明sweepSize是一个纯粹的新增能力不会改变已有reservedSpace/maxUsedSpace/minFreeSpace的行为。适用场景大缓存 高 IO 敏感环境调大sweepSize例如设为允许空间的50%让 GC 少触发、每次清得更彻底减少频繁的小规模回收磁盘紧张环境调小sweepSize让清扫更平滑避免单次回收产生较长的卡顿窗口配合gc.policies可对不同缓存类别通过id、inuse、mutable、type等过滤器区分设置不同的清扫粒度。变更Host.directory 增加 noCache 参数解决的问题Host.directory等宿主资源访问在 Dagger 中默认会命中引擎侧缓存相同的访问相同路径与过滤参数在会话内返回缓存结果。这对普通 build/CI 流程是性能优化但对持久化的 shell/prompt 会话例如与 AI 交互的长会话会产生副作用——宿主上文件被修改后会话内再次读取到的仍是旧内容。v0.18.9 起Host.directory与Host.file都新增了noCache: Boolean false参数。设为true时该目录/文件总是从宿主机重新加载绕过缓存。API 定义在 core/schema/host.go 中可以确认参数与文档描述dagql.NodeFunc(directory, s.directory). WithInput(dagql.RequestedCacheInput(noCache)). Doc(Accesses a directory on the host.). Args( dagql.Arg(path).Doc(Location of the directory to access (e.g., .).), dagql.Arg(exclude).Doc(Exclude artifacts that match the given pattern (e.g., [node_modules/, .git*]).), dagql.Arg(include).Doc(Include only artifacts that match the given pattern (e.g., [app/, package.*]).), dagql.Arg(noCache).Doc(If true, the directory will always be reloaded from the host.), dagql.Arg(gitignore).Doc(Apply .gitignore filter rules inside the directory), ), dagql.NodeFunc(file, s.file). WithInput(dagql.RequestedCacheInput(noCache)). Doc(Accesses a file on the host.). Args( dagql.Arg(path).Doc(Location of the file to retrieve (e.g., README.md).), dagql.Arg(noCache).Doc(If true, the file will always be reloaded from the host.), ),完整的 GraphQL 形态可参考 core/schema/testdata/base_schema.graphqlsdirectory(exclude: [String!] [], include: [String!] [], gitignore: Boolean false, noCache: Boolean false): Directory!实现细节noCache 是请求级缓存输入注意WithInput(dagql.RequestedCacheInput(noCache))这一行——从源码结构看noCache被注册为 DAGQL 请求的缓存输入之一它参与缓存键的构成。也就是说noCache: true的访问与noCache: false的访问落在不同的缓存槽位上前者每次都会向宿主重新拉取内容。这与参数文档the directory will always be reloaded from the host的语义一致。同样的处理也出现在Host.findUpcore/schema/host.go 第 66-71 行上它同样声明了noCache请求级缓存输入保证向上查找文件/目录这类依赖宿主当前状态的操作不被旧结果污染。使用方式在模块或 TUI 会话代码中以 Go SDK 为例其他语言 SDK 参数名一致dir : client.Host(). Directory(dagger.DirectoryPath(.), dagger.DirectoryWithNoCache(true), // 始终从宿主机重新读取 )典型用法是在 prompt/REPL 循环的每一轮迭代中对工作目录启用noCache从而让 LLM 或用户在同一持久会话中看到宿主文件的最新状态而不必重启会话。修复shell 参数处理的两处问题发布说明还记录了两处 shell 相关修复对应上游 PR 10452 与 10441_前缀保留给解释器内建命令在 shell 风格的 API 描述中以_开头的条目现在被正确保留为解释器内建builtin不再与普通参数混淆解析对象列表参数修复了当 shell 参数值是一个对象列表而非简单标量/字符串列表时的解析错误。这两处修复保证了复合类型参数尤其是模块函数中接收结构化输入的场景在 shell 语义下能被正确序列化与解析属于参数处理管线的健壮性改进。小结变更内容源码依据Addedengine.json新增gc.sweepSize控制单次 GC 清扫的最小空间量支持字节数、带单位字符串、百分比三种写法engine/config/config.go 中GCSpace.SweepSizeChangedHost.directory/Host.file新增noCache参数持久 shell/prompt 会话中可强制从宿主重载core/schema/host.go 中RequestedCacheInput(noCache)Fixedshell_前缀保留给内建命令修复对象列表参数解析.changes/v0.18.9.mdv0.18.9 的改动虽不算大但方向明确把缓存生命周期的控制权GC 粒度与缓存新鲜度的选择权noCache都交还给使用者正好覆盖了引擎长期运行调优与交互式长会话两类高频痛点。若你在运行长驻引擎或搭建 AI 驱动的 Dagger 会话这两个能力值得纳入配置。【免费下载链接】daggerAutomation engine to build, test and ship any codebase. Runs locally, in CI, or directly in the cloud项目地址: https://gitcode.com/GitHub_Trending/da/dagger创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
RELATED READING

延伸阅读

更多一线实战笔记与深度复盘,助您持续精进