Debugging
The rule
Never fix code before you understand why it broke. The temptation to "just make the test pass" or "just patch the symptom" leads to fragile fixes that hide deeper problems. Follow the three-step workflow below every time.
Choose the cheapest truthful feedback loop
Keep implementation moving. Use a minimal reproducer and focused TDD checks
during coding, then return to the next implementation item. Broad qualification
runs belong at the end of a major phase; a small fix does not justify another
whole contract/workspace/VM/install run. The bounded wrapper retains timeout
and cleanup without a routine machine lease.
Capsem now has two distinct execution surfaces:
- Just exposes the small public product interface.
- Python under
build_system/builder/gate/owns build/test/release plans, graph edges,
locking, resources, evidence, and cleanup.
For a gate failure, debug the Python step and action that failed; do not infer
the implementation from the Just recipe or recreate it with shell commands.
Start with:
uv run --project build_system --frozen capsem-gate runs last --failed
uv run --project build_system --frozen capsem-gate <command> --dry-run
uv run --project build_system --frozen capsem-gate <command> --graph
Use the smallest focused pytest, cargo, pnpm, or script command for red/green
work. Use just focus-test functional for focused integration feedback, and
just fast-test for the fast gate itself. Use just test when the forward fix
is ready for the complete local verification a release requires.
Direct diagnostics which may block, build, launch children, or wait on input
must use the portable bounded-process wrapper rather than a bare shell command:
python3 build_system/scripts/ci/run-bounded-command.py --timeout-seconds 1800 -- <command> <args...>
The wrapper closes stdin, creates a dedicated process group, and terminates the
whole group on timeout or interruption. This prevents a PTY-backed `docker
build -f -`, compiler, test runner, or child helper from surviving its owning
diagnostic. Pick a finite timeout appropriate to the focused operation; do not
wrap just test or a release command, whose config-owned step timeouts,
journal, teardown, and resumable graph are the authority.
Diagnostic continuation for a late gate failure
When a clean candidate fails after expensive predecessors have succeeded, use
diagnostic continuation to reuse that retained state and reach the frontier
quickly. The current CLI retains legacy flag names:
uv run --project build_system --frozen capsem-gate runs last --failed
uv run --project build_system --frozen capsem-gate candidate --prefix <retained-prefix> --from <failed-step>
The --from step runs; graph predecessors are reported as carried. Before
using it, match the prefix and failed step to the origin run, confirm the
required predecessor really completed there, and record the origin run ID in
the diagnosis. Prefer a fresh focused test when the edit invalidates the
expensive producer itself.
Carried steps with external runtime products are revalidated before resumed
work. If one was reclaimed, use the exact owning --from label in the refusal;
do not guess an earlier frontier or recreate the product by hand.
Call the result diagnostic-passed or diagnostic-failed, even if the current
implementation still summarizes a zero exit as ok. It combines earlier
outputs with current source and therefore answers only whether the new segment
can proceed. It does not prove the complete current tree.
Never use diagnostic continuation with release-binaries or
release-assets, and never let it authorize publication. After the fix, use
the smallest owning focus-test group. Before release, run just test <commit>
to success: the public release command requires its complete local journal for
that commit or an identical Git tree by default. An explicitly authorized
release force permits a focused test-only correction without repeating the
complete local run; source guards and full hosted qualification remain.
The unattended nightly scheduler is also exempt ([release].unattended_channels in