Repository navigation
fix(loop): read loop-config.json in budget.mjs, which require() never did - #58
Conversation
… 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
left a comment
There was a problem hiding this comment.
🧐 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
| "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", |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
| * | ||
| * 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. |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
|
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 — The docblock stopped asserting that a plugin cache ships Left open. The version conflict with #55 is real — Whether 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 |
The failure this prevents
Every budget the loop has ever measured was
DEFAULT_BUDGETS, notwriting.budgets. Tuningloop-config.jsondid nothing.budget.mjs:70calledrequire('node:fs')inside an ESM module, whererequireis undefined. The line threw aReferenceErrorinto the barecatchon every invocation, from every directory, so the config read never ran.It is silent by construction. The
catchhas no message, and the two numbers agree onmain, so a check from either path returned the same answer for the wrong reason.Reproduced on
main, with aloop-config.jsonholdingjournalComment: 9999beside the process:The open #55 raises
journalCommentinloop-config.json. Without this, that half of it has no effect at all.The change
loadLoopConfig()inlib/config.mjsalready 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 readloop-config.jsonrelative to the process, so even a workingrequirewould 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:
The third line is the second half of the fix. A
loop-config.jsonthat exists and will not parse threw out ofJSON.parseinto the samecatch, and the run measuredDEFAULT_BUDGETSwith 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
loop-config.jsonOK — 1/2500 (config)loop-config.jsonsays9999OK — 1/9999 (config)—2500before this changeloop-config.jsonis malformedOK — 1/2500 (fallback, loop-config.json unreadable: …)— bareOK — 1/2500beforeworkflow/alone, run from/tmpOK — 1/2500 (fallback), and600forreviewReplyRows three and four are checked against real directories, not inferred. Walking up from
budget.mjsinside this checkout always finds the repo's own config, so a probe run in place proves nothing about the fallback.claude plugin validate ./workflow --strictpasses. No skill file is touched, sorule-delta.mjshas nothing to measure.What is NOT claimed
An earlier draft said the
catchexists because an installed plugin cachesworkflow/alone, with noloop-config.jsonabove 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/cachedoes not exist andinstalled_plugins.jsonis 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 whetherDEFAULT_BUDGETShas a reader at all.Merge order — these two PRs are NOT independent
version→0.2.5. #55 takes0.2.4. Both branch frome3e3802and both rewrite that line, sogit merge-treereports a content conflict onworkflow/.claude-plugin/plugin.jsonbetween the two branches.budget.mjsmerges clean; only the version line does not.Whichever lands second must resolve to the higher version. That rule always moves
mainforward. Keeping the second branch's own lower number would move it backwards.Both PRs claiming
0.2.4was 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.4gap 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