agentmemory icon indicating copy to clipboard operation
agentmemory copied to clipboard

engine-config: block-style `allowed_origins` produces invalid iii-config.runtime.yaml (engine crash-loops; affects deploy/coolify)

Open cbsincool opened this issue 1 month ago • 0 comments

Summary

setManagedCorsOrigins() rewrites only the allowed_origins: line into an inline flow list but leaves the following block-list items in place. When the source config uses block style (which the repo's own deploy/coolify/entrypoint.sh does), the generated iii-config.runtime.yaml is invalid YAML and the engine crash-loops on startup.

Root cause

src/cli/engine-config.ts:

function setManagedCorsOrigins(lines, restPort, viewerPort) {
  const originsIndex = lines.findIndex((line, index) =>
    index > block.start && index < block.end && line.trim().startsWith("allowed_origins:"));
  if (originsIndex === -1) return;
  const indent = lines[originsIndex].match(/^\s*/)?.[0] ?? "        ";
  lines[originsIndex] =
    `${indent}allowed_origins: [` + `"http://localhost:${restPort}", ` + ... + `]`;
}

Only lines[originsIndex] is replaced. A block-style source leaves its - "..." children behind:

      cors:
        allowed_origins: ["http://localhost:3111", "http://localhost:3113", "http://127.0.0.1:3111", "http://127.0.0.1:3113"]
          - "http://localhost:3111"     # orphaned, invalid YAML
          - "http://localhost:3113"
          - "http://127.0.0.1:3111"
          - "http://127.0.0.1:3113"
        allowed_methods: [GET, POST, PUT, DELETE, OPTIONS]

renderEngineConfig is always called with ports for a non-bundled config (src/cli.ts:1511-1518), so this path is unconditional for a custom iii-config.yaml.

Reproduction

Use the config this repo ships in deploy/coolify/entrypoint.sh (block-style allowed_origins, written to <pkg>/dist/iii-config.yaml, i.e. a non-bundled path), start the container, and the engine exits with:

Error: Failed to parse config file '/data/iii-config.runtime.yaml':
did not find expected key at line 13 column 11, while parsing a block mapping
at line 12 column 9

Verified on @agentmemory/[email protected] with iiidev/iii:0.22.1; the generated file contained exactly the orphaned block above. Changing the source to an inline list (allowed_origins: ["http://localhost:3111", ...], as the npm-bundled iii-config.yaml has) makes it start normally.

Impact

  • Any custom iii-config.yaml written with a block-style allowed_origins (which is the natural, more readable YAML form) cannot boot.
  • The repo's own deploy/coolify entrypoint uses that style, so the documented Coolify/Docker deploy path is affected.

Suggested fix

Make setManagedCorsOrigins consume the block's children when the key is a block sequence — e.g. after replacing the key line, drop following lines that are more indented than originsIndex and start with - . Alternatively render the whole cors: block instead of a single line.

(Workaround used locally: write allowed_origins inline in the entrypoint config.)

cbsincool avatar Oct 09 '26 08:10 cbsincool