From c2e24eaf261a71c7148db99af18cbc6733e58a21 Mon Sep 17 00:00:00 2001 From: Danny Avila Date: Tue, 14 Apr 2026 21:39:10 -0400 Subject: [PATCH] fix: pass entity_id=skillId on batch upload, eliminates per-user cache thrashing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit primeSkillFiles now passes entity_id: skill._id.toString() to batchUploadCodeEnvFiles. This scopes the code env session to the skill, not the user. All users sharing a skill share the same uploaded files — no more cache thrashing from overwriting each other's codeEnvIdentifier. The stored codeEnvIdentifier now includes ?entity_id= suffix so freshness checks pass the entity_id through to the per-object stat endpoint. Both primeSkillFiles and primeInvokedSkills store consistent identifier formats. --- packages/api/src/agents/skillFiles.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/api/src/agents/skillFiles.ts b/packages/api/src/agents/skillFiles.ts index 80a6055e16..399147bdc9 100644 --- a/packages/api/src/agents/skillFiles.ts +++ b/packages/api/src/agents/skillFiles.ts @@ -145,7 +145,13 @@ export async function primeSkillFiles( } try { - const result = await batchUploadCodeEnvFiles({ req, files: filesToUpload, apiKey }); + const entityId = skill._id.toString(); + const result = await batchUploadCodeEnvFiles({ + req, + files: filesToUpload, + apiKey, + entity_id: entityId, + }); const files = result.files.map((f) => ({ id: f.fileId, session_id: result.session_id, @@ -159,7 +165,7 @@ export async function primeSkillFiles( .map((f) => ({ skillId: skill._id, relativePath: f.filename.slice(f.filename.indexOf('/') + 1), - codeEnvIdentifier: `${result.session_id}/${f.fileId}`, + codeEnvIdentifier: `${result.session_id}/${f.fileId}?entity_id=${entityId}`, })); if (updates.length > 0) { updateSkillFileCodeEnvIds(updates).catch((err: unknown) => { @@ -393,10 +399,13 @@ export async function primeInvokedSkills( `[primeInvokedSkills] No skill record found for filename "${f.filename}"`, ); } + const entityId = record?.skill._id?.toString() ?? ''; return { skillId: record?.skill._id ?? '', relativePath: relPath, - codeEnvIdentifier: `${result.session_id}/${f.fileId}`, + codeEnvIdentifier: entityId + ? `${result.session_id}/${f.fileId}?entity_id=${entityId}` + : `${result.session_id}/${f.fileId}`, }; }) .filter((u) => u.skillId !== '');