Skip to content

Fix backend code relooping issue #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion cofounder/api/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ async function build({ system }) {
return await queues[id].add(async () => {
events.log.node.emit(`start`, { id, context, data });
const response = await retry(
async (bail) => {
async (bail, attempt) => {
try {
const fnresponse = await system.functions[id]({
context: { ...context, run: system.run },
Expand All @@ -94,6 +94,14 @@ async function build({ system }) {
: data,
});

if (!fnresponse || (id === 'BACKEND:SERVER::GENERATE' && !fnresponse.backend.server.main.mjs)) {
if (attempt >= (parseInt(system.nodes[id].queue?.retry) || 5)) {
console.error(`backend:server:generate error - generated is empty after ${attempt} attempts`);
return { success: false };
}
throw new Error("backend:server:generate error - generated is empty");
}

return !fnresponse
? { success: false }
: system.nodes[id].out?.length
Expand Down
15 changes: 14 additions & 1 deletion cofounder/api/system/functions/backend/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,20 @@ now do the analysis , write the full working script and specify the dependencies

const { mjs } = extraction;
if (!mjs.length || !extraction.yaml) {
throw new Error("backend:server:generate error - generated is empty");
console.error("backend:server:generate error - generated is empty");
return {
backend: {
...data.backend,
server: {
main: {
mjs: "",
dependencies: {},
env: {},
timestamp: Date.now(),
},
},
},
};
}

const parsedYaml = extraction.yaml ? yaml.parse(extraction.yaml) : {};
Expand Down