Skip to content
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

Fix backend code relooping issue #15

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Fix backend code relooping issue
Related to #11

Improve error handling and retry mechanism for backend code generation process.

* **Handle empty generated server code gracefully in `cofounder/api/system/functions/backend/server.js`**
  - Add a check to handle empty generated server code in the `backendServerGenerate` function.
  - Log a specific error message if the generated server code is empty.
  - Return an empty server code structure if the generated server code is empty.

* **Update retry mechanism in `cofounder/api/build.js`**
  - Add a condition to stop retrying if the generated server code is empty after a certain number of attempts in the `system.run` function.
  - Update the retry mechanism to include the new condition in the `fn` function.
  - Log a specific error message if the generated server code is empty after the maximum retries.

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/raidendotai/cofounder/issues/11?shareId=XXXX-XXXX-XXXX-XXXX).
willchrisjr committed Nov 1, 2024
commit fdfc0a83f072feeb8d43fdf77b438ec5f1a47f3e
10 changes: 9 additions & 1 deletion cofounder/api/build.js
Original file line number Diff line number Diff line change
@@ -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 },
@@ -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
15 changes: 14 additions & 1 deletion cofounder/api/system/functions/backend/server.js
Original file line number Diff line number Diff line change
@@ -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) : {};