Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Changelog

## 2026-12-01 - docks-kit 0.32.2: fast toggles refuse a retargeted or replaced config

`docks-kit --fast` and `docks-kit --ultrafast` now also leave `config.yml`
unchanged and ask you to run the toggle again when their checks see its link
move to another file, or see another writer save it as a new file
(DocksDocks/docks-kit#293). Before, the toggle could write the old target
while omp read the new one, or overwrite the save. When the checks of
`config.yml` find a folder of its path that is not a folder, the toggle
refuses and exits 2: it reports that `config.yml` does not exist, or that it
changed when the folder changes during a check. It exited 1 before.

`docks-kit docs omp-context` now says that sync does not follow a YAML merge
key (`<<`) to find a retired setting.

## 2026-12-01 - docks-kit 0.32.1: fast toggles accept an empty tier section

`docks-kit --fast` and `docks-kit --ultrafast` now accept a deployed
Expand Down
2 changes: 1 addition & 1 deletion SoT/.omp/plugin/extensions/talk.js

Large diffs are not rendered by default.

11 changes: 9 additions & 2 deletions cli/docs/omp-context.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,19 @@ Sync cannot tell the old kit value from the same value that you set again.
It prunes both on every sync. To keep an old kit value, set it in a project
configuration or in a `PI_CONFIG_FILES` file, which sync does not write.

Sync finds a retired key only where `config.yml` sets it directly. It does not
follow a YAML merge key (`<<`): it does not prune a retired value that a merge
supplies, and after it prunes a direct entry, a merge left in `config.yml`
can still supply the value. When the pruned entry holds an anchor that a
merge still uses, the prune can fail to write, and the entry stays.

The kit writes no OpenCode setting. Sync still prunes
`commands.enableOpencodeProject: false` (the row above) and
`commands.enableOpencodeUser: false`, which the kit dropped in the omp 18.19.0
cleanup, while they hold that old kit value, also when you set that value
yourself. omp then uses the value of another settings layer, such as a
project configuration or a `PI_CONFIG_FILES` file, or else its own default.
yourself. After a prune, omp reads the key from its other settings layers,
such as a project configuration, a `PI_CONFIG_FILES` file, or a merge left in
`config.yml`, in their usual order, or else uses its own default.
`commands.enableOpencodeProject: false` turns off the project OpenCode
commands, so to keep that opt-out, set it in a project configuration or a
`PI_CONFIG_FILES` file.
Expand Down
116 changes: 92 additions & 24 deletions cli/src/engine-native/ompFastMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,12 +287,40 @@ const missingConfig = (configPath: string) =>
new ConfigMissing({ message: `${configPath} does not exist; run 'docks-kit sync' first` }),
);

/**
* True when a folder of the path is not a folder (`ENOTDIR`). The Effect file
* system reports that as `BadResource`, with the system error as its cause.
*/
function notADirectory(error: PlatformError): boolean {
const cause = error.reason.cause;
return (
error.reason._tag === "BadResource" &&
typeof cause === "object" &&
cause !== null &&
"code" in cause &&
cause.code === "ENOTDIR"
);
}

/** True when the path names no file now: it is missing, or a folder of it is not a folder. */
function pathMissing(error: PlatformError): boolean {
return error.reason._tag === "NotFound" || notADirectory(error);
}

/** Refuse the toggle when the deployed config.yml is missing. */
export const requireDeployedConfig = Effect.fn("requireDeployedConfig")(function* (
configPath: string,
) {
const fs = yield* FileSystem.FileSystem;
if (!(yield* fs.exists(configPath))) return yield* missingConfig(configPath);
// `exists` is false for a missing path, and fails on a folder that is a file.
const present = yield* fs
.exists(configPath)
.pipe(
Effect.catchTag("PlatformError", (error) =>
notADirectory(error) ? Effect.succeed(false) : Effect.fail(error),
),
);
if (!present) return yield* missingConfig(configPath);
});

/** The file that config.yml names, with its type, identity, and time. */
Expand All @@ -304,6 +332,19 @@ interface ConfigIdentity {
readonly mtimeMs: number | undefined;
}

/** The identity and time of the file that a `stat` or `lstat` result describes. */
function identityFields(info: {
readonly dev: bigint;
readonly ino: Option.Option<bigint>;
readonly mtime: Option.Option<Date>;
}) {
return {
dev: info.dev,
ino: Option.getOrUndefined(info.ino),
mtimeMs: Option.getOrUndefined(info.mtime)?.getTime(),
};
}

/** True when `now` names the same regular file, unchanged in identity and time. */
function sameIdentity(before: ConfigIdentity, now: ConfigIdentity): boolean {
return (
Expand All @@ -322,13 +363,24 @@ function sameBytes(a: Uint8Array, b: Uint8Array): boolean {
/**
* Toggle `tier.openai` to or from `onTier` in the deployed config.yml with an
* atomic 0600 write, checked against omp's reader. The toggle resolves a
* symlinked config.yml once and writes its target, so the link stays. Right
* before the write it resolves the link and reads the file's type, identity,
* and time again, refuses any change before it reads the bytes, reads them,
* and checks the link and the identity once more, so a replace or a retarget
* during that read also refuses. A missing file is `ConfigMissing` at each
* step. A writer that changes the file after that last check and before the
* rename still loses its change: omp shares no lock with the kit.
* symlinked config.yml and writes its target, so the link stays.
*
* Each identity check resolves the link with `realPath`, reads the type,
* identity, and time of its target with `lstat`, reads them again through
* config.yml with `stat`, which follows the link as omp does, and resolves the
* link once more. A retarget or a replace that a check sees gives another
* file, time, or path and refuses with `ConfigChanged`, also in the first
* check, before the toggle parses anything; the second `realPath` also sees a
* move to a hard link of the same file. The toggle runs one check before it
* reads the bytes, one before it reads them again, and one after, and refuses
* each change that these checks detect. A path that names no file (missing, or
* a folder of it that is not a folder) at the first `realPath` of a check is
* `ConfigMissing`; a file that goes away later in the same check is
* `ConfigChanged`.
*
* The last check leaves two windows before the rename: a save of the file
* after its `stat` is overwritten, and after its last `realPath` a retarget of
* the link gets the old target written. omp shares no lock with the kit.
*/
export const toggleDeployedOpenAiTier = Effect.fn("toggleDeployedOpenAiTier")(function* (
configPath: string,
Expand All @@ -340,30 +392,46 @@ export const toggleDeployedOpenAiTier = Effect.fn("toggleDeployedOpenAiTier")(fu
Effect.catchTag(
"PlatformError",
(error): Effect.Effect<never, PlatformError | TierToggleError> =>
error.reason._tag === "NotFound"
? Effect.fail(missingConfig(configPath))
: Effect.fail(error),
pathMissing(error) ? Effect.fail(missingConfig(configPath)) : Effect.fail(error),
),
);
// The file that config.yml names now, with its type, identity, and time.
const identityOf = Effect.gen(function* () {
const target = yield* missingAsRefusal(fs.realPath(configPath));
const info = yield* missingAsRefusal(fs.lstat(target));
return {
target,
type: info.type,
dev: info.dev,
ino: Option.getOrUndefined(info.ino),
mtimeMs: Option.getOrUndefined(info.mtime)?.getTime(),
};
});
const changed = refuse(
new ConfigChanged({
message: `${configPath} changed while the toggle checked it; run the toggle again`,
}),
);
// After the link resolved, a file that goes away is a change.
const goneAsChange = <A>(read: Effect.Effect<A, PlatformError>) =>
read.pipe(
Effect.catchTag(
"PlatformError",
(error): Effect.Effect<never, PlatformError | TierToggleError> =>
pathMissing(error) ? Effect.fail(changed) : Effect.fail(error),
),
);
// The file that config.yml names now, with its type, identity, and time.
// The `stat` through config.yml sees a retarget of the link, or a replace of
// the file, after the `lstat` of the old target; the last `realPath` sees a
// move to another path of the same file.
const identityOf = Effect.gen(function* () {
const target = yield* missingAsRefusal(fs.realPath(configPath));
const info = yield* goneAsChange(fs.lstat(target));
const live = yield* goneAsChange(fs.stat(configPath));
const targetNow = yield* goneAsChange(fs.realPath(configPath));
const identity: ConfigIdentity = { target, type: info.type, ...identityFields(info) };
const now = identityFields(live);
if (
targetNow !== target ||
identity.dev !== now.dev ||
identity.ino !== now.ino ||
identity.mtimeMs !== now.mtimeMs
) {
return yield* changed;
}
return identity;
});

const identity: ConfigIdentity = yield* identityOf;
const identity = yield* identityOf;
const bytes = yield* missingAsRefusal(fs.readFile(identity.target));
// Decoding drops a UTF-8 byte order mark, as omp's reader does; the change
// check compares the raw bytes, so an added or removed mark still counts.
Expand Down
Loading
Loading