Skip to content

fix(daemon): accept a negative log offset for tail reads - #13

Merged
XuehaiWang merged 1 commit into
mainfrom
fix/log-tail-offset
Nov 25, 2026
Merged

XuehaiWang merged 1 commit into
mainfrom
fix/log-tail-offset

Conversation

@kiri603

@kiri603 kiri603 commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

What and why

Run detail (Overview tab) showed "No output." for the Log tail card and fired two 400 Bad Requests on every load:

GET /api/v1/runs/:id/logs?offset=-16384&limit=16384
-> 400 {"error":"query number must be a non-negative safe integer"}

Root cause: GET /runs/:id/logs parsed offset with the non-negative num() helper (packages/orbit/src/daemon/http.ts), while the documented tail-read convention is a negative offset. records.readLog (packages/orbit/src/records/index.ts) already implements it (offset < 0 ? Math.max(0, size + offset) : Math.min(offset, size), plus skipping the first partial line), and three existing callers depend on it:

  • packages/web/src/pages/run/Overview.tsx: api.logs(id, -16 * 1024, 16 * 1024)
  • packages/orbit/src/feishu/index.ts: offset=-4096&limit=4096
  • packages/orbit/src/cli/program.ts: -o.tail ? -o.tail : 0

The route was the only place rejecting it. This fixes the contract at the daemon instead of changing the Web caller.

Changes

  • packages/orbit/src/daemon/http.ts: new signed() query helper — a safe integer, negative allowed, raising query number must be a safe integer otherwise.
  • packages/orbit/src/daemon/routes/runs.ts: parse the log offset with signed(); limit stays non-negative via num().
  • packages/orbit/test/daemon.test.ts: drop the log offset entry from the rejects-negatives table; add a non-integer offset table (1.5, 1e21, 9007199254740992, NaN, Infinity, abc -> 400 "safe integer") and a tail-read test (-6 -> third\n with next 19; -4096 and 0 -> whole log).
  • packages/orbit/test/security-api.test.ts: end-to-end tail read through createApp on a terminal run (-6 -> {offset: 13, next: 19, text: "third\n"}), plus a fractional offset -> 400.
  • docs/design.md: the numeric-query-parameter rule now states that only the log offset may be negative (tail read) and the rest must be non-negative.

Validation

Tested revision: this commit on top of 8e5cd9b. Windows 11, Node v22.19.0.

Check Result Notes
biome check (changed files) passed
tsc -p packages/orbit/tsconfig.json --noEmit passed
vitest run packages/orbit/test/security-api.test.ts 10 passed / 2 failed The 2 failures are the pre-existing serves ordinary and empty files... refuses escaping links cases (EPERM: operation not permitted, symlink), which fail on this box because it lacks symlink rights. The new tail-read case passes.
vitest run packages/orbit/test/daemon.test.ts not_run The daemon cannot start here: packages/orbit/src/lib/lock.ts reads /proc/<pid>/stat for the process start time, which does not exist on Windows, so acquireProcessLock throws cannot determine process start time. Same for port.daemon.test.ts, bench.daemon.test.ts, cluster.daemon.test.ts.
Browser check against a real daemon passed Same Web build, backend before/after: the request went 400 -> 200 and the Log tail card rendered the tail (09:14:35 ... 09:14:44 [orbit] lease granted), with no remaining /api/ error responses. Also checked a failed run and a running run.

pnpm verify was not run as a whole locally: this box has no pnpm, no Docker, and the daemon-based tests cannot start (see above). The CI verify job (ubuntu-24.04, Node 24.18) passed on this commit, including pnpm smoke:package.

  • pnpm verify passes — run by CI on ubuntu-24.04 / Node 24.18 (job verify, green); not run on the Windows dev box, see Validation
  • Task record / design / status updated when needed (docs/design.md query-parameter rule)

How to verify

git fetch origin && git switch fix/log-tail-offset
pnpm install
pnpm verify

Then in the Web UI open any finished run -> Overview: the Log tail card shows the tail instead of "No output."

GET /runs/:id/logs parsed offset with the non-negative num() helper, so
Web's log tail request (offset=-16384) failed with 400 and the run page
showed an empty log. records.readLog already documents a negative offset
as tail bytes, and the Feishu watcher and CLI --tail rely on it.

Parse offset with a new signed() helper; limit stays non-negative. Cover
the tail read and non-integer offsets, and update the design note.
@kiri603
kiri603 requested a review from XuehaiWang as a code owner November 21, 2026 13:17
@XuehaiWang
XuehaiWang merged commit cdff042 into main Nov 25, 2026
1 check passed
@crepuscular-drizzle
crepuscular-drizzle deleted the fix/log-tail-offset branch November 26, 2026 11:29
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.

2 participants