Skip to content

Commit aa2b04e

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 61a2153 commit aa2b04e

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(74);
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
@@ -109,7 +109,7 @@ import {
109109
} from "./protected-tail-boundary";
110110
import { readRawSessionMessages } from "./read-session-chunk";
111111
import { findLastAssistantModelFromOpenCodeDb, isMidTurn } from "./read-session-db";
112-
import { estimateTokens, extractTexts, hasMeaningfulUserText } from "./read-session-formatting";
112+
import { extractTexts, hasMeaningfulUserText } from "./read-session-formatting";
113113
import { extractInMemoryMessageViews } from "./read-session-raw";
114114
import { createRustModeTransform, type RustModeModuleClient } from "./rust-mode-transform";
115115
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
@@ -346,7 +346,7 @@ describe("buildSidebarSnapshot — Rust module status merge", () => {
346346
});
347347

348348
describe("compaction-off sidebar RPC data", () => {
349-
test("reports the resolved mode and raw native usage independently of threshold fill", () => {
349+
test("reports the resolved mode and raw native usage independently of threshold fill", async () => {
350350
const db = createTestDb();
351351
try {
352352
const sessionId = "ses-native-sidebar";
@@ -388,7 +388,7 @@ describe("compaction-off sidebar RPC data", () => {
388388
},
389389
false,
390390
);
391-
const detail = buildStatusDetail(
391+
const detail = await buildStatusDetail(
392392
db,
393393
sessionId,
394394
process.cwd(),
@@ -415,7 +415,11 @@ describe("compaction-off sidebar RPC data", () => {
415415
);
416416
expect(snapshot.archivedCompartmentCount).toBe(1);
417417

418-
const enabledDetail = buildStatusDetail(db, "ses-native-sidebar-on", process.cwd());
418+
const enabledDetail = await buildStatusDetail(
419+
db,
420+
"ses-native-sidebar-on",
421+
process.cwd(),
422+
);
419423
expect(enabledDetail.compaction_enabled).toBe(true);
420424
} finally {
421425
closeQuietly(db);
@@ -424,7 +428,7 @@ describe("compaction-off sidebar RPC data", () => {
424428
});
425429

426430
describe("buildStatusDetail — history token reuse (council audit bg_51106601 #1)", () => {
427-
test("sets historyBlockTokens from compartmentTokens only (facts retired in v2)", () => {
431+
test("sets historyBlockTokens from compartmentTokens only (facts retired in v2)", async () => {
428432
const db = createTestDb();
429433
try {
430434
const sessionId = "ses-status-history-tokens";
@@ -465,7 +469,7 @@ describe("buildStatusDetail — history token reuse (council audit bg_51106601 #
465469
],
466470
);
467471

468-
const detail = buildStatusDetail(db, sessionId, directory);
472+
const detail = await buildStatusDetail(db, sessionId, directory);
469473

470474
// v2: facts are retired as a render source (promoted to memories), so
471475
// factTokens is 0 and the history block is compartments only — facts
@@ -480,10 +484,10 @@ describe("buildStatusDetail — history token reuse (council audit bg_51106601 #
480484
});
481485

482486
describe("buildStatusDetail — storage versions probe", () => {
483-
test("reports the live context.db schema version and the plugin fence", () => {
487+
test("reports the live context.db schema version and the plugin fence", async () => {
484488
const db = createTestDb();
485489
try {
486-
const detail = buildStatusDetail(db, "ses-storage-versions", process.cwd());
490+
const detail = await buildStatusDetail(db, "ses-storage-versions", process.cwd());
487491

488492
// The probe must carry the live MAX(schema_migrations) value, not a
489493
// hardcoded one, plus this build's fence. A fully migrated test DB sits
@@ -500,14 +504,14 @@ describe("buildStatusDetail — storage versions probe", () => {
500504
}
501505
});
502506

503-
test("follows an older live DB version while the fence stays put", () => {
507+
test("follows an older live DB version while the fence stays put", async () => {
504508
const db = createTestDb();
505509
try {
506510
// Simulate a DB migrated by an older plugin: drop the recorded versions
507511
// above 50. The probe must follow the live value down.
508512
db.prepare("DELETE FROM schema_migrations WHERE version > ?").run(50);
509513

510-
const detail = buildStatusDetail(db, "ses-storage-versions-old", process.cwd());
514+
const detail = await buildStatusDetail(db, "ses-storage-versions-old", process.cwd());
511515

512516
expect(detail.storage_versions.context_db_schema_version).toBe(50);
513517
expect(detail.storage_versions.plugin_supported_version).toBe(LATEST_SUPPORTED_VERSION);
@@ -533,21 +537,6 @@ describe("buildStatusDetail — external memory section", () => {
533537
}
534538
});
535539

536-
test("provider on, fake backend exposes fetchFailedRetainCount → detail surfaces the count", async () => {
537-
const db = createTestDb();
538-
try {
539-
const sessionId = "ses-status-ext-on";
540-
db.prepare(
541-
"INSERT INTO session_meta (session_id, last_input_tokens, last_context_percentage) VALUES (?, 0, 0)",
542-
).run(sessionId);
543-
_setTestExternalBackendFactory(() => ({
544-
backendId: "fake:ext-status",
545-
initialize: async () => true,
546-
retain: async () => 0,
547-
dispose: async () => {},
548-
_getCircuitState: () => "closed",
549-
fetchFailedRetainCount: async () => 3,
550-
}));
551540
test("provider on, fake backend exposes fetchFailedRetainCount → detail surfaces the count", async () => {
552541
const db = createTestDb();
553542
try {
@@ -635,7 +624,7 @@ describe("buildStatusDetail — external memory section", () => {
635624
});
636625

637626
describe("buildStatusDetail — cacheNeverExpires with 'never' TTL", () => {
638-
test("sets cacheNeverExpires: true when cache_ttl is 'never'", () => {
627+
test("sets cacheNeverExpires: true when cache_ttl is 'never'", async () => {
639628
const db = createTestDb();
640629
try {
641630
const sessionId = "ses-status-never";
@@ -650,7 +639,7 @@ describe("buildStatusDetail — cacheNeverExpires with 'never' TTL", () => {
650639
"UPDATE session_meta SET cache_ttl = ?, last_response_time = ? WHERE session_id = ?",
651640
).run("never", Date.now() - 60_000, sessionId);
652641

653-
const detail = buildStatusDetail(db, sessionId, directory);
642+
const detail = await buildStatusDetail(db, sessionId, directory);
654643

655644
expect(detail.cacheNeverExpires).toBe(true);
656645
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,
@@ -1061,7 +1060,7 @@ function createCtxMemoryTool(deps: CtxMemoryToolDeps): ToolDefinition {
10611060

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

0 commit comments

Comments
 (0)