fix: stop the boss-attack button abandoning its own target immediately
Found this by reproducing locally (installed a Go toolchain + helm earlier in this session; this time added Chromium anti-throttling flags and instrumented walkTo/pendingAction/keys onto window.__aeternalis to watch it live) rather than guessing from CI logs again: the "Target Harbinger" button sets pendingAction/walkTo directly, bypassing action() entirely -- so the give-up budget from the last commit, which only got initialized inside action(), read Date.now() against its initial value of 0 on the very first tick after clicking. That's always "expired" by billions of milliseconds, so it gave up on "boss" immediately, blacklisted it, and reselected the nearest sentinel mob instead -- explaining every "boss out of reach" / zero-progress boss failure we've chased across the last several rounds. Confirmed via a throwaway diagnostic test logging position/target every second: the character walked calmly away from the boss it started standing on top of, chasing first one sentinel then another. Fixed the immediate bug (also set the budget's clock in the button's handler), then found a second one the same repro immediately exposed: attack against a live target is *mostly* cooldown rejections between the hits that land, so "no progress since the initial click" was still wrong -- it gave up mid-fight after ~10 successful hits during a lull. Replaced the give-up condition with an actual progress signal (target HP for attack, held-item count for gather/loot); it now only gives up once that has genuinely stopped moving, confirmed via the same diagnostic: 10 clean hits (1200 -> 1020 HP) holding position, matching the server's own attack cooldown. Also added the standard Chromium flags (--disable-background-timer-throttling etc.) to the test browser launch: the CI logs' 2-11s gaps between retries (instead of the intended ~0.3s) are the classic signature of requestAnimationFrame throttling down to ~1Hz for a backgrounded/occluded headless tab, which independently made every frame-driven client action crawl. Left walkTo/pendingAction/keys exposed on window.__aeternalis since they were useful for this and will be again. Verified: tsc/build clean, and three full local e2e runs (7/7 each) all show the boss test landing clean periodic hits via "attack cooldown" rejections between them, never wandering to a mob. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
+27
-10
@@ -19,11 +19,26 @@ let inputElapsed = 0;
|
||||
let walkTo: { x: number; z: number } | undefined;
|
||||
let pendingAction: { op: string; target: string } | undefined;
|
||||
let actionElapsed = 0;
|
||||
let actionAttempts = 0;
|
||||
// A gather target can stay legitimately, persistently unreachable for a long time (a
|
||||
// depleted resource waits out a real respawn timer measured in minutes, not a stray
|
||||
// frame) -- retrying it forever would starve everything else. Give up on a target after
|
||||
// a few tries and steer the next action() call to a fresh one instead.
|
||||
// frame) -- retrying it forever would starve everything else. But a *working* attack is
|
||||
// mostly cooldown rejections between the hits that land, so "stuck" can't just mean
|
||||
// "hasn't succeeded since the click": it has to mean no progress at all for a while.
|
||||
// Track a per-target progress signal (target HP for attack, held-item count for
|
||||
// gather/loot) and only give up once that's stopped moving for a wall-clock budget --
|
||||
// not a frame/attempt count, since a throttled or backgrounded tab can go seconds
|
||||
// between rendered frames, and counting attempts instead of real elapsed time let a
|
||||
// "few tries" balloon into tens of real seconds.
|
||||
let lastProgress: number | undefined;
|
||||
let lastProgressAt = 0;
|
||||
function progressSignature(): number | undefined {
|
||||
if (!pendingAction || !snapshot) return undefined;
|
||||
if (pendingAction.op === 'attack') {
|
||||
if (pendingAction.target === 'boss') return snapshot.world.bossHp;
|
||||
return snapshot.entities.find(e => e.id === pendingAction!.target)?.hp;
|
||||
}
|
||||
return Object.values(snapshot.self.inventory).reduce((a: number, b: number) => a + b, 0);
|
||||
}
|
||||
const avoidUntil = new Map<string, number>();
|
||||
let requestedClose = false;
|
||||
const keys = new Set<string>();
|
||||
@@ -60,7 +75,7 @@ function action(op: string) {
|
||||
selection(target);
|
||||
pendingAction = { op: target.kind === 'corpse' ? 'loot' : op, target: target.id };
|
||||
walkTo = target.position;
|
||||
actionAttempts = 0;
|
||||
lastProgress = undefined; lastProgressAt = Date.now();
|
||||
}
|
||||
function connect() {
|
||||
requestedClose = false; sequence = 0;
|
||||
@@ -174,13 +189,15 @@ async function boot() {
|
||||
// under the intent rate limit) instead of giving up forever -- the server's
|
||||
// own action cooldown makes repeat attempts harmless. But a target can also be
|
||||
// legitimately, persistently rejected (a depleted resource waits out a real
|
||||
// respawn timer), so give up on THIS target after a few tries and let the next
|
||||
// action() pick a fresh one rather than retrying a lost cause indefinitely.
|
||||
// respawn timer), so give up on THIS target after a wall-clock budget and let
|
||||
// the next action() pick a fresh one rather than retrying a lost cause forever.
|
||||
else {
|
||||
actionElapsed += dt;
|
||||
if (actionElapsed >= 0.3) {
|
||||
actionElapsed = 0;
|
||||
if (++actionAttempts > 8) {
|
||||
const sig = progressSignature();
|
||||
if (sig !== undefined && sig !== lastProgress) { lastProgress = sig; lastProgressAt = Date.now(); }
|
||||
if (Date.now() - lastProgressAt > 5000) {
|
||||
avoidUntil.set(pendingAction.target, Date.now() + 8000);
|
||||
const retryOp = pendingAction.op === 'loot' ? 'gather' : pendingAction.op;
|
||||
walkTo = undefined; pendingAction = undefined;
|
||||
@@ -188,7 +205,7 @@ async function boot() {
|
||||
} else { send(pendingAction.op, pendingAction.target); }
|
||||
}
|
||||
}
|
||||
} else { x = dx / distance; z = dz / distance; actionElapsed = 0.3; actionAttempts = 0; }
|
||||
} else { x = dx / distance; z = dz / distance; actionElapsed = 0.3; }
|
||||
}
|
||||
view.moving = !!(x || z);
|
||||
if (inputElapsed >= 0.05) { send('move', '', x, z); inputElapsed = 0; }
|
||||
@@ -228,7 +245,7 @@ async function boot() {
|
||||
for (const id of ['inventory', 'settings']) { $(`${id}-toggle`).onclick = () => { visible(id, $(id).hidden); visible('movement', $('inventory').hidden && $('settings').hidden && !!snapshot); if (id === 'inventory' && snapshot) inventory(snapshot.self); }; }
|
||||
document.querySelectorAll<HTMLButtonElement>('[data-close]').forEach(button => button.onclick = () => visible(button.dataset.close!, false));
|
||||
$('attack').onclick = () => action('attack'); $('gather').onclick = () => action('gather'); $('heal').onclick = () => send('heal'); $('keystone').onclick = () => send('return');
|
||||
$('target-boss').onclick = () => { selection(snapshot?.entities.find(e => e.id === 'boss')); walkTo = { x: 0, z: 0 }; pendingAction = { op: 'attack', target: 'boss' }; };
|
||||
$('target-boss').onclick = () => { selection(snapshot?.entities.find(e => e.id === 'boss')); walkTo = { x: 0, z: 0 }; pendingAction = { op: 'attack', target: 'boss' }; lastProgress = undefined; lastProgressAt = Date.now(); };
|
||||
$('dev-boss').onclick = () => void api('/api/dev/boss', {}).catch(e => notice(e.message));
|
||||
$('reconnect').onclick = () => location.reload();
|
||||
$('new-character').onclick = () => { requestedClose = true; ws?.close(); location.reload(); };
|
||||
@@ -257,6 +274,6 @@ async function boot() {
|
||||
if (hit.entity) { selection(hit.entity); action(['boss', 'sentinel'].includes(hit.entity.kind) ? 'attack' : 'gather'); }
|
||||
else if (hit.point) { selection(); walkTo = hit.point; pendingAction = undefined; }
|
||||
});
|
||||
Object.defineProperty(window, '__aeternalis', { value: { diagnostics: () => view.diagnostics(), get snapshot() { return snapshot; } }, configurable: true });
|
||||
Object.defineProperty(window, '__aeternalis', { value: { diagnostics: () => view.diagnostics(), get snapshot() { return snapshot; }, get walkTo() { return walkTo; }, get pendingAction() { return pendingAction; }, get keys() { return [...keys]; } }, configurable: true });
|
||||
}
|
||||
boot().catch(error => { console.error(error); $('arrival-error').textContent = `Unable to enter the world: ${error.message}`; $('connection-status').textContent = 'Unavailable'; });
|
||||
|
||||
+10
-1
@@ -2,7 +2,16 @@ import { defineConfig } from '@playwright/test';
|
||||
|
||||
export default defineConfig({
|
||||
testDir: './tests', timeout: 45000, workers: 1, fullyParallel: false,
|
||||
use: { baseURL: 'http://127.0.0.1:18089', browserName: 'chromium', channel: process.env.PLAYWRIGHT_CHANNEL || undefined, headless: true, screenshot: 'only-on-failure', trace: 'retain-on-failure', launchOptions: { args: ['--use-angle=swiftshader', '--enable-unsafe-swiftshader'] } },
|
||||
use: { baseURL: 'http://127.0.0.1:18089', browserName: 'chromium', channel: process.env.PLAYWRIGHT_CHANNEL || undefined, headless: true, screenshot: 'only-on-failure', trace: 'retain-on-failure', launchOptions: { args: [
|
||||
'--use-angle=swiftshader', '--enable-unsafe-swiftshader',
|
||||
// The CI runner's headless page was getting treated as backgrounded/occluded,
|
||||
// which throttles requestAnimationFrame to ~1Hz or worse -- turning every
|
||||
// frame-driven client action (movement steering, gather/attack retries) into a
|
||||
// multi-second-per-tick crawl and blowing well past assertion timeouts even
|
||||
// though the server side was fine. These are the standard flags to keep a
|
||||
// headless/automated tab running at full rAF rate regardless of visibility.
|
||||
'--disable-background-timer-throttling', '--disable-backgrounding-occluded-windows', '--disable-renderer-backgrounding',
|
||||
] } },
|
||||
webServer: {
|
||||
command: 'node tools/dev-server.mjs', url: 'http://127.0.0.1:18089/readyz',
|
||||
timeout: 180000, reuseExistingServer: false,
|
||||
|
||||
Reference in New Issue
Block a user