Skip to content

[CTX-1361] fix(runtime): harden activation record read/write and the ignored acceptance guard - #2295

Merged
Xuepoo merged 1 commit into
mainfrom
ctx-1361/fix-activation-hardening
Oct 20, 2026
Merged

Xuepoo merged 1 commit into
mainfrom
ctx-1361/fix-activation-hardening

Conversation

@Xuepoo

@Xuepoo Xuepoo commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Fixes the blocking findings from the independent review of #2276 (CTX-1361 /
#2254). One commit, no behavior change for a well-behaved filesystem.

Priority: P1 | Area: runtime | Labels: fix,area:runtime,P1 | Milestone: 0.0.24 | RFC: OQ-xxx | Task: CTX-1361

F1/CR1 — write side followed a planted symlink

write_activation wrote the record with std::fs::write to the predictable
activation.tmp-<pid>-<serial> path, so a same-user process with write access
to the component directory could pre-create that name as a symlink and redirect
the write. Now:

  • the temp record is created with OpenOptions::new().write(true).create_new(true)
    (mode 0600 on Unix): O_CREAT|O_EXCL refuses an existing entry, including a
    planted link, and nothing is truncated;
  • AlreadyExists retries under a fresh name (bounded: 8 attempts), and a failed
    creation never removes an entry the writer did not create;
  • the record is flushed with sync_all, renamed over activation, and the
    component directory is flushed so the rename survives a crash;
  • any other failure removes the temp file best-effort and returns the new typed
    ActivationWriteError (RecordNotRegular, RecordOversize,
    TempNameExhausted, TempCreate, TempWrite, Rename, SyncDir). The three
    broker call sites drop it explicitly: activation is diagnostics and never a
    request or stop gate.

F2 — the read bound was not a bound

The size came from symlink_metadata while std::fs::read re-resolved the path,
so a symlink swapped in afterwards was followed and read to EOF. Now the record
is opened once without following a link (O_NOFOLLOW|O_NONBLOCK|O_CLOEXEC via
rustix/nix, FILE_FLAG_OPEN_REPARSE_POINT on Windows, fail-closed on a
platform without such an open), the regular-file test and length come from that
handle, and the read is take(MAX + 1) with a length-mismatch rejection, so a
record that grew between snapshot and read is rejected instead of parsed. A FIFO
at the record path can no longer block the open.

B1 — vacuous ignored acceptance test

real_bitty_net_serves_and_denies_with_a_named_class returned Ok when
BITTY_NET_COMPONENTS_DIR was unset, so --run-ignored ignored-only reported
PASS without running. It now panics with a clear message when the fixture is
missing, and asserts the fixture actually contains the installed component, so a
green run always means the acceptance flow executed. (I did not re-run the real
bitty-net flow: the recorded evidence in recording/ctx-1361-component-broker/
still stands, and this PR only changes the guard.)

B2 — docs

Docs-only sync merged first: bitty-terminal/bitty-terminal-docs#249
(squash 86e0897), describing the ACTIVATION column, its labels and denial
classes, and the persistent activation record beside current.

Deferred (tracked)

bitty#2294 covers F3 (name-scoped state on every version row), F4 (active is
last-recorded, not liveness), F5/P3 (system-tier projection), F6 (a denial
overwriting the crashed latch), F7 (stale temp files blocking prune).

Tests and mutation evidence

New tests (crates/bitty-runtime/src/component/activation.rs):

Test Guard it pins
planted_temp_link_is_refused_and_the_write_retries_under_a_fresh_name an activation.tmp-* symlink is not followed and the write lands under a fresh name
exhausted_temp_names_surface_a_typed_error bounded retries surface TempNameExhausted, create nothing
grown_record_is_rejected_by_the_handle_bound a record grown after the metadata snapshot is rejected, the same handle still accepts an unchanged one
symlinked_oversize_record_is_rejected_without_reading_it symlink + oversize reads as installed
symlinked_record_is_never_followed (extended) write now reports RecordNotRegular, link target untouched
acceptance test without the fixture panics instead of reporting a vacuous PASS

Mutation checks (each reverts one guard; the named test fails):

  • create_new(true) -> create(true).truncate(true): the planted link is
    followed and the victim is overwritten with v1 stopped
    (planted_temp_link_..., exhausted_temp_names_... fail).
  • dropping the bytes.len() != metadata.len() rejection:
    grown_record_is_rejected_by_the_handle_bound fails.
  • open_record_no_follow -> std::fs::File::open:
    symlinked_record_is_never_followed fails.
  • restoring the old return guard: the ignored acceptance test reports PASS
    without the fixture (with the guard it fails, see the run log in the PR
    conversation).

Gates (local)

  • cargo fmt --all -- --check: PASS
  • cargo clippy --workspace --all-targets --locked with RUSTFLAGS=-D warnings: PASS
  • cargo nextest run -p bitty-terminal -p bitty-runtime --locked: 3881 passed, 3 skipped
  • cargo check --workspace --all-targets --locked --target x86_64-pc-windows-msvc: PASS
  • just scratch-paths: OK
  • just ci-local: not run — the repository lock
    (.git/ci-local.lock) is held by another run in this repo; remote
    Quality gates runs the same job.

CARGO_BUILD_JOBS=8, CARGO_TARGET_DIR=$BITTY_WORKSPACE/.targets/ctx-1361-findings
(removed after the PR).

Refs #2276, #2254, #2294

…ignored acceptance guard

Follow-up to #2276 review findings F1, F2 and B1.

F1 (write side): the record was written with `std::fs::write` to the
predictable `activation.tmp-<pid>-<serial>` path, so a same-user process
could pre-plant that name as a symlink and redirect the write. The temp
record is now created with `create_new` (mode 0600; `O_CREAT|O_EXCL`
refuses a link), flushed with `sync_all`, renamed over `activation`, and
the directory is flushed. `AlreadyExists` retries under a fresh name
(bounded, 8 attempts) without ever removing an entry this writer did not
create; any other failure removes the temp file best-effort and returns
the new typed `ActivationWriteError` (the broker drops it - activation is
diagnostics, never a request gate).

F2 (read side): the size bound came from `symlink_metadata` while
`std::fs::read` re-resolved the path, so a swapped-in symlink or a grown
file defeated both the no-follow and the size guarantee. The record is
now opened once without following a link (`O_NOFOLLOW|O_NONBLOCK|O_CLOEXEC`
via rustix/nix; `FILE_FLAG_OPEN_REPARSE_POINT` on Windows; fail-closed
elsewhere), the length and regular-file checks come from that handle, and
the read is bounded by `take(MAX + 1)` with a length-mismatch rejection.

B1: the ignored `bitty-net` acceptance test returned `Ok` when
`BITTY_NET_COMPONENTS_DIR` was unset, so `--run-ignored ignored-only`
reported a vacuous PASS. It now fails with a clear message when the
fixture is missing or does not contain the installed component.

Tests: planted temp symlink is not followed and the write retries;
exhausted temp names surface `TempNameExhausted`; a record grown after
the metadata snapshot is rejected; a symlinked oversize record reads as
`installed`; the acceptance test fails without its fixture. Mutation
evidence: `create_new` -> `create|truncate` makes both write tests fail
(the planted link is followed and the victim overwritten); dropping the
length-mismatch check makes the grown-record test fail; `File::open`
instead of the no-follow open makes the symlinked-record test fail; the
old `return` guard makes the ignored test PASS without the fixture.

Refs #2276, #2254
@Xuepoo Xuepoo added this to the 0.0.24 milestone Oct 20, 2026
@Xuepoo Xuepoo added fix Bug fix P1 Priority: high area:runtime Area: runtime orchestration labels Oct 20, 2026
@coderabbitai

coderabbitai Bot commented Oct 20, 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 7 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
  • Configuration used: Repository UI (base), Organization UI (inherited)
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3864d1cb-7f04-4867-9693-0cdf1d95a85e
📥 Commits

Reviewing files that changed from the base of the PR and between 470c20a and a929219.

📒 Files selected for processing: 3
  • crates/bitty-runtime/src/component/activation.rs
  • crates/bitty-runtime/src/component/broker.rs
  • crates/bitty-terminal/tests/component_broker_acceptance.rs
  • 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.

@Xuepoo
Xuepoo merged commit f9be45d into main Oct 20, 2026
17 checks passed
@Xuepoo
Xuepoo deleted the ctx-1361/fix-activation-hardening branch October 20, 2026 02:27
Xuepoo added a commit that referenced this pull request Oct 20, 2026
The first pass was audited at `470c20ab`; four commits merged while it was open
and one of them changes a claim the entry makes.

- #2296 adds the production component request surface
  (`bitty.component.request` / `bitty.component.poll`) and closes #2254, so the
  Known issues bullet no longer says no request producer exists. Its real
  limits replace it: no IPC verb, no streaming or retained handle, lossy UTF-8
  response bodies, and a mirrored grant surviving a runtime-only suspend.
- #2295 hardens the activation record against a planted symlink on both the
  write and read side, with a typed `ActivationWriteError`.
- #2291 moves all six extracted extension pins to their upstream heads and adds
  the pin drift gate.
- #2298 deflakes the cross-VM `command_invoke` test against the 50 ms
  production RC-1 wall budget.

The provenance line now records the audited head `6c4ae437`. The RC-1 fuel
accounting fix is still not claimed: PR #2292 remains open.

Docs-only: no code, scripts, workflows, or pins touched.
Xuepoo added a commit that referenced this pull request Oct 20, 2026
The first pass was audited at `470c20ab`; four commits merged while it was open
and one of them changes a claim the entry makes.

- #2296 adds the production component request surface
  (`bitty.component.request` / `bitty.component.poll`) and closes #2254, so the
  Known issues bullet no longer says no request producer exists. Its real
  limits replace it: no IPC verb, no streaming or retained handle, lossy UTF-8
  response bodies, and a mirrored grant surviving a runtime-only suspend.
- #2295 hardens the activation record against a planted symlink on both the
  write and read side, with a typed `ActivationWriteError`.
- #2291 moves all six extracted extension pins to their upstream heads and adds
  the pin drift gate.
- #2298 deflakes the cross-VM `command_invoke` test against the 50 ms
  production RC-1 wall budget.

The provenance line now records the audited head `6c4ae437`. The RC-1 fuel
accounting fix is still not claimed: PR #2292 remains open.

Docs-only: no code, scripts, workflows, or pins touched.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:runtime Area: runtime orchestration fix Bug fix P1 Priority: high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant