Skip to content

feat(daemon): export squad and initiator identity to the task environment - #9008

Open
ggbdpq wants to merge 1 commit into
multica-ai:mainfrom
ggbdpq:fix/squad-initiator-env
Open

ggbdpq wants to merge 1 commit into
multica-ai:mainfrom
ggbdpq:fix/squad-initiator-env

Conversation

@ggbdpq

@ggbdpq ggbdpq commented Oct 1, 2026

Copy link
Copy Markdown

What does this PR do?

Export the squad and initiator identity that the claim payload already carries into the daemon-owned task environment, so tools inside a task (git hooks, MCP gateways) can record who a run is for without an extra API round-trip.

taskMulticaEnvironment (server/internal/daemon/daemon.go) now sets, only when the claim carries a value:

Variable Source
MULTICA_SQUAD_ID Task.SquadID
MULTICA_SQUAD_NAME Task.SquadName
MULTICA_INITIATOR_ID Task.InitiatorID
MULTICA_INITIATOR_NAME Task.InitiatorName
MULTICA_INITIATOR_EMAIL Task.InitiatorEmail

Thinking path

The daemon already injects MULTICA_AGENT_ID / MULTICA_TASK_ID / MULTICA_AGENT_NAME, but a task that wants its squad or initiator must call GET /api/agents/{id}/tasks with its own token and find its own row — an extra startup round-trip coupled to an endpoint shape. The claim payload already holds all five fields, so the daemon is one mapping away.

Unset-vs-empty matters: an autopilot run has no initiator and a direct member task has no squad, and consumers (commit authorship, On-behalf-of trailers, audit logs, ${MULTICA_SQUAD_NAME:-} in MCP headers) need to tell that apart from an empty value. So each variable is set only when the claim value is non-empty. Ownership needs no new mechanism: isBlockedEnvKey already drops every MULTICA_ key from agent custom_env, and a test asserts the new IDs survive a forging custom_env.

Delegated member tasks still export whatever the claim carries — squad_id is only set when a squad was the picker. Filling squad_id/squad_name server-side for delegated tasks (the delegated_from_task_id walk) is a separate server-side change the daemon needs no knowledge of.

Docs: the task-environment table in daemon-runtimes.mdx gains the five rows (IDs under Integration contract, display names and email under Informational, mirroring the existing agent ID/name split), synced to the zh/ja/ko/fr locales.

Related Issue

Closes #9002

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Refactor / code improvement (no behavior change)
  • Documentation update
  • Tests (adding or improving test coverage)
  • CI / infrastructure

Changes Made

  • server/internal/daemon/daemon.go: taskMulticaEnvironment maps the five squad/initiator claim fields into the task env, each only when non-empty.
  • server/internal/daemon/daemon_test.go: TestTaskMulticaEnvironmentExportsSquadAndInitiator (red before the fix; also asserts custom_env cannot override the new IDs) and TestTaskMulticaEnvironmentOmitsAbsentSquadAndInitiator (locks the unset contract).
  • apps/docs/content/docs/daemon-runtimes{,.zh,.ja,.ko,.fr}.mdx: five new rows in the task-environment table.

How to Test

  1. go test -p 2 -run TestTaskMulticaEnvironment ./internal/daemon/ — all three task-env tests pass; the exports test fails on the parent commit.
  2. go test -p 2 -run 'TestIsBlockedEnvKey|TestLayerCustomEnv|TestConfigureCodexTaskShellEnvironment|TestCodexShellAuthorizedCustomEnvNamesUsesDaemonBlocklist|TestTaskScopedAuthToken' ./internal/daemon/ — env-adjacent groups stay green.
  3. go build ./internal/daemon/ ./internal/cli/.

All of the above ran locally on Windows (the touched tests are pure unit tests, no database). The internal/daemon package has pre-existing Windows-only failures elsewhere in the package, unchanged by this diff; CI is the authority for those. gofmt checked clean on both Go files via a CRLF-stripped probe (Windows checkout).

Checklist

  • I have included a thinking path that traces from project context to this change
  • I have run tests locally and they pass
  • I have added or updated tests where applicable
  • If this change affects the UI, I have included before/after screenshots
  • I have updated relevant documentation to reflect my changes
  • If I added a new runtime / coding tool / UI tab, I synced the change to landing copy (apps/web/features/landing/i18n/) and relevant docs (apps/docs/content/docs/)
  • If this PR touches Chinese product copy, I checked it against apps/docs/content/docs/developers/conventions.zh.mdx (terminology, mixed-rule for task / issue / skill)
  • I have considered and documented any risks above
  • I will address all reviewer comments before requesting merge

AI Disclosure

AI tool used: GLM-5.3-Flash (ZCode)

Prompt / approach: Verified the issue's code pointers against the current tip first, wrote the failing tests before the implementation, then kept the mapping minimal and mirrored the docs across the four locales. Commit carries the Generated-by: GLM-5.3-Flash (ZCode) trailer.

…ment

taskMulticaEnvironment now maps five claim fields into the daemon-owned
task env: MULTICA_SQUAD_ID / MULTICA_SQUAD_NAME / MULTICA_INITIATOR_ID /
MULTICA_INITIATOR_NAME / MULTICA_INITIATOR_EMAIL. Each is set only when
the claim carries a value, so "no squad or initiator" (autopilot runs,
direct member tasks) stays distinguishable from empty. They are
daemon-owned like the rest of the MULTICA_ namespace: isBlockedEnvKey
already drops any such key from agent custom_env.

Tools inside a task (git hooks, MCP gateways) can now record who a run
is for — commit authorship, On-behalf-of trailers, audit logs — without
an extra GET /api/agents/{id}/tasks round-trip at startup. Delegated
member tasks still export whatever the claim carries; filling
squad_id/squad_name server-side for delegated tasks is a separate,
server-side change.

Fixes multica-ai#9002

Generated-by: GLM-5.3-Flash (ZCode)
@vercel

vercel Bot commented Oct 1, 2026

Copy link
Copy Markdown

@ggbdpq is attempting to deploy a commit to the IndexLabs Team on Vercel.

A member of the Team first needs to authorize it.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Export squad and initiator to the task environment (MULTICA_SQUAD_*, MULTICA_INITIATOR_*)

1 participant