Repository navigation
Conversation
Implement step 1 of RFC 0027. The scanner walks raw protobuf bytes against the compiled public and storage descriptors before prost decodes them, reporting unknown tags, reserved tags, and unrecognized enum values with dotted field paths. It bounds nesting at 32 levels and stops after 16 violations, never echoes field contents, and redacts enum values on fields marked secret. Rejections map to INVALID_ARGUMENT with ErrorInfo reason UNKNOWN_PROTOBUF_FIELD and BadRequest field violations. Add helpers that extract, scan, and splice raw Sandbox.spec.policy bytes so read-modify-writes on an older gateway can preserve policy fields a newer gateway wrote. Ingress and persistence callers follow in later steps. Refs #6097 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
Implement step 2 of RFC 0027. A wrapper ahead of the gateway interceptors scans every request frame of strict RPCs against the method's input descriptor before interceptors or tonic decode it. Strict RPCs are those with unauthenticated, bearer, operator, or dual auth, plus any RPC whose request reaches a policy type, such as SubmitPolicyAnalysis. Non-policy sandbox, peer, and supervisor RPCs stay exempt during 0.x. Unary and server-streaming requests are reassembled and validated before dispatch, so a rejected request never reaches durable request admission. Client streams are validated frame by frame and end with the scanner's status. Compressed frames return UNIMPLEMENTED and frames above the route's decoding limit return RESOURCE_EXHAUSTED. Keep the exact status and details when a request body fails: interceptor body collection, the interactive exec start frame, and ForwardTcp relay frames now pass the validation status to the client. Rejections count in openshell_server_grpc_unknown_fields_total. Refs #6097 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
Implement step 3 of RFC 0027. Stored payloads that carry policy are scanned before prost decodes them, so a policy written by a newer gateway is refused instead of silently broadened: - Policy revisions and the global policy setting are scanned on load and fail with FAILED_PRECONDITION, which configuration delivery turns into a not-admitted configuration. Only the legacy NetworkBinary advisor flag is tolerated. - Draft chunks scan proposed_rule and both effective policies before the proposed rule is re-encoded. - Stored provider profiles scan their endpoint restrictions. - Sandbox.spec.policy is scanned from the raw row wherever it is evaluated, canonicalized, compared, or delivered. Sandbox writes through the store, and the policy-revision projection, keep the stored spec.policy bytes when the update leaves the policy this build understands unchanged, so an unrelated status or label update on an older gateway no longer erases newer restrictions. A test pins the durable roots that reach policy types. Make the oversized-configuration delivery test truncate providers with compare-and-swap. Its unconditional write raced the gateway's concurrent admission update and could be lost. Rejections count in openshell_server_stored_policy_unknown_fields_total. Refs #6097 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
Implement the release-train check from RFC 0027 step 4. train_policy() now classifies the active train as none, patch, or minor instead of returning one allows_breaks flag: - none: no pre-release train is active. Additive changes may merge so a feat change can start the next minor train; breaking changes fail. - patch: proto/ is frozen. Added services, RPCs, messages, fields, extensions, enums, or enum values fail alongside breaking changes. - minor: additive changes pass and breaking changes are warnings during 0.x. Additions are found by comparing definition inventories from buf JSON images, keyed by number so renames are not additions. Add unit tests, including an end-to-end buf check when buf is installed, and run them with test:python-scripts. Refs #6097 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
Describe RFC 0027 for operators and API authors: - The support matrix gains the gateway-first upgrade order, the collector-settings exception, version-skew behavior, and rollback guidance, and notes that new protobuf definitions ship only in minor releases. - proto/README.md asks authors to add definitions only on minor trains, leave unset fields at defaults, and gate new policy restrictions on a supervisor capability. - Gateway metrics list the ingress and stored-policy rejection counters. Refs #6097 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
Cover the RFC 0027 acceptance case for the two RPCs that carry policy: UpdateConfig, which sandboxes may call, and SubmitPolicyAnalysis, which is sandbox-authenticated but strict because its proposed rule reaches a policy type. A restriction nested inside the policy is rejected before dispatch with UNKNOWN_PROTOBUF_FIELD and its field path. Refs #6097 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
|
🌿 Preview your docs: https://nvidia-preview-pr-6114.docs.buildwithfern.com/openshell |
| //! | ||
| //! A gateway that decodes a `Sandbox` written by a newer gateway drops the | ||
| //! newer policy restrictions. Re-encoding that `Sandbox` after an unrelated | ||
| //! change (status, labels, image state) would erase them from storage. These |
There was a problem hiding this comment.
🤖 blocking 🔴 – Image updates still erase newer policy fields. ImageTransaction::write_projection in persistence/sandbox_image.rs calls sandbox.encode_to_vec() and writes directly to SQLite or PostgreSQL. Carry the policy bytes from the locked row through both begin and complete, and test that the stored bytes survive each operation.
There was a problem hiding this comment.
Fixed in 924ce73. lock_sandbox now returns the migrated stored payload with the decoded sandbox, and write_projection encodes through encode_preserving_spec_policy, so both begin and complete keep the stored spec.policy bytes. image_updates_preserve_newer_spec_policy_bytes checks the stored bytes after each operation.
| return Ok(()); | ||
| } | ||
| let Some(record) = store | ||
| .get(Sandbox::object_type(), sandbox.object_id()) |
There was a problem hiding this comment.
🤖 blocking 🔴 – This fetch can validate a different revision from the Sandbox the caller evaluates. If the row is replaced or deleted between reads, the check can succeed and the caller can deliver the earlier policy with unknown fields already stripped. Validate and decode the same row, or require matching resource versions and retry the whole read on a mismatch.
There was a problem hiding this comment.
Fixed in 924ce73. with_known_spec_policy replaces require_known_spec_policy, and callers use the sandbox it returns. When the caller's policy equals the known fields of the stored row, that row is scanned. When a sandbox read from storage no longer matches the row, it returns ABORTED so the caller reads again; a deleted row returns NOT_FOUND. I compare policies rather than resource versions because unconditional put does not bump the version. Unsaved sandboxes (version 0) keep their in-memory policy, which create validation needs. spec_policy_check_and_use_share_one_stored_row covers the stripped copy, the replaced row, a deleted row, and an unsaved sandbox.
| source: StoredPolicySource, | ||
| ) -> Result<(), Status> { | ||
| match scan_named(SANDBOX_POLICY, payload, LEGACY) { | ||
| Ok(()) | Err(WireRejection::Malformed(_)) => Ok(()), |
There was a problem hiding this comment.
🤖 blocking 🔴 – A scanner error does not guarantee a prost decode error. For example, prost supports unknown protobuf groups while FieldIter reports them as malformed. Returning Ok(()) lets a policy pass without a complete scan. Reject unscannable stored data before decoding it, including in the draft and provider-profile loaders.
There was a problem hiding this comment.
Fixed in 924ce73. Any scan error now refuses the stored payload: require_known_stored_policy for revisions, global and spec policy, plus the draft and provider-profile loaders. unscannable_stored_policy_is_refused uses an unknown group that prost decodes successfully, to show the scanner is the only guard.
| .await | ||
| .map_err(|e| { | ||
| Status::internal(format!("list platform provider profiles failed: {e}")) | ||
| crate::grpc::persistence_error_to_status(e, "list platform provider profiles") |
There was a problem hiding this comment.
🤖 should-fix 🟡 – One incompatible platform profile now rejects configuration for every sandbox, including sandboxes with no providers. load_sandbox_config_inputs snapshots the entire catalog, and collect_messages stops on the first incompatible row. Keep the incompatibility associated with that profile and reject configurations that depend on it. Cover an unrelated sandbox in the same test.
There was a problem hiding this comment.
Fixed in 924ce73. The user profile source decodes rows one at a time. An unreadable profile is left out of the catalog and recorded with its scope. load_sandbox_config_inputs refuses only sandboxes whose providers resolve to it, using the same workspace/platform resolution as get_type_profile_for_scope. unreadable_provider_profile_rejects_only_dependent_configurations builds a dependent sandbox (not admitted) and an unrelated one (built). I also made DeleteProviderProfile read the raw row, so an operator can still remove an unreadable profile.
|
|
||
| let sandbox_id_in = sandbox_id.to_string(); | ||
| let channel_id_in = channel_id.to_string(); | ||
| let tx_in = tx.clone(); |
There was a problem hiding this comment.
🤖 should-fix 🟡 – tx_in keeps the response channel open after relay EOF if the client leaves its request stream open. The detached task can wait indefinitely in inbound.message() while the client waits for response EOF. Tie the task to the relay reader’s lifetime, and test relay EOF with the request sender still open.
There was a problem hiding this comment.
Fixed in 924ce73. The request reader now holds a WeakSender and upgrades it only to report a rejected frame, so the response ends when the relay reader drops its sender. I left the reader running after relay EOF so TCP half-close still delivers late client data. forward_tcp_response_ends_at_relay_eof_while_request_stream_stays_open would hang with the previous strong sender.
| match crate::wire_validation::stored::scan_draft_chunk_payload(payload) { | ||
| Ok(()) | Err(crate::wire_validation::WireRejection::Malformed(_)) => {} | ||
| Err(rejection) => { | ||
| return Err(PersistenceError::UnknownFields(format!( |
There was a problem hiding this comment.
🤖 should-fix 🟡 – GetDraftPolicy and ApproveDraftChunk wrap this new UnknownFields error in Status::internal. Use persistence_error_to_status at the draft RPC boundaries so clients receive FAILED_PRECONDITION for an incompatible stored draft. Assert the status through the RPC.
There was a problem hiding this comment.
Fixed in 924ce73. Every draft read in grpc/policy.rs (11 sites, including GetDraftPolicy and ApproveDraftChunk) now goes through persistence_error_to_status. draft_rpcs_refuse_drafts_with_newer_restrictions asserts FAILED_PRECONDITION through both RPCs.
|
|
||
| @property | ||
| def allows_breaks(self) -> bool: | ||
| return self.kind == MINOR |
There was a problem hiding this comment.
🤖 should-fix 🟡 – Every minor train permits breaking changes here, including v1.0.x to v1.1.0. The RFC requires additive-only changes within 1.x. Include the major version in this decision and test a breaking change on a 1.x minor train.
There was a problem hiding this comment.
Fixed in 7a8d05f. Added a major train kind. Breaking changes are allowed only on 0.x minor trains and on major trains (including 1.0.0); 1.x minor trains are additive-only. Tests cover the classification and an end-to-end breaking change on a 1.x minor train with real buf.
Address review feedback on RFC 0027 persistence-boundary validation: - Image update begin and complete keep the locked row's spec.policy bytes; they wrote the sandbox directly and erased newer restrictions. - The spec policy check and its use share one stored row. A sandbox read from storage whose policy no longer matches the row gets ABORTED so the caller reads again, and a deleted row gets NOT_FOUND. Resource versions alone cannot detect this because unconditional writes keep them. - Stored policies, drafts, and profile endpoints the scanner cannot parse are refused, even where prost would decode them, such as unknown groups. - An unreadable provider profile no longer fails the whole catalog. It is left out, configurations whose providers resolve to it are not admitted, and DeleteProviderProfile can still remove it. - Draft RPCs map an unreadable stored draft to FAILED_PRECONDITION instead of INTERNAL. - ForwardTcp holds a weak response sender in its request reader, so the response still ends at relay EOF while the client keeps sending. Refs #6097 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
Breaking changes are now allowed only on 0.x minor trains and on major trains, including 1.0.0. Within 1.x and later majors, a minor train is additive-only, as RFC 0027 requires. Add a major train kind and test a breaking change on a 1.x minor train. Refs #6097 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
| return Ok(policy); | ||
| } | ||
| sandbox | ||
| Box::pin(with_known_spec_policy(store, sandbox)) |
There was a problem hiding this comment.
🤖 blocking 🔴 – A single incompatible sandbox policy can still prevent the gateway from starting. With provider composition enabled, startup calls current_base_policy_for_sandbox for every sandbox with providers and propagates the first error out of run_server. Handle the stored-policy incompatibility per sandbox during preflight and retain the refusal on delivery. Cover startup with one affected sandbox and one healthy sandbox.
There was a problem hiding this comment.
Fixed in 6ac8a47. Stored-data incompatibility refusals now carry ErrorInfo reason UNKNOWN_PROTOBUF_FIELD (wire_validation::stored::is_incompatible). The startup preflight sets aside a sandbox whose stored policy, or whose provider profile, this gateway cannot read, and keeps validating the rest; configuration delivery still refuses that sandbox. startup_preflight_sets_aside_a_sandbox_with_an_unreadable_policy runs the preflight with one affected and one healthy sandbox and checks that delivery refuses the affected one; startup_preflight_still_checks_sandboxes_beside_an_unreadable_policy checks that a real violation elsewhere still fails startup.
| }); | ||
| } | ||
| build_effective_profiles(snapshots) | ||
| let mut catalog = build_effective_profiles(snapshots)?; |
There was a problem hiding this comment.
🤖 blocking 🔴 – The token broker reads this catalog through get_type_profile_for_scope, which ignores incompatible. When a workspace profile is unreadable and a same-ID platform profile exists, GetSandboxProviderAccessToken can authorize a grant from the platform profile. Enforce incompatibility in scoped resolution itself and test this case through the token RPC.
There was a problem hiding this comment.
Fixed in 6ac8a47. scoped_type_profile_for_scope now calls require_compatible_profile first and returns None when the profile in the resolving scope is unreadable, so it never falls back to a same-ID platform profile. Every caller already treats None as fail-closed. unreadable_workspace_profile_never_falls_back_to_the_platform_grant drives grant_configuration, the profile-authorization step of GetSandboxProviderAccessToken: the grant is authorized with only the platform profile, and refused with PERMISSION_DENIED once an unreadable workspace profile shadows it. I tested that step rather than the full RPC because the full RPC needs a signed sandbox session and a persisted session lineage.
| warn_incompatible_profile(&name, &reason); | ||
| incompatible.push((name, resource_version)); | ||
| } | ||
| Err(error) => { |
There was a problem hiding this comment.
🤖 should-fix 🟡 – An unreadable endpoint can still take down the whole catalog. decode_record runs legacy_time_wire::migrate before the profile scanner. A group inside an endpoint fails migration as PersistenceError::Decode and takes this branch, so unrelated sandboxes get INTERNAL. Classify unscannable raw endpoint bytes before migration and extend the isolation test to cover this path.
There was a problem hiding this comment.
Fixed in 6ac8a47. decode_record now scans provider-profile endpoints on the raw row before legacy migration. Endpoints contain no messages the time-field migration rewrites, so the raw and migrated scans agree. An endpoint group now surfaces as UnknownFields and stays isolated to its profile. The isolation test runs both an unknown endpoint field and an endpoint group, and checks that an unrelated sandbox still builds.
| // Read the row without decoding it: a profile this build cannot read | ||
| // safely (RFC 0027) must still be removable. | ||
| let existing = state | ||
| .store |
There was a problem hiding this comment.
🤖 should-fix 🟡 – Raw lookup makes an unused incompatible profile deletable, but an in-use profile still cannot be repaired in place. profile_update_target_diagnostics and handle_update_provider_profiles both decode the old profile and return INTERNAL, even for a full compatible replacement with the correct resource version. Read the row metadata independently and retain the existing version check on replacement.
There was a problem hiding this comment.
Fixed in 6ac8a47. stored_profile_metadata reads only StoredProviderProfile.metadata (tag 1) from the raw row, migrates and decodes that, and takes the resource version from the row. profile_update_target_diagnostics and handle_update_provider_profiles use it, so a compatible full replacement can repair an unreadable profile, and the MatchResourceVersion check is unchanged. unreadable_custom_profile_can_be_replaced_in_place checks that a stale version gets ABORTED, the correct version repairs the profile, and labels and the ID are kept.
Address the second round of RFC 0027 review feedback: - Startup preflight sets aside a sandbox whose stored policy or provider profile this gateway cannot read, instead of failing run_server. Delivery still refuses it. Such refusals now carry ErrorInfo reason UNKNOWN_PROTOBUF_FIELD so callers can tell them apart. - Scoped profile resolution enforces incompatibility itself, so an unreadable workspace profile never falls back to a same-ID platform profile, including for brokered token grants. - Provider profile endpoints are scanned before legacy migration, so an unreadable endpoint, such as one with a group, stays isolated to that profile instead of failing the whole catalog. - UpdateProviderProfiles reads only the stored metadata and row version, so a compatible full replacement can repair an unreadable profile in place while keeping the version check. Refs #6097 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
|
|
||
| let raw = hex::decode(encoded) | ||
| .map_err(|e| Status::internal(format!("global policy decode failed: {e}")))?; | ||
| crate::wire_validation::stored::require_known_stored_policy( |
There was a problem hiding this comment.
🤖 blocking 🔴 – An incompatible global policy still prevents gateway startup. validate_provider_composition_startup_preflight decodes the global override to decide whether composition is enabled. This rejection reaches run_server before it can serve repair requests. Treat the incompatible override as present for preflight, keep refusing configuration delivery, and test that a compatible replacement restores delivery.
There was a problem hiding this comment.
Fixed in a867864. provider_policy_composition_enabled now treats a global policy this gateway cannot read as a present global override (composition off), so neither the startup preflight nor profile changes fail on it. Configuration delivery still refuses it. unreadable_global_policy_starts_the_gateway_and_can_be_replaced stores an unreadable global policy, runs the preflight, checks that delivery is refused, replaces the policy through UpdateConfig with global: true, and checks that delivery recovers. I also checked the other startup step, endpoint-status reconciliation: it does not decode policies.
| .await | ||
| .unwrap() | ||
| .unwrap() | ||
| .resource_version; |
There was a problem hiding this comment.
🤖 should-fix 🟡 – This test gets the repair version directly from the store. Operators get it through GetProviderProfile or CLI export. An unreadable workspace profile is absent from that lookup, so export returns NOT_FOUND or the same-ID platform profile and its version. Return the incompatibility with the affected row’s resource version and exercise repair using only public RPCs.
There was a problem hiding this comment.
Fixed in a867864. IncompatibleProfile now records its row resource version. GetProviderProfile calls require_compatible_profile for the requested scope before the catalog lookup, so an unreadable profile is reported with UNKNOWN_PROTOBUF_FIELD, resource_version in ErrorInfo metadata, and the version in the message, never NOT_FOUND or the same-ID platform profile. The repair test now uses public RPCs only, with a same-ID platform profile present: GetProviderProfile (refused, with version), LintProviderProfiles, UpdateProviderProfiles with that version (a stale version gets ABORTED), then GetProviderProfile returns the repaired workspace profile. The CLI shows the message, which includes the version; it does not yet parse the metadata itself.
| .get_message_by_name::<StoredProviderProfile>(workspace, target_id) | ||
| .await | ||
| .map_err(|e| Status::internal(format!("fetch provider profile failed: {e}")))? | ||
| if stored_profile_metadata(store, workspace, target_id) |
There was a problem hiding this comment.
🤖 should-fix 🟡 – A CLI update containing a stable_placeholder credential calls LintProviderProfiles before the update RPC. Its profile_conflict_diagnostics still does a typed read to check existence, so an unreadable existing profile returns INTERNAL even with the correct version and a compatible replacement. Use a metadata-only existence check there too.
There was a problem hiding this comment.
Fixed in a867864. Both existence checks in profile_conflict_diagnostics use stored_profile_metadata. The repair test calls LintProviderProfiles with the replacement and gets the normal "already exists" diagnostic instead of INTERNAL.
| .await | ||
| { | ||
| Ok(policy) => policy, | ||
| Err(error) if crate::wire_validation::stored::is_incompatible(&error) => { |
There was a problem hiding this comment.
🤖 should-fix 🟡 – The same isolation is missing in profile_attached_sandbox_diagnostics. It reads each sandbox’s base policy before checking whether any attached provider uses the profile being changed. An unreadable policy on an unrelated sandbox can block every platform profile import or update. Identify affected sandboxes before loading their policies and retain validation for actual dependents.
There was a problem hiding this comment.
Fixed in a867864. profile_attached_sandbox_diagnostics now fetches a sandbox's providers first and skips the sandbox before loading its base policy unless a provider uses a changed profile, which is the condition the old imported_profiles_used.is_empty() check applied after the load. unreadable_policy_blocks_only_profile_changes_its_sandbox_depends_on checks that a platform import succeeds beside an unrelated sandbox with an unreadable policy, while an import a dependent sandbox uses is still refused with the incompatibility.
Address the third round of RFC 0027 review feedback: - An unreadable global policy counts as a global override, so provider composition is treated as off. Startup and profile changes no longer fail on it, delivery still refuses it, and a compatible UpdateConfig replacement restores delivery. - GetProviderProfile reports an unreadable profile in the requested scope with its row resource_version in ErrorInfo metadata and the message, instead of NOT_FOUND or a same-ID platform profile. Operators can repair it using public RPCs alone. - LintProviderProfiles checks profile existence from stored metadata only, so linting a replacement for an unreadable profile works. - Profile change diagnostics load a sandbox's base policy only when the sandbox uses a changed profile, so an unrelated unreadable policy no longer blocks platform profile imports or updates. Refs #6097 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
| pub(super) async fn provider_policy_composition_enabled(store: &Store) -> Result<bool, Status> { | ||
| let global_settings = load_global_settings(store).await?; | ||
| provider_policy_composition_enabled_in(&global_settings) | ||
| match provider_policy_composition_enabled_in(&global_settings) { |
There was a problem hiding this comment.
🤖 should-fix 🟡 – Startup and replacement now work, but openshell policy delete --global still fails on an unreadable override. handle_update_config_inner calls provider_policy_composition_enabled_in before removing the key, bypassing this handling. Put the incompatibility handling in the shared composition check and test deletion with the normal preflight for re-enabling composition.
There was a problem hiding this comment.
Fixed in 3d5ec87. The handling for an unreadable global override now lives in provider_policy_composition_enabled_in, so global deletion, sandbox merge validation, and the async wrapper share it. unreadable_global_policy_can_be_deleted deletes an unreadable override through UpdateConfig (delete_setting) and checks that delivery recovers. deleting_unreadable_global_policy_still_validates_reactivated_composition checks that the normal re-enable preflight still refuses the deletion when a sandbox would get an ambiguous binding, and that the setting is kept.
| // Only sandboxes that use a changed profile are validated, so an | ||
| // unrelated sandbox's policy, readable or not, never blocks the change. | ||
| if !providers.iter().any(|(_, provider)| { | ||
| !scope_mismatch(provider) && candidate_profiles.contains_key(&profile_id_of(provider)) |
There was a problem hiding this comment.
🤖 should-fix 🟡 – A provider with a nonempty profile_workspace still uses the platform profile when its workspace has no same-ID override. This filter skips that sandbox on platform updates, so the update can commit without validating a real dependent. Use the effective profile scope for both this filter and the candidate layer. Cover a platform update with and without a same-ID workspace override.
There was a problem hiding this comment.
Fixed in 3d5ec87. A new profile_change_applies_to decides dependence by effective resolution. A platform change reaches platform providers, and workspace-scoped providers whose workspace has no same-ID override; the override check reads metadata only, so an unreadable override still shadows. A workspace change reaches workspace-scoped providers. The same decision drives both the dependent filter and whether the provider contributes the candidate layer or its current layer. platform_profile_change_validates_workspace_providers_without_an_override covers a platform import with and without a same-ID workspace override.
Address the fourth round of RFC 0027 review feedback: - The shared composition check treats an unreadable global policy as an override, so every caller, including global policy deletion and sandbox merge validation, handles it the same way. Deleting it works, and re-enabling composition still runs the normal preflight. - Profile change diagnostics decide whether a provider depends on the changed profile by the scope it actually resolves. A workspace-scoped provider whose workspace has no same-ID override, readable or not, uses the platform profile, so a platform update now validates its sandbox and composes the candidate layer for it. Refs #6097 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
| if object_type != <openshell_core::proto::Sandbox as ObjectType>::object_type() { | ||
| return Ok(Cow::Borrowed(payload)); | ||
| } | ||
| let Some(stored) = self.get(object_type, id).await? else { |
There was a problem hiding this comment.
🤖 blocking 🔴 – An unconditional sandbox write reads the policy here and commits the splice in a separate database operation. A concurrent policy update between the two can be overwritten with the earlier restriction bytes. Preserve the policy from the row being updated inside the write transaction, or detect a changed row and retry. Please cover two overlapping writes on both backends.
There was a problem hiding this comment.
Fixed in b3333fb. For an unconditional sandbox write (put, put_if(Unconditional)), a policy splice is now written with MatchResourceVersion of the row it was computed from. On a conflict the write re-reads and recomputes, up to 5 attempts. When nothing needs keeping, the original unconditional write runs unchanged. Version-conditioned writes (put_if(MatchResourceVersion), write_atomically updates) were already protected by the backend's version check. put_scoped now refuses sandbox objects, since nothing writes them that way. *_overlapping_sandbox_writes_never_restore_stale_policy runs on SQLite and on PostgreSQL (#[ignore]d like the other backend tests; I could not run that one here). It checks that a splice from a stale read is refused after a concurrent policy replacement, that the retried write does not restore the old restriction bytes, and that two overlapping unrelated updates keep the newer restriction. That test also exposed a separate issue: incoming policy bytes that already carry unknown fields were being replaced by the stored copy. They now win, covered by incoming_policy_bytes_with_unknown_fields_are_kept.
| record: &PolicyRecord, | ||
| ) -> Result<(ProtoSandboxPolicy, String), Status> { | ||
| crate::wire_validation::stored::require_known_stored_policy( | ||
| record.policy_payload.as_slice(), |
There was a problem hiding this comment.
🤖 should-fix 🟡 – policy_record_from_parts decodes PolicyRevisionPayload.policy as optional bytes, so this scan sees only the last occurrence. Protobuf merges all occurrences of an embedded message. The current writer emits one, but a valid stored revision can lose restrictions from an earlier occurrence. Collect the policy payloads in wire order before scanning and decoding, as extract_spec_policy already does.
There was a problem hiding this comment.
Fixed in b3333fb. policy_record_from_parts now builds policy_payload with wire_validation::merged_embedded, which concatenates every tag 1 occurrence in wire order, as protobuf merge does. I dropped the RawPolicyRevisionPayload decode there. policy_revision_merges_every_policy_occurrence puts the unknown restriction in an earlier occurrence and a clean one last, and checks that the history scan refuses it.
| .options | ||
| .allowed_reserved | ||
| .iter() | ||
| .any(|(message, number)| *number == tag && *message == descriptor.full_name()); |
There was a problem hiding this comment.
🤖 should-fix 🟡 – The legacy exception accepts any wire type for NetworkBinary tag 2. Only a varint represents the old advisor_proposed boolean. A different wire type passes this check and a spec or draft reader can then drop it. Include the wire type in the exception and test that stored reads reject a mismatched type.
There was a problem hiding this comment.
Fixed in b3333fb. The exception is now a ReservedException { message, tag, wire_type }, and LEGACY_STORED_POLICY_RESERVED accepts only NetworkBinary tag 2 as a varint. Tests check that a length-delimited tag 2 is reported by the scanner, refused by the stored spec-policy check, and refused by the draft scan.
| if scope_mismatch { | ||
| for ((provider_name, provider), uses) in providers.into_iter().zip(uses_changed) { | ||
| let profile_id = profile_id_of(&provider); | ||
| if !uses { |
There was a problem hiding this comment.
🤖 should-fix 🟡 – During a platform profile update, catalog contains only platform and static profiles. If a dependent sandbox also uses a second provider with a workspace override, this branch computes its bindings and policy layer from the wrong profile or omits them. Resolve the other providers against that sandbox’s workspace catalog. A two-provider test should reject a candidate that conflicts only with the workspace override.
There was a problem hiding this comment.
Fixed in b3333fb. profile_attached_sandbox_diagnostics now takes the profile sources. For a platform-scope change it snapshots each dependent sandbox's workspace catalog (once per workspace) and resolves that sandbox's other providers, both bindings and policy layers, against it. platform_profile_change_composes_other_providers_from_their_workspace builds a sandbox with a platform provider and a second provider whose workspace override conflicts with the candidate's endpoint, and checks that the platform import is rejected. I confirmed the test fails with the platform-only catalog.
Address the fifth round of RFC 0027 review feedback: - An unconditional sandbox write commits a policy splice only against the row version it was computed from, then re-reads and retries on a conflict, so a concurrent policy change is never overwritten with earlier restriction bytes. Without anything to keep, the write stays unconditional. Incoming policy bytes with fields this build does not know are kept rather than replaced. Sandboxes are refused on the scoped write path. - Policy revisions merge every embedded policy occurrence in wire order before scanning, as protobuf does. - The legacy NetworkBinary tag 2 exception now requires the varint encoding of the former advisor_proposed boolean. - Platform profile change diagnostics resolve a dependent sandbox's other providers against its workspace catalog, so a conflict with a workspace override is caught. Refs #6097 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
| if is_sandbox(object_type) | ||
| && Box::pin(self.put_sandbox_preserving_policy(id, name, workspace, payload, labels)) | ||
| .await? | ||
| .is_some() |
There was a problem hiding this comment.
🤖 blocking 🔴 – The no-splice branch still falls through to plain put. A concurrent writer can add a restriction after the preservation read, and the label write then erases it. Plain put also leaves resource_version unchanged on both backends, so an earlier splice can still pass its version check after a plain policy replacement. Please make the preservation decision and write atomic for existing sandbox rows, including the no-splice case. An unrelated update that loses a race must preserve the winning policy or return a conflict. The new overlap test currently expects known after the retry, even though the other writer committed replacement.
There was a problem hiding this comment.
Fixed in b358a01. An unconditional write to an existing sandbox row (put, put_if(Unconditional)) now always commits with MatchResourceVersion of the row its preservation decision was made on, spliced or not. It therefore always advances the version, and any write in between makes it re-read and decide again; the plain path remains only for rows that do not exist yet. A writer whose payload carries an older read version (decoded sandboxes keep the version they were read at) and would change the stored policy gets Conflict instead of overwriting the winner. A writer whose policy matches the winner's known fields gets the winner's bytes spliced in. Retries are bounded at 256 with a yield, because sqlite_concurrent_writes_return_their_own_resource_version (8 contending writers) exhausted a small bound; each round some writer commits, so this cannot livelock.
The overlap test (SQLite, plus a PostgreSQL variant ignored here) now checks three cases:
- A stale label update after a policy replacement gets
Conflictand the replacement stays. - A restriction added after the writer's preservation read survives: the stale attempt sees the row changed, and the retry splices the restriction in.
- Two overlapping unrelated updates keep the restriction, and the unconditional write advances the version.
sandbox_updates_preserve_newer_spec_policy_bytes now also checks that a policy replacement made from a stale read is refused, while one made from a fresh read wins.
Address the final RFC 0027 review comment. An unconditional write to an existing sandbox row now always commits against the row version its preservation decision was made on, whether or not it splices, so it advances the version and a concurrent write forces it to re-read and decide again. A plain write could previously erase a restriction added after the read, and left the version unchanged so an earlier splice could still pass its version check. A writer whose payload was read from an older version and would change the stored policy gets a conflict instead of overwriting the policy that won the race. Writes to rows that do not exist yet keep their plain path. Retries are bounded generously so unconditional writes do not fail under ordinary contention. Refs #6097 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
Summary
Implement RFC 0027: the gateway rejects protobuf fields and enum values it does not know, both at gRPC ingress and when loading stored policies, so version skew can no longer silently drop policy restrictions. Patch release trains now freeze
proto/.Related Issue
Part of #6097. Not closing yet: the
supported_policy_capabilitiesdiscovery field and the RFC 0014 companion edit are still open.Changes
Each step is a separate commit for review.
bytes/stringpayloads by length, and never echoes field contents.SubmitPolicyAnalysis. Unary and server-streaming requests are fully checked before dispatch, so a rejected request never consumes itsrequest_id. Rejections returnINVALID_ARGUMENTwithErrorInforeasonUNKNOWN_PROTOBUF_FIELDandBadRequestviolations. Interceptor body collection, theExecSandboxInteractivestart frame, andForwardTcpnow keep that status instead of turning it intoINTERNALor closing silently.Sandbox.spec.policyare scanned beforeprostdecodes them. Unknown restrictions returnFAILED_PRECONDITION, which yields a not-admitted configuration. Sandbox writes through theStore, and the policy-revision projection, keep the storedspec.policybytes when an update leaves the known policy unchanged. A test pins the five durable roots that reach policy types.check_proto_compatibility.pyclassifies the train asnone,patch, orminor. On patch trains, added services, RPCs, messages, fields, enums, or enum values fail.UNKNOWN_PROTOBUF_FIELDin API errors; authoring rules inproto/README.md; two new metrics.Review notes:
Storewrites to an existing sandbox row now do one extra read to preserve the stored policy bytes.oversized_configuration_is_rejected_over_grpc_and_smaller_configuration_recoversnow truncates providers with compare-and-swap. Its unconditional write could lose to the gateway's concurrent admission update, and the extra read made that race reproducible.mainis in a patch train (v0.1.11), so PRs that add protobuf definitions fail the compatibility check until that train ships.Release Notes
The gateway now rejects requests and stored policies that use protobuf fields or enum values it does not know, returning
UNKNOWN_PROTOBUF_FIELDinstead of silently dropping them. Upgrade gateways before clients and supervisors.Testing
cargo clippy -p openshell-server --tests, ruff, markdownlint,docs:navopenshell-servertests pass. The 8 that failed locally also fail without this change, because the local sandbox blocks Unix-socket binds and writes under~/.local/state. The newcheck_proto_compatibility_test.pyincludes end-to-endbufcases.Checklist
🤖 Generated with Claude Code