mirror of
https://github.com/NeuralNomadsAI/CodeNomad.git
synced 2026-11-17 05:49:28 +00:00
Some checks are pending
Download Caches / seed (windows-2025) (push) Waiting to run
Download Caches / seed (ubuntu-24.04) (push) Waiting to run
Download Caches / seed (macos-15-intel) (push) Waiting to run
Download Caches / seed (macos-26) (push) Waiting to run
Publish help / build (push) Waiting to run
Publish help / deploy (push) Blocked by required conditions
## Problem OpenCode 2.2.7 intentionally removes `Plugin.awaitActivation` from `rpc.call`. On unchanged CodeNomad, native cold history/pruning returns `rpc.unavailable`, `/goal` incorrectly reports unsupported, and a headless integration host can fail its first advertisement. The same native checks pass on 2.2.6. ## Adaptation - Adopt the existing bounded, connection-owned pruning readiness foundation and its eight fixed broker families. Preparation targets the already-authorized exact native Location and requires a fresh lease/registration-scope acknowledgement, rather than treating a backend-wide startup marker as universal readiness. - Preserve session/workspace/connection, deletion/ABA, cancellation and extension-grant fences around waits and the single functional dispatch. No pruning mutation is probed, replayed or retried; generic RPC proxy access stays closed. - Share the native catalogue activation wait with `/goal`. Only method absence after activation proves unsupported; transient registration loss remains unavailable. - Preserve current Memory provisioning and ownership options while adopting the foundation. Abort the startup marker observer on close so cleanup does not wait on an unreferenced polling timer. - Correct the reference host discovery client, vendored byte-for-byte from [opencode-integrations #17](https://github.com/NeuralNomadsAI/opencode-integrations/pull/17): payload-free status preparation may repeat while registration is unavailable; advertise/withdraw are sent once, with no directory fallback after dispatch. The external PR publishes source only; installed hosts need the corresponding host update. - Keep minimum, recommendation and authoring dependency pins unchanged. Add cold fixed-broker native coverage to minimum/latest and Windows/Linux/macOS native lanes. ## Validation - **199** affected broker/lifecycle/readiness/goal tests pass; the final cancellation cleanup additionally passes **40** focused tests. - **30** real-browser Images/panel-extension journeys pass. - Official isolated **2.2.3, 2.2.6 and 2.2.7**, driven by pinned **Node 24.22.2**: full pruning/history/Images/replay fixture, production goal route, cold fixed preview/prune/history/Images brokers and headless integration discovery/advertise/attach/withdraw all pass. The cold broker check asserts one prune dispatch and retained conclusion bytes, plus a new backend lease. - **2.2.7 split storage** passes full pruning, native proxy/UI contracts, assets/gallery, mixed split+inline content after flag disable/restart, receipts, active-claim refusal and retained model payload. - Server/UI typechecks, complete server/UI/native-plugin build, **27** package/vendor parity tests, **31** help tests, native driver test, YAML and whitespace checks pass. - External Python reference tests **9/9** and kit test typechecking pass; Blender's vendored copy equals the reference. Only private synthetic daemons, local providers and owned fixture state were used. No shared service restart, real credentials/database/configuration change or stable publication. Earlier fixture attempts exposed an import-ID conflict, Windows path normalization in the fixture ownership stub, and teardown ordering; those harness defects were corrected without relaxing assertions. One final rerun was needed after a simultaneous build cleaned its dist input; the post-build rerun passes. The native tests reuse source from the independently prepared readiness foundation and broker work, adapted onto current dev without taking the unrelated multi-backend branch. Public labels, controls and documented steps stay unchanged; the fix restores their documented behavior. Large existing touched files: `packages/server/src/index.ts` (~758 lines), `packages/server/src/server/http-server.ts` (~2574), `packages/server/src/workspaces/manager.ts` (~1230), and `packages/server/src/server/routes/pending-requests.test.ts` (~1025). Integrated CI and platform builds remain the final gate.
88 lines
6 KiB
JavaScript
88 lines
6 KiB
JavaScript
// Real fixed brokers, shipped plugin and synthetic private daemon/storage only.
|
|
import assert from "node:assert/strict"
|
|
import { mkdir, readFile } from "node:fs/promises"
|
|
import path from "node:path"
|
|
import Fastify from "fastify"
|
|
import { withProductRuntime } from "./native-product-fixture.mjs"
|
|
import { DesktopPluginLifecycle } from "../packages/server/src/opencode/desktop-plugin-lifecycle.ts"
|
|
import { registerSessionPruningRoutes } from "../packages/server/src/server/routes/session-pruning.ts"
|
|
import { registerImagesConversationRoute } from "../packages/server/src/server/routes/images-conversation.ts"
|
|
import { WorktreeDeletionFence } from "../packages/server/src/workspaces/worktree-session-evacuation.ts"
|
|
|
|
const bundle = await readFile(new URL("../packages/server/dist/plugins/session-pruning/plugin.mjs", import.meta.url))
|
|
let lifecycle = new DesktopPluginLifecycle("session-pruning", async () => bundle), paths
|
|
try {
|
|
await withProductRuntime(process.argv[2], async ({ root, configDirectory }) => {
|
|
paths = { config: configDirectory, data: path.join(root, "codenomad") }
|
|
await lifecycle.start(paths)
|
|
return { experimental: { media_blob: true, part_rows: process.argv.includes("--part-rows") } }
|
|
}, async ({ root, client, connection, requests }) => {
|
|
const claim = await lifecycle.prepare(paths, connection.assertCurrent, connection)
|
|
claim.commit(); await claim.release()
|
|
const base = { directory: root }, workspace = { id: "fixture", path: root }
|
|
const admitted = new Set([root]), calls = []
|
|
const rpc = client.rpc.call
|
|
client.rpc.call = async (...args) => { calls.push(args[0]); return rpc(...args) }
|
|
const manager = {
|
|
get: id => id === "fixture" ? workspace : undefined,
|
|
getServiceLocation: id => id === "fixture" ? base : undefined,
|
|
getSharedServiceClient: async () => client, getSharedServiceConnection: async () => connection,
|
|
ownsLocation: async (id, location) => id === "fixture" && admitted.has(path.resolve(location.directory)),
|
|
getWorktreeIdentityForPath: async (_id, directory) => admitted.has(path.resolve(directory)) ? path.resolve(directory) : undefined,
|
|
getWorktrees: async () => [], getServiceWslDistro: () => undefined, getHostPathForServicePath: async (_id, file) => file,
|
|
desktopPluginsReady: target => lifecycle.ready(target),
|
|
}
|
|
const app = Fastify(), fence = new WorktreeDeletionFence()
|
|
registerSessionPruningRoutes(app, { workspaceManager: manager, worktreeDeletionFence: fence })
|
|
registerImagesConversationRoute(app, { workspaceManager: manager, worktreeDeletionFence: fence })
|
|
const send = async (suffix, payload) => {
|
|
const response = await app.inject({ method: "POST", url: `/api/workspaces/fixture/${suffix}`, payload })
|
|
assert.equal(response.statusCode, 200, response.body)
|
|
return response.json()
|
|
}
|
|
try {
|
|
const seed = await client.session.create({ location: base })
|
|
await client.session.prompt({ sessionID: seed.id, text: "Return the synthetic fixture answer." })
|
|
await client.session.wait({ sessionID: seed.id }, { signal: AbortSignal.timeout(20000) })
|
|
const exported = await client.session.export({ sessionID: seed.id })
|
|
await client.session.remove({ sessionID: seed.id })
|
|
const template = exported.messages.find(message => message.type === "assistant")
|
|
assert(template)
|
|
const cold = path.join(root, "cold-project")
|
|
await mkdir(cold); admitted.add(cold)
|
|
const session = await client.session.import({ ...exported, location: { directory: cold }, messages: [{
|
|
...template, id: "msg_cold_pruning_fixture", content: [
|
|
{ type: "reasoning", text: "REMOVE_ONLY_THIS", time: { created: 1, completed: 2 } },
|
|
{ type: "text", text: "Keep this conclusion" },
|
|
],
|
|
}] })
|
|
assert.equal(session.location.directory, cold)
|
|
const input = { sessionID: session.id, messageID: "msg_cold_pruning_fixture" }
|
|
const preview = await send("session-pruning/preview", input)
|
|
assert.equal(preview.status, "preview", JSON.stringify(preview))
|
|
assert.equal(calls.filter(call => call.method === "preview").length, 1)
|
|
const result = await send("session-pruning/prune", { ...input, revision: preview.revision, indexes: [0] })
|
|
assert.equal(result.status, "pruned", JSON.stringify(result))
|
|
assert.equal(calls.filter(call => call.method === "prune").length, 1, "A readiness wait never replays the write")
|
|
const stored = await client.session.message.get(input)
|
|
assert.deepEqual(stored.content, [{ type: "text", text: "Keep this conclusion" }])
|
|
const history = await send("session-history/query", { sessionID: session.id, purpose: "search", query: "conclusion", includeTechnical: false })
|
|
assert.equal(history.status, "page", JSON.stringify(history))
|
|
assert.equal(history.hits.length, 1, JSON.stringify(history))
|
|
const imageCold = path.join(root, "cold-images")
|
|
await mkdir(imageCold); admitted.add(imageCold)
|
|
assert.deepEqual(await send("images-conversation", { directory: imageCold, mode: "lookup" }), { status: "absent" })
|
|
// A new backend lease gets a fresh proof even when the native catalogue
|
|
// retains an active plugin entry and a preceding scope's files existed.
|
|
await lifecycle.stop()
|
|
lifecycle = new DesktopPluginLifecycle("session-pruning", async () => bundle)
|
|
const renewed = await lifecycle.prepare(paths, connection.assertCurrent, connection)
|
|
renewed.commit(); await renewed.release()
|
|
const again = await send("session-pruning/preview", input)
|
|
assert.equal(again.status, "preview", JSON.stringify(again))
|
|
assert.equal(calls.filter(call => call.method === "prune").length, 1)
|
|
assert.equal(requests.length > 0, true)
|
|
console.log(`PASS ${(await client.server.info()).version}: fixed cold-Location preview/prune/history/Images, fresh backend lease, one mutation dispatch and retained conclusion`)
|
|
} finally { await app.close(); await lifecycle.stop() }
|
|
})
|
|
} finally { await lifecycle.stop() }
|