Skip to content

Commit f244ecb

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 2b8ea86 commit f244ecb

7 files changed

Lines changed: 23 additions & 39 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/features/magic-context/migrations-v74.test.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ describe("migration v74: detected context-limit provenance", () => {
3636
runMigrations(db);
3737

3838
expect(columnNames(db, "session_meta")).toContain("detected_context_limit_provenance");
39-
expect(LATEST_SUPPORTED_VERSION).toBe(75);
39+
// v74 is a floor, not a ceiling: downstream migrations append above it.
40+
// The lockstep assertion below is the invariant that actually matters.
41+
expect(LATEST_SUPPORTED_VERSION).toBeGreaterThanOrEqual(74);
4042
expect(LATEST_SUPPORTED_VERSION).toBe(LATEST_MIGRATION_VERSION);
4143
} finally {
4244
closeQuietly(db);

‎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
@@ -373,7 +373,7 @@ describe("buildSidebarSnapshot — Rust module status merge", () => {
373373
});
374374

375375
describe("compaction-off sidebar RPC data", () => {
376-
test("reports the resolved mode and raw native usage independently of threshold fill", () => {
376+
test("reports the resolved mode and raw native usage independently of threshold fill", async () => {
377377
const db = createTestDb();
378378
try {
379379
const sessionId = "ses-native-sidebar";
@@ -415,7 +415,7 @@ describe("compaction-off sidebar RPC data", () => {
415415
},
416416
false,
417417
);
418-
const detail = buildStatusDetail(
418+
const detail = await buildStatusDetail(
419419
db,
420420
sessionId,
421421
process.cwd(),
@@ -442,7 +442,11 @@ describe("compaction-off sidebar RPC data", () => {
442442
);
443443
expect(snapshot.archivedCompartmentCount).toBe(1);
444444

445-
const enabledDetail = buildStatusDetail(db, "ses-native-sidebar-on", process.cwd());
445+
const enabledDetail = await buildStatusDetail(
446+
db,
447+
"ses-native-sidebar-on",
448+
process.cwd(),
449+
);
446450
expect(enabledDetail.compaction_enabled).toBe(true);
447451
} finally {
448452
closeQuietly(db);
@@ -451,7 +455,7 @@ describe("compaction-off sidebar RPC data", () => {
451455
});
452456

453457
describe("buildStatusDetail — history token reuse (council audit bg_51106601 #1)", () => {
454-
test("sets historyBlockTokens from compartmentTokens only (facts retired in v2)", () => {
458+
test("sets historyBlockTokens from compartmentTokens only (facts retired in v2)", async () => {
455459
const db = createTestDb();
456460
try {
457461
const sessionId = "ses-status-history-tokens";
@@ -492,7 +496,7 @@ describe("buildStatusDetail — history token reuse (council audit bg_51106601 #
492496
],
493497
);
494498

495-
const detail = buildStatusDetail(db, sessionId, directory);
499+
const detail = await buildStatusDetail(db, sessionId, directory);
496500

497501
// v2: facts are retired as a render source (promoted to memories), so
498502
// factTokens is 0 and the history block is compartments only — facts
@@ -507,10 +511,10 @@ describe("buildStatusDetail — history token reuse (council audit bg_51106601 #
507511
});
508512

509513
describe("buildStatusDetail — storage versions probe", () => {
510-
test("reports the live context.db schema version and the plugin fence", () => {
514+
test("reports the live context.db schema version and the plugin fence", async () => {
511515
const db = createTestDb();
512516
try {
513-
const detail = buildStatusDetail(db, "ses-storage-versions", process.cwd());
517+
const detail = await buildStatusDetail(db, "ses-storage-versions", process.cwd());
514518

515519
// The probe must carry the live MAX(schema_migrations) value, not a
516520
// hardcoded one, plus this build's fence. A fully migrated test DB sits
@@ -527,14 +531,14 @@ describe("buildStatusDetail — storage versions probe", () => {
527531
}
528532
});
529533

530-
test("follows an older live DB version while the fence stays put", () => {
534+
test("follows an older live DB version while the fence stays put", async () => {
531535
const db = createTestDb();
532536
try {
533537
// Simulate a DB migrated by an older plugin: drop the recorded versions
534538
// above 50. The probe must follow the live value down.
535539
db.prepare("DELETE FROM schema_migrations WHERE version > ?").run(50);
536540

537-
const detail = buildStatusDetail(db, "ses-storage-versions-old", process.cwd());
541+
const detail = await buildStatusDetail(db, "ses-storage-versions-old", process.cwd());
538542

539543
expect(detail.storage_versions.context_db_schema_version).toBe(50);
540544
expect(detail.storage_versions.plugin_supported_version).toBe(LATEST_SUPPORTED_VERSION);
@@ -560,21 +564,6 @@ describe("buildStatusDetail — external memory section", () => {
560564
}
561565
});
562566

563-
test("provider on, fake backend exposes fetchFailedRetainCount → detail surfaces the count", async () => {
564-
const db = createTestDb();
565-
try {
566-
const sessionId = "ses-status-ext-on";
567-
db.prepare(
568-
"INSERT INTO session_meta (session_id, last_input_tokens, last_context_percentage) VALUES (?, 0, 0)",
569-
).run(sessionId);
570-
_setTestExternalBackendFactory(() => ({
571-
backendId: "fake:ext-status",
572-
initialize: async () => true,
573-
retain: async () => 0,
574-
dispose: async () => {},
575-
_getCircuitState: () => "closed",
576-
fetchFailedRetainCount: async () => 3,
577-
}));
578567
test("provider on, fake backend exposes fetchFailedRetainCount → detail surfaces the count", async () => {
579568
const db = createTestDb();
580569
try {
@@ -662,7 +651,7 @@ describe("buildStatusDetail — external memory section", () => {
662651
});
663652

664653
describe("buildStatusDetail — cacheNeverExpires with 'never' TTL", () => {
665-
test("sets cacheNeverExpires: true when cache_ttl is 'never'", () => {
654+
test("sets cacheNeverExpires: true when cache_ttl is 'never'", async () => {
666655
const db = createTestDb();
667656
try {
668657
const sessionId = "ses-status-never";
@@ -677,7 +666,7 @@ describe("buildStatusDetail — cacheNeverExpires with 'never' TTL", () => {
677666
"UPDATE session_meta SET cache_ttl = ?, last_response_time = ? WHERE session_id = ?",
678667
).run("never", Date.now() - 60_000, sessionId);
679668

680-
const detail = buildStatusDetail(db, sessionId, directory);
669+
const detail = await buildStatusDetail(db, sessionId, directory);
681670

682671
expect(detail.cacheNeverExpires).toBe(true);
683672
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)