mirror of
https://github.com/NeuralNomadsAI/CodeNomad.git
synced 2026-11-17 05:49:28 +00:00
## Problem On OpenCode 2.2.6, scheduled Mission wakes no longer start their passage. Upstream anomalyco/opencode#61018 removed the `metadata` copy from the LLM messages plugins see in session context hooks. CodeNomad classified wakes from `metadata.schedule` on that projection, so a 2.2.6 wake looked inconsistent: the drain failed with `schedule-carrier-wake` and the passage was never admitted. ## Fix The context projection still carries each native message `id`, and the stored native message still carries `metadata.schedule`. Wake classification now resolves user-role context IDs through the existing bounded native message reader and classifies the authoritative stored records by type and status, ignoring projected metadata. Resolved records are reused for the candidate proof, so a wake row is read once. Classification and recovery reads have separate read and byte budgets, and exceeding a bound surfaces a coverage error instead of dropping the wake. Placement, mapping, deterministic identities, source-byte fences, RPC checks and CAS/high-water behavior are unchanged. The minimum stays 2.2.3. The canonical authority and bounds contract is in `dev-docs/MISSIONS_NATIVE_SCHEDULE_TRANSPORT.md`. Native facts, checked on isolated CLIs: | CLI | Context message ID | Context `metadata.schedule` | Stored `metadata.schedule` | |---|---|---|---| | 2.2.3 | kept | present | present | | 2.2.5 | kept | present | present | | 2.2.6 | kept | absent | present | ## Tests - Unit coverage for metadata-free and conflicting projections, notices, compactions, invalid native records, a context of 128 wake entries, eight recovery reads and independent byte budgets. - `tests-runtime-contracts` gains a native context/storage check and the cold scheduled-Mission product check on minimum and latest, and uploads the fixtures' receipts and failure diagnostics when a step fails. The schedule fixtures read the actual CLI version instead of a hardcoded 2.2.3, poll for the PID-matching ready registration, and set the `at` time after activation, just before Play. The cold wait allows 120 s (leader-lease recovery exceeds 45 s on dev too). - On 2.2.6, an `origin/dev` snapshot fails the cold product check (`schedule-carrier-wake`); this branch passes `at` and `in` with the exact CI command (product step: 102 s on 2.2.3, 208 s on 2.2.6). - Foundation fixtures pass on 2.2.3 and 2.2.6 (3 CAS applications, cold recovery, no provider requests); an earlier revision also passed them on 2.2.5. Server Missions suites: 1,406 passed. Server/UI typechecks and native bundle builds pass. The full runtime-contract sequence passes locally on 2.2.3 (15 min) and 2.2.6 (23 min 26 s, against the job's 25-minute timeout). ## Known limitation `experimental.part_rows` (off by default) stores assistant parts in `session_part`, which CodeNomad's history, search, outline, gallery and pruning readers do not read. Documented in `dev-docs/SESSION_HISTORY_QUERIES.md`, not addressed here.
53 lines
3.2 KiB
JavaScript
53 lines
3.2 KiB
JavaScript
import assert from "node:assert/strict"
|
|
import { readFile, mkdir, writeFile } from "node:fs/promises"
|
|
import path from "node:path"
|
|
import { DatabaseSync } from "node:sqlite"
|
|
import { setTimeout as delay } from "node:timers/promises"
|
|
import { withProductRuntime } from "./native-product-fixture.mjs"
|
|
import { fixtureCliVersion } from "./native-fixture-cli-version.mjs"
|
|
|
|
const cli = process.argv[2], version = await fixtureCliVersion(cli)
|
|
await withProductRuntime(cli, async ({ root }) => {
|
|
const plugin = path.join(root, "observer")
|
|
await mkdir(plugin)
|
|
await writeFile(path.join(plugin, "package.json"), JSON.stringify({ name: "schedule-context-observer", type: "module", exports: "./index.mjs" }))
|
|
await writeFile(path.join(plugin, "index.mjs"), `
|
|
import { Plugin } from "@opencode/plugin/effect"
|
|
import { Effect } from "effect"
|
|
import { appendFileSync } from "node:fs"
|
|
export default Plugin.define({ id: "fixture.schedule-context", effect: ctx => Effect.gen(function* () {
|
|
yield* ctx.session.hook("context", event => Effect.sync(() => appendFileSync(${JSON.stringify(path.join(root, "context.jsonl"))},
|
|
JSON.stringify({ sessionID: event.sessionID, messages: event.messages.map(({ id, role, metadata }) => ({ id, role, metadata })) }) + "\\n")))
|
|
}) })
|
|
`)
|
|
return { experimental: { schedules: true }, plugins: [plugin] }
|
|
}, async ({ client, root }) => {
|
|
assert.equal((await client.server.info()).version, version)
|
|
const session = await client.session.create({ title: "Schedule context contract", location: { directory: root } })
|
|
const schedule = await client.experimental.schedule.create({ sessionID: session.id,
|
|
when: { at: new Date(Date.now() + 2000).toISOString() }, prompt: "FIXTURE_SCHEDULE_WAKE" })
|
|
const id = `msg_${schedule.id}_1`
|
|
let context
|
|
for (const end = Date.now() + 20000; Date.now() < end;) {
|
|
const lines = await readFile(path.join(root, "context.jsonl"), "utf8").catch(() => "")
|
|
context = lines.trim().split("\n").filter(Boolean).map(JSON.parse).find(event => event.messages.some(message => message.id === id))
|
|
if (context) break
|
|
await delay(50)
|
|
}
|
|
assert(context, "The native scheduled input retains its ID in context")
|
|
const db = new DatabaseSync(path.join(root, "fixture.db"), { readOnly: true })
|
|
let stored
|
|
try { stored = db.prepare("SELECT id,type,data FROM session_message WHERE id=? AND session_id=?").get(id, session.id) } finally { db.close() }
|
|
assert.equal(stored.type, "user")
|
|
const metadata = JSON.parse(stored.data).metadata.schedule
|
|
assert.equal(metadata.id, schedule.id); assert.equal(metadata.run, 1)
|
|
assert(Number.isSafeInteger(metadata.dueAt) && metadata.dueAt >= 0)
|
|
assert.equal(typeof metadata.late, "boolean")
|
|
assert.equal(JSON.parse(stored.data).text, "FIXTURE_SCHEDULE_WAKE")
|
|
const projected = context.messages.find(message => message.id === id)
|
|
assert.equal(projected.role, "user")
|
|
if (projected.metadata?.schedule) assert.deepEqual(projected.metadata.schedule, metadata)
|
|
const result = { version, context: projected, stored: { id: stored.id, type: stored.type, schedule: metadata } }
|
|
await writeFile(path.join(root, "schedule-context-proof.json"), JSON.stringify(result, null, 2))
|
|
console.log(JSON.stringify(result))
|
|
}, { service: true })
|