Skip to content

Commit f804cb9

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 f1a5bf4 commit f804cb9

6 files changed

Lines changed: 20 additions & 72 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
@@ -81,8 +81,6 @@ import {
8181
DEFAULT_MEMORY_BUDGET_TOKENS,
8282
DEFAULT_USER_PROFILE_BUDGET_TOKENS,
8383
type MemoryRenderOptions,
84-
type PreparedCompartmentInjection,
85-
prepareCompartmentInjection,
8684
renderExternalMemoryBlock,
8785
renderExternalMemoryDelta,
8886
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 & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -70,49 +70,15 @@ describe("executeStatus", () => {
7070
db.close();
7171
});
7272

73-
test("shows the exact nudge hygiene ratio and keeps zero values", () => {
74-
const db = new Database(":memory:");
75-
initializeDatabase(db);
76-
getOrCreateSessionMeta(db, SESSION_ID);
77-
78-
const status = executeStatus(
79-
db,
80-
SESSION_ID,
81-
20,
82-
undefined,
83-
undefined,
84-
undefined,
85-
undefined,
86-
undefined,
87-
undefined,
88-
undefined,
89-
undefined,
90-
{
91-
u: 0,
92-
t: 0,
93-
severity: 0,
94-
evaluable: true,
95-
generationInvalidated: false,
96-
baselineGeneration: 0,
97-
computedAt: 0,
98-
},
99-
);
100-
101-
expect(status).toContain("### Tail Hygiene");
102-
expect(status).toContain("0.0% · 0 / 0 tok");
103-
expect(status).toContain("Reasoning is excluded from both terms");
104-
db.close();
105-
});
106-
107-
test("renders 'never expires' for cacheTtl 'never'", () => {
73+
test("renders 'never expires' for cacheTtl 'never'", async () => {
10874
const db = new Database(":memory:");
10975
initializeDatabase(db);
11076
getOrCreateSessionMeta(db, SESSION_ID);
11177
db.prepare("UPDATE session_meta SET cache_ttl = 'never' WHERE session_id = ?").run(
11278
SESSION_ID,
11379
);
11480

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

11783
expect(status).toContain("- Configured: never");
11884
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
@@ -112,7 +112,7 @@ import {
112112
} from "./protected-tail-boundary";
113113
import { readRawSessionMessages } from "./read-session-chunk";
114114
import { findLastAssistantModelFromOpenCodeDb, isMidTurn } from "./read-session-db";
115-
import { estimateTokens, extractTexts, hasMeaningfulUserText } from "./read-session-formatting";
115+
import { extractTexts, hasMeaningfulUserText } from "./read-session-formatting";
116116
import { extractInMemoryMessageViews } from "./read-session-raw";
117117
import { createRustModeTransform, type RustModeModuleClient } from "./rust-mode-transform";
118118
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
@@ -453,7 +453,7 @@ describe("buildSidebarSnapshot — Rust module status merge", () => {
453453
});
454454

455455
describe("compaction-off sidebar RPC data", () => {
456-
test("reports the resolved mode and raw native usage independently of threshold fill", () => {
456+
test("reports the resolved mode and raw native usage independently of threshold fill", async () => {
457457
const db = createTestDb();
458458
try {
459459
const sessionId = "ses-native-sidebar";
@@ -495,7 +495,7 @@ describe("compaction-off sidebar RPC data", () => {
495495
},
496496
false,
497497
);
498-
const detail = buildStatusDetail(
498+
const detail = await buildStatusDetail(
499499
db,
500500
sessionId,
501501
process.cwd(),
@@ -522,7 +522,11 @@ describe("compaction-off sidebar RPC data", () => {
522522
);
523523
expect(snapshot.archivedCompartmentCount).toBe(1);
524524

525-
const enabledDetail = buildStatusDetail(db, "ses-native-sidebar-on", process.cwd());
525+
const enabledDetail = await buildStatusDetail(
526+
db,
527+
"ses-native-sidebar-on",
528+
process.cwd(),
529+
);
526530
expect(enabledDetail.compaction_enabled).toBe(true);
527531
} finally {
528532
closeQuietly(db);
@@ -531,7 +535,7 @@ describe("compaction-off sidebar RPC data", () => {
531535
});
532536

533537
describe("buildStatusDetail — history token reuse (council audit bg_51106601 #1)", () => {
534-
test("sets historyBlockTokens from compartmentTokens only (facts retired in v2)", () => {
538+
test("sets historyBlockTokens from compartmentTokens only (facts retired in v2)", async () => {
535539
const db = createTestDb();
536540
try {
537541
const sessionId = "ses-status-history-tokens";
@@ -572,7 +576,7 @@ describe("buildStatusDetail — history token reuse (council audit bg_51106601 #
572576
],
573577
);
574578

575-
const detail = buildStatusDetail(db, sessionId, directory);
579+
const detail = await buildStatusDetail(db, sessionId, directory);
576580

577581
// v2: facts are retired as a render source (promoted to memories), so
578582
// factTokens is 0 and the history block is compartments only — facts
@@ -587,10 +591,10 @@ describe("buildStatusDetail — history token reuse (council audit bg_51106601 #
587591
});
588592

589593
describe("buildStatusDetail — storage versions probe", () => {
590-
test("reports the live context.db schema version and the plugin fence", () => {
594+
test("reports the live context.db schema version and the plugin fence", async () => {
591595
const db = createTestDb();
592596
try {
593-
const detail = buildStatusDetail(db, "ses-storage-versions", process.cwd());
597+
const detail = await buildStatusDetail(db, "ses-storage-versions", process.cwd());
594598

595599
// The probe must carry the live MAX(schema_migrations) value, not a
596600
// hardcoded one, plus this build's fence. A fully migrated test DB sits
@@ -607,14 +611,14 @@ describe("buildStatusDetail — storage versions probe", () => {
607611
}
608612
});
609613

610-
test("follows an older live DB version while the fence stays put", () => {
614+
test("follows an older live DB version while the fence stays put", async () => {
611615
const db = createTestDb();
612616
try {
613617
// Simulate a DB migrated by an older plugin: drop the recorded versions
614618
// above 50. The probe must follow the live value down.
615619
db.prepare("DELETE FROM schema_migrations WHERE version > ?").run(50);
616620

617-
const detail = buildStatusDetail(db, "ses-storage-versions-old", process.cwd());
621+
const detail = await buildStatusDetail(db, "ses-storage-versions-old", process.cwd());
618622

619623
expect(detail.storage_versions.context_db_schema_version).toBe(50);
620624
expect(detail.storage_versions.plugin_supported_version).toBe(LATEST_SUPPORTED_VERSION);
@@ -640,21 +644,6 @@ describe("buildStatusDetail — external memory section", () => {
640644
}
641645
});
642646

643-
test("provider on, fake backend exposes fetchFailedRetainCount → detail surfaces the count", async () => {
644-
const db = createTestDb();
645-
try {
646-
const sessionId = "ses-status-ext-on";
647-
db.prepare(
648-
"INSERT INTO session_meta (session_id, last_input_tokens, last_context_percentage) VALUES (?, 0, 0)",
649-
).run(sessionId);
650-
_setTestExternalBackendFactory(() => ({
651-
backendId: "fake:ext-status",
652-
initialize: async () => true,
653-
retain: async () => 0,
654-
dispose: async () => {},
655-
_getCircuitState: () => "closed",
656-
fetchFailedRetainCount: async () => 3,
657-
}));
658647
test("provider on, fake backend exposes fetchFailedRetainCount → detail surfaces the count", async () => {
659648
const db = createTestDb();
660649
try {
@@ -742,7 +731,7 @@ describe("buildStatusDetail — external memory section", () => {
742731
});
743732

744733
describe("buildStatusDetail — cacheNeverExpires with 'never' TTL", () => {
745-
test("sets cacheNeverExpires: true when cache_ttl is 'never'", () => {
734+
test("sets cacheNeverExpires: true when cache_ttl is 'never'", async () => {
746735
const db = createTestDb();
747736
try {
748737
const sessionId = "ses-status-never";
@@ -757,7 +746,7 @@ describe("buildStatusDetail — cacheNeverExpires with 'never' TTL", () => {
757746
"UPDATE session_meta SET cache_ttl = ?, last_response_time = ? WHERE session_id = ?",
758747
).run("never", Date.now() - 60_000, sessionId);
759748

760-
const detail = buildStatusDetail(db, sessionId, directory);
749+
const detail = await buildStatusDetail(db, sessionId, directory);
761750

762751
expect(detail.cacheNeverExpires).toBe(true);
763752
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,
@@ -1075,7 +1074,7 @@ function createCtxMemoryTool(deps: CtxMemoryToolDeps): ToolDefinition {
10751074

10761075
if (args.action === "verify") {
10771076
const verifyIds = args.ids;
1078-
if (!verifyIds || verifyIds.length !== 1 || !verifyIds.every(Number.isInteger)) {
1077+
if (verifyIds?.length !== 1 || !verifyIds.every(Number.isInteger)) {
10791078
return "Error: 'ids' must contain exactly one integer memory ID when action is 'verify'.";
10801079
}
10811080
const verifyId = verifyIds[0];

0 commit comments

Comments
 (0)