feat(security): add safety profile model and enforcement stubs #450
Merged
CoreRasurae
merged 1 commits from 2026-03-02 20:09:47 +00:00
feature/post-safety-profile into master
Dismiss Review
Are you sure you want to dismiss this review?
Labels
Clear labels
auto/needs-reevaluation
controller-managed
overdue
auto/blocked-by-deps
auto/ci-timeout
auto/claimed-implementer
auto/claimed-merge
auto/claimed-reviewer
auto/driver-down
auto/invariant-violation
auto/last-attempt-tier-0
auto/last-attempt-tier-1
auto/last-attempt-tier-2
auto/last-attempt-tier-min
Automation Tracking
auto/needs-conflict-resolution
auto/needs-implementer
auto/postmortem
auto/ready-to-merge
auto/restart-throttled
auto/revert
auto/sentinel
auto/stale-inactivity
auto/unstable
Blocked
Needs Feedback
Signed-off: Owner
Signed-off: Scrum Master
Signed-off: Tech Lead
Spike
Controller deferred this PR; awaiting Phase 6+ scope-evaluator or operator re-enablement.
Auto-agents controller manages this PR/issue (see tools/controller/deploy/RUNBOOK.md). Remove this label to abandon controller management.
PR blocked by an open issue dependency. Operator must close the dep (or remove the dependency link) before the merge driver can act. Auto-cleared by merge_drive when no open deps remain.
Most recent merge cycle hit CI timeout. Driver excludes this PR while last merge_cycle row is < 30 min old; label persists thereafter as visible history.
Currently being processed by an implementer worker.
Currently being processed by the merge driver.
Currently being processed by a reviewer worker.
Merge driver heartbeat stale; pipeline halted. Closed automatically on next clean tick.
Detected master commit violating the strict merge invariant. Tracked as an issue (not a PR label); kept here for label completeness.
In-cycle escalation: most recent attempt ran at the Tier 0 slot (`tier-0`). Slot's model defined in .opencode/models/tiers.yaml.
In-cycle escalation: most recent attempt ran at the Tier 1 slot (`tier-1`). Slot's model defined in .opencode/models/tiers.yaml.
In-cycle escalation: most recent attempt ran at the Tier 2 slot (`tier-2`). Slot's model defined in .opencode/models/tiers.yaml. Gated behind IMPLEMENTER_ESCALATION_TIER2_ENABLED.
In-cycle escalation: most recent attempt ran at the Tier -1 slot (`tier-min`). Slot's model defined in .opencode/models/tiers.yaml. Suffix is ``-min`` (not ``--1``) so the Forgejo UI reads naturally.
Tracking issues used by the AI Automation system for agents to communicate and report.
Rebase conflict needs LLM conflict-resolver.
Failing CI needs implementer attention.
Documenting a driver incident or rollback.
Reviewer has APPROVED this PR and no later REQUEST_CHANGES is outstanding. The merge driver requires this label to even consider a PR for merging. Set by the reviewer worker on APPROVE; cleared on REQUEST_CHANGES.
Train repeatedly lost master-tempo races. Driver excludes via merge_cycle until cooldown elapses; label persists as visible history.
Revert PR backing out an invariant violation. Fast-tracked through the merge driver.
Sentinel PR duplicated from upstream into a personal fork by tools/duplicate_prs_to_fork.py for pipeline testing. Lives only in the fork; the canonical pipeline never sees it.
No implementer activity for N days. Flagged for human review. Auto-cleared on next push to head branch.
Repeatedly fails on current master (>= 3 ci-fail-on-rebased-sha releases in 12 h). Excluded from driver until human triage.
A ticket in a blocked state and unable to complete until some other task is completed first.
Bounty
$100
A bounty of $100 for any open-source contributor who provides a MR that solves this issue
Bounty
$1000
A bounty of $1000 for any open-source contributor who provides a MR that solves this issue
Bounty
$10000
A bounty of $10000 for any open-source contributor who provides a MR that solves this issue
Bounty
$20
A bounty of $20 for any open-source contributor who provides a MR that solves this issue
Bounty
$2000
A bounty of $2000 for any open-source contributor who provides a MR that solves this issue
Bounty
$250
A bounty of $250 for any open-source contributor who provides a MR that solves this issue
Bounty
$50
A bounty of $50 for any open-source contributor who provides a MR that solves this issue
Bounty
$500
A bounty of $500 for any open-source contributor who provides a MR that solves this issue
Bounty
$5000
A bounty of $5000 for any open-source contributor who provides a MR that solves this issue
Bounty
$750
A bounty of $750 for any open-source contributor who provides a MR that solves this issue
MoSCoW
Could have
Could have feature in order to satisfy the epic/legendary.
MoSCoW
Must have
Must have feature in order to satisfy the epic/legendary.
MoSCoW
Should have
Should have feature in order to satisfy the epic/legendary.
There are questions in the ticket that can not be completed until the project owner provides clarity.
Points
1
1 man-hours worth of work for an expert with no learning curve.
Points
13
13 man-hours worth of work for an expert with no learning curve.
Points
2
2 man-hours worth of work for an expert with no learning curve.
Points
21
21 man-hours worth of work for an expert with no learning curve.
Points
3
3 man-hours worth of work for an expert with no learning curve.
Points
34
34 man-hours worth of work for an expert with no learning curve.
Points
5
5 man-hours worth of work for an expert with no learning curve.
Points
55
55 man-hours worth of work for an expert with no learning curve.
Points
8
8 man-hours worth of work for an expert with no learning curve.
Points
88
88 man-hours worth of work for an expert with no learning curve.
Priority
Backlog
This ticket has backlogged priority and is not to be worked on yet
Priority
CI Blocker
Critical priority issue that blocks CI/CD pipeline and prevents PR merges
Priority
Critical
The priority is critical
Priority
High
The priority is high
Priority
Low
The priority is low
Priority
Medium
The priority is medium
When an epic or legendary is in review it must be signed off by owner, tech lead, and scrum master before being marked as completed.
When an epic or legendary is in review it must be signed off by owner, tech lead, and scrum master before being marked as completed.
When an epic or legendary is in review it must be signed off by owner, tech lead, and scrum master before being marked as completed.
A ticket for learning a tool or technology that is needed to be able to do future planning and design.
State
Completed
The ticket has been fully implemented, completed, and merged with the source code. This label should only be applied once a ticket is closed.
State
Duplicate
A ticket that represents the same content as an existing ticket.
State
In Progress
A ticket that is actively being developed.
State
In Review
A ticket that has had some code completed to implement but is waiting to pass peer review and is not yet merged in.
State
Paused
This ticket's work started but wasn't finished. It's on hold (likely in a feature branch) and will be resumed later, either due to a blocker or a delay.
State
Unverified
All new tickets start in this state. A developer may set it to show the ticket is unverified. This means we haven't agreed to work on it. It will either move to a verified state or be closed as wontdo.
State
Verified
The issue has been verified by a developer as legitimate. It will be worked on and verified tickets are now considered part of the backlog.
State
Wont Do
This ticket has been decided it wont be done. This may mean the bug has been determined to not be real (cant verify) or the feature is one we have decided we dont want to adopt.
Type
Automation
Any edits or discussion about the AI automated coding system.
Type
Bug
Something that doesnt work as intended.
Type
Discussion
Anytime a ticket represents a discussion about a subject and doesnt fall into one of the other categories.
Type
Documentation
An error or improvement needed in the documentation.
Type
Epic
Any first tier epic. That is, an epic which contains only issues as children and will not have sub-epics.
Type
Feature
Some new functionality not present.
Type
Legendary
A type of Epic which will contain other Epics.
Type
Refactor
A code change that restructures existing code without changing its external behavior.
Type
Support
Someone needs help using the project.
Type
Task
A generic task that doesnt fit into the other type categories.
Type
Testing
Work exclusively focusing on fixing or expanding testing.
Projects
Clear projects
No project
Assignees
aditya (Aditya Chhabra)
aleenaumair (Aleena Umair)
brent.edwards (Brent Edwards)
CoreRasurae (Luis Mendes)
drew (Drew Morris)
eugen.thaci (Eugen Thaci)
freemo (Jeffrey Phillips Freeman)
HAL9000 (HAL 9000)
HAL9001 (HAL9001)
hamza.khyari (Hamza Khyari)
hurui200320 (Rui Hu)
justin.morris
khird (Kyle Hird)
org.cleveragents
Clear assignees
No Assignees
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: cleveragents/cleveragents-core#450
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Delete Branch "feature/post-safety-profile"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Add
SafetyProfiledomain model with configurable safety constraints (allowed skill categories, sandbox/checkpoint requirements, human-approval flag, unsafe-tool gating, cost/retry limits) and integrate it into theActionmodel viafrom_config/as_cli_dictsupport. Persistence is backed by asafety_profile_jsoncolumn onLifecycleActionModelwith Alembic migrationc4_001_safety_profile_columnand a merge migration for multiple heads.The
resolve_safety_profile()stub raisesNotImplementedErrorin local mode, signalling that real enforcement is deferred to server mode. Resolution follows plan > action > project > global precedence.Covered by 26 Behave BDD scenarios, 6 Robot Framework smoke tests, 5 ASV benchmark suites (11 timing functions), and
docs/reference/safety_profile.mdreference documentation.Issue Reference
Closes #332
Dependencies
This PR blocks issue #332 (safety profile model and enforcement stubs).
ccb96e8261tofff9da60eeReview Summary
Scope: SafetyProfile domain model + Action integration + persistence JSON field + tests/bench/docs.
CI status isn’t visible via the API on my side. Please confirm required checks per
docs/development/ci-cd.md(lint, typecheck, security, quality, unit_tests, integration_tests, coverage, build) pass before merge.Findings
P1:must-fix — Missing Alembic migration for the new
safety_profile_jsoncolumn. The ORM now reads/writessafety_profile_json, but no migration exists (and docs referencec4_001_safety_profile_columnwhich is missing). This will break persistence once an Action usessafety_profile.src/cleveragents/infrastructure/database/models.py:268,src/cleveragents/infrastructure/database/models.py:368,src/cleveragents/infrastructure/database/models.py:421docs/reference/safety_profile.md:174P2:should-fix —
Action.from_configsilently ignores invalidsafety_profiletypes. If a user supplies a non-dict, the field is dropped instead of raising a validation error. Consider raising whensafety_profileis present but not a dict/SafetyProfile for strict config validation.src/cleveragents/domain/models/core/action.py:626P2:should-fix —
docs/timeline.mdcontains a large, unrelated historical rewrite (dates/status regressions). Please split it into a separate PR or revert to keep this change focused on safety profiles.docs/timeline.mdP3:nit — New
docs/reference/safety_profile.mdisn’t added to the reference nav list. Add it indocs/gen_ref_pages.pyso it appears in the Reference sidebar.docs/reference/safety_profile.mddocs/gen_ref_pages.pyPositive Notes
fff9da60eeto78142df33b78142df33bto1b6e585b9d1b6e585b9dto2677abb4adCode Review: PR #450 —
feat(security): add safety profile model and enforcement stubsOverall Assessment
The SafetyProfile domain model, its Action integration, persistence layer, and test coverage are technically well-implemented. The composition approach (
AutomationProfile.safety: SafetyProfile) correctly follows the project owner's guidance from issue #332 comments, and the code quality is solid throughout. However, there are several process-level violations ofCONTRIBUTING.mdthat must be addressed before this PR can be merged.Critical / High Priority — Process Violations
H1: Empty PR Description (CONTRIBUTING.md §PR Process #1)
The PR body is completely empty. Per CONTRIBUTING.md:
The guidelines also state: "PRs submitted without a description or without an issue reference will not be reviewed."
Action required: Add a PR description with a summary,
Closes #332closing keyword, and set up the Forgejo dependency (PR blocks #332, issue #332 depends on the PR).H2: Non-Atomic Commit — Unrelated Deletions (CONTRIBUTING.md §Atomic Commits)
This single commit bundles the safety profile feature with the deletion of unrelated code:
src/cleveragents/acp/clients.pysrc/cleveragents/acp/server_config.pysrc/cleveragents/cli/commands/server.pysrc/cleveragents/application/services/subplan_service.pysrc/cleveragents/domain/models/acms/__init__.py+crp.pyfeatures/consolidated_*.feature(17 files)benchmarks/crp_model_bench.py,server_stub_bench.py,subplan_spawn_bench.pyrobot/crp_models.robot,server_stubs.robot,subplan_spawn.robotPer CONTRIBUTING.md: "One logical change per commit. Each commit must encapsulate a single, focused change." and "Never bundle cosmetic changes with functional changes in the same commit."
The safety profile feature, the removal of server/CRP/subplan code, and the feature file reorganization are three separate logical changes that should be in separate commits, each with their own issue.
Action required: The unrelated deletions (server stubs, CRP models, subplan service) and the feature file reorganization should be extracted into separate commits under their own issues. The PR should contain only the safety profile changes.
H3: Incorrect Labels on PR (CONTRIBUTING.md §PR Process #12)
The PR currently carries:
MoSCoW/Must have,Points/8,Priority/Low,State/Verified,Type/Feature.Per CONTRIBUTING.md:
Action required: Remove
State/Verified,Priority/Low,MoSCoW/Must have, andPoints/8from the PR. OnlyType/Featureshould remain.Medium Priority — Process Items
M1: Missing Changelog Update (CONTRIBUTING.md §PR Process #6)
No changelog update is present in the diff.
M2: Missing CONTRIBUTORS.md Update (CONTRIBUTING.md §PR Process #8)
No CONTRIBUTORS.md update is present in the diff. Please verify if your name is already listed; if not, add it.
M3: Issue #332 Ref Field Not Set
The issue Metadata specifies branch
feature/post-safety-profile, but the Forgejo Ref field on issue #332 is empty. Per CONTRIBUTING.md: "The Ref field must be set to the same branch named in the issue body's Metadata section" for development issues in active states.M4:
Needs feedbackLabel Still on Issue #332The
Needs feedbacklabel appears to be stale — the feedback from the project owner (composition approach, spec updates) has been addressed in the current implementation. This label should be removed if the feedback is resolved.Low Priority — Code Quality Notes
See inline comments below for specific code observations on:
resolve_safety_profile()stub implementationfrom_yaml()missing explicit encoding_row_to_domain()hardcoded safety field defaultsL1: Commit Body Inaccuracy
The commit message body states "20 BDD scenarios" but
features/safety_profile.featurecontains approximately 30 scenarios. The numbers should match the actual content.Positive Observations
SafetyProfileis well-designed with proper Pydantic validation, frozen immutability, cross-field validators, factory methods, and comprehensive type annotations. Stays under 500 lines.AutomationProfile.safety: SafetyProfilecomposition correctly follows the project owner's directive and eliminates dual authority for overlapping safety flags.docs/reference/safety_profile.mdis thorough — covers schema, defaults, validation, precedence, YAML config, action integration, stub enforcement, and persistence.Summary
The safety profile feature itself is well-implemented and demonstrates good engineering practices. The blocking issues are primarily process-related: the empty PR body (H1), the bundled unrelated deletions (H2), and the incorrect labels (H3). Of these, H2 is the most significant as it makes the commit non-atomic and non-revertible in isolation. H1 and H3 are straightforward to fix.
Requesting changes primarily for H1 (empty PR body) and H2 (non-atomic commit). Once these are addressed, this PR should be in good shape for approval.
@@ -0,0 +222,4 @@file_path = Path(path)if not file_path.exists():raise FileNotFoundError(f"Safety profile YAML file not found: {file_path}")with open(file_path) as fh:[L2] Missing explicit encoding parameter
open(file_path)should specifyencoding="utf-8"explicitly. While the default encoding on most systems is UTF-8, relying on the platform default is fragile and can cause issues on Windows or in non-standard environments. Per Python best practices:addressed
@@ -0,0 +312,4 @@Raises:NotImplementedError: Always, in local mode."""raise NotImplementedError([L3] Stub does no resolution before raising
This function accepts four precedence levels (
plan_profile,action_profile,project_profile,global_profile) but performs zero resolution logic before raisingNotImplementedError. Even as a stub, it would be valuable to include the intended resolution flow as commented-out logic or pseudocode, so that the future implementer has a clear roadmap. For example:This would also make the function more self-documenting and align with the docstring's description of the resolution order.
comments inserted
@@ -4291,0 +4289,4 @@safety=SafetyProfile(require_sandbox=bool(row.require_sandbox),require_checkpoints=bool(row.require_checkpoints),require_human_approval=False,[L4] Hardcoded safety field defaults deserve a comment
The new
SafetyProfilefields (require_human_approval,max_retries_per_step) are hardcoded here because the database table does not have columns for them — only the original three booleans (require_sandbox,require_checkpoints,allow_unsafe_tools) are persisted. This is a reasonable approach for backwards compatibility, but a clarifying comment would prevent future confusion:addressed as requested
2677abb4adto01686f8cd001686f8cd0to66b9a4279fApprove.