Skip to content

fix: stop system tasks from minting per-user agent rows; add agent prune#2865

Open
chubes4 wants to merge 3 commits into
mainfrom
fix-stray-agent-provisioning
Open

fix: stop system tasks from minting per-user agent rows; add agent prune#2865
chubes4 wants to merge 3 commits into
mainfrom
fix-stray-agent-provisioning

Conversation

@chubes4

@chubes4 chubes4 commented Jul 8, 2026

Copy link
Copy Markdown
Member

Closes #2864.

Problem

datamachine_resolve_system_agent_context() conflated attribution (which human triggered the work) with agent identity (a persistent row in the agents table). Any authenticated user who triggered a system-owned queued task — uploading an image, generating alt text, meta descriptions, image optimization, internal linking — got a full agent identity minted from their login. ChatOrchestrator is the only legitimate auto-provision surface.

Fix: attribution vs. identity

  • datamachine_resolve_system_agent_context() now always resolves to the install's default agent owner (DirectoryManager::get_default_agent_user_id() → its agent id). It only calls datamachine_resolve_or_create_agent_id() for that default owner, never for the triggering human.
  • The original triggering user is returned separately as triggering_user_id.
  • Media/SEO/linking callers pass triggering_user_id into the TaskScheduler context so it is preserved in engine_data['task_context'] for audit, without minting a row.
  • ChatOrchestrator keeps datamachine_resolve_or_create_agent_id() — opening chat is still operating an agent.

Cleanup: wp datamachine agent prune

  • New datamachine/prune-agents ability and matching wp datamachine agent prune subcommand.
  • Default is dry-run listing; --yes applies deletion.
  • A candidate is an agent row with zero references:
    • no chat sessions (network-wide table + legacy per-site tables)
    • no jobs (agent_id)
    • no access grants (user or principal)
    • no on-disk agent directory
    • no datamachine_bundle config block
    • not the install's default agent
  • Uses the existing deleteAgent path so grants are cleaned up; directories are never auto-deleted.

Tests

  • Updated tests/system-agent-context-resolution-smoke.php for the new resolver behavior.
  • Added tests/agent-prune-smoke.php covering zero-reference detection, default-agent protection, and session/job/grant/directory/bundle spares.

Verification

  • Local phpcs clean.
  • homeboy review data-machine --changed-since origin/main --summary: lint passed; test stage failed before running tests due to a missing wp-codebox CLI binary in this environment (infrastructure, not code).
  • Manual smoke-test runs pass.

Fixes #2864

@homeboy-ci

homeboy-ci Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Homeboy Results — data-machine

Lint

review lint — passed

ℹ️ Full options: homeboy self docs commands/lint
Deep dive: homeboy review lint data-machine --changed-since ad09ae9

Artifacts and drill-down
  • CI results artifact: homeboy-ci-results-data-machine-review-lint-quality-Linux-node24 contains immediate command JSON for this action invocation.
  • Observation artifact: homeboy-observations-data-machine-review-lint-quality-Linux-node24 contains exported Homeboy run history for deeper queries.
  • Drill-down: download the observation artifact, then run homeboy runs import <dir>, homeboy runs list, and homeboy runs findings <run-id>.
  • Artifacts are attached to the workflow run: https://github.com/Extra-Chill/data-machine/actions/runs/28970015680

Test

review test — failed

ℹ️ No tests ran — the runner failed before producing results. See raw_output.stderr_tail / raw_output.stdout_tail for the underlying error (bootstrap failure, missing deps, DB connection, etc.).
ℹ️ To run specific tests: homeboy test data-machine -- --filter=TestName
ℹ️ Auto-fix lint issues: homeboy refactor data-machine --from lint --write
ℹ️ Collect coverage: homeboy test data-machine --coverage
ℹ️ Analyze failures: homeboy test data-machine --analyze
ℹ️ Pass args to test runner: homeboy test -- [args]
ℹ️ Full options: homeboy self docs commands/test
Deep dive: homeboy review test data-machine --changed-since ad09ae9

Artifacts and drill-down
  • CI results artifact: homeboy-ci-results-data-machine-review-test-quality-Linux-node24 contains immediate command JSON for this action invocation.
  • Observation artifact: homeboy-observations-data-machine-review-test-quality-Linux-node24 contains exported Homeboy run history for deeper queries.
  • Drill-down: download the observation artifact, then run homeboy runs import <dir>, homeboy runs list, and homeboy runs findings <run-id>.
  • Artifacts are attached to the workflow run: https://github.com/Extra-Chill/data-machine/actions/runs/28970015680

Audit

review audit — passed

  • audit — 43 finding(s)
  • Total: 43 finding(s)

Deep dive: homeboy review audit data-machine --changed-since ad09ae9

Artifacts and drill-down
  • CI results artifact: homeboy-ci-results-data-machine-review-audit-quality-Linux-node24 contains immediate command JSON for this action invocation.
  • Observation artifact: homeboy-observations-data-machine-review-audit-quality-Linux-node24 contains exported Homeboy run history for deeper queries.
  • Drill-down: download the observation artifact, then run homeboy runs import <dir>, homeboy runs list, and homeboy runs findings <run-id>.
  • Artifacts are attached to the workflow run: https://github.com/Extra-Chill/data-machine/actions/runs/28970015680
Tooling versions
  • Homeboy CLI: homeboy 0.281.20+123145ee082b+dcdd8a98
  • Extension: wordpress from https://github.com/Extra-Chill/homeboy-extensions
  • Extension revision: f89b4297
  • Action: unknown@unknown

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.

System tasks mint a persistent agent identity row for every acting user — agents table silts up with stray rows

1 participant