Skip to content

fix(#297): drop the hard-coded three-cycle cap - #325

Open
macoladik wants to merge 1 commit into
zerocracy:masterfrom
macoladik:297
Open

macoladik wants to merge 1 commit into
zerocracy:masterfrom
macoladik:297

Conversation

@macoladik

Copy link
Copy Markdown
Contributor

entry.sh capped every update at three cycles, so a dependency chain that needs a fourth cycle stopped before the fixed point the README promises.

Removed the flag so judges update runs its own convergence loop (default cap 8); job-id, lib, and factbase forwarding are unchanged. A new fixture in test_entry models a five-cycle A→B→C→D→E chain and fails if the entry point caps below it.

Closes #297

The hard-coded --max-cycles=3 stopped dependency chains that need more than three update cycles, contradicting the README promise that judges run until no new facts appear. Drop the flag so judges converge on their own default cap.
@macoladik
macoladik requested a review from yegor256 as a code owner November 7, 2026 22:06

@macoladik macoladik 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.

Drops --max-cycles=3 from entry.sh and adds a stub-based test. The change replaces a bounded failure with an unbounded run, and the new test never runs judges, so it cannot detect either regression.

Comment thread entry.sh
self=$(dirname "$(readlink -f "$0")")

judges update --summary --max-cycles=3 --no-log \
judges update --summary --no-log \

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.

Removing the flag leaves judges update without any ceiling. In the gem, the cycle loop ends only when a cycle makes zero changes to the factbase, on --max-cycles, or on --lifetime; neither of the last two is passed here. Scenario: a judge that inserts a fact with a fresh when or _id on every cycle (a (absent ...) guard forgotten) keeps delta non-zero, so the process never returns and the swarm container runs until the platform kills it. The old --max-cycles=3 was the only stop. Fix: keep a bound, just a larger one, e.g. --max-cycles=10.

Comment thread entry.sh

judges update --summary --max-cycles=3 --no-log \
judges update --summary --no-log \
--option "id=${id}" --lib "${self}/lib" "${self}/judges" "${home}/base.fb"

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.

Nothing here bounds a single cycle either. judges update supports --lifetime, and without it one judge blocked on a network call (Octokit without a timeout, a hanging git clone) holds the job forever regardless of the cycle cap. Fix: add --lifetime=3600 to this argument list.

Comment thread test/test_entry.rb
File.write(ENV.fetch('JUDGES_ARGS_FILE'), ARGV.join("\n"))
RUBY

# Models a chain A→B→C→D→E plus the confirming cycle, so it needs five cycles.

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 comment promises a modelled chain A->B->C->D->E plus the confirming cycle, but the stub models no chain at all - it parses one integer and aborts below 5. A reader will believe the convergence path is covered when only a string comparison is. Fix: either drop the comment or make the stub behave like a converging chain (count invocations, exit non-zero while the count is under 5).

Comment thread test/test_entry.rb
#!/usr/bin/env ruby
File.write(ENV.fetch('JUDGES_ARGS_FILE'), ARGV.join("\n"))
args = ARGV.dup
cap = 8

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.

cap = 8 invents a default that judges does not have: with no --max-cycles the gem's loop is unbounded (opts['max-cycles'].nil? in Judges::Update#loop_them). Because of this fake default the test passes when entry.sh passes no cap at all - which is exactly what this PR does - so it cannot tell "raised the cap" from "removed the cap", and it documents a contract the gem does not implement. Fix: model reality (cap = Float::INFINITY) and assert on the recorded argv instead.

Comment thread test/test_entry.rb
cap = args.shift.to_i
end
end
abort("chain needs 5 cycles, got #{cap}") if cap < 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 assertion is one-sided: it rejects 0..4 and accepts everything above, so --max-cycles=999999 passes, and so does no flag at all. That means the test stays green for the regression it exists for (an unbounded run) and for any cap so large it is meaningless. Fix: read the args file and require an explicit bound, e.g. assert_match(/--max-cycles=(\d+)/, passed.join(' ')) plus assert_operator(cap, :>=, 5).

Comment thread test/test_entry.rb
# Models a chain A→B→C→D→E plus the confirming cycle, so it needs five cycles.
CHAIN_STUB = <<~'RUBY'
#!/usr/bin/env ruby
File.write(ENV.fetch('JUDGES_ARGS_FILE'), ARGV.join("\n"))

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 write is dead in the only test that uses the stub: test_allows_chain_longer_than_three_cycles calls run_entry and throws the returned lines away, so JUDGES_ARGS_FILE is written and never read. Consequence: entry.sh could invoke the stub with a wrong --lib, a wrong base.fb, or no --summary, and the test would still pass. Fix: assert on the returned argv in that test, or drop the write from this stub.

Comment thread test/test_entry.rb
Dir.mktmpdir do |dir|
home = File.join(dir, 'home')
FileUtils.mkdir_p(home)
run_entry(judges_stub(dir, CHAIN_STUB), home, File.join(dir, 'args.txt'))

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 result of run_entry is discarded, so the test proves only that the exit status is zero. Any change that keeps the stub happy but breaks the real invocation - losing --summary, --no-log, --option id=job-42, or the --lib path - stays green. Fix: passed = run_entry(...) and assert the argv, as test_forwards_job_id_to_judges_options does two methods below.

Comment thread test/test_entry.rb
assert_equal(File.expand_path('../judges', __dir__), passed[passed.index('--lib') + 2])
end

def test_allows_chain_longer_than_three_cycles

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 name says the chain may run longer than three cycles, but the real judges is never executed - run_entry puts the stub first on PATH. So the gem's own behaviour (whatever its default cap is, and whether --max-cycles was actually the blocker) is untested; a version of judges that still stops at 3 cycles for another reason would keep this green. judges is already a dependency (Gemfile:9), so an integration test with a 5-step chain of judges fixtures would prove the fix; the stub only proves the flag string.

Comment thread test/test_entry.rb
FileUtils.mkdir_p(bin)
stub = File.join(bin, 'judges')
File.write(stub, JUDGES_STUB)
File.write(stub, source)

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 new source parameter is written verbatim, and CHAIN_STUB duplicates JUDGES_STUB's shebang and write line instead of extending it. When JUDGES_STUB grows (for example a check on the factbase argument), CHAIN_STUB silently keeps the old behaviour and the test passes for the wrong reason. Fix: build the chain stub from the plain one, e.g. CHAIN_STUB = "#{JUDGES_STUB}\n<cycle check>", and add one assertion on the recorded argv so the two stubs cannot drift unnoticed.

@yegor256 yegor256 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The regression fixture requested in #297 is still missing: the new test checks a flag value without exercising convergence or verifying the output factbase. Please add a real multi-cycle chain test before merging.

Comment thread test/test_entry.rb
Dir.mktmpdir do |dir|
home = File.join(dir, 'home')
FileUtils.mkdir_p(home)
run_entry(judges_stub(dir, CHAIN_STUB), home, File.join(dir, 'args.txt'))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This invokes CHAIN_STUB, which only records argv and rejects caps below five; it never executes a judge or produces any facts. For example, replacing the old cap with --max-cycles=5 would pass even for a chain needing six cycles, leaving its output incomplete. Add an integration fixture that runs the real judges update through the entry point with a dependency chain requiring more than three cycles, asserts the final facts, and fails with the original --max-cycles=3.

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.

entry.sh stops the judge swarm after three cycles despite the documented convergence behavior

2 participants