Repository navigation
fix(policy): refuse history stamped ahead of the clock - #410
Conversation
## Problem `durable_config()` set `with_max_future_skew(Duration::MAX)`. This disabled the guard in `dogwood-local-engine` that refuses a durable high-water mark more than five minutes ahead of the wall clock. No decision records a reason for the override. If `private/dogwood.redb` holds an event stamped far in the future, for example after an edit while the box is stopped, the next start accepts that timestamp. Each real event then gets that timestamp plus one nanosecond, so the event clock stops. All real history moves out of every `within` window, and history-gated denials stop with no refusal, warning, or record. ## Solution Remove the override, so the box uses the engine default of five minutes. Every open path uses `durable_config()`. Thus `open`, the staged opens, and the test-clock open now refuse a history stamped more than five minutes ahead of the clock. During a run, an append fails while the clock is more than five minutes behind the last event, so the request is denied. Decisions continue when the clock catches up. This changes recorded behaviour: before, a box opened after any backward clock step. The decision entry "History is durable per box", `docs/design/policy.md`, and `docs/user/policy.md` now state the bound, the refusal text, and the remedy. No frozen interface changes. The history file format does not change. ## Tests - `history_stamped_beyond_the_skew_bound_is_refused_by_every_open_path` (new): a history stamped one hour ahead is refused by all four production open paths with the engine's skew reason. On `main`, the previous test opened this same history on all four paths, so this test fails without the fix. - `wall_clock_rollback_within_the_skew_bound_preserves_history_across_every_open_path` (was `wall_clock_rollback_preserves_history_across_every_open_path`): a 60-second rollback still keeps the consumed budget on all four open paths. The previous one-hour case is now the refusal above. - `cargo build`, `test`, `clippy --all-targets`, and `fmt --check` for `-p strands-box-policy`, with and without `--all-features`, and `RUSTDOCFLAGS="-D warnings" cargo doc`: pass. Clippy shows only the six existing `strands-shell` vendored warnings. - `cargo test -p strands-box --test site_manifest --locked --all-features`: pass. - feature-critic: no blockers. It ran `cargo build -p strands-box --all-features` and the containment suite (129 pass, 12 Linux-only skips on macOS). - Not run: Linux targets, and a test that steps the clock back more than five minutes during a run. That behaviour comes from the engine.
|
Assessment: Request Changes Removing the Checks that held
The upgrade effect and the bound are clearly written down in the decision entry and the user docs. |
|
Assessment: Comment e34dff2 closes the in-run budget bypass: a lost outcome now makes the engine deny every later request in that run. One gap remains. The flag doesn't survive a restart, and the docs point operators to a restart as the remedy (inline on Checks that held
|
|
Assessment: Comment 201d73a fixes the restart gap from my last review. A refused outcome is now kept and recorded before the next decision, so it counts after a restart once it has been saved. One ordering is still open: the operator corrects the clock and then restarts before any request arrives (inline on Checks that held
|
|
Assessment: Approve 4908777 fixes the ordering I flagged last time: the operator corrects the clock, then restarts with no request in between. Checks that held
|
…against the upstream Shell The vendored Shell files that #397 changed are deleted here. #397's Shell tests move to crates/shell/tests/main_shell_semantics.rs and the broker tests, and its two Lua stdin tests move to the broker. The tests for #397's Shell fixes fail until the upstream Shell fixes land.
Description
Human readable section
Problem: Box keeps a history of what the agent did, with a timestamp on each event, so time-based rules such as "at most 2 writes per hour" still apply after a restart. The policy engine normally refuses a history whose newest timestamp is more than five minutes ahead of the system clock, because that means the clock or the file is wrong. Box had set that limit to unlimited. So if the history file held one event stamped years ahead, the box accepted it at the next start and stamped every later event just after it. All real history then looked years old, time-based limits stopped applying, and nothing warned about it.
Solution: Box now uses the engine's own five-minute limit on every path that opens history. A history stamped further ahead is refused at startup, and the error names the skew. During a run, a request is denied while the gap exceeds five minutes, and decisions return once the clock is within five minutes again. If an action that already ran can't be recorded, Box keeps the record, saves it before the next decision or when the box shuts down, and denies every request until it is saved. So a refused record can't free up a budget, during the run or after a restart. The design pages and the user policy page describe the limit and how to recover.
Trade-off: If the system clock is moved back more than five minutes, the box refuses to start until the clock catches up, or until the operator removes the box directory. Time-zone changes and daylight saving don't move the system clock, which counts UTC seconds, so they don't trigger this. A forged event less than five minutes ahead is still accepted, and it can keep timestamps ahead for up to five minutes.
What we tested:
history_stamped_beyond_the_skew_bound_is_refused_by_every_open_pathwall_clock_rollback_within_the_skew_bound_preserves_history_across_every_open_patha_clock_behind_history_beyond_the_skew_bound_denies_until_it_returns_within_ita_skew_refused_outcome_is_recorded_before_the_next_decision_and_survives_a_restarta_kept_outcome_is_recorded_when_the_engine_shuts_downstrands-boxbinary on macOSTZ=America/ChicagoTZset to America/New_York, Asia/Kolkata, Pacific/Auckland, and UTCDetails
durable_config()setwith_max_future_skew(Duration::MAX). This disabled the guard indogwood-local-enginethat refuses a durable high-water mark more than five minutes ahead of the wall clock. No decision records a reason for the override.If
private/dogwood.redbholds an event stamped far in the future, for example after an edit while the box is stopped, the next start accepts that timestamp. Each real event then gets that timestamp plus one nanosecond, so the event clock stops. Real history moves out of everywithinwindow, and history-gated denials stop with no refusal, warning, or record.This PR removes the override, so the box uses the engine default of five minutes on every open path. During a run, while the clock is more than five minutes behind the last event, the engine refuses to timestamp the event and the request is denied. Decisions continue once the clock is within five minutes again. An outcome the history refuses is kept on the engine. Each later decision records the kept events first and denies with
InternalFaultuntil they append, andDrop for DogwoodEnginerecords them at shutdown. An event that still can't append at shutdown, or a killed process, loses it; the docs state this.Decision this depends on. This changes recorded behaviour: before, a box opened after any backward clock step. The PR uses the engine's five-minute default rather than a box-specific bound. If maintainers want more tolerance for clock corrections, a modest named constant is the alternative, never an unbounded one. The entry History is durable per box,
docs/design/policy.md, anddocs/user/policy.mdnow state the bound, the refusal, and the remedy.Upgrade effect. An existing box whose clock moved back more than five minutes in an earlier run already has a high-water mark ahead of wall time. After this change, it refuses to open until the clock catches up or the box directory is wiped.
No frozen interface changes. The history file format does not change.
Related Issues
None public.
Type of Change
Bug fix
Testing
history_stamped_beyond_the_skew_bound_is_refused_by_every_open_path(new): a history stamped one hour ahead is refused by every open path (three production paths and the fault-injection variant) with the engine's skew reason. Onmain, the previous test opened this same history on all four paths, so the new test fails without the fix.a_clock_behind_history_beyond_the_skew_bound_denies_until_it_returns_within_it(new): during a run, a clock 200 s behind history is still decided, 400 s behind denies as an internal fault, and decisions return once the clock is within the bound again. The refusal does not persist.wall_clock_rollback_within_the_skew_bound_preserves_history_across_every_open_path(renamed fromwall_clock_rollback_preserves_history_across_every_open_path): a 60-second rollback still keeps the consumed budget on all four open paths.cargo build/test/clippy --all-targets/fmt --checkfor-p strands-box-policy, with and without--all-features, plusRUSTDOCFLAGS="-D warnings" cargo doc: pass. Clippy shows only the six existing vendoredstrands-shellwarnings.cargo test -p strands-box --test site_manifest --locked --all-features: pass.cargo build -p strands-box --all-featuresand the containment suite on macOS: pass (129 pass, 12 Linux-only skips).End to end on macOS with the built binary: a box that spent a two-run budget restarted under
TZset to America/New_York, Asia/Kolkata, Pacific/Auckland, and UTC. Each restart opened and kept the budget, so a time-zone change does not trigger the refusal.Not run: Linux targets (no local cross compiler) and the full workspace suite.
I ran the relevant suites (
just check, orcargo test --workspace --all-features)If I touched Rust, I ran
cargo fmt --allandcargo clippy --workspace --all-targets --all-features -- -D warningsChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.