Skip to content

Commit 6be61b9

Browse files
author
alvinttang
committed
fix: Codex review — batch item size check, version-pinned npm install, truncated tag scan
- Validate each batch item text against MAX_INGEST_TEXT_BYTES (Codex P1) - Pin npm binary download to package.json version tag, not /releases/latest (Codex P2) - Add scanned/truncated fields to tag_list_taxonomy response (Codex P2)
1 parent 1bedb3a commit 6be61b9

2 files changed

Lines changed: 26 additions & 6 deletions

File tree

cortex-mcp-server/src/tools.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,6 +1017,14 @@ fn tool_memory_ingest_batch(cortex: &Arc<Cortex>, args: &Value) -> Result<String
10171017
return Err(format!("batch too large: {} items (max {})", items_arr.len(), MAX_BATCH_SIZE));
10181018
}
10191019

1020+
// Validate each item's text size (same guard as memory_ingest)
1021+
for (i, item) in items_arr.iter().enumerate() {
1022+
let text_len = item.get("text").and_then(|v| v.as_str()).map(|s| s.len()).unwrap_or(0);
1023+
if text_len > MAX_INGEST_TEXT_BYTES {
1024+
return Err(format!("item[{}] text too large: {} bytes (max {})", i, text_len, MAX_INGEST_TEXT_BYTES));
1025+
}
1026+
}
1027+
10201028
let items: Vec<cortex_core::types::BatchIngestItem> = items_arr.iter().map(|item| {
10211029
cortex_core::types::BatchIngestItem {
10221030
text: item.get("text").and_then(|v| v.as_str()).unwrap_or("").to_string(),
@@ -1049,8 +1057,14 @@ fn tool_tag_list_taxonomy(cortex: &Arc<Cortex>) -> Result<String, String> {
10491057
cortex_core::types::MemoryTier::Procedural,
10501058
];
10511059

1060+
let mut scanned_total: usize = 0;
1061+
let mut truncated = false;
10521062
for tier in &tiers {
10531063
if let Ok(mems) = cortex.storage().list_by_tier(*tier, MAX_TAG_SCAN_PER_TIER) {
1064+
if mems.len() >= MAX_TAG_SCAN_PER_TIER {
1065+
truncated = true;
1066+
}
1067+
scanned_total += mems.len();
10541068
for mem in mems {
10551069
for tag in &mem.tags {
10561070
*tag_counts.entry(tag.clone()).or_insert(0) += 1;
@@ -1069,6 +1083,8 @@ fn tool_tag_list_taxonomy(cortex: &Arc<Cortex>) -> Result<String, String> {
10691083
Ok(json!({
10701084
"tags": items,
10711085
"total_unique": items.len(),
1086+
"scanned": scanned_total,
1087+
"truncated": truncated,
10721088
}).to_string())
10731089
}
10741090

npm/bin/install.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const REPO = "gambletan/cortex";
1111
const BINARY_NAME = "cortex-mcp-server";
1212
const BIN_DIR = path.join(__dirname);
1313
const BINARY_PATH = path.join(BIN_DIR, BINARY_NAME);
14+
const PKG_VERSION = require("../package.json").version;
1415

1516
function getPlatformSuffix() {
1617
const platform = os.platform();
@@ -79,16 +80,19 @@ function httpsGet(url, redirectCount = 0) {
7980
});
8081
}
8182

82-
async function fetchLatestRelease() {
83-
const url = `https://api.github.com/repos/${REPO}/releases/latest`;
83+
async function fetchRelease() {
84+
// Pin to the version in package.json for reproducible installs
85+
const tag = `v${PKG_VERSION}`;
86+
const url = `https://api.github.com/repos/${REPO}/releases/tags/${tag}`;
8487
const data = await httpsGet(url);
8588
try {
8689
return JSON.parse(data.toString());
8790
} catch {
8891
throw new Error(
89-
`Failed to parse GitHub API response. ` +
90-
`This may be due to rate limiting. Try again in a few minutes, or ` +
91-
`download manually from: https://github.com/${REPO}/releases/latest`
92+
`Failed to parse GitHub API response for v${PKG_VERSION}. ` +
93+
`This may be due to rate limiting or a missing release tag. ` +
94+
`Try again in a few minutes, or download manually from: ` +
95+
`https://github.com/${REPO}/releases/tag/v${PKG_VERSION}`
9296
);
9397
}
9498
}
@@ -100,7 +104,7 @@ async function install() {
100104
console.log(`[cortex-memory] Detected platform: ${suffix}`);
101105
console.log(`[cortex-memory] Fetching latest release from ${REPO}...`);
102106

103-
const release = await fetchLatestRelease();
107+
const release = await fetchRelease();
104108
const asset = release.assets.find((a) => a.name === assetName);
105109

106110
if (!asset) {

0 commit comments

Comments
 (0)