Skip to content

Autonomous development for real products. Governed agents build from specs you approve, follow the rules you set, and nothing merges until another agent proves it. Your decisions, judgement and taste are the bar that work must clear. Declare your vision and let agents build it.

fix(landing): spread active shards across idle runners [C7,V4]

Corey Olson0ae98cd694cd
diff --git a/src/resources.js b/src/resources.js
index 7a21f596..a7f40281 100644
--- a/src/resources.js
+++ b/src/resources.js
@@ -464,12 +464,15 @@ function gateAdmission(db, ticket, capacity, shortCapacity, runners, order = ARR
return { host: '', slots: capacity, browser: waiter.browser === 1 ? 1 : 0, shortSlot: false };
}
if (waiter.remote === 1) {
- for (const runner of runners) {
- if (unavailable.has(runner.host) || (waiter.browser === 1 && runner.browser < 1)) continue;
+ const compatible = runners.filter(runner => {
+ if (unavailable.has(runner.host) || (waiter.browser === 1 && runner.browser < 1)) return false;
const used = usage.get(runner.host);
- if (used.slots >= runner.slots || (waiter.browser === 1 && used.browsers >= runner.browser)) continue;
- return { ...runner, shortSlot: false };
- }
+ return used.slots < runner.slots && (waiter.browser !== 1 || used.browsers < runner.browser);
+ });
+ // A landing spreads its active shards before filling another slot on the same runner.
+ // Choose under this transaction's holder snapshot, so concurrent acquisitions cannot tie on stale use.
+ if (waiter.landing === 1) compatible.sort((left, right) => usage.get(left.host).slots - usage.get(right.host).slots);
+ if (compatible.length) return { ...compatible[0], shortSlot: false };
}
const earlierLanding = waiters.some(other => other.landing === 1 && other.ticket < waiter.ticket);
if (waiter.shortEligible === 1 && !earlierLanding && localShortUsed < shortCapacity
diff --git a/test/landing-shards.test.js b/test/landing-shards.test.js
index 7d99ee3b..3f9f4666 100644
--- a/test/landing-shards.test.js
+++ b/test/landing-shards.test.js
@@ -16,6 +16,44 @@ const BIN = join(SOURCE, 'bin', 'pullboard.js');
const HOST = 'fixture-host';
const NAMES = ['a', 'b', 'c', 'd', 'e', 'f'];
+test('six shards land on six different runners [C7,V4]', (t) => {
+ const box = fixture({ runner: false });
+ t.after(() => rmSync(box.dir, { recursive: true, force: true }));
+ const hosts = NAMES.map(name => `fixture-${name}`);
+ for (const host of hosts) {
+ const added = runFixtureChild(process.execPath, [BIN, 'runner', 'add', host, '--slots', '4', '--browser', '4', '--json'],
+ { cwd: box.repo, env: box.env, encoding: 'utf8' });
+ assert.equal(added.status, 0, added.context);
+ }
+ const script = `import { withGateSlot } from ${JSON.stringify(pathToFileURL(join(SOURCE, 'src/gate.js')).href)};
+import { runLandingShards } from ${JSON.stringify(pathToFileURL(join(SOURCE, 'src/landing-shards.js')).href)};
+const root = ${JSON.stringify(box.repo)};
+const calls = [];
+let release;
+const allStarted = new Promise(resolve => { release = resolve; });
+const remoteRun = async (_root, _command, options) => {
+ calls.push(options.runner.host);
+ if (calls.length === 6) release();
+ await allStarted;
+ return { isGreen: true, output: '' };
+};
+// Hold the two real local slots, so all six shards must acquire actual registered runner leases.
+const result = await withGateSlot(root, () => withGateSlot(root, () => runLandingShards({ root,
+ runner: ${JSON.stringify(join(box.repo, 'bin/run-tests.js'))},
+ files: ${JSON.stringify(NAMES.map(name => `./test/${name}.test.js`))}, count: 6, remoteRun, write: () => {},
+}), { remote: false, kind: 'check' }), { remote: false, kind: 'check' });
+process.stdout.write(JSON.stringify({ green: result.isGreen, calls }));`;
+ const env = { ...box.env };
+ delete env.NODE_TEST_CONTEXT;
+ const result = runFixtureChild(process.execPath, ['--input-type=module', '-e', script],
+ { cwd: box.repo, env, encoding: 'utf8' });
+ assert.equal(result.status, 0, result.context);
+ const measured = JSON.parse(result.stdout);
+ assert.equal(measured.green, true);
+ assert.equal(measured.calls.length, 6, 'all six shards used the registered runner admission path');
+ assert.deepEqual([...new Set(measured.calls)].sort(), hosts, 'every runner gets a shard before another gets two');
+});
+
/** Run Git in a fixture repository and fail with its context. */
function git(cwd, env, ...args) {
const result = runFixtureChild('git', args, { cwd, env, encoding: 'utf8' });