Skip to content

feat(storage): keep run context and config snapshots out of control.sqlite - #1405

Merged
zhaozhaozz merged 3 commits into
agent-CI-Infra:mainfrom
zhaozhaozz:feat/issue-1403-bodies-out-of-db
Nov 26, 2026
Merged

zhaozhaozz merged 3 commits into
agent-CI-Infra:mainfrom
zhaozhaozz:feat/issue-1403-bodies-out-of-db

Conversation

@zhaozhaozz

@zhaozhaozz zhaozhaozz commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Refs #1403 (phase 1 of 4, see the plan).

What

task_runs.context_snapshot / config_snapshot are the largest bodies in control.sqlite (≈37 GB of 87 GB, 476 KB + 54 KB per run). They now live in the trajectory file store:

  • New runs (beginRun, src/tasks/trace.ts): a snapshot larger than 2 KiB is appended to the run's trajectory file as one event record before the row is inserted. The column keeps a header only: {"$trajectory":"<file>:<offset>:<length>:<sha256>","schema_version":1,"sha256":…,"original_bytes":…,"complete":…} (≈250 bytes). Smaller snapshots stay inline.
  • No duplicate bodies: when the context is identical to the one the task's latest run stored (same sha256 and size, record not expired), the new row points at that record instead of writing it again. The lookup reads octet_length(context_snapshot) first, so a latest run that still holds a whole legacy snapshot costs one record header, not its body (measured: 1.1 ms vs 689 ms for 100 rows of 4 MB).
  • One reader (runSnapshot(), src/storage/payloads.ts) returns the exact text traceSnapshot produced, for migrated, unmigrated and small inline rows alike. An unreadable record (missing, truncated, expired file) reads as {complete:false, missing_reason} like every other trajectory-backed source.
  • Existing rows move through a new task_runs phase of PayloadMigration (first in the walk, since it is the largest): rowid slices, files synced off the event loop, every record read back against its hash before the row's columns are replaced; resumable from its cursor. Runs of a task with the same context share one record here too. Records are appended through the migration's own append(), so like every other phase its open files are bounded: openFiles (32) kept between slices plus the files of the slice being moved (a slice reads for at most readMs and at most 200 rows). A row that runs out of descriptors or memory (EMFILE/ENFILE/ENOMEM), while being moved or while its records are read back, is read again after a pause instead of being counted failed and passed by the cursor; TrajectoryError now carries the file system error as its cause so the read-back case is recognised. A snapshot whose text is not the canonical JSON of its value (never written by the bot; only hand-made rows) stays in its column so it still reads byte-identical.

Read paths covered

  • traceSource(task, 'task_runs:<id>:context|config'), which serves the task trace API (section=source, and section=runs&include_snapshots=1) and every tool that reads trace references: read_task_record (Manager/team, retries, long execution, Manager recovery, consolidation), the role gateway's trace read, and task commands.
  • recoverRoleCheckpoint (src/roles/recovery.ts), which compares the dev run's source_sha.
  • Nothing filters on these columns (json_extract or otherwise), so no extra column or index is needed.

Side effects: columns added after the snapshots (role, harness, lease_scope, run_context, …) no longer sit behind ~0.5 MB of overflow pages, so per-run reads of them (the role gateway's SELECT * FROM task_runs WHERE id=? on every gateway call, board/flow queries on role) and every UPDATE task_runs (status, lease, recovery mode, CLI version) stop reading/rewriting the snapshot bodies once a row is new or migrated.

Bytes per day (production, read-only sample 2026-11-19 → 11-26)

per day
runs started 4,534 (31,738 in 7 days; 64% attempt)
snapshot bytes written into control.sqlite before ≈2.11 GB (context 2.03 GB, config 0.09 GB)
after ≤ 18 MB (a ≈250-byte header per moved snapshot; at most two columns of ≤ 2 KiB per run stay inline)
written to trajectory files instead ≤ 2.11 GB; up to 58% of the context bytes (8.28 of 14.19 GB that week) had the same size as the task's previous run and are shared instead when their sha256 matches

The existing ≈37 GB (69.7 k rows) move in the background after deploy (storage page → 历史数据迁移 → task_runs). The database file only shrinks after a compaction, which needs downtime and separate approval; it will be planned with measurements on a copy once all phases are in.

Background migration speed (synthetic copy)

.tmp benchmark on this branch (not committed): 1,000 legacy runs, 260 KB context + 21 KB config each, half of them on the same context as the task's previous run, default PayloadMigration options on a local disk:

moved 1,000 rows, 281 MB, 0 failed, 14.8 s (67 rows/s, ≈19 MB/s)
left in the columns 495 KB (headers)
trajectory files written 151 MB (500 context records for 1,000 runs)
longest event-loop block 44 ms (p99 33 ms)

At that rate production's ≈37 GB would take about half an hour of slices on an idle disk; with production's IO pressure expect a few times longer. It only pauses for the disk reserve, like the other phases.

Retention

New records live in the run's trajectory file, migrated ones in the task's legacy trajectory file, so they follow trajectory_days like the run's other records (unset in production = keep everything) and are removed with the project. One difference when trajectory_days is set: a shared context record stays in the earlier run's file, so a later run's context snapshot expires with that earlier file, possibly before the later run's other records (stated in docs/design/storage-and-knowledge.md).

Tests

New or changed tests:

  • test/ut/src/tasks/task-trace.test.mjs: new runs keep only a header in both columns and the record sits in the run's own file; trace source and include_snapshots=1 read the whole snapshot; an unchanged context shares the record, a changed one does not; a small snapshot stays inline; an expired record reads as trajectory_expired and is never shared; a legacy inline row reads as before.
  • test/ut/src/storage/trajectory-migration.test.mjs: the legacy fixture now has runs (shared context, small config, non-canonical text); every trace source reads identically before and after the migration, including across a restart mid-walk; runs of a task share one context record; 40 tasks with openFiles: 4 never hold more than 5 migration files open and leave no descriptor into trajectories/ (fails before the fix with 40); a row whose append hits EMFILE is moved after a pause, not counted failed (fails before the fix); a slice whose read-back hits EMFILE is read again with failed: 0 (fails without the cause check), and read()/getBlob() of a missing file carry cause.code === 'ENOENT'; task_runs is read by rowid ranges.
  • test/st/src/roles/roles.test.mjs: recoverRoleCheckpoint reconciles from a dev run whose context is in its trajectory record.
  • test/st/src/agent/agent-runtime.test.mjs: the immutable run config is read through runSnapshot().

Local record for head 3323cfa8 (on 4a407415, current main):

command exit result
npm run check 0
BOT_TEST_JOBS=8 npm test 1 2864 / 2866; only failed set runner-transport
TMPDIR=$PWD/.tmp/s node --test test/ut/manager/runner-transport.test.mjs 0 4 / 4: the known EADDRINUSE from a Unix socket path over 108 bytes in this deep worktree

Older records below are for the earlier heads.

Local record for head ddf655b3 (on a6c824ca). Head 5aea0415 is the same two commits rebased onto 4a407415 (#1406) without conflicts (git range-diff shows both patches identical; docs/features/deployment-and-operations.md keeps main's rate-limit sentence and adds this PR's line); on it npm run check exited 0, and the npm test record below still applies to this code:

command exit result
npm ci / (cd runner && npm ci) 0 / 0 lockfiles unchanged since
npm run check 0
BOT_TEST_JOBS=8 npm test 1 2858 / 2861; failed sets distributed-nodes (node_agent_connect_timeout), runner-transport
node test/framework/test-sets.mjs --jobs 1 test/st/src/cluster/distributed-nodes.test.mjs 0 5 / 5
TMPDIR=$PWD/.tmp/s node --test test/ut/manager/runner-transport.test.mjs 0 4 / 4: the full-suite failure is the known EADDRINUSE from a Unix socket path over 108 bytes in this deep worktree

The review's reproduction on this head (1,500 tasks × 2 legacy runs, ulimit -n 1024, default options, .tmp probe): migrated 3000, failed 0, 0 rows still holding a whole snapshot, 0 descriptors into trajectories/ left open afterwards; sampling every 20 ms saw at most 37 at once, and the bot review measured peaks of ~130 with small rows (32 kept + one slice's files). The review measured 1,005 rows failing with EMFILE on a2cfd24e in that setup.

Earlier head a2cfd24e: npm run check 0; npm test 2852 / 2859 (codex-harness wall-clock budgets under load, runner-transport socket path); codex-harness alone failed only the "Codex model reroute" wall-clock test, which also fails on main under the same load (4.8–6.8 s from interrupt to end, budget 3.5 s); CI unit passed it.

@zhaozhaozz

Copy link
Copy Markdown
Collaborator Author

Blocking: the new task_runs migration phase bypasses the descriptor bound that every other migration phase relies on, and at production scale it will run into EMFILE.

Where

src/storage/migration.ts:198-214 (the new phase). At line 207 it calls storedRunSnapshot(), and src/storage/payloads.ts:124 appends through store.trajectories.append(). That is not the migration's own append() (src/storage/migration.ts:164-167), which registers the scope in touched so that closeTouched(this.options.openFiles ?? 32) (line 151, openFiles default 32, also called with 0 at the end of a pass) closes it.

Trajectories.handle() keeps exactly one descriptor per scope in its open map, and the only other thing that closes such a file is the idle timer (Trajectories.closeIdle, idleMs default 30 min). No migration code ever adds these scopes to touched, so the migration never closes the legacy files it opens; they stay open until the idle timer fires.

Expected vs actual

  • Expected: at most openFiles (32) legacy trajectory files open at a time while the phase runs, the same bound task_tools, model_requests, task_logs and task_history get by appending through this.append().
  • Actual: one open descriptor per task whose runs are migrated, held for 30 minutes after the file's last append. The peak is the number of distinct task files appended within any 30-minute window.

Evidence (built this head a2cfd24e, fixture: N tasks, 2 legacy runs each, snapshots > 2 KiB)

run result
400 tasks, default limits phase migrated: 800, failed: 0; 400 descriptors into trajectories/ still open after the phase finished (0 before it)
1,500 tasks, ulimit -n 1024 failed: 1005, last_error: "task_runs rowid 3000: EMFILE: too many open files, open '.../task-1499/legacy.jsonl'"; 1,005 of 3,000 rows still hold their whole snapshots

ulimit -n 1024 is the soft limit of this deployment's control-plane container (docker exec bot-bot-1 ulimit -n → 1024, hard 524288), i.e. the same Compose service this PR deploys into.

At production's numbers from the PR description (69.7k runs over ~9.4k tasks, ≈19 MB/s on an idle disk, "a few times longer" under IO pressure) a 30-minute window holds roughly 1.5k–4.7k distinct task files, and a ~30-minute pass holds all of them, so the phase reaches the descriptor limit well before the table is walked.

Impact

  1. EMFILE is counted as a row failure and the read loop then advances the cursor past the row; the phase marks itself finished_at and later passes start at WHERE rowid > cursor, so those rows are never retried. The 37 GB this PR is about stay in control.sqlite and the storage page only shows a failed count.
  2. While the control plane is at the limit, unrelated openSync/accept calls fail too (my probe could not even open /proc/self/fd at that point), so the background migration can break webhook, manager and model-gateway file/socket opens for its duration.

Suggested fix

  1. Append through the migration's own append() so closeTouched() bounds the descriptors: for example let storedRunSnapshot() take an optional append callback ((scope, type, id, data) => this.append(scope, type, id, data)), or split "build the header" from "append the record" and append in the phase.
  2. Add a regression test that migrates more tasks than openFiles and asserts the descriptor count stays bounded (e.g. count /proc/self/fd links into <store>/trajectories on Linux, or expose the open-handle count), plus that no row keeps its body under a low ulimit -n.
  3. Consider not advancing the cursor past a move that failed with EMFILE/ENFILE/ENOMEM, or leaving the phase unfinished while failed > 0, so a transient resource error is retried instead of silently leaving the largest bodies in the database.

Non-blocking note: retention of shared records

storedRunSnapshot() (src/storage/payloads.ts:122-124) lets a new run reference the record in an earlier run's file, and that reference is not bounded by age. With trajectory_days set, a file expires trajectory_days after it was closed, and the latest run's column may point all the way back to the task's first identical context, so a run started today can read trajectory_expired as soon as that oldest file expires, while its own file is still inside the window. The PR body says "Retention unchanged in effect"; either bound the reuse (for example only share with records from files younger than the project's window) or state the behavior in docs/design/storage-and-knowledge.md.

Verified without findings

  • Both columns are only read through runSnapshot(): traceSource (src/tasks/trace.ts:175), the runs view with include_snapshots=1 (same function), and recoverRoleCheckpoint (src/roles/recovery.ts:11); there is no other context_snapshot/config_snapshot reader in src/.
  • src/storage/migration.ts:206 keeps non-canonical snapshot text inline, so an unmigrated row still reads byte-identically, and the JSON.stringify(JSON.parse(text)) guard is the same transformation runSnapshot() performs.
  • Syncing only refs.at(-1) per move is still sufficient: both refs of a task_runs move belong to the same legacy file (reuse is per task), and sync() fdatasyncs the file.
  • docs/features/deployment-and-operations.md and docs/design/storage-and-knowledge.md are both updated; no verification artifacts or workflow files in the diff; the branch is a single linear commit on current main.

@agent-ci-infra-bot agent-ci-infra-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed commit: a2cfd24
Coverage: PR #1405; 10 changed file(s)

Comment thread src/storage/payloads.ts Resolved
@agent-ci-infra-bot

agent-ci-infra-bot Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

第 3 次检视,更新于 2026-11-26 10:47 UTC,检视提交 3323cfa

Review — head 3323cfa8, base 4a407415 (11 files, +242/−30)

Round 3. Since the last review the branch was rebased onto 4a407415 (#1406; the two commits replay unchanged) and got one new commit, 3323cfa8, which addresses F2. That commit touches only src/storage/migration.ts, src/storage/trajectories.ts and its test, so the rebase added nothing outside the PR.

F1 — answered/resolved. Unchanged: docs/design/storage-and-knowledge.md documents that a shared context record expires with the earlier run's file when trajectory_days is set; default (null, production) is unaffected. Inline thread resolved.

F2 — fixed. TrajectoryError now carries the file system error as cause (src/storage/trajectories.ts:31-34, :209, :275) and exhausted() walks the cause chain (src/storage/migration.ts:15-19), so a read-back that hits EMFILE is dropped and retried instead of counted as a failed row. Verified on the same 400-task fixture at ulimit -n 64: the pre-fix build (ddf655b3) ends migrated 594, failed 206, finished true; this head ends migrated 800, failed 0 with retries logged, all rows reading back identical. The new test also asserts the ENOENT cause that keeps a genuinely missing file a failure.

F3 — new (suggestion, medium). A slice retried after descriptor exhaustion appends its records again and never references the lines from the dropped attempt; at ulimit -n 40 (166 retries) the fixture's trajectory files grew from 2.4 MB to 19.1 MB with 5,372 orphan lines, and there is no per-line compaction. Details and fix options in the inline comment. Non-blocking.

Previous note on the old "at most 37" wording is closed: the PR body now states the real bound (openFiles kept between slices plus the slice's files), matching my measurement of ~130 at default options.

Verified at this head

  • npm run check: exit 0 (854 runtime files).
  • node --test test/ut/src/tasks/task-trace.test.mjs test/ut/src/storage/*.test.mjs → 84/84 pass (with the workspace's real TMPDIR; the checkout path is a symlink, which breaks two unrelated fixture tests when TMPDIR=$PWD/.tmp).
  • Probes above are gitignored .tmp scripts against the built dist; all migrated rows compare byte-identical through runSnapshot().

No must-fix issues remain.

Reviewed commit: 3323cfa
Coverage: PR #1405; 11 changed file(s)

已关闭 1 条后续提交已修复的行内意见:src/storage/migration.ts:146。

Reviewed commit: 3323cfa
Earlier heads this review also read: ddf655b
Coverage: PR #1405; 11 changed file(s)

@zhaozhaozz

Copy link
Copy Markdown
Collaborator Author

Thanks, the descriptor finding was right: the task_runs phase appended through store.trajectories.append(), so its legacy files never entered touched. My fixture hid it because every task there also had task_tools rows, and the later phases closed the same legacy files.

Fixed in ddf655b3:

  1. storedRunSnapshot() takes the append to use; the phase passes (scope, type, id, data) => this.append(...), so closeTouched(openFiles) bounds its files like every other phase.
  2. EMFILE / ENFILE / ENOMEM are no longer row failures. When a move hits one, the slice ends before that row; when a read-back hits one, the whole slice is dropped. Either way the migration's files are closed and the row is read again after a pause (exhaustedMs, default 60 s). The cursor never passes it, and the phase cannot be marked finished while it still holds its body. Disk-full handling is unchanged.
  3. Regression tests in trajectory-migration.test.mjs. Both fail on a2cfd24e:
    • 40 run-only tasks with openFiles: 4: never more than 5 migration files open, and no descriptor into trajectories/ afterwards (/proc/self/fd).
    • A row whose append throws EMFILE is moved later and is not counted failed.
  4. Your reproduction on the new head (1,500 tasks × 2 runs, ulimit -n 1024): migrated 3000, failed 0, no row still holding a whole snapshot, at most 37 descriptors into trajectories/ at once, 0 left open afterwards.

On the retention note, I chose to document the behavior rather than change it. docs/design/storage-and-knowledge.md now says that a shared context record stays in the earlier run's file and, with trajectory_days set, expires with that file. The PR description's Retention section says the same and no longer claims "unchanged in effect". Expiry only applies to files of finished tasks, and production keeps everything, so I kept the sharing unbounded.

npm run check and npm test for ddf655b3 are recorded in the description. The branch is still linear on a6c824ca.

…qlite

task_runs.context_snapshot and config_snapshot hold about 37 GB of the
production database (476 KB + 54 KB per run). A snapshot larger than
2 KiB is now appended to the run's trajectory file as one event record;
the column keeps its header (schema_version, sha256, original_bytes,
complete, ...) and the record's ref in $trajectory. A context identical
to the one the task's latest run stored shares that run's record.

Every reader goes through runSnapshot(): traceSource task_runs:<id>:
context|config (the runs view with include_snapshots, the
read_task_record tools) and recoverRoleCheckpoint. Rows written before
this move in the background through a new task_runs migration phase
into the task's legacy trajectory file; they read the same before and
after.

Refs agent-CI-Infra#1403
The task_runs phase appended through store.trajectories.append, so the
legacy files it opened were never registered with the migration and
stayed open until the 30-minute idle close: one descriptor per task,
which reaches EMFILE at production scale. storedRunSnapshot now takes
the append to use and the phase passes the migration's own, which
closes files beyond openFiles after each slice.

A row that runs out of descriptors or memory (EMFILE, ENFILE, ENOMEM)
is no longer counted failed and passed by the cursor: the slice ends
before it (or is dropped when a record cannot be read back for that
reason), the migration's files are closed, and the row is read again
after a pause.

Document that a shared context record expires with the earlier run's
file when trajectory_days is set.

Refs agent-CI-Infra#1403
@zhaozhaozz
zhaozhaozz force-pushed the feat/issue-1403-bodies-out-of-db branch from ddf655b to 5aea041 Compare November 26, 2026 10:09
@zhaozhaozz

Copy link
Copy Markdown
Collaborator Author

Rebased onto 4a407415 (#1406): new head 5aea0415. The two commits replay unchanged (git range-diff reports both identical to a2cfd24e/ddf655b3). The only overlap was docs/features/deployment-and-operations.md, which keeps main's new rate-limit sentence plus this PR's snapshot line. npm run check on 5aea0415: exit 0. The npm test record in the description was taken on ddf655b3 and still covers this code.

@agent-ci-infra-bot agent-ci-infra-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed commit: 5aea041
Earlier heads this review also read: ddf655b
Coverage: PR #1405; 10 changed file(s)

Comment thread src/storage/migration.ts Resolved
…riptors

Trajectories.read() and getBlob() report a file they cannot open as
trajectory_truncated without saying why, so the migration's check for
EMFILE/ENFILE/ENOMEM never matched while reading records back: a slice
verified while the process was out of descriptors counted its rows as
failed and the cursor passed them. TrajectoryError now carries the file
system error as its cause, and the migration looks through it. Readers
see the same code and message as before.

Refs agent-CI-Infra#1403
@zhaozhaozz

Copy link
Copy Markdown
Collaborator Author

New head 3323cfa8 (one commit on 5aea0415, still linear on 4a407415) for F2 from the bot review: the read-back half of the exhaustion handling was unreachable. Trajectories.read()/getBlob() turn any failure to open a file into trajectory_truncated without saying why, so EMFILE during verification was counted as a row failure.

  • TrajectoryError now carries the file system error as cause (readers get the same code and message as before), and the migration's exhausted() looks through it.
  • New test: a slice whose read-back hits EMFILE is read again with failed: 0. It fails without the cause check (failed 1). The test also asserts that read()/getBlob() of a really missing file carry cause.code === 'ENOENT'.
  • Description corrected: the bound is openFiles kept between slices plus the files of the slice being moved, not "at most 37".

npm run check on 3323cfa8: exit 0. The full npm test for this head is running; I will add its record to the description when it finishes.

@zhaozhaozz
zhaozhaozz added this pull request to the merge queue Nov 26, 2026
@zhaozhaozz

Copy link
Copy Markdown
Collaborator Author

Reviewed head 3323cfa818874dbcb187b820dba53c5c6435c7d6 (linear on current main). Verdict: no blocking findings; enqueued for merge.

What I verified on this head:

  • Rebase integrity: the feat commit is byte-identical to the previously reviewed a2cfd24e (only index lines differ), and the branch sits on top of 4a407415; no merge commits, no reverted main content.
  • Descriptor bound: run snapshots now append through the migration's own writer, so legacy files land in touched and get closed by closeTouched(openFiles). The regression test fails with "40 migration files open at once" when the writer parameter is dropped. At production-like scale (1,500 tasks x 2 legacy runs, ulimit -n 1024, default openFiles): 3,000 rows moved, 0 failed, peak 37 descriptors, 0 left after settle, no bodies left in control.sqlite; the parent head failed 1,005 of 3,000 rows with EMFILE.
  • Read-back exhaustion: read()/getBlob() keep the filesystem error as TrajectoryError.cause and exhausted() walks the cause chain, so an EMFILE during verification discards and retries the slice instead of counting the rows failed and moving the cursor past them. The new test is red on the parent head and green here; TrajectoryError keeps its codes and messages and only gains a non-enumerable cause.
  • Known trade-offs (non-blocking): the shared-record retention asymmetry (F1) is documented in docs/design/storage-and-knowledge.md and the PR body; a read-back retry can re-append a slice's records under sustained descriptor pressure, which is bounded and has no data effect.
  • All required checks pass on this head: unit (both shards), e2e, the four image builds, and Analyze/CodeQL.

Enqueued with expectedHeadOid = 3323cfa8...; the queue rebases onto main, so a later head makes this entry stale.

@agent-ci-infra-bot agent-ci-infra-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed commit: 3323cfa
Earlier heads this review also read: ddf655b
Coverage: PR #1405; 11 changed file(s)

Comment thread src/storage/migration.ts
});
this.logSlowSlice(phase.name, 'verify', this.now() - verifyStarted, moves.length);
// A record that could not be read back for want of descriptors is not known to be bad: the whole slice is read again.
if (unchecked) { await this.waitForResources(); continue; }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

suggestion (medium): a slice retried after running out of descriptors appends its records a second time; the lines from the dropped attempt are never referenced, so each retry adds up to a slice's worth of snapshot bodies to the trajectory files for good.

Why: move() appends at read time (storedRunSnapshot(..., (scope, type, id, data) => this.append(...)) at :222-223), before the slice is synced and verified. When verification cannot run (unchecked here) or the pre-apply sync fails (:141), the slice continues without applying and without moving the cursor, so the next attempt calls move() for the same rows and appends new lines. The lines of the dropped attempt are unreferenced; nothing rewrites a trajectory file (cleanup only removes whole files, by closed_at), so they stay until the file expires. waitForResources() also clears this.contexts (:87), so a retried row whose context was shared with the previous run's record now appends its own copy instead of sharing it.

Measured at this head (built dist, 400 tasks × 2 legacy runs → 800 records of ~2.8 KB, default openFiles: 32, exhaustedMs: 20):

ulimit -n retry rounds migrated failed record lines orphan lines bytes on disk
1024 0 800 0 800 0 2.4 MB
64 10 800 0 1050 250 3.2 MB
40 166 800 0 6172 5372 19.1 MB

orphan lines counts lines whose record id appears more than once (appends no row points at); all 800 rows read back identical to the fixture in every run, so this is disk growth, not data loss. At production sizes (~530 KB per migrated run) a 200-row slice is ~106 MB, so a retry series like the ulimit -n 40 row can write gigabytes while the phase is stalling on descriptors — the case this retry path exists for. The new test throws once from read and checks failed/the read view, so it does not see this.

Fix options: remember each move's refs (and columns) per rowid for the current slice and apply/verify those on retry instead of calling move() again; or closeTouched(0) before verification so read-back, not the append, is what must fit under the limit; and keep the dropped rows' contexts entries so a retry does not write an extra unshared context record.

@zhaozhaozz

Copy link
Copy Markdown
Collaborator Author

Local test record for 3323cfa8 is complete: npm run check exit 0. BOT_TEST_JOBS=8 npm test exited 1 with 2864 / 2866 passing; the only failed set was runner-transport, where both listen EADDRINUSE socket paths (134 and 147 bytes) exceed the 108-byte sun_path limit in this deep worktree. Rerun alone on the same head right after the suite: TMPDIR=$PWD/.tmp/s node --test test/ut/manager/runner-transport.test.mjs exited 0 with 4 / 4 passing. No new commit; the head stays 3323cfa8 in the merge queue.

Merged via the queue into agent-CI-Infra:main with commit 8a211c1 Nov 26, 2026
12 checks passed
@zhaozhaozz
zhaozhaozz deleted the feat/issue-1403-bodies-out-of-db branch November 26, 2026 11:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant