Skip to content

fix(server): make the queue ETA count the long file running now, so clients stop picking a busy box - #476

Merged
GeiserX merged 5 commits into
mainfrom
fix/b120
Oct 29, 2026
Merged

GeiserX merged 5 commits into
mainfrom
fix/b120

Conversation

@GeiserX

@GeiserX GeiserX commented Oct 29, 2026

Copy link
Copy Markdown
Owner

Problem

A client that picks the fastest server reads queue.eta_seconds and queue.mean_job_seconds from /healthz or /v1/server, and both numbers can point it the wrong way.

  • eta_seconds was the jobs left, in rounds of server.concurrency, times the mean running time of the last 50 jobs. It knew nothing about the job running now. With one long file running and nothing queued, the box reported one mean's worth of wait, a few seconds, while the file still had well over an hour left. A short note sent there waited behind it until its own deadline.
  • mean_job_seconds is a plain per-job mean. After a few long files, a fast idle box shows a large mean and looks like the slowest one.

Fix

  • The queue keeps the running time and the audio length of the last 50 jobs and publishes seconds_per_audio_second: their running times summed over their audio summed. Long files no longer swing it. A failed job has no audio and counts in the mean only. mean_job_seconds stays as it was, for clients that read it.
  • eta_seconds is now the longest of the concurrency slots. A slot starts with what its running job has left: the audio not yet done (total_s - done_s from its progress) times that rate, or the mean while its length is unknown (during decode, or before any job with audio is done). Each queued job adds the mean to the slot that frees first. A job out on a remote runs beside the slots, using the length and progress the remote reports (the remote's done_s is now kept too).
  • Known gap, documented: a queued long file still counts at the mean, since its length is known only at its decode.
  • The retry time of a queue_full refusal (SV-Q3) is unchanged.

Docs: SV-Q4 points at a new SV-Q5 row in docs/ux/SERVER.md, plus the GET /v1/server description (docs/api/openapi.json, regenerated) and docs/server-hardware.md.

Evidence

  • tests/queue-eta.test.ts: the pure queueEta cases (one long file with an empty queue, unknown total_s, slots shared by short and long jobs, a remote job) and three cases on a live JobService: a 300 s file running with an empty queue after 10 s of audio ran in 2 s reads eta_seconds 60; a remote job with 1000 s left reads 200, then 60 once the remote reports 900 s done; ten short notes plus four long files move the mean from about 1 s to over 160 s while seconds_per_audio_second stays 0.1.
  • Positive control: with eta_seconds put back to the old formula, the long-file case reads 2 instead of 60 and the remote case times out; both fail.
  • tests/job-queue.e2e.test.ts checks the field is a number on /v1/server after real jobs ran. The existing SV-Q4 ETA tests pass unchanged.

@coderabbitai

coderabbitai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 41 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
Commits

Reviewing files that changed from the base of the PR and between aabcec6 and e381a10.

Files selected for processing: 8
  • docs/api/openapi.json
  • docs/server-hardware.md
  • docs/ux/SERVER.md
  • src/main/api/routes/server.ts
  • src/main/server/jobs.ts
  • src/main/server/remotes.ts
  • tests/job-queue.e2e.test.ts
  • tests/queue-eta.test.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

…ce alone

A job forwarded to a remote waits in the remote's queue and runs at the remote's pace, so timing it from the send would make this box look as slow as the remote's backlog. It is not timed today, because dispatch hands it on as its queued row. The new test ends a forwarded job after a long wait there and checks that the mean, the per-audio rate and the local slot's ETA stay as they were; passing the claimed row instead turns it red.
@GeiserX

GeiserX commented Oct 29, 2026

Copy link
Copy Markdown
Owner Author

A review flagged that a job forwarded to a remote would feed its time, from the send to the end, into the new per-audio rate, so a fast box with a busy remote would publish the remote's backlog as its own pace and price its local slots with it.

That does not happen. dispatch claims the job in the store, then hands runRemote the row it read from store.queued(), spread with status: "running". That row still has running_at: null, so when the forwarded job ends, measure counts it in jobs_last_hour and audio_seconds_last_hour and skips runTimes. It stays out of mean_job_seconds too, which matches what SV-Q4 says the mean is: jobs this process ran from their start.

No test covered a forwarded job ending, so e381a10 adds one in tests/queue-eta.test.ts. A 60 s job sits 6000 s in the fake remote's queue and then ends there, with a 300 s local file running. The test checks that the hour's counts take the job and that mean_job_seconds (2), seconds_per_audio_second (0.2) and the local eta_seconds (60) do not move. Positive control: with dispatch changed to pass the claimed row (this.store.job(j.id), which has running_at set), the test fails on all three. The commit also adds a comment on measure and one sentence to SV-Q5 in docs/ux/SERVER.md saying that a job sent to a remote counts in neither the mean nor the rate.

@GeiserX
GeiserX merged commit e7cd7db into main Oct 29, 2026
29 checks passed
@GeiserX
GeiserX deleted the fix/b120 branch October 29, 2026 02:01
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.

1 participant