Skip to content

Commit 9ef2022

Browse files
author
Tehan
committed
chore(external-memory): rebase onto upstream v0.34.0 (external-recall v75)
Upstream v0.34.0 claimed v73 (todowrite permission verdict) and v74 (detected context-limit provenance), so external-recall renumbers v73 -> v75 and LATEST_SUPPORTED_VERSION follows. Its test file moves to migrations-v75.test.ts; upstream's own migrations-v73.test.ts is taken as-is. Merged against four upstream changes: - The mural graduation (cortexkit#278) removed ExperimentalConfig, so the schema conflict resolves to upstream's shape with the memory.external block appended. project-security keeps all three strips: mural.model, experimental.mural.model (legacy spelling), and memory.external. - executeStatus grew a `dreamer` parameter and stayed sync upstream; ours made it async for the external-memory section. Both kept — dreamer first, and the signature is Promise<string>. - rpc-handlers gained the dream-task backlog imports alongside ours. - promotion.test.ts: upstream's mock.module fix (7eb943e, our issue cortexkit#279) removed the ./embedding stub this file used to graft onto, so only the external-memory imports are added to upstream's provider-factory version. Fallout from executeStatus/buildStatusDetail being async: three test call sites needed `await` plus `async` on the enclosing test. A missing await does not fail typecheck — the assertions read undefined off a pending promise — so these surface only as confusing runtime failures. The migrations-v74 fence assertion is relaxed from equality to a floor, matching v72: asserting LATEST_SUPPORTED_VERSION is exactly 74 cannot hold once anything is appended above it. The lockstep assertion against LATEST_MIGRATION_VERSION is kept. Lint: dropped three imports upstream stopped using (estimateTokens in transform.ts, saveEmbedding in ctx-memory/tools.ts, prepareCompartmentInjection in inject-compartments-pi.ts) and took the optional-chain rewrite in both ctx-memory verify guards.
1 parent 7b9f239 commit 9ef2022

6 files changed

Lines changed: 20 additions & 38 deletions

File tree

‎packages/pi-plugin/src/inject-compartments-pi.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,6 @@ import {
8282
DEFAULT_MEMORY_BUDGET_TOKENS,
8383
DEFAULT_USER_PROFILE_BUDGET_TOKENS,
8484
type MemoryRenderOptions,
85-
type PreparedCompartmentInjection,
86-
prepareCompartmentInjection,
8785
renderExternalMemoryBlock,
8886
renderExternalMemoryDelta,
8987
renderMemoryBlockV2,

‎packages/pi-plugin/src/tools/ctx-memory.ts‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -997,11 +997,7 @@ export function createCtxMemoryTool(
997997
// backend (refreshes Hindsight's recency with zero duplicate risk).
998998
// Mirrors OpenCode's verify action.
999999
const verifyIds = params.ids;
1000-
if (
1001-
!verifyIds ||
1002-
verifyIds.length !== 1 ||
1003-
!verifyIds.every(Number.isInteger)
1004-
) {
1000+
if (verifyIds?.length !== 1 || !verifyIds.every(Number.isInteger)) {
10051001
return err(
10061002
"Error: 'ids' must contain exactly one integer memory ID when action is 'verify'.",
10071003
);

‎packages/plugin/src/hooks/magic-context/execute-status.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,15 @@ describe("executeStatus", () => {
7070
db.close();
7171
});
7272

73-
test("renders 'never expires' for cacheTtl 'never'", () => {
73+
test("renders 'never expires' for cacheTtl 'never'", async () => {
7474
const db = new Database(":memory:");
7575
initializeDatabase(db);
7676
getOrCreateSessionMeta(db, SESSION_ID);
7777
db.prepare("UPDATE session_meta SET cache_ttl = 'never' WHERE session_id = ?").run(
7878
SESSION_ID,
7979
);
8080

81-
const status = executeStatus(db, SESSION_ID, 20);
81+
const status = await executeStatus(db, SESSION_ID, 20);
8282

8383
expect(status).toContain("- Configured: never");
8484
expect(status).toContain("- Remaining: never expires (always-warm lane)");

‎packages/plugin/src/hooks/magic-context/transform.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ import {
110110
} from "./protected-tail-boundary";
111111
import { readRawSessionMessages } from "./read-session-chunk";
112112
import { findLastAssistantModelFromOpenCodeDb, isMidTurn } from "./read-session-db";
113-
import { estimateTokens, extractTexts, hasMeaningfulUserText } from "./read-session-formatting";
113+
import { extractTexts, hasMeaningfulUserText } from "./read-session-formatting";
114114
import { extractInMemoryMessageViews } from "./read-session-raw";
115115
import { createRustModeTransform, type RustModeModuleClient } from "./rust-mode-transform";
116116
import { sendIgnoredMessage } from "./send-session-notification";

‎packages/plugin/src/plugin/rpc-handlers.test.ts‎

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ describe("buildSidebarSnapshot — Rust module status merge", () => {
378378
});
379379

380380
describe("compaction-off sidebar RPC data", () => {
381-
test("reports the resolved mode and raw native usage independently of threshold fill", () => {
381+
test("reports the resolved mode and raw native usage independently of threshold fill", async () => {
382382
const db = createTestDb();
383383
try {
384384
const sessionId = "ses-native-sidebar";
@@ -420,7 +420,7 @@ describe("compaction-off sidebar RPC data", () => {
420420
},
421421
false,
422422
);
423-
const detail = buildStatusDetail(
423+
const detail = await buildStatusDetail(
424424
db,
425425
sessionId,
426426
process.cwd(),
@@ -447,7 +447,11 @@ describe("compaction-off sidebar RPC data", () => {
447447
);
448448
expect(snapshot.archivedCompartmentCount).toBe(1);
449449

450-
const enabledDetail = buildStatusDetail(db, "ses-native-sidebar-on", process.cwd());
450+
const enabledDetail = await buildStatusDetail(
451+
db,
452+
"ses-native-sidebar-on",
453+
process.cwd(),
454+
);
451455
expect(enabledDetail.compaction_enabled).toBe(true);
452456
} finally {
453457
closeQuietly(db);
@@ -456,7 +460,7 @@ describe("compaction-off sidebar RPC data", () => {
456460
});
457461

458462
describe("buildStatusDetail — history token reuse (council audit bg_51106601 #1)", () => {
459-
test("sets historyBlockTokens from compartmentTokens only (facts retired in v2)", () => {
463+
test("sets historyBlockTokens from compartmentTokens only (facts retired in v2)", async () => {
460464
const db = createTestDb();
461465
try {
462466
const sessionId = "ses-status-history-tokens";
@@ -497,7 +501,7 @@ describe("buildStatusDetail — history token reuse (council audit bg_51106601 #
497501
],
498502
);
499503

500-
const detail = buildStatusDetail(db, sessionId, directory);
504+
const detail = await buildStatusDetail(db, sessionId, directory);
501505

502506
// v2: facts are retired as a render source (promoted to memories), so
503507
// factTokens is 0 and the history block is compartments only — facts
@@ -512,10 +516,10 @@ describe("buildStatusDetail — history token reuse (council audit bg_51106601 #
512516
});
513517

514518
describe("buildStatusDetail — storage versions probe", () => {
515-
test("reports the live context.db schema version and the plugin fence", () => {
519+
test("reports the live context.db schema version and the plugin fence", async () => {
516520
const db = createTestDb();
517521
try {
518-
const detail = buildStatusDetail(db, "ses-storage-versions", process.cwd());
522+
const detail = await buildStatusDetail(db, "ses-storage-versions", process.cwd());
519523

520524
// The probe must carry the live MAX(schema_migrations) value, not a
521525
// hardcoded one, plus this build's fence. A fully migrated test DB sits
@@ -532,14 +536,14 @@ describe("buildStatusDetail — storage versions probe", () => {
532536
}
533537
});
534538

535-
test("follows an older live DB version while the fence stays put", () => {
539+
test("follows an older live DB version while the fence stays put", async () => {
536540
const db = createTestDb();
537541
try {
538542
// Simulate a DB migrated by an older plugin: drop the recorded versions
539543
// above 50. The probe must follow the live value down.
540544
db.prepare("DELETE FROM schema_migrations WHERE version > ?").run(50);
541545

542-
const detail = buildStatusDetail(db, "ses-storage-versions-old", process.cwd());
546+
const detail = await buildStatusDetail(db, "ses-storage-versions-old", process.cwd());
543547

544548
expect(detail.storage_versions.context_db_schema_version).toBe(50);
545549
expect(detail.storage_versions.plugin_supported_version).toBe(LATEST_SUPPORTED_VERSION);
@@ -565,21 +569,6 @@ describe("buildStatusDetail — external memory section", () => {
565569
}
566570
});
567571

568-
test("provider on, fake backend exposes fetchFailedRetainCount → detail surfaces the count", async () => {
569-
const db = createTestDb();
570-
try {
571-
const sessionId = "ses-status-ext-on";
572-
db.prepare(
573-
"INSERT INTO session_meta (session_id, last_input_tokens, last_context_percentage) VALUES (?, 0, 0)",
574-
).run(sessionId);
575-
_setTestExternalBackendFactory(() => ({
576-
backendId: "fake:ext-status",
577-
initialize: async () => true,
578-
retain: async () => 0,
579-
dispose: async () => {},
580-
_getCircuitState: () => "closed",
581-
fetchFailedRetainCount: async () => 3,
582-
}));
583572
test("provider on, fake backend exposes fetchFailedRetainCount → detail surfaces the count", async () => {
584573
const db = createTestDb();
585574
try {
@@ -667,7 +656,7 @@ describe("buildStatusDetail — external memory section", () => {
667656
});
668657

669658
describe("buildStatusDetail — cacheNeverExpires with 'never' TTL", () => {
670-
test("sets cacheNeverExpires: true when cache_ttl is 'never'", () => {
659+
test("sets cacheNeverExpires: true when cache_ttl is 'never'", async () => {
671660
const db = createTestDb();
672661
try {
673662
const sessionId = "ses-status-never";
@@ -682,7 +671,7 @@ describe("buildStatusDetail — cacheNeverExpires with 'never' TTL", () => {
682671
"UPDATE session_meta SET cache_ttl = ?, last_response_time = ? WHERE session_id = ?",
683672
).run("never", Date.now() - 60_000, sessionId);
684673

685-
const detail = buildStatusDetail(db, sessionId, directory);
674+
const detail = await buildStatusDetail(db, sessionId, directory);
686675

687676
expect(detail.cacheNeverExpires).toBe(true);
688677
expect(detail.cacheExpired).toBe(false);

‎packages/plugin/src/tools/ctx-memory/tools.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import {
1717
type MemoryCategory,
1818
mergeMemoryStats,
1919
removeFromExternalBackend,
20-
saveEmbedding,
2120
saveEmbeddingIfHashMatches,
2221
supersededMemory,
2322
teeToExternalBackend,
@@ -1063,7 +1062,7 @@ function createCtxMemoryTool(deps: CtxMemoryToolDeps): ToolDefinition {
10631062

10641063
if (args.action === "verify") {
10651064
const verifyIds = args.ids;
1066-
if (!verifyIds || verifyIds.length !== 1 || !verifyIds.every(Number.isInteger)) {
1065+
if (verifyIds?.length !== 1 || !verifyIds.every(Number.isInteger)) {
10671066
return "Error: 'ids' must contain exactly one integer memory ID when action is 'verify'.";
10681067
}
10691068
const verifyId = verifyIds[0];

0 commit comments

Comments
 (0)