Skip to content

Fire a first-contact event after initial agent attach#692

Merged
lilyshen0722 merged 2 commits into
mainfrom
codex/686-agent-first-contact
Jul 19, 2026
Merged

Fire a first-contact event after initial agent attach#692
lilyshen0722 merged 2 commits into
mainfrom
codex/686-agent-first-contact

Conversation

@lilyshen0722

@lilyshen0722 lilyshen0722 commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Closes #686.

Summary

  • add an append-only AgentFirstContact marker with a unique (userId, agentName, instanceId) index, independent of replaceable AgentInstallation rows
  • atomically enqueue first_contact only for the first human-to-agent-identity relationship install; reinstall, concurrent install, second-pod install, and agent-to-agent install do not replay it
  • treat duplicate-key losers in a concurrent upsert race as the expected no-op instead of logging a false install error
  • deliver the exact inline first-impression cue through AgentEvent, with install remaining best-effort if marker/event work fails
  • teach both the native runtime and local CLI wrapper to consume first_contact as a model prompt; the OpenClaw and webhook poll paths are already type-generic
  • make existing integration tests select the event type they exercise now that a fresh install also queues first_contact

Identity semantics

  • First contact is once per durable agent identity: human userId + agentName + instanceId. Aria and Pixel each greet once even though both use the openclaw runtime.
  • Installing the same identity into another pod does not replay the greeting; uninstall/reinstall also remains silent because the marker outlives AgentInstallation.
  • The existing deterministic team-pod install intro is unchanged. A first attach in a team pod can therefore produce that system-authored intro plus the agent-authored first-contact greeting. I left this visible rather than silently changing the older flow in this PR.

Verification

  • focused correction set: 4/4 suites, 13/13 tests passed
  • backend full suite on the original head: 172/172 suites, 1,235/1,235 tests passed (Jest printed its known open-handle warning after the green summary; the idle container was then stopped)
  • affected integration suite: 23/23 passed
  • CLI full suite: 15/15 suites, 156 passed, 8 skipped
  • backend TypeScript check and production build passed after the identity-key correction
  • real Mongo probes after the correction:
    • 8 simultaneous calls for the same identity produced 1 marker and 1 event
    • Aria + Pixel for the same human produced 2 markers and 2 events
  • git diff --check passed
  • new JS test files pass ESLint when the repository's broken TS import-resolution rules are disabled

Known repository baseline: backend npm run lint currently reports 1,318 existing parser/import-resolution/style problems across the tree, and the CLI lint script has no eslint dependency/config. This PR does not attempt that unrelated lint migration.

@lilyshen0722
lilyshen0722 merged commit 4cec20e into main Jul 19, 2026
11 checks passed
@lilyshen0722
lilyshen0722 deleted the codex/686-agent-first-contact branch July 19, 2026 11:13
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.

First contact flips: the agent speaks first after attach

2 participants