Skip to content

fix(company-os): every service writes its audit row by default, and a failed audit fails the operation (#20101) - #20426

Merged
mrveiss merged 31 commits into
mainfrom
issue-20101-activity-default
Nov 4, 2026
Merged

mrveiss merged 31 commits into
mainfrom
issue-20101-activity-default

Conversation

@mrveiss

@mrveiss mrveiss commented Nov 1, 2026 •

Copy link
Copy Markdown
Owner

Refs #20101
Refs #8214

Follow-up: #20417, the services that still write no row. #20412, which this stacked on, has landed, so this diff is now its own.

Thinking Path

Most Company OS services never received an activity log and guarded each write with if self.activity_log:, so audit writes silently did nothing. Making a real log the default removes that state. Once the log was always there, the guards turned out to have hidden calls that could never have worked.

What Changed

  • services/base.py: LLCServiceBase builds a real LLCActivityLogService unless given one. The if self.activity_log: guards are gone from 17 services and audit().
  • Calls that only "worked" because of the guard: sprint_autoclose.py called .log(...) and portability.py called .append(...), neither of which exists. reporting_line passed user:<uuid> as an entity id; workflow passed free text. TEMPLATE_PUBLISHED and TEMPLATE_IMPORTED were referenced but undefined.
  • handoff.py: three swallowed audit failures now fail the handoff with ActivityRecordError.
  • TemplateService now uses the base class. plan_convert.py and company_os/workflows.py pass their log to child services.
  • Sprint close and company export pass the authenticated user as the actor.
  • tests/company_os_e2e/_expected_activity.py: the goal row is asserted. Rows nothing writes yet now name bug(company-os): many services write no activity row at all, so the audit trail misses whole workflow steps #20417.
  • services/portability.py reached 601 lines after the merge, so _goal_titles_exist moved to PortabilityImportMixin.
  • Test schemas gained the activity table; several tests use UUID company ids, because record rejects anything else.

From review, also fixed:

  • One audit path: the wrapping lives in LLCActivityLogService.record, so all 40 raw call sites raise ActivityRecordError on a failed write. A bad actor_id stays a ValueError, checked before the log is touched. A guard fails on any other way of writing a row.
  • handoff.py: both directions audit before releasing the key or notifying, so a failed audit changes nothing.
  • Live events publish after commit: record queues them on the session, with commit and rollback listeners, so a rollback, or a savepoint rollback, publishes nothing. run_after_commit wouldn't work here, as most llc sessions don't use async_session_scope.
  • liveness_monitor.py now has a real log and writes a valid row, and each run recovers in its own savepoint, so one failure doesn't hit the others. Its old record call would have raised TypeError, hidden because no monitor was ever given a log. Its exemptions in the guards are gone.

Behaviour changes to check:

  • A failed audit write now fails the operation on these paths. That is the point of criterion 3, and a non-UUID company or entity id is now a hard failure there.
  • Company creation now writes the first member's agent.assigned row.

Verification

Not established:

  • Postgres: all database tests run on SQLite, including .returning on workflow delete. CI's end-to-end stack is the first Postgres run.
  • The end-to-end step 9 assertions haven't run.
  • Criterion 4, host evidence.
  • Savepoint and aborted-transaction behaviour is shown only on SQLite. The reason for liveness_monitor's savepoint, that a failed flush aborts a Postgres transaction, is a read of how Postgres behaves.
  • Delivery to /ws/live is tested through a spy.

Model Used

Claude Sonnet 5 for implementation, Claude Opus 5.5 for direction and the merge

🤖 Generated with Claude Code

… issue-20101-activity-default

# Conflicts:
#	autobot-backend/llc/api/sprints.py
#	autobot-backend/llc/services/sprint_autoclose.py
#	scripts/python_file_size_known_large.py
@mrveiss mrveiss added this to the M2 - Company OS workflow-ready milestone Nov 1, 2026
@coderabbitai

coderabbitai Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 14 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
Commits

Reviewing files that changed from the base of the PR and between 9fba9f3 and f5b1e0f.

Files ignored due to path filters: 1
  • scripts/python_file_size_known_large.py is excluded by !scripts/python_file_size_known_large.py
Files selected for processing: 67
  • autobot-backend/llc/api/companies.py
  • autobot-backend/llc/api/company_members.py
  • autobot-backend/llc/api/sprint_access.py
  • autobot-backend/llc/api/sprints.py
  • autobot-backend/llc/models/enums.py
  • autobot-backend/llc/scheduler/liveness_monitor.py
  • autobot-backend/llc/services/activity_log.py
  • autobot-backend/llc/services/actor.py
  • autobot-backend/llc/services/base.py
  • autobot-backend/llc/services/company_os/plan_convert.py
  • autobot-backend/llc/services/company_os/workflows.py
  • autobot-backend/llc/services/company_tool.py
  • autobot-backend/llc/services/contact.py
  • autobot-backend/llc/services/contact_directory.py
  • autobot-backend/llc/services/goal.py
  • autobot-backend/llc/services/handoff.py
  • autobot-backend/llc/services/label_service.py
  • autobot-backend/llc/services/lazy_import_test.py
  • autobot-backend/llc/services/membership_service.py
  • autobot-backend/llc/services/portability.py
  • autobot-backend/llc/services/portability_import.py
  • autobot-backend/llc/services/reporting_line.py
  • autobot-backend/llc/services/role.py
  • autobot-backend/llc/services/role_assignment.py
  • autobot-backend/llc/services/role_credential.py
  • autobot-backend/llc/services/role_permission.py
  • autobot-backend/llc/services/role_rate.py
  • autobot-backend/llc/services/role_tool.py
  • autobot-backend/llc/services/role_workflow.py
  • autobot-backend/llc/services/secret.py
  • autobot-backend/llc/services/sprint_autoclose.py
  • autobot-backend/llc/services/template.py
  • autobot-backend/llc/services/work_item_relations.py
  • autobot-backend/llc/services/workflow.py
  • autobot-backend/llc/tests/test_activity_log.py
  • autobot-backend/llc/tests/test_activity_record_commit_scope_20101.py
  • autobot-backend/llc/tests/test_activity_record_names_actor_13999.py
  • autobot-backend/llc/tests/test_audit_rows_by_default_20101.py
  • autobot-backend/llc/tests/test_company_delete_purges_contacts.py
  • autobot-backend/llc/tests/test_company_os_api.py
  • autobot-backend/llc/tests/test_company_os_plan_convert_19936.py
  • autobot-backend/llc/tests/test_company_os_workflow_plans_19934.py
  • autobot-backend/llc/tests/test_company_tools.py
  • autobot-backend/llc/tests/test_contact_directory.py
  • autobot-backend/llc/tests/test_contact_service.py
  • autobot-backend/llc/tests/test_contacts_no_embedding.py
  • autobot-backend/llc/tests/test_contacts_no_login.py
  • autobot-backend/llc/tests/test_contacts_scoping.py
  • autobot-backend/llc/tests/test_every_service_has_an_activity_log_20101.py
  • autobot-backend/llc/tests/test_export.py
  • autobot-backend/llc/tests/test_goal_post_commit_boundary_15612.py
  • autobot-backend/llc/tests/test_goals.py
  • autobot-backend/llc/tests/test_liveness_monitor.py
  • autobot-backend/llc/tests/test_membership.py
  • autobot-backend/llc/tests/test_process_nodes.py
  • autobot-backend/llc/tests/test_reporting_lines.py
  • autobot-backend/llc/tests/test_role_assignments.py
  • autobot-backend/llc/tests/test_role_credentials.py
  • autobot-backend/llc/tests/test_role_permissions.py
  • autobot-backend/llc/tests/test_role_tools.py
  • autobot-backend/llc/tests/test_role_workflows.py
  • autobot-backend/llc/tests/test_roles_scoping.py
  • autobot-backend/llc/tests/test_secrets.py
  • autobot-backend/llc/tests/test_tool_nodes.py
  • autobot-backend/llc/tests/test_work_item_relations.py
  • autobot-backend/llc/tests/test_workflows_scoping.py
  • autobot-backend/tests/company_os_e2e/_expected_activity.py
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Notice: 29 open PRs — past the runaway threshold (25)

This is not a request to defer this PR. There is no cap on open PRs (#19397) -- nothing blocks opening or pushing a PR.

This notice only means the count is high enough to be worth a glance for a runaway — something opening PRs in a loop, or a merge pipeline that has stalled so nothing is draining.

Currently open:

If the queue is draining normally, ignore this. Otherwise:

  1. Check whether CI is dispatching at all — see the ci-dispatch-watchdog status on these PRs
  2. Approved PRs land through the merge train the coordinator sequences (merge commits, never squash) -- check the open chore(merge-train) PR is moving, not each PR on its own
  3. Look for a loop opening near-identical PRs

Warn-only runaway detector — .github/workflows/pr-queue-gate.yml. It never blocks a merge.

@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

✅ SSOT Configuration Compliance: Passing

🎉 No new hardcoded values of either class — ssot and other both block.

Known backlog in pipeline-scripts/hardcoded_values_baseline.txt is suppressed and tracked in #14371.

This was referenced Nov 1, 2026
@github-actions

github-actions Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Auto-sync: merging main into issue-20101-activity-default conflicts

The sync aborted the merge and pushed nothing. Conflicts are information, so it never resolves one itself. Below, for each conflicted file, are the commits that touched it on each side since the merge base 58cbf98c43. Merge main in yourself and push; the label clears on the first run that finds this branch 0 behind.

scripts/python_file_size_known_large.py

side commit subject issue refs
main ac18f28f3 Merge #20684 @ e17171d into the merge train #20684
main 8d5876690 Merge #20672 @ 430178c into the merge train #20672
main e17171d9e Merge main into issue-19725-lazy-collections (auto-sync) [skip ci] none
main 3f372114e Merge #20540 @ e474ca5 into the merge train #20540
main 1aa2d0e7d chore(merge): merge origin/main into issue-20234-file-cleanup-proposals (#20234) #20234
main 470afb93e Merge main into issue-19725-lazy-collections (auto-sync) [skip ci] none
main 430178c05 Merge main into issue-19726-bm25-refresh (auto-sync) [skip ci] none
main 3e7dc5531 Merge main into issue-19725-lazy-collections (auto-sync) [skip ci] none
main b1d49e90a Merge main into issue-19726-bm25-refresh (auto-sync) [skip ci] none
main a9185a872 fix(kb): a collection appears on its first write, not with its entity (#19725) #19725
main fcb856a7e fix(kb): writes share one corpus-stats recompute instead of one each (#19726) #19726
main 607c06e5d Merge main into issue-20234-file-cleanup-proposals (auto-sync) [skip ci] none
main 941e1e8de chore(merge): merge origin/main into issue-20234-file-cleanup-proposals (#20234) #20234
main 2d1fa12e0 fix(chat): keep _hard_delete_file, note it is unwired behind the gate (#20234) #20234
main e6caf4c5a fix(chat): re-propose failed or expired file cleanups, gate hard_delete bytes (#20234) #20234
main 3 more commit(s) not listed
this branch 6d40f13cd Merge main into issue-20101-activity-default (auto-sync) [skip ci] none
this branch 18b23a2a4 refactor(company-os): move the sprint org guard out of the routes, keeping the ceiling (#20101) #20101
this branch 93aef44fc Merge remote-tracking branch 'origin/main' into issue-20101-activity-default none
this branch 651638dfe Merge main into issue-20101-activity-default (auto-sync) [skip ci] none
this branch d33a41329 Merge main into issue-20101-activity-default (auto-sync) [skip ci] none
this branch 33a84fbd0 Merge main into issue-20101-activity-default (auto-sync) [skip ci] none
this branch ea7c78d92 Merge remote-tracking branch 'origin/main' into issue-20101-activity-default none
this branch 880bbd6cd Merge remote-tracking branch 'origin/main' into issue-20101-activity-default none
this branch c7f0f9532 Merge remote-tracking branch 'origin/issue-8214-approval-reland' into issue-20101-activity-default none
this branch 695744122 fix(company-os): role assignment test stays at its ceiling, and open audit rows name #20417 (#20101) #20417, #20101
this branch b337b465f fix(company-os): every service writes its audit row by default, and a failed audit write fails the operation (#20101) #20101

…default

# Conflicts:
#	scripts/python_file_size_known_large.py
@github-actions github-actions Bot removed the sync-conflict Set by the branch sync (#19548) label Nov 2, 2026
@github-actions github-actions Bot added the sync-conflict Set by the branch sync (#19548) label Nov 2, 2026
@github-actions github-actions Bot removed the sync-conflict Set by the branch sync (#19548) label Nov 3, 2026
mrveiss added a commit that referenced this pull request Nov 3, 2026
@mrveiss

mrveiss commented Nov 4, 2026

Copy link
Copy Markdown
Owner Author

Code review on PR #20426 (head b690d1e): APPROVE

Delta since the reviewed head 93aef44: one own commit, 18b23a2 (sprint org guard moved into llc/api/sprint_access.py). The rest is automatic main merges, not reviewed.

Reviewed: behaviour is identical to the inlined guard (same query, same str() company comparison, same 404 and detail). select and LLCSprint are still used elsewhere in sprints.py, so no unused import. The helper has a docstring, is 4 lines, and has one call site. The size ceiling in scripts/python_file_size_known_large.py is lowered, never raised, and matches the head's file size.

Severity file:line issue fix
LOW autobot-backend/llc/api/sprints.py:859,878,905,964,1085,1151,1209 Other handlers raise the same 404 for a missing sprint. Whether any of them repeat the org check was not verified. If any repeat the org check, call require_sprint_in_org there too (separate follow-up).
LOW autobot-backend/llc/api/sprint_access.py The guard has no direct unit test in the delta. Add a test: other org gives 404, own org passes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

phase:M2.8 Audit trail and run supervision

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant