Skip to content

[front] feat: add agent head fields to agents - #32957

Open
sfriquet wants to merge 1 commit into
mainfrom
sf/feat-agent-head-fields
Open

sfriquet wants to merge 1 commit into
mainfrom
sf/feat-agent-head-fields

Conversation

@sfriquet

@sfriquet sfriquet commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

Description

Refs https://github.com/dust-tt/tasks/issues/10447

Adds status, scope, reinforcement, lastReinforcementAnalysisAt, templateId to agents,
nullable for now. They mirror the same columns of the configuration row the agent points at:

Tests

added tests + tested manually that agent changes propagates to agents table.

Risk

Low, nothing reads agents fields for now.

Deploy Plan

migrate then deploy

@sfriquet
sfriquet requested a review from a team as a code owner September 22, 2026 11:17
@vercel

vercel Bot commented Sep 22, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Actions Updated
playground Ignored Ignored Preview Sep 22, 2026 4:30pm UTC
storybook Ignored Ignored Preview Sep 22, 2026 4:30pm UTC

Request Review

@sfriquet

sfriquet commented Sep 22, 2026

Copy link
Copy Markdown
Contributor Author

@sfriquet

Copy link
Copy Markdown
Contributor Author

r? @tdraier

@github-actions
github-actions Bot requested a review from tdraier September 22, 2026 11:28

@github-actions github-actions Bot 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.

cc-verify: violations found!

  • agent-verbs: Lifecycle writes bypass write permission
  • index-foreign-keys: Template foreign key lacks index
  • no-unsafe-type-assertions: Incomplete attributes cast as complete
  • models-behind-resources: Head-field writes bypass Resource

Findings and notifications outside the PR diff:

Source: front/lib/api/assistant/configuration/agent.ts:96

models-behind-resources in front/CONTRACTS requires runtime model access through Resources. This change extends the pre-existing direct AgentModel.create call with head-field initialization, leaving the new persistence logic owned by the business layer; move pending-agent persistence behind an AgentResource operation.

Comment thread front/lib/resources/agent_resource.ts Outdated
Comment thread front/lib/resources/agent_resource.ts Outdated
Comment thread front/lib/resources/agent_resource.ts Outdated
@sfriquet
sfriquet force-pushed the sf/feat-agent-head-fields branch from b5a58b9 to 6a80f07 Compare September 22, 2026 11:44
@zeropath-ai

zeropath-ai Bot commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

🟡 1 security issue detected below the blocking threshold. Reviewed everything up to d21ec7f.

The following issues were found:

  • Issue 1: Broken Access Control
    • Location: front/lib/api/assistant/configuration/agent.ts:713-736
    • Score: MEDIUM (52.0)
    • Description: Restoring an archived agent re-enables every trigger associated with it by constructing an Authenticator for each trigger editor and calling trigger.enable, without checking that the editor remains an authorized editor of the agent or that the restored agent is still restricted to an accessible space. A user who was removed from the agent's editor grants (or whose space access was revoked) can therefore have their trigger silently reactivated, allowing their external trigger to invoke a restored agent despite the current authorization state.

Evidence: After updated, the code lists all triggers, resolves each trigger.editor to a user, builds editorAuth solely from that user's identity/workspace at lines 731-734, and calls trigger.enable(editorAuth) at line 735. No auth.can(...), current editor/grant lookup, or space-membership check gates reactivation. The prior archive path disables all triggers, so this new restore behavior is the security-relevant reactivation sink.

Security Overview
Detected Code Changes
Change Type Relevant files
Enhancement ► front/lib/api/assistant/configuration/agent.ts
    Modify createPendingAgentConfiguration to set initial head fields (status, scope, reinforcement, templateId)
Enhancement ► front/lib/models/agent/agent.ts
    Add new fields to AgentModel: status, scope, reinforcement, lastReinforcementAnalysisAt, templateId
Enhancement ► front/lib/models/agent/agent.ts
    Define new fields in model initialization and indexes for head fields
Enhancement ► front/lib/models/agent/agent.ts
    Establish template relationship via foreign keys and ORM associations
Enhancement ► front/lib/resources/agent_resource.ts
    Introduce head fields handling and integration points for mirroring head fields
Enhancement ► front/lib/resources/agent_resource.ts
    Update setCurrentConfiguration to mirror head fields when changing current configuration
Enhancement ► front/lib/resources/agent_resource.ts
    Add internal updateAgent helper to update head fields and agent model atomically
Enhancement ► front/lib/resources/agent_resource.ts
    Adapt archive/restore paths to utilize updateAgent and mirror head fields
Enhancement ► front/lib/resources/agent_resource.ts
    Augment delete/activate flows to reflect head-field mirroring and status changes
Enhancement ► front/lib/resources/agent_resource.ts
    Modify scope updates to use updateAgent and invalidate cache accordingly
Enhancement ► front/migrations/pre-deploy/20260915211031_add_head_fields_to_agents.sql
    Add head fields to agents table and create related indexes/foreign key
Enhancement ► front/migrations/20260813_revert_sonnet46_to_auto_migration.test.ts
    Update seeding to initialize head fields on identity and align currentVersion logic
Enhancement ► front/tests/utils/AgentConfigurationFactory.ts
    Pass through templateId and reinforcement in factory overrides

Comment thread front/lib/api/assistant/configuration/agent.ts Outdated
@sfriquet
sfriquet force-pushed the sf/feat-agent-head-fields branch 2 times, most recently from f46fa38 to a8dabb3 Compare September 22, 2026 13:49
@github-actions

github-actions Bot commented Sep 22, 2026

Copy link
Copy Markdown
Contributor
Fails
🚫 Please include a detailed Deploy Plan section in your PR description, at least 20 characters long.
Warnings
⚠️

Files in **/lib/models/ have been modified and the PR has the migration-ack label. Don't forget to run the migration from prodbox.

Before deleting an index, make sure it is actually not used by running:

SELECT s.relname AS table_name,
       indexrelname AS index_name,
       i.indisunique,
       idx_scan AS index_scans
FROM   pg_catalog.pg_stat_user_indexes s,
       pg_index i
WHERE  i.indexrelid = s.indexrelid;

Generated by 🚫 dangerJS against d21ec7f

@sfriquet sfriquet added the migration-ack 📁 Label to acknowledge that a migration is required. label Sep 22, 2026
@sfriquet
sfriquet force-pushed the sf/feat-agent-head-fields branch 2 times, most recently from b02fc6f to 500fffb Compare September 22, 2026 15:36
@sfriquet sfriquet changed the title [front] Add agent head fields to agents [front] feat: add agent head fields to agents Sep 22, 2026
@sfriquet

Copy link
Copy Markdown
Contributor Author

r? @tdraier

@github-actions github-actions Bot 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.

cc-verify: violations found!

  • unreadable-agent-is-light: Light resources retain private fields
  • agent-publish-capability: Draft identities store visible scope
  • models-behind-resources: Direct model access (existing finding)

Comment thread front/lib/resources/agent_resource.ts Outdated
Comment thread front/lib/resources/agent_resource.ts Outdated
@@ -559,7 +563,6 @@ export async function destroyAgentConfigurationRow(

const remainingConfiguration = await AgentConfigurationModel.findOne({

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.

This extends a pre-existing models-behind-resources violation (front/CONTRACTS): removing the projection makes this business-layer query load the full configuration for the new head-field mirroring, keeping that persistence access outside Resources. Move the replacement-configuration lookup and repointing behind AgentResource.

updatedAt: new Date(content.updatedAt),
// The cached row is the current version, so its version is the agent's `currentVersion`.
currentVersion: content.version,
...NO_HEAD_FIELDS,

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.

why no field here ? they must be restored (and should be in the toSnapshot)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

it's not needed atm they are read from content

createdAt: new Date(),
updatedAt: new Date(),
currentVersion: configuration.version,
...NO_HEAD_FIELDS,

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.

not even a scope: global ?

);
}

private async updateAgent(

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.

maybe make it more clear we're updating the agent head fields ?

Comment thread front/lib/resources/agent_configuration_save.ts Outdated
@sfriquet
sfriquet force-pushed the sf/feat-agent-head-fields branch 2 times, most recently from 37a6edd to aff28e0 Compare September 22, 2026 15:56
…configuration

Adds `status`, `scope`, `reinforcement`, `lastReinforcementAnalysisAt`, `templateId` and
`requestedSpaceIds` to `agents`, nullable for now. They mirror the same columns of the
configuration row the agent points at:

- `AgentResource.createIdentity` writes them with the identity, and
  `setCurrentConfiguration` copies them whenever the pointer moves (create, upgrade,
  pending activation, rollback re-point).
- The in-place writers on a current configuration row (archive, restore, bulk scope
  change, requested-spaces propagation) also write the agent, in the same transaction,
  through `AgentResource.updateSettingsForCurrentConfigurations`.

An index on (workspaceId, status, scope) prepares listings that filter agents before
joining their configuration. Reads still come from `agent_configurations`; the backfill
and NOT NULL step follow.
@sfriquet
sfriquet force-pushed the sf/feat-agent-head-fields branch from aff28e0 to d21ec7f Compare September 22, 2026 16:30

This branch has not been deployed

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

Labels

migration-ack 📁 Label to acknowledge that a migration is required.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants