Skip to content

Port: port/pr-38-fix/update-preserve-config-json#12

Merged
briansumma merged 3 commits into
developfrom
port/pr-38-fix/update-preserve-config-json
May 15, 2026
Merged

Port: port/pr-38-fix/update-preserve-config-json#12
briansumma merged 3 commits into
developfrom
port/pr-38-fix/update-preserve-config-json

Conversation

@briansumma
Copy link
Copy Markdown
Collaborator

Ported from upstream cytostack/openwolf. Needs review before merge.

…ostack#37)

`update.ts` was unconditionally copying `src/templates/config.json`
over every registered project's `.wolf/config.json`. That file is
not template content — it carries each project's daemon port,
dashboard port, scan intervals, and exclude patterns. Overwriting it
across all projects in one shot resets every registered project to
the same defaults (`daemon=18790`, `dashboard=18791`), so only the
first daemon to start binds and the rest crash-loop on `EADDRINUSE`.

Move `config.json` from `ALWAYS_OVERWRITE` to `USER_DATA_FILES`. It
is still included in `BACKUP_FILES` via the spread, so `openwolf
restore` can still recover it.

Reproduced on Linux (PVE 7) and Windows 11. After local apply, ten
projects on one host kept their unique ports through a simulated
update; pre-patch, all ten fell to defaults inside one second.

No behavior change for `OPENWOLF.md` or `reframe-frameworks.md` —
those remain protocol-doc overwrites.
@briansumma briansumma mentioned this pull request May 14, 2026
@briansumma
Copy link
Copy Markdown
Collaborator Author

Now I have everything I need. Here's my review of PR #12:


PR #12 Code Review: port/pr-38-fix/update-preserve-config-json

Overview

This PR ports a fix from upstream (cytostack/openwolf). The change moves config.json out of ALWAYS_OVERWRITE (files stamped over on every openwolf update) and into USER_DATA_FILES (files never touched once they exist). The root cause described in the new block comment is real and serious: overwriting config.json resets all projects to the same default ports (18790/18791), causing all but the first daemon to crash-loop on EADDRINUSE.

The fix is directionally correct. Two issues need attention before merge.


Issues

⚠️ WARNING 1 — Stale inline comment (line 177)

The updateProject() function still has:

// 2. Update template files (OPENWOLF.md, config.json)

config.json is no longer in ALWAYS_OVERWRITE and is no longer updated by this loop. The comment is now actively misleading — a future reader will wonder why the loop doesn't copy config.json when the comment says it should.

Fix:

// 2. Update template files (OPENWOLF.md, reframe-frameworks.md)

⚠️ WARNING 2 — No "create if missing" bootstrap for config.json during update

Moving config.json to USER_DATA_FILES means the update command never touches it — not even to create it when it doesn't exist. Older projects initialized before config.json was introduced to the template will run openwolf update and still have no config.json. The daemon will then attempt to start without it.

Whether that's a hard crash depends on how the daemon reads config, but the update command already handles a similar problem for hooks (copyHookScripts creates the hooks dir and files). config.json should get the same treatment.

The block comment says "Keep it in BACKUP_FILES (via the spread below) so openwolf restore can still recover it" — that's correct — but it doesn't address the creation gap.

Fix — add a "create if missing" step after the template copy loop (around line 186):

// Seed config.json if it doesn't exist yet (never overwrite — user data)
const configDest = path.join(wolfDir, "config.json");
const configSrc = path.join(templatesDir, "config.json");
if (!fs.existsSync(configDest) && fs.existsSync(configSrc)) {
  fs.copyFileSync(configSrc, configDest);
  console.log(`    ✓ config.json seeded (first time)`);
}

What's Good

  • The core fix is correct. config.json absolutely should not be overwritten on update. The EADDRINUSE scenario described in the comment is real.
  • The block comment is excellent — it explains why, names the specific fields at risk, and describes the failure mode. Keep it.
  • BACKUP_FILES spread is correctconfig.json will be included in pre-update backups, so openwolf restore can recover it.
  • No behavioral regression for existing projects — projects that already have config.json will have it preserved as intended.

Summary

# Severity Issue
1 ⚠️ WARNING Line 177: stale comment still names config.json as a file being updated
2 ⚠️ WARNING No "create if missing" seed for config.json on update — older projects won't get the file

Fix both before merging; neither is a blocker, but #2 will silently break daemon startup for any project that predates the config.json template addition.

@briansumma
Copy link
Copy Markdown
Collaborator Author

Autofixer skipped: merge conflicts with main detected.

briansumma and others added 2 commits May 14, 2026 16:58
- Fix stale comment on line 177: remove config.json reference since it
  is no longer in ALWAYS_OVERWRITE (now lists OPENWOLF.md and
  reframe-frameworks.md accurately)
- Add "create if missing" seed block for config.json after the template
  copy loop so older projects that predate the config.json template
  addition receive the file on their next `openwolf update`

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@briansumma
Copy link
Copy Markdown
Collaborator Author

✅ Autofixer applied. Build and tests passed. Promoting to Ready for Review.

@briansumma briansumma marked this pull request as ready for review May 14, 2026 22:01
@briansumma briansumma changed the base branch from main to develop May 14, 2026 23:46
@briansumma briansumma merged commit f55be98 into develop May 15, 2026
@briansumma briansumma deleted the port/pr-38-fix/update-preserve-config-json branch May 15, 2026 01:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants