Alaa Tawalbeh / Fractional CTO
Field report

Three AI builders, one workstation

How we copied the CI runner's envelope onto one Linux machine with CPU pinning, cgroups and two locks, and the timing miss that turned out not to be the code.

3 / 1AI builders on one six-core workstation
2 cores, 7 GBThe envelope of every final gate
0Out-of-memory kills since boot
533 → 42 msOne write, in a shared vs a fresh process

Five AI coding sessions share one Linux workstation, and three of them are builders. Each builder runs a full test pipeline against the same PostgreSQL, Redis and object-storage services. Left unpartitioned, the builds compete for 12 hardware threads and 30 GiB of memory: timing tests stop meaning anything, and one run's memory spike can kill another's.

We copied the CI runner's resource envelope onto the workstation: every final gate gets 2 pinned CPUs and a 7 GB memory cgroup. Two locks of different kinds let only one gate run at a time, and lighter checks get CPU slots of their own. Since early November 2026, three builders have worked in parallel under this rule, with rare lock waits and with local gates that predicted CI.

The rule did not stop timing misses on GitHub's runners. On one identical source tree, a 400 ms limit passed once and missed twice, at 533 ms and 498 ms. The evidence points away from neighbouring processes and toward the state of a long-lived test process. Isolating CPUs and memory does not address that, but running the timing tests in a fresh process should.

01

Context

The product is a multi-tenant SaaS application in a TypeScript monorepo: an API, a background worker and a web app, backed by PostgreSQL, Redis for queues and sessions, and S3-compatible object storage.

The work is done by five Claude Code sessions with fixed roles. The CTO makes the product and architecture decisions and merges every pull request. The sessions message each other directly, and the CTO drives the workstation's sessions from a laptop over Remote Control.

SessionMachineRoleLoad it puts on the machine
RadadLaptop, Windows 11Architect: plans, briefs, decisions, deployment, directs the buildersLight: git and GitHub reads, research and critic sub-agents
Joudie on LegionWorkstation, UbuntuBuilderHeavy: builds, checks, database gates, exit proofs
ScarlettWorkstationBuilderHeavy, as above
MegWorkstationBuilderHeavy, as above
NicoleWorkstationRead-only reviewerLight to medium: diff reading, review sub-agents

Each builder works in its own git worktree on its own branch. It pushes after every phase and opens a draft pull request, and GitHub's CI runs on each push. On 8 November the three builders moved five pull requests between them, and Nicole reviewed all five. Every session can also start sub-agents, whose commands run on the same machine, so the real number of processes asking for CPU is higher than the five sessions suggest.

02

The workload

A builder's pipeline has four kinds of run, and the database gate dominates: about 12 minutes on two cores. The figures are from the builders' reports and the CI logs of 5 to 8 November. Test counts grow with every feature, so they are ranges.

RunWhat it doesSizeWall timeWhere it runs
pnpm checkType check, lint, module boundaries, unit tests4,364 to 5,077 tests240 to 296 sA check slot on the workstation; CI's check job
Database gateIntegration specs against real PostgreSQL, Redis and S3906 to 982 tests699 to 758 sThe workstation's final gate; on CI, three parallel shards of 4 to 8 min
Exit proofDrives the built stack over HTTP with no JavaScript, as each type of user251 to 289 steps105 to 151 sThe workstation's final gate; CI's exit-proof job
Browser testsPlaywright against the built web app48 to 56 tests12 to 13.5 minCI only: the workstation runs no browser

Memory. The integration tier runs one Jest worker per job, and its heap grows from suite to suite. CI logs show 560 MB to 1,030 MB by the later suites. Since an out-of-memory failure on 3 November, a worker that ends a suite above 1 GB is replaced (workerIdleMemoryLimit). We have no peak-RSS figure for a whole workstation gate, because none ran under /usr/bin/time.

Demand against supply. At peak, each of three builders wants a check or a gate at the same moment. That is up to 3 × 2 cores against a six-core machine, before PostgreSQL, Redis, sub-agents and the desktop take their share.

03

The machine and its shared services

The workstation is a Lenovo Legion with an Intel Core i7-9750H: 6 physical cores, 2 hardware threads each, 2.6 GHz base and 4.5 GHz boost. It has 30 GiB of memory and 8 GiB of swap, and runs Ubuntu 26.04.1 on kernel 7.0 with cgroup v2 and systemd 259. Node is 24.21 and pnpm 10.34. The same services that production uses run here too, and every builder shares them.

ServiceOn the workstationOn GitHub's CI
PostgreSQL18.6, a systemd service, always on, one server for all builderspostgres:18.6, a fresh container per job, through Testcontainers
Redis8.0.5, a systemd service, always on, no password (one spec that needs a password is skipped here)redis:8.2-alpine, a fresh container per job
S3 storageSeaweedFS 4.48, started only for a database gate, on loopback, with a fresh data folder and a key pair made for that run, then removedSeaweedFS 4.48 in a container
DisksA 915 GB ext4 NVMe for worktrees, and a 1.9 TB NTFS data drive (Linux's ntfs3 driver) for the main checkout and the lockThe runner's own disk
The asymmetry that matters

On CI, the database containers share the runner's 2 vCPUs with the tests: Jest and PostgreSQL compete inside one envelope. On the workstation, a gate's 2 cores and 7 GB hold Node and Jest only. PostgreSQL and Redis serve the gate's queries from outside it, on any core. So a database-heavy test has more room on the workstation than on CI, and local timings are optimistic.

The CTO's laptop runs the same services natively on Windows: PostgreSQL 18, and Memurai, a Redis-compatible server for Windows. Neither starts by itself after a restart; each needs an administrator to start it.

04

What went wrong

The failures fall into three groups: resource contention, state left behind by a process, and the platform itself. Newest first.

DateWhereWhat happenedCauseResponse
8 NovCI, integration branchA 400 ms limit missed at 533 ms; on the rerun, another 400 ms limit missed at 498 msNot the code: the same tree passed on its own pull requestThe timing specs run alone in a fresh process
6 NovWorkstationThe machine restarted during final gates, and the NTFS data drive didn't remountPlatformDrive mounted by hand, all three gates rerun from the start
6 NovCIThe same performance spec missed; the log was cutAs on 8 NovemberRerun
5 NovCI328 ms against a 300 ms limitJudged a runner stallRerun, green
5 NovCI282 ms against 300 ms: a pass, but a near missSame familyNone
5 NovWorkstationThe web app's production build failed in worktrees on the NTFS drivepnpm's links reach about 164 characters, and ntfs3 breaks links of about 146 or moreNew worktrees on the ext4 disk; a relink script for old ones
3 NovIntegration testsOut of memoryThe Jest worker's heap grows suite by suiteReplace a worker that ends a suite above 1 GB
27 OctLaptopAn interrupted build kept the shared gate lock, and the next build waited about 20 minutes before anyone noticedA lock that outlived its ownerOwner lines on the lock, and a second lock the kernel frees when its process dies

Two patterns stand out. Every timing miss happened on GitHub's runners; the workstation's gates reported none. And the costly failures were silent: a lock nobody owned, a build that stopped with no message.

05

Method: copy CI's envelope, then share what's left

The principle: a final gate on the workstation runs in the same envelope as a CI job, so a local pass predicts a CI pass. Our CI jobs run on GitHub's standard runner for a private repository, which we mirrored as 2 vCPUs and 7 GB. Four Linux mechanisms enforce it, and all four ship with a stock Ubuntu.

CPU pinning

taskset -c 0,1 sets the gate's CPU affinity, and every process it starts inherits it: Node, Jest and the build tools. The gate can't use more than two CPUs, and it can't spill onto anyone else's.

A memory cap

systemd-run --user --scope -p MemoryMax=7G runs the gate in a transient cgroup v2 scope. If the gate's processes together pass 7 GB, the kernel reclaims or kills inside that scope only, and the rest of the machine is untouched. We set no Node heap flag, so Node sizes its heap as it would on CI.

Two locks, one gate at a time

A gate takes both locks before it runs. The first is a directory, mkdir .gate.lock, holding an owner line: session, task, commit, folder and start time. mkdir is atomic, and the directory survives a crash, so a stale lock says whose it was. The second is a kernel lock, flock -n /tmp/gates.lock, which the kernel frees when its process dies, so it can't go stale.

The gate's command runs with that descriptor closed (9>&-), so a server it leaves running can't hold the lock, and a shell trap clears both on exit. A busy lock returns exit code 75, and the wrapper refuses a tree with uncommitted changes (exit 76), so every gate result names one commit. Clearing someone else's stale lock is the CTO's decision, never a builder's.

Check slots

pnpm check and single-spec runs don't take the gate lock. A helper tries slot A (CPUs 2 and 3) and then slot B (CPUs 4 and 5), each behind its own flock, and polls every 5 seconds while both are busy. Checks have no memory cap.

Each job owns two whole cores; their siblings stay free of pinned work

Intel i7-9750H, 6 cores with 2 threads each. Top row: a core's first thread. Bottom row: its hyperthread sibling.

CPU map: the gate holds cores 0 and 1, check slot A cores 2 and 3, check slot B cores 4 and 5; CPUs 6 to 11 take no pinned work; services run unpinned on any CPU. GATE: ONE AT A TIME, 7 GB CHECK SLOT A, ITS OWN FLOCK CHECK SLOT B, ITS OWN FLOCK CORE 0 CORE 1 CORE 2 CORE 3 CORE 4 CORE 5 CPU 0 CPU 1 CPU 2 CPU 3 CPU 4 CPU 5 CPU 6 CPU 7 CPU 8 CPU 9 CPU 10 CPU 11 Not pinned: scheduled on any CPU, siblings included PostgreSQL 18.6, Redis 8.0.5, SeaweedFS during a database gate, five sessions, sub-agents, the desktop
From lscpu -e and the check-slot and gate scripts on the workstation, 8 November 2026.

The pairs are whole physical cores. On this CPU, logical CPUs 0 to 5 are cores 0 to 5, and 6 to 11 are their hyperthread siblings (0 with 6, 1 with 7, and so on). Pinned work uses 0 to 5 only, so no two pinned jobs share a core's execution units. The services aren't pinned, and the scheduler can still place them on a sibling. At most one gate and two checks run at once: six cores of work on a six-core machine.

The CI trial

The envelope makes local gates trustworthy, but they are also slow and serialised. So while a builder iterates, GitHub's CI is the gate: she pushes once pnpm check passes, and the workstation's gates run once, on a pull request's final head. CI was estimated at about $0.006 a runner-minute. Splitting the database tier into three parallel shards cut a CI run from about 17 minutes to about 7.

06

Results

The rule held memory and concurrency. It didn't make CI's timings stable. The figures cover the workstation's uptime from 7 November at 17:51 to 8 November, which includes every gate below.

MeasureResultSource
Out-of-memory kills0Kernel counter oom_kill since boot
Swap used0 B; 0 pages in or outswapon --show, pswpin, pswpout
Concurrent builders3, plus a reviewer and an architect, moving 5 pull requests in a daySession reports
Database gate, 2 cores and 7 GB727 s for 913 tests; 758 s for 982Wrapper logs
Exit proof, 2 cores and 7 GB124 s for 274 stepsWrapper and proof logs
pnpm check in a slot268 sWrapper log
Passed locally, failed a function on CI0 casesThree pull requests
CI timing misses on a tree that passed elsewhere3, all on GitHub's runnersCI logs

The envelope did what it was for. Every pull request whose workstation gates passed also passed CI's functional jobs, and no builder reported a run disturbed by another's gate. It didn't do two things.

  • It isn't a perfect replica. PostgreSQL and Redis serve a local gate from outside its 2 cores, so database-heavy tests get more CPU locally than on CI. That makes local timings optimistic, and it may explain why the workstation never reported a timing miss while CI did.
  • It caps memory but not swap. MemoryMax=7G sets no MemorySwapMax, so a gate over its cap could spill into swap and slow down before the kernel kills it. That hasn't happened since boot, but nothing in the rule prevents it.
07

Case study: a timing miss that wasn't the code

The strongest evidence came from an accident. A pull request passed CI. Merged into the integration branch, the same source tree failed CI twice. Git confirms the two commits hold an identical tree (7dec285fcbf3). Whatever failed, it wasn't the code.

The first run missed in the first timing spec: a write of 50 rows took 533 ms against a 400 ms limit. In the same run, the next measurement, a write of 500 rows, took 275 ms. Ten times the work took half the time. The rerun passed that spec and missed in the second: a state change took 498 ms against 400. On a healthy run these operations take 15 to 45 ms.

Four hypotheses, tested against that evidence

  1. RejectedThe code is slow.

    The identical tree passed, and the cost didn't scale with the work.

  2. RejectedNeighbouring test suites took the CPU.

    Each CI shard runs on its own virtual machine with maxWorkers: 1, so no other suite ran beside the timing spec. We had first assumed this cause, and reading the configuration refuted it.

  3. SupportedThe test process's own state.

    By the time the timing specs ran, the single Jest worker had run every earlier suite in its shard, and its heap had grown to between 560 MB and 1 GB. A garbage-collection pause, or leftovers from earlier suites, would land on whichever measurement came first. That fits a small write costing more than a large one. On CI, PostgreSQL also shares the same 2 vCPUs.

  4. OpenThe virtual machine's host.

    A cloud VM can lose CPU time to other tenants on its host, and nothing inside the job can observe that.

Each miss ran 9% to 33% over its limit; isolated, the same write used 11%

Measured time as a share of its limit, GitHub CI, 5 to 8 November 2026

Timing results as a share of their limits: 282.1 ms of 300, 328 of 300, 533 of 400, 498 of 400, and 42 of 400 in a fresh process. THE LIMIT Pull request, 5 Nov a paged read 282.1 ms against 300 ms (94%) 282.1 ms of 300 Pull request, 5 Nov a read 328 ms against 300 ms (109%) 328 ms of 300 Integration branch, run 1 a write of 50 rows 533 ms against 400 ms (133%) 533 ms of 400 Integration branch, rerun a state change 498 ms against 400 ms (125%) 498 ms of 400 Fresh process a write of 50 rows 42 ms against 400 ms (11%) 42 ms of 400
From the CI logs of two pull requests, the integration branch and the fix. One near miss, three misses, one isolated run.

The intervention. The CTO chose to isolate the timing specs and leave every limit unchanged. Raising a limit to absorb noise would also hide a real slowdown. The fix runs the two *-performance specs alone, in a fresh Jest process, after the shard's other suites. It runs them in band, which turns off the 1 GB worker guard, so it does this for those two files only.

First observation. In the fresh process, the write that had taken 533 ms took 42 ms, and the process's heap ended near 655 MB. That is one run, so it supports hypothesis 3 without proving it. The test is the next few weeks of runs: if misses mostly stop, the process's state was the cause; if they continue, the host was.

08

Can Windows do this?

Yes at the kernel level, and only partly at the command line. Windows has had per-process CPU affinity and Job Objects, its counterpart to cgroups, for over two decades. What Linux adds is composition: each mechanism is one stock command, and together they fit in two short shell scripts.

MechanismLinux, as used hereWindows, nativelyWindows, through WSL2
Pin to CPUstaskset -c 0,1start /affinity 3 in cmd (a hex mask for CPUs 0 and 1), or ProcessorAffinity from PowerShell; children inherit ittaskset, unchanged
Cap a process tree's memorysystemd-run --scope -p MemoryMax=7GA Job Object with a job memory limit; no stock command, so a small PowerShell or C# toolsystemd-run, once systemd is enabled in wsl.conf
Cap a tree's CPU timeCPUQuota= on the same scope (not used here)A Job Object's CPU rate controlAs Linux
A lock that dies with its ownerflockA named mutex: when its owner dies, the next waiter receives it marked abandonedflock, unchanged
A lock that shows its ownermkdir plus an owner filemkdir is atomic on NTFS tooAs Linux
Pin to whole physical coreslscpu -e shows each CPU's coreSysinternals Coreinfo or GetLogicalProcessorInformationEx show the pairs, and affinity can target themNot controllable: WSL2's CPUs are a VM's virtual CPUs

WSL2 runs the whole method unchanged, with two costs. The VM has its own CPU and memory budget (.wslconfig), and the method's caps sit inside it. And the VM hides the physical topology, so "two whole cores" becomes "two virtual CPUs". Repositories should live on WSL2's own ext4 disk: /mnt/c crosses into Windows through a much slower file protocol. That is the same lesson the workstation taught on its NTFS drive.

What we did on Windows

Until early November the builds ran on the CTO's Windows laptop, and the rule there was a count: at most two builds running gates at once, behind one shared lock, with no pinning and no memory caps. A count limits contention, but it doesn't make a run's resources predictable, and nothing tied the lock to a live process. That gap cost the 20-minute wait in section 04. Moving the builders to the Linux workstation, under the envelope and the two locks, addressed both.

09

Limitations

This is a field report, not a controlled experiment. Read its claims with these limits in mind.

  • Small sample. One machine, a few days of runs, and four timing incidents. Nothing was run twice under controlled conditions.
  • Self-reported numbers. The builders, which are AI sessions, reported most figures from their own logs. CI logs were checked directly. No peak memory was measured for a whole workstation gate.
  • Two cores aren't two vCPUs. The laptop-class CPU boosts from 2.6 to 4.5 GHz with temperature and load, and a cloud vCPU is a shared hyperthread at its host's clock. The envelope matches count and memory, not speed.
  • A partial envelope. The services run outside the cgroup; swap isn't capped; CPU time isn't capped. Each makes the workstation more generous than CI.
  • An unobservable host. Contention on GitHub's hosts can't be tested from inside a job.
  • One supporting run. The fresh-process result is a single observation.
10

Conclusions and a recipe

Several AI builders on one machine have the same problem as several engineers on one CI server: they share CPUs, memory, services and locks. They just hit it faster, and more quietly. They don't get tired, they start sub-agents, and none of them notices another's lock unless the lock says whose it is. Making each run's resources fixed and each lock's owner visible turned that from a source of silent failures into a queue.

The second lesson is about measurement. Isolating CPUs and memory makes a run's resources predictable. It doesn't make a long-lived process's state predictable. A timing test inherits whatever the process did before it, so it needs a fresh process as much as a quiet core.

The recipe, in the order we'd set it up again

  1. Mirror CI's envelope for final gates only.Pin to as many CPUs, and cap at as much memory, as a CI job gets. Iterate against CI itself.
  2. Partition by physical core.Read the topology with lscpu -e, give each job whole cores, and keep pinned work off the hyperthread siblings.
  3. Use two locks.One the filesystem keeps, with an owner line, and one the kernel frees when its process dies. Clearing a stale lock stays the CTO's call.
  4. Give light work its own slots.A check never waits behind a 12-minute gate, and a waiting job polls instead of oversubscribing.
  5. Make every result name one commit.Refuse a gate on a dirty tree, and log each run's exit code and duration.
  6. Decide where the services sit.Put the database inside the envelope for timing parity with CI, or accept that local timings are optimistic, and write that down.
  7. Run timing tests in a fresh process.Never raise a limit to absorb noise.
  8. On Windows, use WSL2.The same scripts run there; a native setup needs Job Object tooling.
Appendix

The scripts and the machine

Both scripts are as they ran on 8 November 2026, with some header comments shortened and project names removed, and were checked for secrets first. Neither is in the repository. The gate wrapper sources a SeaweedFS start-and-stop helper, not shown here.

The check-slot helper, ~/check-slot.sh
#!/usr/bin/env bash
# The Legion's two shared check slots: pnpm check, and any spec run that isn't a gate,
# runs on A (CPUs 2,3) or B (CPUs 4,5), each held by a flock. Gates stay on CPUs 0-1
# under the gate lock; 6-11 stay idle. It never touches the gate lock or the cgroup.
check_slot() {
  if [ $# -eq 0 ]; then
    echo "usage: check_slot <cmd...>" >&2
    return 2
  fi
  (
    asked=$(date +%s)
    told=
    while :; do
      for pair in A:2,3 B:4,5; do
        slot=${pair%%:*}
        cpus=${pair#*:}
        exec {fd}>"/tmp/check-slot-$slot.lock" || exit 1
        if flock -n "$fd"; then
          began=$(date +%s)
          echo "[check-slot] slot $slot (CPUs $cpus) taken at $(date -Is), after $((began - asked)) s" >&2
          taskset -c "$cpus" "$@" {fd}>&-
          rc=$?
          echo "[check-slot] slot $slot released at $(date -Is), exit $rc, $(($(date +%s) - began)) s" >&2
          exit "$rc"
        fi
        exec {fd}>&-
      done
      if [ -z "$told" ]; then
        told=1
        echo "[check-slot] both slots busy at $(date -Is): waiting" >&2
      fi
      sleep "${CHECK_SLOT_POLL:-5}"
    done
  )
}

if [ "${BASH_SOURCE[0]}" = "$0" ]; then
  check_slot "$@"
fi
A builder's gate wrapper
#!/usr/bin/env bash
#   check-*  pnpm check: a check slot, no lock, clean tree   unit-*  unit runs: a check slot, no lock
#   gate-*   db gate, exit proof: lock + cgroup, clean tree   any other name: lock + cgroup
source "$HOME/check-slot.sh"
L=/run/media/alaa/Data/theDev/.gate.lock; N=$1; shift
SHA=$(git rev-parse --short HEAD); LOG=/tmp/gate-$N-$SHA.log
case "$N" in gate-*|check-*) [ -z "$(git status --porcelain)" ] || { echo "dirty tree: commit first"; exit 76; } ;; esac
s=$(date +%s)
case "$N" in
  check-*|unit-*) check_slot "$@" > "$LOG" 2>&1; rc=$? ;;
  *)
    mkdir "$L" 2>/dev/null || { echo "busy: $(cat "$L/owner" 2>/dev/null || echo 'a lock with no owner file')"; exit 75; }
    exec 9>/tmp/gates.lock
    flock -n 9 || { rmdir "$L"; echo "busy: /tmp/gates.lock"; exit 75; }
    echo "Joudie on Legion, $N on $SHA in $PWD, since $(date -Is)" > "$L/owner"
    source "$HOME/s3-helper.sh"; S3=0; case "$N" in gate-db*) S3=1 ;; esac
    trap 's3_stop; rm -f "$L/owner"; rmdir "$L" 2>/dev/null' EXIT
    trap 'exit 130' INT TERM HUP
    { if [ "$S3" = 1 ]; then s3_start || exit 1; fi; systemd-run --user --scope -p MemoryMax=7G --quiet taskset -c 0,1 "$@"; } > "$LOG" 2>&1 9>&-; rc=$?
    s3_stop ;;
esac
echo "exit=$rc duration=$(( $(date +%s) - s ))s" >> "$LOG"
echo "$LOG: exit=$rc"; exit "$rc"
ItemValue
CPUIntel Core i7-9750H, 6 cores, 2 threads each, 2.6 GHz base, 4.5 GHz boost
CPU numberingCPUs 0 to 5 are cores 0 to 5; CPUs 6 to 11 are their siblings (0 with 6, 1 with 7, through 5 with 11)
Memory30 GiB, with 8 GiB of swap
SystemUbuntu 26.04.1, kernel 7.0.0, cgroup v2, systemd 259
ToolchainNode 24.21.0, pnpm 10.34.5
ServicesPostgreSQL 18.6, Redis 8.0.5, SeaweedFS 4.48
Disks915 GB ext4 NVMe for worktrees; 1.9 TB NTFS through ntfs3 for the main checkout and the gate lock
تقرير من أرض الواقع

ثلاثة AI Builders على Workstation واحدة

كيف طبّقنا حدود موارد CI runner على جهاز Linux واحد باستخدام CPU pinning وcgroups واثنين من Locks، وكيف اكتشفنا أن مشكلة Timing لم تكن من الكود.

3 / 1AI Builders على Workstation بستّ أنوية
2 cores, 7 GBحدود الموارد لكل Final Gate
0حالات Out-of-Memory منذ تشغيل الجهاز
533 → 42 msعملية Write واحدة: Shared مقابل Fresh Process

تتشارك خمس Claude Code Sessions جهاز Linux واحداً، ثلاث منها تعمل كـ Builders. كل Builder يشغّل Test Pipeline كاملة باستخدام خدمات PostgreSQL وRedis وObject Storage نفسها. من دون توزيع واضح للموارد، تتنافس عمليات Build على 12 Hardware Threads و30 GiB من الذاكرة؛ عندها تفقد Timing Tests معناها، وقد تؤدي قفزة في استهلاك الذاكرة بإحدى العمليات إلى إيقاف عملية أخرى.

نقلنا Resource Envelope الخاصة بـ CI runner إلى الـ Workstation: يحصل كل Final Gate على 2 pinned CPUs وMemory cgroup بحدّ 7 GB. واستخدمنا نوعين مختلفين من Locks للسماح بتشغيل Gate واحدة في كل مرة، مع تخصيص CPU Slots مستقلة للـ Checks الأخف. منذ بداية نوفمبر 2026، يعمل ثلاثة Builders بالتوازي وفق هذا التنظيم، مع حالات انتظار نادرة للـ Locks ونتائج Local Gates كانت متوافقة مع CI.

لكن هذا التنظيم لم يمنع تجاوز حدود Timing على GitHub runners. فقد نجح Source Tree نفسه مرة في اختبار حدّه 400 ms، وفشل مرتين بنتيجتي 533 ms و498 ms. تشير الأدلة إلى أن السبب ليس العمليات المجاورة، بل حالة Test Process طويلة العمر. عزل CPU والذاكرة لا يعالج هذه المشكلة، بينما يُرجّح أن يساعد تشغيل Timing Tests داخل Fresh Process.

01

السياق

المنتج عبارة عن تطبيق Multi-tenant SaaS مبني ضمن TypeScript Monorepo، ويضم API وBackground Worker وWeb App، مع PostgreSQL للبيانات وRedis للـ Queues والـ Sessions، بالإضافة إلى Object Storage متوافق مع S3.

ينفّذ العمل خمس Claude Code Sessions لكل منها دور محدد. يتخذ الـ CTO قرارات المنتج والـ Architecture، وهو المسؤول الوحيد عن Merge لكل Pull Request. تتواصل الـ Sessions مباشرة فيما بينها، بينما يدير الـ CTO جلسات الـ Workstation من لابتوب باستخدام Remote Control.

Sessionالجهازالدورالحِمل على الجهاز
Radadلابتوب، Windows 11Architect: التخطيط، تحديد المهام، القرارات، Deployment وتوجيه الـ Buildersخفيف: قراءة Git وGitHub، وResearch وCritic Sub-agents
Joudie on LegionWorkstation، UbuntuBuilderثقيل: Builds وChecks وDatabase Gates وExit Proofs
ScarlettWorkstationBuilderثقيل، مثل السابق
MegWorkstationBuilderثقيل، مثل السابق
NicoleWorkstationReviewer بصلاحية Read-onlyخفيف إلى متوسط: قراءة Diffs وReview Sub-agents

يعمل كل Builder في Git Worktree مستقلة وعلى Branch خاصة به. ينفّذ Push بعد كل مرحلة ويفتح Draft Pull Request، ويبدأ GitHub CI مع كل Push. في 8 نوفمبر، عمل الـ Builders الثلاثة على خمس Pull Requests، وراجعت Nicole جميعها. تستطيع كل Session أيضاً تشغيل Sub-agents تنفّذ أوامرها على الجهاز نفسه؛ لذلك فإن عدد العمليات التي تطلب CPU فعلياً أكبر مما توحي به الجلسات الخمس.

02

حجم العمل

تحتوي Pipeline كل Builder على أربعة أنواع من التشغيل، وأكثرها استهلاكاً للوقت هو Database Gate: قرابة 12 دقيقة على نواتين. الأرقام مأخوذة من تقارير الـ Builders وسجلات CI بين 5 و8 نوفمبر. يزداد عدد الاختبارات مع كل Feature، لذلك عُرضت الأعداد كنطاقات.

التشغيلماذا ينفّذ؟الحجمالمدة الفعليةمكان التشغيل
pnpm checkType Check وLint وفحص Module Boundaries وUnit Tests4,364 إلى 5,077 Tests240 إلى 296 sداخل Check Slot على الـ Workstation؛ وداخل Job باسم check job
Database GateIntegration Tests على PostgreSQL وRedis وS3 فعليّة906 إلى 982 Tests699 إلى 758 sFinal Gate على الـ Workstation؛ وعلى CI ثلاثة Shards متوازية، مدة كل منها 4 إلى 8 دقائق
Exit Proofيختبر الـ Stack المبنية عبر HTTP ومن دون JavaScript، بمختلف أنواع المستخدمين251 إلى 289 Steps105 إلى 151 sFinal Gate على الـ Workstation؛ وJob باسم exit-proof job
Browser Testsاختبارات Playwright على الـ Web App المبنية48 إلى 56 Tests12 إلى 13.5 دقيقةعلى CI فقط؛ لا تُشغّل Browser Tests على الـ Workstation

الذاكرة. تُشغّل طبقة Integration Tests واحد Jest Worker لكل Job، ويزداد حجم الـ Heap مع توالي Test Suites. تُظهر سجلات CI أن الاستهلاك وصل إلى 560 MB–1,030 MB في الـ Suites المتأخرة. بعد حدوث Out-of-Memory في 3 نوفمبر، أصبح أي Worker ينهي Suite بأكثر من 1 GB يُستبدل (workerIdleMemoryLimit). لا نملك قياس Peak RSS لعملية Gate كاملة على الـ Workstation، لأن أياً منها لم يُشغّل باستخدام /usr/bin/time.

الطلب مقابل الموارد المتاحة. في أوقات الذروة، قد يحتاج كل واحد من الـ Builders الثلاثة إلى Check أو Gate في الوقت نفسه. هذا يعني طلباً يصل إلى 3 × 2 cores من جهاز يحوي ست أنوية، حتى قبل احتساب PostgreSQL وRedis والـ Sub-agents والـ Desktop.

03

الجهاز والخدمات المشتركة

الـ Workstation هو Lenovo Legion بمعالج Intel Core i7-9750H يحوي 6 Physical Cores، وكل نواة تدعم 2 Hardware Threads، بتردد أساسي 2.6 GHz وBoost يصل إلى 4.5 GHz. يحتوي على 30 GiB RAM و8 GiB Swap، ويعمل بنظام Ubuntu 26.04.1 وKernel 7.0 مع cgroup v2 وsystemd 259. إصدارات Node وpnpm هي 24.21 و10.34. الخدمات المستخدمة في Production تعمل هنا أيضاً، ويتشاركها جميع الـ Builders.

الخدمةعلى الـ Workstationعلى GitHub CI
PostgreSQLالإصدار 18.6 يعمل كـ systemd Service بشكل دائم؛ Server واحد لكل الـ Builderspostgres:18.6، Container جديدة لكل Job عبر Testcontainers
Redisالإصدار 8.0.5 يعمل كـ systemd Service بشكل دائم، من دون Password (ويتم تخطي Test واحدة تحتاج Password)redis:8.2-alpine، Container جديدة لكل Job
S3 StorageSeaweedFS 4.48 يبدأ فقط عند Database Gate على Loopback، مع Data Folder جديدة وKey Pair خاصتين بالتشغيل، ثم تتم إزالتهماSeaweedFS 4.48 داخل Container
الأقراصقرص ext4 NVMe بسعة 915 GB للـ Worktrees، وقرص بيانات NTFS بسعة 1.9 TB عبر Driver باسم ntfs3 من Linux للـ Main Checkout والـ Lockقرص الـ Runner الخاص به
الاختلاف المهم بين البيئتين

على CI، تتشارك Database Containers مع الاختبارات 2 vCPUs المخصصة للـ Runner؛ أي أن Jest وPostgreSQL يتنافسان داخل Resource Envelope واحدة. أما على الـ Workstation، فتشمل حدود الـ Gate المكونة من 2 cores و7 GB عمليتي Node وJest فقط، بينما يخدم PostgreSQL وRedis طلباتهما من خارجها وعلى أي نواة. لذلك تحصل الاختبارات كثيفة الاستخدام لقاعدة البيانات على موارد أكبر محلياً مقارنة بـ CI، وقد تبدو أزمنتها أفضل من الواقع.

يشغّل لابتوب الـ CTO الخدمات نفسها على Windows بشكل Native: ‏PostgreSQL 18 وMemurai المتوافق مع Redis على Windows. لا تبدأ أي منهما تلقائياً بعد Restart، بل تحتاج إلى تشغيلها بصلاحية Administrator.

04

ما الذي حدث بشكل خاطئ؟

يمكن تصنيف الإخفاقات إلى ثلاث مجموعات: Resource Contention، والحالة التي تتركها Process سابقة، ومشكلات المنصة نفسها. الترتيب من الأحدث إلى الأقدم.

التاريخالمكانما الذي حدث؟السببالإجراء
8 نوفمبرCI، Integration Branchتجاوز اختبار حدّ 400 ms وسجّل 533 ms؛ وعند إعادة التشغيل تجاوز اختبار آخر الحد نفسه وسجّل 498 msليس الكود: الـ Source Tree نفسها نجحت في Pull Request مستقلةتشغيل Timing Specs منفردة داخل Fresh Process
6 نوفمبرWorkstationأُعيد تشغيل الجهاز أثناء Final Gates، ولم يُعد تركيب قرص بيانات NTFSالمنصةتركيب القرص يدوياً وإعادة تشغيل الـ Gates الثلاث من البداية
6 نوفمبرCIتجاوزت Performance Spec نفسها الحدّ، لكن الـ Log كان مقطوعاًكما في 8 نوفمبرإعادة التشغيل
5 نوفمبرCIسجّل 328 ms مقابل حدّ 300 msرُجّح أنه Runner Stallإعادة التشغيل، ونجاح الاختبار
5 نوفمبرCI282 ms مقابل 300 ms: نجاح، لكنه قريب من الحدمن نوع المشكلة نفسهلا إجراء
5 نوفمبرWorkstationفشل Production Build للـ Web App داخل Worktrees على قرص NTFSتصل Links الخاصة بـ pnpm إلى نحو 164 حرفاً، بينما يفشل ntfs3 مع Links بطول 146 حرفاً تقريباً أو أكثرإنشاء Worktrees جديدة على قرص ext4 واستخدام Relink Script للقديمة
3 نوفمبرIntegration TestsOut-of-Memoryيزداد Heap الخاص بـ Jest Worker مع كل Suiteاستبدال أي Worker ينهي Suite باستهلاك يزيد عن 1 GB
27 أكتوبراللابتوباحتفظ Build متوقف بـ Shared Gate Lock، وانتظرت العملية التالية قرابة 20 دقيقة قبل اكتشاف المشكلةLock بقي موجوداً بعد انتهاء العملية المالكة لهإضافة بيانات المالك إلى الـ Lock، وLock ثانٍ يحرره الـ Kernel عند انتهاء الـ Process

هناك نمطان واضحان: جميع حالات تجاوز Timing حدثت على GitHub runners، بينما لم تسجّل Gates على الـ Workstation أياً منها. كذلك كانت الإخفاقات المكلفة صامتة: Lock بلا مالك أو Build توقف من دون رسالة.

05

المنهجية: محاكاة حدود CI ثم توزيع الموارد المتبقية

الفكرة الأساسية: تشغيل Final Gate على الـ Workstation ضمن حدود الموارد نفسها التي تحصل عليها CI Job، بحيث يكون النجاح محلياً مؤشراً على النجاح في CI. تعمل الـ Jobs عندنا على Standard GitHub Runner لمستودع Private، فحاكينا حدودها: 2 vCPUs و7 GB. فرضنا هذه القيود باستخدام أربع آليات متوفرة افتراضياً في Ubuntu.

CPU Pinning

taskset -c 0,1 يحدد CPU Affinity للـ Gate، وترث هذا التخصيص جميع العمليات الناتجة عنه، بما فيها Node وJest وأدوات Build. بذلك لا يستطيع الـ Gate استخدام أكثر من وحدتَي CPU ولا التوسع إلى الوحدات المخصصة للآخرين.

حدّ للذاكرة

systemd-run --user --scope -p MemoryMax=7G يشغّل الـ Gate ضمن cgroup v2 Scope مؤقتة. إذا تجاوز إجمالي استهلاك عملياته 7 GB، يستعيد الـ Kernel الذاكرة أو يوقف عمليات ضمن هذا الـ Scope فقط، من دون التأثير على بقية الجهاز. لم نضع Node Heap Flag، ليضبط Node الـ Heap بالطريقة نفسها التي يستخدمها على CI.

اثنان من Locks، وGate واحدة في كل مرة

يحصل الـ Gate على كلا الـ Locks قبل التشغيل. الأول عبارة عن Directory باسم mkdir .gate.lock، ويحتوي بيانات المالك: Session وTask وCommit وFolder ووقت البدء. العملية mkdir من نوع Atomic، ويبقى الـ Directory حتى بعد Crash، لذلك يمكن معرفة صاحب أي Stale Lock. أما الثاني فهو Kernel Lock باسم flock -n /tmp/gates.lock، ويحرره الـ Kernel عندما تنتهي العملية المالكة له، فلا يمكن أن يبقى Stale.

يُشغَّل أمر الـ Gate مع إغلاق File Descriptor المعني (9>&-)، حتى لا يستطيع Server متروك قيد التشغيل الاحتفاظ بالـ Lock. كما يقوم Shell trap بتنظيف الاثنين عند الخروج. إذا كان الـ Lock مشغولاً يرجع Exit Code 75، ويرفض الـ Wrapper أي Source Tree تحتوي تعديلات غير محفوظة في Commit باستخدام Exit 76؛ وبالتالي يمكن ربط كل نتيجة Gate بـ Commit واحدة. وحده الـ CTO يقرر حذف Stale Lock تخص جلسة أخرى، وليس الـ Builder.

Check Slots

pnpm check وتشغيل Single-spec لا يحتاجان إلى Gate Lock. يجرّب Helper أولاً Slot A على CPUs 2 و3، ثم Slot B على CPUs 4 و5، ولكل Slot أمر flock خاص به. وعندما تكون الـ Slots مشغولة، يفحص التوفر كل 5 ثوانٍ. لا يوجد Memory Cap على الـ Checks.

تستخدم كل Job نواتين كاملتين، وتبقى Hyperthread Siblings خارج العمل المقيّد بـ CPU Pinning

المعالج Intel i7-9750H: ستّ أنوية، لكل منها Threads اثنتان. الصف العلوي: First Thread؛ والصف السفلي: Hyperthread Sibling.

مخطط CPU: ‏Gate على Cores 0 و1؛ ‏Check Slot A على 2 و3؛ ‏Check Slot B على 4 و5. الخدمات غير مقيّدة. GATE: ONE AT A TIME, 7 GB CHECK SLOT A, ITS OWN FLOCK CHECK SLOT B, ITS OWN FLOCK CORE 0 CORE 1 CORE 2 CORE 3 CORE 4 CORE 5 CPU 0 CPU 1 CPU 2 CPU 3 CPU 4 CPU 5 CPU 6 CPU 7 CPU 8 CPU 9 CPU 10 CPU 11 غير مقيّد: يمكن تشغيله على أي CPU، بما فيها Siblings PostgreSQL 18.6، Redis 8.0.5، SeaweedFS، خمس Sessions، Sub-agents، Desktop
من lscpu -e ومن Check-slot وGate Scripts على الـ Workstation بتاريخ 8 نوفمبر 2026.

كل زوج في التوزيع يمثل Physical Cores كاملة. على هذا المعالج، تشير Logical CPUs من 0 إلى 5 إلى Cores من 0 إلى 5، بينما تمثل CPUs من 6 إلى 11 الـ Hyperthread Siblings المقابلة لها (0 مع 6، و1 مع 7، وهكذا). يستخدم العمل المقيّد وحدات CPU من 0 إلى 5 فقط، فلا تتشارك أي وظيفتين مقيّدتين وحدات التنفيذ للنواة نفسها. الخدمات غير مقيّدة، ويمكن للـ Scheduler تشغيلها على Sibling. الحدّ الأقصى هو Gate واحدة واثنتان من Checks في الوقت نفسه: ستّ أنوية عمل على جهاز بستّ أنوية.

تجربة CI

تجعل Resource Envelope الـ Local Gates موثوقة، لكنها بطيئة وتعمل بالتسلسل. لذلك، أثناء تطوير الـ Builder، نعتمد GitHub CI بوصفه الـ Gate: ينفّذ Push بعد نجاح pnpm check ، بينما تُشغّل Gates المحلية مرة واحدة على آخر Commit من Pull Request. قُدّرت تكلفة CI بنحو $0.006 لكل Runner-minute. وأدى تقسيم Database Tier إلى ثلاثة Shards متوازية إلى تقليص مدة CI من 17 دقيقة تقريباً إلى 7 دقائق.

06

النتائج

نجح التنظيم في ضبط الذاكرة والتزامن، لكنه لم يجعل Timing على CI مستقراً. تغطي الأرقام فترة تشغيل الـ Workstation من 7 نوفمبر الساعة 17:51 حتى 8 نوفمبر، وتشمل كل Gates المعروضة أدناه.

المؤشرالنتيجةالمصدر
حالات Out-of-Memory Kill0عداد Kernel باسم oom_kill منذ تشغيل الجهاز
استهلاك Swap0 B؛ لا توجد Pages داخلة أو خارجةswapon --show, pswpin, pswpout
Builders متزامنون3، بالإضافة إلى Reviewer وArchitect، مع 5 Pull Requests في يوم واحدتقارير الـ Sessions
Database Gate، بحدود 2 cores و7 GB727 s لـ 913 Tests؛ و758 s لـ 982سجلات الـ Wrapper
Exit Proof، بحدود 2 cores و7 GB124 s لـ 274 Stepsسجلات Wrapper وProof
pnpm check داخل Slot268 sسجل الـ Wrapper
نجح محلياً وفشل Functional Test على CI0 حالاتثلاث Pull Requests
Timing Misses على CI لشجرة كود نجحت في مكان آخر3، جميعها على GitHub Runnersسجلات CI

أدت Resource Envelope الغرض منها: كل Pull Request نجحت Gates الخاصة بها على الـ Workstation نجحت أيضاً في Functional Jobs على CI. ولم يُبلّغ أي Builder عن تأثر تشغيله بـ Gate أخرى. لكن هناك أمران لم يعالجهما التنظيم:

  • ليست نسخة مطابقة بالكامل. تخدم PostgreSQL وRedis الـ Local Gate من خارج النواتين المخصصتين لها. لذلك تحصل Database-heavy Tests على CPU أكبر محلياً مقارنة بـ CI. وهذا يجعل Local Timings متفائلة، وقد يفسّر غياب Timing Misses على الـ Workstation وظهورها في CI.
  • يضع حدّاً للذاكرة لكن ليس للـ Swap. MemoryMax=7G لا يضبط MemorySwapMax، وبالتالي قد ينتقل استهلاك Gate المتجاوزة للحدّ إلى Swap ويتباطأ قبل أن يوقفه الـ Kernel. لم يحدث هذا منذ آخر تشغيل للجهاز، لكن القاعدة الحالية لا تمنعه.
07

دراسة حالة: Timing Miss لم يكن سببها الكود

ظهر أقوى دليل بالصدفة: نجحت Pull Request على CI، لكن بعد Merge إلى Integration Branch فشلت Source Tree نفسها مرتين. أكّد Git أن الـ Commits تحتوي الشجرة نفسها تماماً (7dec285fcbf3). أياً كان سبب الفشل، فهو ليس اختلافاً في الكود.

في التشغيل الأول، فشلت أول Timing Spec: استغرقت كتابة 50 Rows مدة 533 ms مقابل حدّ 400 ms. وفي التشغيل نفسه، استغرقت كتابة 500 Rows مدة 275 ms فقط: عشرة أضعاف العمل خلال نصف الزمن تقريباً. عند إعادة التشغيل، نجحت تلك الـ Spec، وفشلت الثانية: استغرق State Change مدة 498 ms مقابل 400 ms. في التشغيل الطبيعي، تستغرق هذه العمليات ما بين 15 و45 ms.

أربع فرضيات اختبرناها مقابل الأدلة

  1. مرفوضةالكود بطيء.

    نجحت الشجرة نفسها، ولم يرتفع الزمن مع حجم العمل.

  2. مرفوضةTest Suites المجاورة استهلكت CPU.

    يعمل كل CI Shard على Virtual Machine مستقلة، مع maxWorkers: 1، ولذلك لم تكن هناك Suite أخرى تعمل بجانب Timing Spec. افترضنا هذا السبب أولاً، لكن قراءة الـ Configuration دحضته.

  3. مدعومةحالة Test Process نفسها.

    عند بدء Timing Specs، كان Jest Worker الوحيد قد شغّل جميع الـ Suites السابقة ضمن Shard، وارتفع Heap لديه إلى ما بين 560 MB و1 GB. يمكن أن تؤثر Garbage Collection Pause أو آثار Suites سابقة على أول قياس يأتي بعدها. وهذا يفسّر احتمال أن تستغرق عملية Write صغيرة زمناً أطول من عملية أكبر. وعلى CI، تتشارك PostgreSQL أيضاً نفس 2 vCPUs.

  4. مفتوحةHost الخاص بالـ Virtual Machine.

    قد تفقد Cloud VM وقت CPU بسبب Tenants آخرين على الـ Host نفسه، وهو أمر لا يمكن رصده من داخل الـ Job.

تجاوزت حالات الفشل الحدّ بنسبة 9% إلى 33%؛ وبعد العزل استهلكت عملية Write نفسها 11% فقط

الزمن المقاس كنسبة من الحدّ المسموح، GitHub CI، من 5 إلى 8 نوفمبر 2026

نتائج Timing كنسبة من حدودها: ‏282.1/300، ‏328/300، ‏533/400، ‏498/400، ‏42/400 ms في Fresh Process. الحدّ Pull Request، 5 نوفمبر Paged Read 282.1 ms مقابل 300 ms (94%) 282.1 ms of 300 Pull Request، 5 نوفمبر Read 328 ms مقابل 300 ms (109%) 328 ms of 300 Integration Branch، Run 1 Write لـ 50 Rows 533 ms مقابل 400 ms (133%) 533 ms of 400 Integration Branch، Rerun State Change 498 ms مقابل 400 ms (125%) 498 ms of 400 Fresh Process Write لـ 50 Rows 42 ms مقابل 400 ms (11%) 42 ms of 400
من سجلات CI لاثنتين من Pull Requests، وIntegration Branch، والـ Fix. حالة واحدة قريبة من الحدّ، وثلاث حالات تجاوز، وتشغيل واحد معزول.

التعديل الذي طبقناه. قرر الـ CTO عزل Timing Specs مع إبقاء جميع الحدود كما هي. رفع الحدّ لاستيعاب Noise قد يخفي بطئاً حقيقياً. يشغّل الـ Fix ملفَّي *-performance بشكل منفصل داخل Fresh Jest Process، بعد اكتمال بقية Suites في الـ Shard. يشغّلهما In-band، مما يعطّل حماية الـ Worker عند 1 GB؛ لذلك اقتصر هذا التعديل على هذين الملفّين.

النتيجة الأولية. داخل Fresh Process، انخفض زمن عملية Write نفسها من 533 ms إلى 42 ms، وانتهى الـ Heap عند نحو 655 MB. هذه ملاحظة من تشغيل واحد؛ تدعم الفرضية الثالثة لكنها لا تثبتها. الاختبار الحقيقي سيكون في الأسابيع التالية: إذا اختفت معظم Timing Misses، فالأرجح أن حالة الـ Process كانت السبب؛ وإن استمرت، فقد يكون السبب الـ Host.

08

هل يمكن تنفيذ هذا على Windows؟

نعم على مستوى Kernel، وجزئياً فقط من خلال Command Line. يدعم Windows منذ أكثر من عشرين عاماً CPU Affinity لكل Process وJob Objects، وهي المقابل التقريبي لـ cgroups. الميزة في Linux هي سهولة تركيب هذه الآليات معاً: كل آلية بأمر افتراضي واحد، ويمكن جمعها في Shell Scripts قصيرتين.

الآليةLinux كما استخدمناهWindows بشكل NativeWindows عبر WSL2
تثبيت العمليات على CPUstaskset -c 0,1start /affinity 3 داخل cmd (Hex Mask لوحدتَي CPU 0 و1)، أو ProcessorAffinity من PowerShell؛ وترثه Child Processestaskset، من دون تعديل
تحديد ذاكرة Process Treesystemd-run --scope -p MemoryMax=7Gاستخدام Job Object مع Job Memory Limit؛ لا يوجد أمر افتراضي مباشر، فتحتاج أداة صغيرة بـ PowerShell أو C#systemd-run بعد تفعيل systemd داخل wsl.conf
تحديد CPU Time لشجرة عملياتCPUQuota= على Scope نفسها (لم نستخدمه هنا)خاصية CPU Rate Control في Job Objectكما في Linux
Lock تنتهي مع مالكهاflockNamed Mutex: عند انتهاء مالكها، يحصل عليها المنتظر التالي مع حالة Abandonedflock، من دون تعديل
Lock تكشف هوية مالكهاmkdir مع Owner Filemkdir هي Atomic على NTFS أيضاًكما في Linux
تثبيت العمليات على Physical Cores كاملةlscpu -e يعرض الـ Core الخاصة بكل CPUأداة Sysinternals Coreinfo أو GetLogicalProcessorInformationEx تعرض أزواج الـ Cores، ويمكن تحديدها باستخدام Affinityغير قابل للتحكم: وحدات CPU في WSL2 هي Virtual CPUs تابعة لـ VM

يمكن تطبيق المنهجية نفسها على WSL2 دون تعديل، لكن هناك نقطتين: أولاً، للـ VM ميزانية CPU وMemory خاصة بها (.wslconfig)، وتعمل حدود منهجيتنا داخلها. ثانياً، تخفي الـ VM البنية الفيزيائية للمعالج، فتتحول «نواتان كاملتان» إلى «2 Virtual CPUs». يُفضّل الاحتفاظ بالـ Repositories على قرص ext4 الخاص بـ WSL2؛ فالمسار /mnt/c يصل إلى Windows عبر File Protocol أبطأ بكثير. وهذا هو الدرس نفسه الذي تعلّمناه من قرص NTFS على الـ Workstation.

ما كنا نفعله على Windows

حتى بداية نوفمبر، كانت الـ Builds تعمل على لابتوب Windows الخاص بالـ CTO. كانت القاعدة بسيطة: لا أكثر من عمليتي Build تشغّلان Gates في الوقت نفسه، خلف Shared Lock واحدة، ومن دون CPU Pinning أو Memory Caps. يخفف هذا العدد التنافس على الموارد، لكنه لا يجعل الموارد المتاحة لكل Run قابلة للتوقع، كما لم تكن الـ Lock مرتبطة بـ Process حيّة. هذا النقص تسبب بانتظار 20 دقيقة كما في القسم 04. نقل الـ Builders إلى Linux Workstation مع Resource Envelope واثنتين من Locks عالج المشكلتين.

09

القيود

هذا تقرير من تجربة فعلية، وليس Controlled Experiment. ينبغي قراءة نتائجه مع مراعاة القيود التالية.

  • عينة صغيرة. جهاز واحد، وأيام قليلة من التشغيل، وأربع حوادث Timing. لم نكرر الاختبارات مرتين ضمن ظروف مضبوطة.
  • أرقام مأخوذة من تقارير الجلسات. قدّمت AI Sessions العاملة كـ Builders معظم الأرقام من Logs الخاصة بها. راجعنا CI Logs مباشرة، لكن لم نقس Peak Memory لعملية Gate كاملة على الـ Workstation.
  • نواتان فيزيائيتان لا تساويان بالضرورة 2 vCPUs. يرفع المعالج المحمول تردده من 2.6 إلى 4.5 GHz بحسب الحرارة والحِمل، بينما تمثل Cloud vCPU عادةً Hyperthread مشتركة على سرعة الـ Host. تتطابق حدودنا في عدد وحدات CPU والذاكرة، لا في سرعة التنفيذ.
  • Resource Envelope غير مكتملة. تعمل الخدمات خارج cgroup، ولا يوجد Cap على Swap أو CPU Time. كل ذلك يجعل الـ Workstation أكثر سخاءً في الموارد مقارنة بـ CI.
  • Host لا يمكن مراقبته من الداخل. لا يمكن اختبار Resource Contention على GitHub Hosts من داخل الـ Job نفسها.
  • نتيجة داعمة واحدة. نتيجة Fresh Process مأخوذة من تشغيل واحد فقط.
10

الاستنتاجات وخطوات التطبيق

تشغيل عدة AI Builders على جهاز واحد يخلق المشكلة نفسها التي تواجه عدة مهندسين يشتركون في CI Server واحد: مشاركة CPUs والذاكرة والخدمات والـ Locks. لكن الـ Builders يصلون إلى هذا التنافس بسرعة أكبر وبصمت أكثر؛ فهم لا يتعبون، ويشغّلون Sub-agents، ولا ينتبه أحدهم إلى Lock تخص الآخر ما لم تكشف هوية صاحبها. عندما جعلنا موارد كل Run محددة ومالك كل Lock معروفاً، حوّلنا المشكلة من إخفاقات صامتة إلى Queue يمكن إدارتها.

الدرس الثاني يتعلق بالقياس: عزل CPU والذاكرة يجعل موارد كل Run قابلة للتوقع، لكنه لا يجعل حالة Process طويلة العمر قابلة للتوقع. يرث Timing Test آثار ما نفذته الـ Process قبله؛ لذلك يحتاج إلى Fresh Process بقدر حاجته إلى Core هادئة.

خطوات التطبيق بالترتيب الذي سنستخدمه مجدداً

  1. حاكِ Resource Envelope الخاصة بـ CI للـ Final Gates فقط.خصّص عدد CPUs نفسه وحدّ الذاكرة نفسه كما في CI Job، واستمر في دورة التطوير والتحقق على CI نفسها.
  2. وزّع الموارد على Physical Cores.اقرأ CPU Topology باستخدام lscpu -e، وامنح كل Job أنوية كاملة، واترك Hyperthread Siblings خارج العمل المقيّد.
  3. استخدم نوعين من Locks.الأولى تحتفظ بها File System مع معلومات المالك؛ والثانية يحررها الـ Kernel عندما تنتهي الـ Process. يبقى قرار حذف Stale Lock بيد الـ CTO.
  4. امنح الأعمال الخفيفة Slots مستقلة.لا ينبغي لـ Check أن تنتظر Gate مدتها 12 دقيقة؛ تنتظر الـ Job وتفحص توفر Slot بدلاً من تحميل الجهاز فوق طاقته.
  5. اربط كل نتيجة بـ Commit واحدة.ارفض تشغيل Gate على Dirty Tree، وسجّل Exit Code وDuration لكل Run.
  6. حدّد أين تعمل الخدمات.ضع Database داخل Resource Envelope لتحقيق Timing Parity مع CI؛ أو اقبل أن Local Timings متفائلة ووثّق ذلك بوضوح.
  7. شغّل Timing Tests في Fresh Process.لا ترفع Timing Limit لمجرد استيعاب Noise.
  8. على Windows، استخدم WSL2.تعمل Scripts نفسها على WSL2؛ أما التنفيذ Native فيحتاج أدوات Job Objects.
الملحق

الـ Scripts ومواصفات الجهاز

الـ Scripts التالية هي نفسها التي عملت في 8 نوفمبر 2026، بعد اختصار بعض Comments وإزالة أسماء المشاريع والتأكد من عدم احتوائها على Secrets. لا توجد أيٌّ منهما داخل الـ Repository. يستدعي Gate Wrapper أداة مساعدة لتشغيل وإيقاف SeaweedFS، وهي غير معروضة هنا.

أداة Check-slot المساعدة، ~/check-slot.sh
#!/usr/bin/env bash
# The Legion's two shared check slots: pnpm check, and any spec run that isn't a gate,
# runs on A (CPUs 2,3) or B (CPUs 4,5), each held by a flock. Gates stay on CPUs 0-1
# under the gate lock; 6-11 stay idle. It never touches the gate lock or the cgroup.
check_slot() {
  if [ $# -eq 0 ]; then
    echo "usage: check_slot <cmd...>" >&2
    return 2
  fi
  (
    asked=$(date +%s)
    told=
    while :; do
      for pair in A:2,3 B:4,5; do
        slot=${pair%%:*}
        cpus=${pair#*:}
        exec {fd}>"/tmp/check-slot-$slot.lock" || exit 1
        if flock -n "$fd"; then
          began=$(date +%s)
          echo "[check-slot] slot $slot (CPUs $cpus) taken at $(date -Is), after $((began - asked)) s" >&2
          taskset -c "$cpus" "$@" {fd}>&-
          rc=$?
          echo "[check-slot] slot $slot released at $(date -Is), exit $rc, $(($(date +%s) - began)) s" >&2
          exit "$rc"
        fi
        exec {fd}>&-
      done
      if [ -z "$told" ]; then
        told=1
        echo "[check-slot] both slots busy at $(date -Is): waiting" >&2
      fi
      sleep "${CHECK_SLOT_POLL:-5}"
    done
  )
}

if [ "${BASH_SOURCE[0]}" = "$0" ]; then
  check_slot "$@"
fi
Gate Wrapper الخاصة بأحد الـ Builders
#!/usr/bin/env bash
#   check-*  pnpm check: a check slot, no lock, clean tree   unit-*  unit runs: a check slot, no lock
#   gate-*   db gate, exit proof: lock + cgroup, clean tree   any other name: lock + cgroup
source "$HOME/check-slot.sh"
L=/run/media/alaa/Data/theDev/.gate.lock; N=$1; shift
SHA=$(git rev-parse --short HEAD); LOG=/tmp/gate-$N-$SHA.log
case "$N" in gate-*|check-*) [ -z "$(git status --porcelain)" ] || { echo "dirty tree: commit first"; exit 76; } ;; esac
s=$(date +%s)
case "$N" in
  check-*|unit-*) check_slot "$@" > "$LOG" 2>&1; rc=$? ;;
  *)
    mkdir "$L" 2>/dev/null || { echo "busy: $(cat "$L/owner" 2>/dev/null || echo 'a lock with no owner file')"; exit 75; }
    exec 9>/tmp/gates.lock
    flock -n 9 || { rmdir "$L"; echo "busy: /tmp/gates.lock"; exit 75; }
    echo "Joudie on Legion, $N on $SHA in $PWD, since $(date -Is)" > "$L/owner"
    source "$HOME/s3-helper.sh"; S3=0; case "$N" in gate-db*) S3=1 ;; esac
    trap 's3_stop; rm -f "$L/owner"; rmdir "$L" 2>/dev/null' EXIT
    trap 'exit 130' INT TERM HUP
    { if [ "$S3" = 1 ]; then s3_start || exit 1; fi; systemd-run --user --scope -p MemoryMax=7G --quiet taskset -c 0,1 "$@"; } > "$LOG" 2>&1 9>&-; rc=$?
    s3_stop ;;
esac
echo "exit=$rc duration=$(( $(date +%s) - s ))s" >> "$LOG"
echo "$LOG: exit=$rc"; exit "$rc"
البندالقيمة
CPUIntel Core i7-9750H، ‏6 cores، ‏2 threads لكل Core، ‏2.6 GHz Base، ‏4.5 GHz Boost
ترقيم CPUCPUs من 0 إلى 5 تمثل Cores من 0 إلى 5؛ وCPUs من 6 إلى 11 هي الـ Siblings المقابلة (0 مع 6، و1 مع 7، حتى 5 مع 11)
الذاكرة30 GiB RAM، مع 8 GiB Swap
النظامUbuntu 26.04.1، ‏Kernel 7.0.0، ‏cgroup v2، ‏systemd 259
أدوات التطويرNode 24.21.0، ‏pnpm 10.34.5
الخدماتPostgreSQL 18.6، ‏Redis 8.0.5، ‏SeaweedFS 4.48
الأقراصقرص 915 GB ext4 NVMe للـ Worktrees؛ وقرص 1.9 TB NTFS عبر ntfs3 للـ Main Checkout والـ Gate Lock