Skip to content

fix(loop): read loop-config.json in budget.mjs, which require() never did - #58

Merged
Ardnived merged 3 commits into
mainfrom
claude/fix-budget-config-read
Sep 6, 2026
Merged

Ardnived merged 3 commits into
mainfrom
claude/fix-budget-config-read

Conversation

@sydevs-bot

@sydevs-bot sydevs-bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

The failure this prevents

Every budget the loop has ever measured was DEFAULT_BUDGETS, not writing.budgets. Tuning loop-config.json did nothing.

budget.mjs:70 called require('node:fs') inside an ESM module, where require is undefined. The line threw a ReferenceError into the bare catch on every invocation, from every directory, so the config read never ran.

It is silent by construction. The catch has no message, and the two numbers agree on main, so a check from either path returned the same answer for the wrong reason.

Reproduced on main, with a loop-config.json holding journalComment: 9999 beside the process:

before   OK — 1/2500      # the config is ignored
after    OK — 1/9999      # the config wins

The open #55 raises journalComment in loop-config.json. Without this, that half of it has no effect at all.

The change

loadLoopConfig() in lib/config.mjs already resolves the file correctly — it walks up from the cwd, then from its own location. Reusing it also deletes a second, worse copy of that lookup: the old line read loop-config.json relative to the process, so even a working require would have missed it from any other directory.

The CLI now names which path set the budget. A silent fallback is the same defect one level up, so the answer is printed rather than assumed:

OK — 1/2500 (config)
OK — 1/2500 (fallback)
OK — 1/2500 (fallback, loop-config.json unreadable: <parse error>)

The third line is the second half of the fix. A loop-config.json that exists and will not parse threw out of JSON.parse into the same catch, and the run measured DEFAULT_BUDGETS with nothing printed. Only a genuinely missing file now takes the quiet path. Exit codes are unchanged (0 under, 1 over), so no caller's contract moves.

Verified in four shapes

Shape Reads Prints
Repo root loop-config.json OK — 1/2500 (config)
A directory whose loop-config.json says 9999 that file OK — 1/9999 (config) — 2500 before this change
A directory whose loop-config.json is malformed nothing; falls back OK — 1/2500 (fallback, loop-config.json unreadable: …) — bare OK — 1/2500 before
A copy of workflow/ alone, run from /tmp nothing; falls back OK — 1/2500 (fallback), and 600 for reviewReply

Rows three and four are checked against real directories, not inferred. Walking up from budget.mjs inside this checkout always finds the repo's own config, so a probe run in place proves nothing about the fallback.

claude plugin validate ./workflow --strict passes. No skill file is touched, so rule-delta.mjs has nothing to measure.

What is NOT claimed

An earlier draft said the catch exists because an installed plugin caches workflow/ alone, with no loop-config.json above it. That was an inference, and it is now out of the docblock. No plugin cache exists in any environment available to this run — ~/.claude/plugins/cache does not exist and installed_plugins.json is empty — so the cache's layout is unverified here.

The source label is what answers it. One run from a real installed plugin prints (config) or (fallback), and settles both this and whether DEFAULT_BUDGETS has a reader at all.

Merge order — these two PRs are NOT independent

version → 0.2.5. #55 takes 0.2.4. Both branch from e3e3802 and both rewrite that line, so git merge-tree reports a content conflict on workflow/.claude-plugin/plugin.json between the two branches. budget.mjs merges clean; only the version line does not.

Whichever lands second must resolve to the higher version. That rule always moves main forward. Keeping the second branch's own lower number would move it backwards.

Both PRs claiming 0.2.4 was considered and rejected: identical edits on both sides merge clean, so nobody is prompted, and the second PR's content then ships under a cache key the first already claimed — an installed plugin would never see it. A reserved version only works if merge order claims it, not PR number.

If #55 closes instead, the 0.2.4 gap is harmless. The cache key needs to change, not to be contiguous.

Scope

One behaviour: the config read, and reporting which path it took. The budget numbers are #55's, and stay there.

Found by the adversarial review on #55, then extended by the review on this PR.

🤖 Written by the sydevs autonomous loop — see what this is

🤖 Generated with Claude Code

https://claude.ai/code/session_016FZreqxKVR4MJ197gecH2D

… did

`budget.mjs:70` called `require('node:fs')` inside an ESM module. `require`
is undefined there, so the line threw a `ReferenceError` into the bare
`catch` on every invocation, from every directory. `writing.budgets` has
therefore never overridden `DEFAULT_BUDGETS`. Every budget the loop has
measured was the fallback, and tuning `loop-config.json` did nothing.

The failure is silent by construction: the catch has no message, and the
two numbers agree today, so a check from either path returned the same
answer for the wrong reason. #55 raises `journalComment` in
`loop-config.json` and would have had no effect at all.

`loadLoopConfig()` in `lib/config.mjs` already resolves the file correctly:
it walks up from the cwd, then from its own location. Reusing it also drops
a second, worse copy of that lookup — the old line read `loop-config.json`
relative to the process, so even a working `require` would have missed it
from any other directory.

The `catch` stays, and now has one job. An installed plugin caches
`workflow/` alone, with no `loop-config.json` above it, so `loadLoopConfig`
throws there and `DEFAULT_BUDGETS` is the answer.

Verified in all three shapes. A `loop-config.json` holding
`journalComment: 9999` beside the process printed `2500` before and `9999`
after. The repo root still reads `2500` from config. A copy of `workflow/`
alone, run from `/tmp`, falls back to `2500` and `600`.

`version` → 0.2.5, since `workflow/lib/` ships in the plugin cache. It
skips 0.2.4, which the open #55 takes.

Found by the adversarial review on #55.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WtYsgJTcXzU2unVFtxkJqz

@sydevs-bot sydevs-bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧐 Adversarial review

The diagnosis is right, loadLoopConfig() is the correct reuse, and 12 lines for one behaviour is the right size. Two body claims are unproven. "Either order" is false: git merge-tree against #55 conflicts. And "an installed plugin ships workflow/ alone" was built for the check, not observed — if wrong, this trades the fallback for a stale pinned config.

Findings

  • should-fix — plugin.json:4: a verified conflict with #55, and a version regression if #55 lands second.
  • should-fix — budget.mjs:34: the cache-layout premise behind it is unverified.
  • consider — budget.mjs:79: the catch still hides a malformed config; nothing names which source won.
  • consider — budget.mjs:35: a duplicate kept in step by hand, with an uncovered third copy.

Checked: the diff; budget.mjs and config.mjs whole; git merge-tree of both branches (plugin.json conflicts, budget.mjs clean); #55; marketplace.json; both budget.mjs call sites; a grep for other budget numbers. No cache here, so row 3 is unchecked.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

Comment thread workflow/.claude-plugin/plugin.json Outdated
"name": "workflow",
"description": "Shared issue-to-PR workflow for the sydevs projects. Reads per-repo settings from .claude/workflow.json so one skill body serves every repo.",
"version": "0.2.3",
"version": "0.2.5",

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The body says the two PRs "are independent and can land in either order". At the git level they are not. Both branch from e3e3802 and both rewrite this line, so git merge-tree between the two branches reports a content conflict here — budget.mjs merges clean, this file does not:

CONFLICT (content): Merge conflict in workflow/.claude-plugin/plugin.json

Two consequences, both cheap to avoid before either lands. Whichever merges second needs a hand resolution. And if #55 is the second, its obvious resolution — keeping its own 0.2.4 — moves main's version backwards from 0.2.5. The body answers contiguity ("the cache key needs to change, not to be contiguous"), not ordering.

Simplest fix: take 0.2.4 here and let whichever lands second claim 0.2.5. A reserved version only works if merge order claims it, not PR number.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed — git merge-tree reports the conflict on plugin.json alone.

I did not take 0.2.4. I tested it: two branches making the identical edit merge clean, so nobody is prompted, and the second PR ships under a key the first already claimed. That is the silent shape this PR closes.

0.2.5 keeps the conflict, and "resolve to the higher version" always moves main forward. The body says that now, instead of calling the two independent.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

Comment thread workflow/lib/budget.mjs Resolved
Comment thread workflow/lib/budget.mjs Resolved
Comment thread workflow/lib/budget.mjs Outdated
*
* The fallback is reached only when no `loop-config.json` exists above this
* file or the cwd — an installed plugin, whose cache ships `workflow/` alone.
* Keep these numbers equal to the config's, so both paths agree.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line creates an invariant that nothing enforces, and it is incomplete on arrival: workflow/skills/journal/SKILL.md:16 states the same number a third time in prose ("about 2,500 characters"), which #55 explicitly defers to a later PR. So "both paths" is really three copies, held in step by a comment.

Fixing that is not this PR's job. Worth asking, though, whether DEFAULT_BUDGETS should exist at all. If a cache does ship the repo (see the thread on line 34), the fallback has no reader and the duplicate can go. If it ships workflow/ alone, a small budgets file inside workflow/, read by both paths, would delete the duplicate rather than document it.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed on both counts — three copies, and not this PR's job. The journal/SKILL.md:16 figure is #55's deferred item, on its own thread there.

On whether DEFAULT_BUDGETS should exist: same blocker as the line 34 thread, no cache to read. The source label settles it from a real run. If it reports config, the fallback has no reader and the duplicate goes. If fallback, a budgets file inside workflow/ read by both paths deletes the duplicate.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

…onfig

The review found the catch still swallowed a real failure. A
loop-config.json that EXISTS and will not parse threw out of JSON.parse,
landed in the same catch, and the run measured DEFAULT_BUDGETS with
nothing printed — the exact shape this PR indicts.

The printed line carried the same gap. `OK — 1/2500` never said whether
the config or the fallback produced the 2500, which is why demonstrating
the original bug needed an out-of-tree 9999 probe.

Both close together. The CLI now names its source, and a config that is
present but unreadable says so instead of falling back quietly:

  OK — 1/2500 (config)
  OK — 1/2500 (fallback)
  OK — 1/2500 (fallback, loop-config.json unreadable: <parse error>)

Exit codes are unchanged, so no caller's contract moves.

The docblock also stopped asserting that a plugin cache ships `workflow/`
alone. No cache exists in any environment available to this run, so that
was an inference. The source label is what will answer it from a real
installed run.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016FZreqxKVR4MJ197gecH2D
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

Revised. Two of four review threads applied and resolved. Two answered and left open for you.

Applied. The CLI now names which path set the budget — (config) against (fallback). A loop-config.json that exists but will not parse says so, instead of falling back quietly: this PR's own defect, one level up. Exit codes are unchanged.

The docblock stopped asserting that a plugin cache ships workflow/ alone. No cache exists in any environment this run can reach, so it was an inference. The source label answers it from a real installed run.

Left open. The version conflict with #55 is real — git merge-tree reports it on plugin.json alone. I did not take 0.2.4: identical edits merge clean, so nobody is prompted and the second PR ships under a key the first claimed. The body names the conflict and the resolution rule now.

Whether DEFAULT_BUDGETS should exist needs the same cache evidence nobody here has.

Gate green. Checked in four config shapes, the malformed one confirmed silent on this PR's previous commit.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

@Ardnived
Ardnived merged commit c8d2cf9 into main Sep 6, 2026
1 check passed
@github-project-automation github-project-automation Bot moved this from In progress to Done in SYDevelopers Technical Roadmap Sep 6, 2026
@Ardnived
Ardnived deleted the claude/fix-budget-config-read branch September 6, 2026 18:01
@Ardnived Ardnived removed the awaiting label Sep 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

2 participants