Spaces:
Sleeping
Sleeping
Commit ·
a314cc1
1
Parent(s): 9df3c32
Stability Fix: Prevent HF Space restart loop by disabling internal git pushes, and improve image recognition data flow
Browse files
backend/controllers/ai.js
CHANGED
|
@@ -185,13 +185,18 @@ exports.chat = asyncHandler(async (req, res, next) => {
|
|
| 185 |
});
|
| 186 |
|
| 187 |
response.data.on('end', async () => {
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 195 |
|
| 196 |
res.end();
|
| 197 |
});
|
|
|
|
| 185 |
});
|
| 186 |
|
| 187 |
response.data.on('end', async () => {
|
| 188 |
+
try {
|
| 189 |
+
// Persist Messages after stream ends
|
| 190 |
+
const userContent = message || (req.file ? `[Attached Image: ${req.file.originalname}]` : "[SIGNAL]");
|
| 191 |
+
await Message.create({ sessionId: session._id, sender: 'user', content: userContent });
|
| 192 |
+
await Message.create({ sessionId: session._id, sender: 'ai', content: fullAIResponse, modelUsed: model });
|
| 193 |
+
|
| 194 |
+
user.usage.requestsToday += 1;
|
| 195 |
+
user.usage.lastRequestDate = new Date();
|
| 196 |
+
await user.save();
|
| 197 |
+
} catch (dbErr) {
|
| 198 |
+
console.error("[DATABASE_ERROR] Persistence failed:", dbErr.message);
|
| 199 |
+
}
|
| 200 |
|
| 201 |
res.end();
|
| 202 |
});
|
backend/services/vaultService.js
CHANGED
|
@@ -44,9 +44,13 @@ exports.uploadToVault = async (filePath, fileName) => {
|
|
| 44 |
execSync(`git ${gitIdent} commit -m "Vault: Archived ${fileName} [Auto-Sync]"`, { cwd: rootDir });
|
| 45 |
|
| 46 |
console.log("Vault: Pushing to remote...");
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
-
console.log(`Vault: Sync Complete -> GitHub`);
|
| 50 |
} catch (gitErr) {
|
| 51 |
console.error('Vault: Git Command Failed:', gitErr.message);
|
| 52 |
// We don't throw here to avoid crashing the chat, but we log the error
|
|
|
|
| 44 |
execSync(`git ${gitIdent} commit -m "Vault: Archived ${fileName} [Auto-Sync]"`, { cwd: rootDir });
|
| 45 |
|
| 46 |
console.log("Vault: Pushing to remote...");
|
| 47 |
+
if (process.env.SPACE_ID) {
|
| 48 |
+
console.log("Vault: [HF_SPACE_DETECTED] Skipping remote push to prevent restart loop.");
|
| 49 |
+
} else {
|
| 50 |
+
execSync(`git push "${remoteUrl}" main`, { cwd: rootDir });
|
| 51 |
+
}
|
| 52 |
|
| 53 |
+
console.log(`Vault: Sync Complete -> ${process.env.SPACE_ID ? 'Local Archive Only' : 'GitHub'}`);
|
| 54 |
} catch (gitErr) {
|
| 55 |
console.error('Vault: Git Command Failed:', gitErr.message);
|
| 56 |
// We don't throw here to avoid crashing the chat, but we log the error
|