Skip to content

feat(retention): OSS 5-day community floor + prod-compose LOG_* fix (#1039 — OSS floor) - #1065

Merged
vybe merged 6 commits into
devfrom
feature/1039-retention-oss-floor
Jul 14, 2026
Merged

vybe merged 6 commits into
devfrom
feature/1039-retention-oss-floor

Conversation

@dolho

@dolho dolho commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Summary

Stage 1 of Abilityai/trinity-enterprise#31 — the OSS floor (the issue's "must land first" chunk). The enterprise retention module (private submodule) + Settings → Retention UI follow as separate PRs on the #847 seam.

Prod bug fixed (silent no-op)

docker-compose.prod.yml omitted LOG_RETENTION_DAYS / LOG_ARCHIVE_ENABLED / LOG_CLEANUP_HOUR from backend.environment:. Prod launches standalone (-f docker-compose.prod.yml, no base-compose merge), so an operator-set LOG_RETENTION_DAYS never reached the container and retention always fell back to the code default. Added the three lines.

5-day community floor

Lowered the operator-tunable defaults to the 5-day community floor:

Setting Was Now
LOG_RETENTION_DAYS 90 5
execution_log_retention_days 30 5
execution_row_retention_days 90 5
health_check_retention_days 7 5
agent_soft_delete_retention_days 180 5
schedule_soft_delete_retention_days 30 5
audit_log_retention_days 365 365 (exempt — integrity floor)

New COMMUNITY_RETENTION_FLOOR_DAYS / RETENTION_OPS_KEYS constants — the enterprise module reuses these to clamp unentitled writes.

Read surface

GET /api/settings/retention (admin) reports the effective windows in use + the active edition (community vs enterprise via the retention entitlement) + documented precedence: enterprise (license) DB setting → env → 5-day community default.

Design note

OSS does not hard-clamp env/OPS values — they remain an unsupported self-host escape hatch (per the issue: "not a cryptographic lock on a constant"). The clamp-to-floor lives in the enterprise retention module's managed setter (Stage 2).

⚠️ Release-notes call-out

This sharply shortens soft-delete recovery on community installs (agent 180→5, schedule 30→5). Deliberate per the issue; an enterprise license restores longer windows.

Verification

  • tests/unit/test_retention_floor.py — 7/7 (floor defaults, audit exemption, read-surface edition + windows, audit 365-floor, enterprise-set OPS window).
  • Cleanup/retention suites green (test_cleanup_inner_sweeps, test_execution_retention_prune, test_audit_retention_prune, test_agent_cleanup_parity).
  • Live: GET /api/settings/retention → edition: community, OPS windows 5, audit 365; backend recreated with the new compose → LOG_RETENTION_DAYS=5 flows through to the container.

Remaining Abilityai/trinity-enterprise#31 (follow-up PRs)

  • Enterprise retention module (private trinity-enterprise): enterprise_retention_config table on the two-track runner, GET/PUT /api/enterprise/retention/* gated by requires_entitlement("retention"), live-read write-through, clamp-to-floor when unentitled.
  • Frontend: Settings → Retention panel gated on the retention entitlement; community shows the fixed 5-day default + upgrade hint.

Related to Abilityai/trinity-enterprise#31

🤖 Generated with Claude Code

@dolho

dolho commented Jun 4, 2026 •

Copy link
Copy Markdown
Contributor Author

Now spans all OSS-side stages of Abilityai/trinity-enterprise#31 (Stages 1 + 3); enterprise is trinity-enterprise#4

Per the plan to deliver Abilityai/trinity-enterprise#31 end-to-end, this PR now carries both public-repo stages; the enterprise backend lives in its own repo PR.

✅ Stage 1 — OSS floor (this PR)

Prod-compose LOG_* fix · 5-day floor across all 6 operator-tunable windows (audit exempt, 365) · GET /api/settings/retention read surface (+ edition + precedence) · COMMUNITY_RETENTION_FLOOR_DAYS/RETENTION_OPS_KEYS constants. 7/7 unit tests, live-verified.

✅ Stage 3 — frontend (this PR)

Settings → Retention tab (admin). Reads /api/settings/retention (all editions); community = read-only 5-day floor + upgrade hint; enterprise = editable per-class windows → PUT /api/enterprise/retention/config, applied live. Audit window shown, never editable. Gated via the existing enterprise store (isEntitled('retention')). SFC compiles clean (Vite HMR).

✅ Stage 2 — enterprise module → Abilityai/trinity-enterprise#4

Private enterprise_retention_config + GET/PUT /api/enterprise/retention/config (double-gated) + live-read write-through to OSS system_settings (no recreate) + clamp-to-floor. 5/5 module tests, enterprise suite 24/24.

Live end-to-end (full stack, submodule mounted)

  • enterprise_features = ['audit','retention','siem'] → read surface edition: enterprise.
  • PUT {execution_row:90, execution_log:2} → 90 allowed, 2 clamped to 5, and GET /api/settings/retention reflects execution_row=90 — write-through confirmed, no recreate.

Notes for the reviewer

  • The submodule pointer is intentionally NOT bumped in this PR (it would pin an unmerged enterprise branch); the UI gates at runtime via enterprise_features. Bump the pointer when trinity-enterprise#4 merges.
  • ⚠️ Release notes: community soft-delete recovery shrinks (agent 180→5, schedule 30→5).

Related to Abilityai/trinity-enterprise#31

@dolho
dolho force-pushed the feature/1039-retention-oss-floor branch from af8175a to b10a57b Compare June 4, 2026 12:41
@dolho
dolho marked this pull request as draft June 4, 2026 14:38
@dolho dolho changed the title feat(retention): OSS 5-day community floor + prod-compose LOG_* fix (#1039 — OSS floor) WIP: feat(retention): OSS 5-day community floor + prod-compose LOG_* fix (#1039 — OSS floor) Jun 4, 2026
@github-actions

github-actions Bot commented Jun 5, 2026

Copy link
Copy Markdown

⚠️ Nightly unit-suite check skipped — merge conflict against dev.

Resolve by running git merge dev locally and pushing the result. The next nightly run will re-test once the conflict is gone.

@dolho dolho changed the title WIP: feat(retention): OSS 5-day community floor + prod-compose LOG_* fix (#1039 — OSS floor) feat(retention): OSS 5-day community floor + prod-compose LOG_* fix (#1039 — OSS floor) Jun 23, 2026
@dolho
dolho marked this pull request as ready for review June 23, 2026 10:15
@dolho
dolho requested a review from vybe June 23, 2026 10:15

@vybe vybe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Validated via /validate-pr — one blocker. The OSS 5-day floor logic, the prod-compose LOG_* packaging fix, and the tests are all good.

The architecture.md hunk re-introduces enterprise-module disclosure that the just-merged trinity-enterprise#45 cleanup (the current top commit on dev) removed:

Precedence is enterprise retention license (DB setting) → env → 5-day community default … the enterprise retention module is the managed setter.

Per the CLAUDE.md standing rule, public docs describe the generic open-core seam only — no named paid modules or per-module behavior. The guard CI doesn't catch this (its pattern is SIEM/SCIM/2FA/SSO only), so it would silently re-land.

Fix: genericize that one paragraph to the seam, e.g. "an optional entitled override via the entitlement registry (#847) → env → 5-day community default", without naming the enterprise retention module/license.

— posted via /validate-pr

@dolho

dolho commented Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the blocker in 33bf206. Genericized the retention precedence to the open-core seam in both spots — the Cleanup Service sweeps note and the GET /api/settings/retention endpoint row (the latter had the same retention entitlement disclosure):

Precedence: an optional entitled override (via the entitlement registry, #847) → env → 5-day community default; OSS does not hard-clamp.

No named enterprise module / license / per-module behavior remains (verified by grep). OSS floor logic, the prod-compose LOG_* fix, and tests are unchanged.

@dolho

dolho commented Jun 26, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto dev — blocker confirmed resolved, now mergeable

The enterprise-module disclosure blocker was already genericized in 33bf2061; this push merges current dev (resolving the two architecture.md conflicts the merge surfaced).

Conflict resolution

Standing-rule check (CLAUDE.md / trinity-enterprise#45)

No named paid module, no enterprise retention license, no per-module behavior remains — only the generic open-core seam:

$ grep -ni 'retention module\|managed setter\|retention.*license' docs/memory/architecture.md
(no matches)

OSS floor logic, the prod-compose LOG_* fix, and tests are unchanged.

@dolho
dolho requested a review from vybe July 10, 2026 08:04
dolho and others added 4 commits July 14, 2026 12:52
…ap (#1039)

OSS floor for the #1039 retention work (must land first; the enterprise
`retention` module + Settings UI follow on the #847 seam).

Prod bug fix:
- docker-compose.prod.yml omitted LOG_RETENTION_DAYS / LOG_ARCHIVE_ENABLED /
  LOG_CLEANUP_HOUR from backend.environment. Prod launches standalone (no
  base-compose merge), so operator-set values never reached the container and
  retention silently fell back to the code default. Added the three lines.

Community 5-day floor (was: log 90 / exec-log 30 / exec-row 90 / health 7 /
agent soft-delete 180 / schedule soft-delete 30):
- OPS_SETTINGS_DEFAULTS: the five operator-tunable windows default to 5.
- LOG_RETENTION_DAYS default 5 (log_archive_service, logs.py, docker-compose.yml).
- Audit log EXEMPT — keeps the 365-day integrity floor (audit_retention_service).
- New COMMUNITY_RETENTION_FLOOR_DAYS / RETENTION_OPS_KEYS constants (the
  enterprise module reuses these to clamp unentitled writes).

Read surface:
- GET /api/settings/retention (admin) reports the effective windows in use +
  the active edition (community vs enterprise via the `retention` entitlement)
  + documented precedence (enterprise → env → community-default).

OSS does NOT hard-clamp env/OPS — they remain an unsupported self-host escape
hatch (per the issue: "not a cryptographic lock on a constant"); the clamp is
the enterprise module's managed setter.

Tests: tests/unit/test_retention_floor.py (7) — floor defaults, audit exemption,
read-surface edition + windows. Cleanup/retention suites green (no test pinned
the old defaults).

NOTE: this sharply shortens soft-delete recovery (agent 180→5, schedule 30→5)
on community installs — call out in release notes; enterprise restores it.

Related to #1039

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
… (#1039 Stage 3)

Adds a Retention tab to Settings (admin-only). Reads the OSS read surface
GET /api/settings/retention (available in every edition) and shows the effective
windows + an edition badge.

- Community: read-only windows at the fixed 5-day floor + an upgrade hint.
- Enterprise (retention entitlement present): editable per-class windows that
  PUT /api/enterprise/retention/config and apply live (no restart). 0 disables
  a sweep; sub-floor values are raised to the floor (mirrors the backend clamp).
- Audit-log window always shown, never editable (365-day integrity floor).

Gating reuses the existing enterprise store (enterpriseStore.isEntitled
('retention')); the tab is visible in both editions (read-only vs editable),
matching the issue's "community shows the fixed default + upgrade hint".

Related to #1039

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…ollution (#1039)

The regression-diff CI gate flagged the 4 endpoint tests in test_retention_floor
as new failures under pytest-randomly seeds 12345/67890 (but not 99999) — a
classic test-ordering pollution, not a logic bug.

Root cause: the tests imported `routers.settings` (lazily), which drags
routers/__init__ → routers.agents → `from services.agent_service import
get_agents_by_prefix`. Another unit test (#612) loads services.agent_service
under a fake sys.modules name, so under some orderings that import resolves to
the partial fake module and raises `ImportError: cannot import name
'get_agents_by_prefix'`.

Fix: load routers/settings.py directly from file under a private module name
(spec_from_file_location), bypassing routers/__init__ entirely. settings.py
imports only models/database/dependencies/services.* — none of the polluted
modules — so the load is robust regardless of collection order. Mirrors the
existing conftest EntitlementCls pattern. Also pins LOG_/AUDIT_ env per call so
a polluted process env can't leak in.

Verified: full unit suite under seeds 12345 + 67890 — all 7 test_retention_floor
tests pass; the only remaining failures are the 7 pre-existing base failures
(git_pull_branch, orphaned_execution_recovery), unchanged by this PR.

Related to #1039

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…seam (#1039)

Review feedback (vybe via /validate-pr): the architecture.md hunk re-introduced
named enterprise-module disclosure that the trinity-enterprise#45 cleanup
removed — it named the enterprise `retention` module/license/entitlement as the
managed setter. Per the CLAUDE.md standing rule, public docs describe the
generic open-core seam only (the CI guard's pattern is SIEM/SCIM/2FA/SSO, so it
didn't catch this).

Genericized both spots (the Cleanup Service sweeps precedence note and the
`GET /api/settings/retention` row) to "an optional entitled override via the
entitlement registry (#847) → env → 5-day community default" — no named module,
license, or per-module behavior. OSS floor logic, prod-compose LOG_* fix, and
tests unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@dolho
dolho force-pushed the feature/1039-retention-oss-floor branch from 8ae4523 to fa89fe2 Compare July 14, 2026 09:56
Eugene Vyborov and others added 2 commits July 14, 2026 13:36
…enterprise)

The branch carried accidental gitlink changes from a stale local checkout:
src/backend/enterprise pointed at a commit only reachable from an unmerged
side branch (feature/88-local-dev-submodule-docs), and .claude at a commit
divergent from dev's pointer. Neither bump was intended by this PR.

Co-Authored-By: Claude Fable 5 <[email protected]>

@vybe vybe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Validated via /validate-pr: security greps clean, LOG_* wired into both compose files (the PR's core fix), architecture.md updated, retention read-surface route registered before the /{key} catch-all (Invariant #4), 7/7 retention-floor tests pass locally. Fixed on-branch during validation: stale submodule pointers (.claude, src/backend/enterprise) reset to dev's, and .env.example LOG_RETENTION_DAYS aligned with the 5-day floor. Note for release notes: community soft-delete recovery windows shrink 180→5 (agents) / 30→5 (schedules) — deliberate per trinity-enterprise#31.

@vybe
vybe merged commit 4341137 into dev Jul 14, 2026
22 checks passed
getsal pushed a commit to getsal/trinity that referenced this pull request Aug 15, 2026
…ne-time defaults

The #1039 5-day community floor was applied by lowering OPS_SETTINGS_DEFAULTS.
Those defaults are read at PRUNE time as the fallback for any install with no
system_settings row -- which is the default state, since nothing writes them. So
the dict was not "the default for new installs"; it was live, retroactive policy
for every install that had never opted in, evaluated against a hard DELETE on a
startup sweep seconds after boot. A real instance lost 95.7% of
schedule_executions (~3 months) with a green /health and one INFO line.

Not shipped in any release: 4341137 is not an ancestor of v0.8.0 (the tag
predates it by six days) and is in no tag, so only dev-tracking instances were
ever exposed. Fixed before it could reach a release user.

Invert the mechanism rather than backfill existing installs. Code defaults return
to their wide historical values (30/90/7/180/30) and become a safety floor, not a
policy knob; the community floor now reaches fresh installs only, by seeding rows
into an empty DB. This makes every hole fail SAFE (keeps too much) instead of
fail DESTRUCTIVE: a missed seed, a deleted row, or a future default edit can no
longer delete real data. It is also less code than the backfill the issue
proposed -- no fresh-vs-existing discriminator, no dual-track SQLite+Alembic
pair, no idempotency crash-loop risk.

The floor was never enforced anyway: any admin can widen a window via
PUT /api/settings/ops/config (no clamp), and the enterprise clamp is a MINIMUM
(max(value, 5)). Enterprise sells the managed panel, not the capability -- so
keeping data is no concession.

- Seed on fresh installs only (config.COMMUNITY_FRESH_INSTALL_SEED ->
  database._seed_fresh_install_retention{,_engine}), run inside init_database()
  after init_schema and before _ensure_admin_user: an empty users table is the
  fresh signal. Fail-safe (never raises -- init_database runs at import, so a
  raise would crash-loop boot) and idempotent (INSERT OR IGNORE /
  on_conflict_do_nothing -- both migration locks fail open). Constants live in
  config.py because settings_service imports db from database (circular).
- agent_soft_delete_retention_days is exempt from the floor in every edition: its
  expiry chains purge_agent_ownership -> remove_agent_volumes (Abilityai#1581), destroying
  agent workspaces and data_paths runtime data (Abilityai#1169). That is a recovery
  window, not a log window, and 180 -> 5 was never a deliberate decision.
- POST /api/settings/ops/reset no longer touches retention keys. It deleted every
  OPS row it knew about, so "reset to defaults" re-armed mass deletion -- one
  admin click from worthless.
- GET /api/settings/retention no longer advertises a precedence
  ("enterprise -> env -> community-default") whose env layer does not exist for
  these keys; the one documented mitigation an operator could reach for did
  nothing. Reports the real precedence plus a per-key source (db-row/code-default).
- Visibility: effective windows + source logged at boot BEFORE the first sweep;
  cap-hitting prunes log at WARNING (a routine trickle stays INFO -- alarm fatigue
  would defeat it); agent purges always WARNING. Dead fallback literals removed.
- Fix OPS_SETTINGS_DESCRIPTIONS drift (advertised "default: 90" to the admin UI
  while deleting at 5), pinned by a test.
- Rewrite test_retention_floor.py, which asserted the destructive default AS the
  requirement -- that is why Abilityai#1065 shipped green.

Follow-ups: Abilityai#1644 (blast-radius guard -- the durable fix, deferred to keep this
small), abilityai/trinity-enterprise#168 (mirror divergence).

Fixes Abilityai#1638

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants