Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
189f94c
feat(core,repo,cli): operator-configurable max object size (#213)
tonibergholm-codento Oct 20, 2026
2ac8838
fix(repo): scale the store budget with the object cap, document memor…
tonibergholm-codento Oct 20, 2026
eeb8d61
fix(core,repo,cli): stepped reads, 2 MiB floor, peer-mismatch hint, f…
tonibergholm-codento Oct 20, 2026
76adb06
docs(core): fix floor label and stale by-id/bucket cap statements (#213)
tonibergholm-codento Oct 20, 2026
e7e015d
chore(core,repo): proportional read growth, close PutPack on any spil…
tonibergholm-codento Oct 20, 2026
932d998
Merge remote-tracking branch 'origin/main' into feat/213-max-object-size
tonibergholm-codento Oct 20, 2026
fcc715a
fix(core,repo): review follow-ups: overflow-safe hint, 2x pack decode…
tonibergholm-codento Oct 20, 2026
3d29352
fix(repo): do not apply the server's own object cap to by-id replies …
tonibergholm-codento Oct 20, 2026
2f515a0
Merge remote-tracking branch 'origin/main' into feat/213-max-object-size
tonibergholm-codento Oct 20, 2026
bd65d52
fix(repo): frame limit includes framing overhead, move PutObject body…
tonibergholm-codento Oct 20, 2026
1926094
docs: ADR-0039 framing overhead and single-object peak (#213)
tonibergholm-codento Oct 20, 2026
72b9e3f
Merge branch 'main' into feat/213-max-object-size
tonibergholm-codento Oct 20, 2026
ee13ff2
Merge remote-tracking branch 'origin/feat/213-max-object-size' into f…
tonibergholm-codento Oct 20, 2026
301a8d6
docs,demo: stale object-cap claims in ADRs, isolate the limits demo f…
tonibergholm-codento Oct 20, 2026
5f8b002
Merge branch 'main' into feat/213-max-object-size
tonibergholm-codento Oct 20, 2026
b7b1cc3
fix(repo): chunk size fits the smallest valid receiver, early cap che…
tonibergholm-codento Oct 20, 2026
c8e03a4
Merge branch 'main' into feat/213-max-object-size
tonibergholm-codento Oct 20, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .claude/skills/sc-cli-reference/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,16 @@ cargo run --bin sc -- serve --http <addr> <path> [--read-only] [--allow-public]
# trip; opening keeps its own 30s (P31)
# --max-pack-size <bytes>: incoming-pack aggregate
# cap, both --http and --stdio, default 16 GiB,
# 0=unlimited, floor 256 MiB (MAX_OBJECT_SIZE);
# 0=unlimited, floor = the max object size;
# counted mid-stream abort -> EC_TOO_LARGE (P31)
# --max-object-size <bytes|KiB|MiB|GiB>: largest
# single object accepted from a peer, default
# 256MiB, range 2MiB..1GiB, out of range aborts
# startup (never clamped). Clients use env
# SC_MAX_OBJECT_SIZE (same parse, any command; empty = unset);
# flag beats env. No negotiation: each receiver
# applies its own cap; a larger object fails at
# whichever side receives it (#213)
cargo run --bin sc -- serve token add --label <name> --scope ro|rw [--expires <30m|12h|7d|2w|YYYY-MM-DD>]
# mint an sct-<hex> bearer token in
# .sc/serve-tokens.toml; raw value prints once on
Expand Down
8 changes: 4 additions & 4 deletions ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ a retired pre-P16 snapshot encoding, refused with a clear error):

Objects are serialized canonically (length-prefixed, sorted tree entries) so the
hash is stable across machines. Every decode length prefix is bounded by a
`MAX_OBJECT_SIZE` / remaining-bytes guard (P28) so a hostile object can't drive
max-object-size / remaining-bytes guard (P28) so a hostile object can't drive
an unbounded allocation.

## In-memory VFS layer
Expand Down Expand Up @@ -888,7 +888,7 @@ coarsening rather than per-case gap tolerance. See ADR-0037.
## Phase 28 — security hardening sweep (built)

A dedicated security pass closing exposure introduced by opening the store
to untrusted network peers (P26/P27). One `MAX_OBJECT_SIZE` cap bounds any
to untrusted network peers (P26/P27). One max-object-size cap (`scl_core::max_object_size()`, ADR-0039 addendum) bounds any
single object's decompressed/decoded size at every read/write boundary that
takes attacker-controlled bytes, closing a decompression-bomb / unbounded-
allocation class that P25's `read_frame_inner` had already named as a known
Expand Down Expand Up @@ -943,8 +943,8 @@ limit a new connection gets an immediate busy status at the pre-handshake
opening seam and closes — no queuing), `--timeout` (default 300s; read+write
timeouts now persist for the whole session instead of being cleared after the
opening, connection-fatal on trip since a mid-stream abort desyncs the frame
stream), and `--max-pack-size` (default 16 GiB, floor 256 MiB =
`MAX_OBJECT_SIZE`; lives in the shared `WirePolicy`, so it applies to both
stream), and `--max-pack-size` (default 16 GiB, floor = the max object
size, 256 MiB by default; lives in the shared `WirePolicy`, so it applies to both
`--http` and `--stdio`; a counted mid-stream abort replies `EC_TOO_LARGE`).

The read-only pre-drain is capped at 8 MiB (`RO_DRAIN_CAP`), and the accept
Expand Down
11 changes: 7 additions & 4 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ the code, those win.
| P25 | Streaming pack transfer: bounded RAM on both sides, `ST_PACK_CHUNK` frames (`SC_PACK_CHUNK` tunes), two-pass atomic-after-verify ingest | [0035](docs/adr/0035-streaming-transfer.md) |
| P26 | `sc+http://` transport: `sc serve --http`, thread-per-connection, status-line-before-handshake opening | [0036](docs/adr/0036-http-transport.md) |
| P27 | Partial clone: `sc clone --filter <prefix…>`, `.sc/promisor`, `sc backfill [--all]`; wire `PROTOCOL_VERSION` 3 | [0037](docs/adr/0037-partial-clone.md) |
| P28 | Security hardening: `MAX_OBJECT_SIZE` (256 MiB) caps on every untrusted transfer length; strict ref-name validation | [0039](docs/adr/0039-security-hardening-sweep.md) |
| P28 | Security hardening: a max object size (default 256 MiB; `--max-object-size` / `SC_MAX_OBJECT_SIZE`, 2 MiB to 1 GiB) caps every untrusted transfer length; strict ref-name validation | [0039](docs/adr/0039-security-hardening-sweep.md) |
| P29 | `sc serve --http` access control: bearer tokens (`sc serve token`), `--read-only`, fail-closed non-loopback bind gate | [0040](docs/adr/0040-sc-http-access-control.md) |
| P30 | Sealed agent-session transcripts: `sc transcript attach/show/list/sign/drop`, always-encrypted body, gc-coupled index; `--no-transcripts` on fetch/clone/push (client-side, per command); drop = grow-only tombstone (a bare `Transcript` object, no wire change), kept by gc, hides the body from fetch/reindex | [0038](docs/adr/0038-agent-session-transcripts.md) |
| P31 | Listener resource limits: `--max-connections`, `--timeout`, `--max-pack-size` (both transports), capped read-only drain, accept backoff | [0041](docs/adr/0041-listener-resource-limits.md) |
Expand All @@ -152,7 +152,7 @@ the code, those win.
| P35 | Native Tauri desktop browser: opens `.sc` repositories through `scl-repo`, shows local/remote refs, all-parent snapshot DAG + provenance, public trees and first-parent diffs; protected content is locked and private branches remain opaque; no mutation or identity surface | [0045](docs/adr/0045-native-desktop-read-model.md) |
| P36 | Bucket WAL remotes (sc+wal://, sc+s3://): immutable packs + CAS'd manifest, checkpoints + log-tail cold start, bucket-backed `sc serve --store` with disposable instances | [0046](docs/adr/0046-wal-bucket-remotes.md) |
| P37a | Want-by-id fetch: batched `GetObjects` verb (wire v5), opt-in `.sc/promisor-lazy`, `sc cat <ref>:<path>` fills only the absent trees and blob on its path; `Store::get` stays network-free; sealed objects refused by kind; sparse widen and the lifted P27 refusals are P37b | [0047](docs/adr/0047-want-by-id-fetch-and-gap-fill.md) |
| P37b-i | Presence-based partial clones: push, verify and gc walk what the store holds (`reachable_objects_partial`), not the fetch filter; push checks every gap id against the destination before sending; a view gap fails with `GapInView` before any write (preflight at the top of `materialize`, plus `undo` and `sparse set`); a partial clone fetches from its origin only. 37b-ii: on a lazy, online clone `ensure_view` fills the view closure by id before switch, fast-forward, undo and `sparse set`, `sparse set` may widen past the filter, a by-id reply is capped at `min(--max-pack-size, 512 MiB)` and a refused batch is split. | [0048](docs/adr/0048-presence-based-partial-clones.md) |
| P37b-i | Presence-based partial clones: push, verify and gc walk what the store holds (`reachable_objects_partial`), not the fetch filter; push checks every gap id against the destination before sending; a view gap fails with `GapInView` before any write (preflight at the top of `materialize`, plus `undo` and `sparse set`); a partial clone fetches from its origin only. 37b-ii: on a lazy, online clone `ensure_view` fills the view closure by id before switch, fast-forward, undo and `sparse set`, `sparse set` may widen past the filter, a by-id reply is capped at `min(--max-pack-size, 2 GiB)` (a constant since #213, independent of the object cap) and a refused batch is split. | [0048](docs/adr/0048-presence-based-partial-clones.md) |
| P37c | Merge, cherry-pick and rebase on a partial clone: a tree-recursive engine (`merge_trees`) carries a subtree by id when the sides agree and no protection rule applies, reads only where they differ or a rule intersects, and on a lazy, online clone fills what it asks for by id outside the store lock (a non-lazy clone gets the gap error with `sc backfill <path>`); a carried protected subtree keeps the complete input wrap union; a conflict inside the view is marked and resolved like on a full clone (`sc conflicts`/`sc resolve`/`merge --abort`/`sc commit`; the out-of-view part is grafted from the decided root), while a conflict outside the view, or a result that must be sealed outside it, is refused before any ref, merge-state or working-tree change (fetched objects stay). A subtree identical on all three sides is carried even under a protection rule. Cherry-pick and rebase use the same engine (`replay_commit`): the fold's accumulator may hold absent subtrees, the view is filled before the final write, and a stopped pick or rebase keeps its carried subtrees in the decided root. Mode-only edits now merge and a file/directory collision fails before any write, on full clones too. | [0049](docs/adr/0049-merge-on-partial-clones.md) |
| P37d | Agent sessions on a partial clone: `sc ws fork`/`run`/`harvest`/`abandon` and `sc work` work; a workspace or agent sees the host's sparse view only (`sc work` no longer gets a complete tree there), the view closure is filled (lazy, online) or refused with the gap error before anything is written, a workspace commit grafts the out-of-view subtrees from the base without reading them, and harvest lands through the ADR-0049 merge (any conflict falls back to a `work-<i>` branch as on a full clone) | [0050](docs/adr/0050-sessions-on-partial-clones.md) |

Expand All @@ -163,9 +163,12 @@ Cross-cutting current facts that bite. Security boundaries are consolidated in
transport-adjacent. The rest, imperatively:

- **Wire protocol is version 5** (bumped from 4 in P37 for the additive
`GetObjects` verb; 3 to 4 in P34 for the sealed-branch object kinds). `MAX_OBJECT_SIZE` (256 MiB) guards the
`GetObjects` verb; 3 to 4 in P34 for the sealed-branch object kinds). The max object size (`scl_core::max_object_size()`, default 256 MiB;
`sc serve --max-object-size` and `SC_MAX_OBJECT_SIZE` set it, range 2 MiB to
1 GiB, out of range aborts startup, ADR-0039 addendum) guards the
transfer path only — a larger blob commits locally but fails every
subsequent push/fetch/clone at the receiver.
subsequent push/fetch/clone at the receiver. There is no negotiation: each
receiver applies its own cap, so it must admit the objects it receives. Never inline a size in a new length guard; read the accessor.
- **The P35 desktop app is a keyless, read-only top-level adapter.** Its
renderer has five typed repository commands, no general filesystem/shell
capability, and no DTO field capable of carrying protected ciphertext or
Expand Down
9 changes: 5 additions & 4 deletions ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -800,11 +800,12 @@ scale-&-reach horizon):
secrets to the command on a descriptor (NUL-terminated `NAME=VALUE` records)
instead of its environment. Not built: the same mode for `sc ws run` and
`sc work --with-secrets`, and a stdin variant.
- **`--max-object-size` operator config knob (P28).** `MAX_OBJECT_SIZE`
(256 MiB) is a compile-time constant anchoring every untrusted-length
guard; letting an operator raise or lower it per-deployment is deferred.
- **`--max-object-size` operator knob — shipped (#213, ADR-0039 addendum).**
`sc serve --max-object-size` and `SC_MAX_OBJECT_SIZE` set the per-object cap
(default 256 MiB, range 2 MiB to 1 GiB, out of range aborts startup). No wire
negotiation: each receiver applies its own cap.
- **P28 review follow-ons — shipped.** `refs::write_head`/`delete_branch` run
`validate_branch_name`; `SC_PACK_CHUNK` is clamped to `MAX_OBJECT_SIZE - 1` (a chunk frame carries a tag byte too; an
`validate_branch_name`; `SC_PACK_CHUNK` is clamped to the minimum configurable object cap minus one (2 MiB - 1, so every chunk frame fits any valid receiver) (a chunk frame carries a tag byte too; an
oversized value used to make every transfer fail with a confusing receiver
error); `Repo::worktree_paths` is a paths-only walk (`list_worktree_paths`,
the same ignore and tracked-path rules as `read_worktree`, no file read); and
Expand Down
38 changes: 35 additions & 3 deletions crates/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,10 +364,18 @@ enum Cmd {
#[arg(long)]
timeout: Option<u64>,
/// Maximum incoming pack size in bytes (both --http and --stdio);
/// 0 = unlimited. Default 16 GiB. Must be ≥ 256 MiB (MAX_OBJECT_SIZE)
/// when non-zero. (P31)
/// 0 = unlimited. Default 16 GiB. Must be at least the max object
/// size (default 256 MiB) when non-zero. (P31)
#[arg(long)]
max_pack_size: Option<u64>,
/// Largest single object accepted from a peer: bytes, or a number
/// with a KiB/MiB/GiB suffix. Default 256MiB, range 2MiB to 1GiB;
/// out-of-range values are refused at startup, never clamped. Clients
/// set it with `SC_MAX_OBJECT_SIZE`. Each receiver applies its own
/// cap, so a larger object fails at whichever side is receiving it.
/// (#213)
#[arg(long, value_name = "SIZE")]
max_object_size: Option<String>,
/// Serve TLS (`sc+https://`): auto-mints a self-signed identity into
/// `.sc/serve-tls/` unless --tls-cert/--tls-key supply a PEM pair.
/// `--http` only. (P32)
Expand Down Expand Up @@ -975,8 +983,31 @@ struct DemoArgs {
checkout: bool,
}

/// Fix the process-wide object cap before any command runs: `sc serve
/// --max-object-size` wins over `SC_MAX_OBJECT_SIZE` (empty = unset), which wins over the
/// default. An out-of-range or unparsable value aborts startup (#213).
fn init_max_object_size(flag: Option<&str>) -> Result<()> {
let (src, raw) = match (flag, std::env::var("SC_MAX_OBJECT_SIZE")) {
(Some(f), _) => ("--max-object-size", f.to_string()),
// An empty variable (`SC_MAX_OBJECT_SIZE=`) means unset, so exporting
// it blank in a profile does not abort every command.
(None, Ok(e)) if e.trim().is_empty() => return Ok(()),
(None, Ok(e)) => ("SC_MAX_OBJECT_SIZE", e),
(None, Err(std::env::VarError::NotPresent)) => return Ok(()),
(None, Err(e)) => anyhow::bail!("SC_MAX_OBJECT_SIZE: {e}"),
};
let n = scl_core::parse_object_size(&raw).map_err(|e| anyhow::anyhow!("{src}: {e}"))?;
scl_core::set_max_object_size(n).map_err(|e| anyhow::anyhow!("{src}: {e}"))
}

fn main() -> Result<()> {
let cli = Cli::parse();
init_max_object_size(match &cli.cmd {
Cmd::Serve {
max_object_size, ..
} => max_object_size.as_deref(),
_ => None,
})?;
match cli.cmd {
Cmd::Demo(args) => run_demo(args),
Cmd::Import { repo } => run_import(repo),
Expand Down Expand Up @@ -1072,6 +1103,7 @@ fn main() -> Result<()> {
max_connections,
timeout,
max_pack_size,
max_object_size: _,
tls,
tls_cert,
tls_key,
Expand Down Expand Up @@ -3836,7 +3868,7 @@ fn run_serve(
);
}
let max_pack = max_pack_size.unwrap_or(scl_repo::wire::DEFAULT_MAX_PACK_SIZE);
scl_repo::wire::validate_max_pack_size(max_pack)?;
scl_repo::wire::validate_max_pack_size(max_pack, scl_core::max_object_size())?;
let policy = scl_repo::wire::WirePolicy {
read_only: false,
max_pack_size: max_pack,
Expand Down
Loading
Loading