Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(daemon,cli): One handle for every agent #2184

Merged
merged 3 commits into from
Apr 9, 2024

Conversation

kriskowal
Copy link
Member

Toward sending messages between mailboxes in separate nodes, this change gives every agent (both hosts and guests) a powerless handle that can be used to mention the agent without leaking agency.

This is somewhat tricky because this is the first cycle in the formula graph. The agent contains a handle and the handle identifier and formula are just ways of referring to the facet held by the agent. So, writing an agent formula generates a handle formula as a side-effect and populates the agent id for handle table.

This also means that mkguest and mkhost need to designate the handle (so that messages from the other agent are visible) and might optionally also designate a pet name for the agent.

@kriskowal kriskowal requested a review from rekmarks March 26, 2024 06:50
@kriskowal kriskowal force-pushed the kriskowal-daemon-agent-handle-correspondence branch from 9526387 to 90943df Compare March 26, 2024 06:58
Comment on lines -878 to -894
let currentId = id;
// eslint-disable-next-line no-constant-condition
while (true) {
const controller = provideController(currentId);
// eslint-disable-next-line no-await-in-loop
const internalFacet = await controller.internal;
if (internalFacet === undefined || internalFacet === null) {
return controller;
}
// @ts-expect-error We can't know the type of the internal facet.
if (internalFacet.targetId === undefined) {
return controller;
}
const handle = /** @type {import('./types.js').InternalHandle} */ (
internalFacet
);
currentId = handle.targetId;
Copy link
Member Author

Choose a reason for hiding this comment

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

cha-ching

@kriskowal kriskowal force-pushed the kriskowal-daemon-agent-handle-correspondence branch 3 times, most recently from a37bb43 to 25c404e Compare March 27, 2024 21:23
@kriskowal kriskowal force-pushed the kriskowal-daemon-agent-handle-correspondence branch 2 times, most recently from 2d604a1 to 72b7922 Compare March 27, 2024 22:58
Copy link
Contributor

@rekmarks rekmarks left a comment

Choose a reason for hiding this comment

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

I have some optional suggestions in here, but the familiar chat example is broken on this branch. No names are listed, the console is full of errors, and mailbox requests do not appear. Also, the instructions in cli/demo/README.md are not update (see e.g. endo mkguest).

Comment on lines +729 to +730
handleId: string;
guestId: string;
Copy link
Contributor

Choose a reason for hiding this comment

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

For consistency with hostAgentId and hostHandleId in the same interface:

Suggested change
handleId: string;
guestId: string;
guestHandleId: string;
guestAgentId: string;

Would also accept agentId / handleId.

Copy link
Member Author

Choose a reason for hiding this comment

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

I would like to keep these as present, or instead ownHandleId and ownAgentId. The role of handleId and agentId is the same between Host and Guest so I would like to use the same names. Whereas a guest has a host, but a host does not. (I would imagine adding PARENT for hosts created by other hosts. If we explored that path, we’d have to consider how to accommodate the specialness of the root host. We could borrow the /.. == / trick from *ix file systems.)

Copy link
Contributor

Choose a reason for hiding this comment

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

That makes sense. I'd prefer the more explicit ownHandleId / ownAgentId in that case, but I leave it up to you.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure. I will circle back for this.

Comment on lines +745 to +746
hostId: string;
handleId: string;
Copy link
Contributor

Choose a reason for hiding this comment

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

See comment on FormulateNumberedGuestParams above.

packages/daemon/src/daemon.js Show resolved Hide resolved
@kriskowal kriskowal force-pushed the kriskowal-daemon-agent-handle-correspondence branch from 72b7922 to d08debf Compare April 2, 2024 19:06
@kriskowal kriskowal requested a review from rekmarks April 2, 2024 19:06
@kriskowal
Copy link
Member Author

@rekmarks This is ready for another review. I’ve appended a fixup commit with the necessary changes to the demo script to get it on the right path again.

@kriskowal kriskowal force-pushed the kriskowal-daemon-agent-handle-correspondence branch from d08debf to 53cc062 Compare April 2, 2024 20:06
Copy link
Contributor

@rekmarks rekmarks left a comment

Choose a reason for hiding this comment

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

LGTM. The remaining optional suggestion left as an exercise to the author.

@kriskowal kriskowal force-pushed the kriskowal-daemon-agent-handle-correspondence branch from 53cc062 to 5ed0d66 Compare April 9, 2024 13:58
@kriskowal kriskowal enabled auto-merge April 9, 2024 13:58
@kriskowal kriskowal merged commit 983900d into master Apr 9, 2024
18 checks passed
@kriskowal kriskowal deleted the kriskowal-daemon-agent-handle-correspondence branch April 9, 2024 14:05
kriskowal added a commit that referenced this pull request Apr 11, 2024
Toward delivering mail over the network, this change introduces a
`deliver` method on guest and host agents that accepts arbitrary
messages into the agent’s inbox. Any other agent can send mail to any
other local agent for whom they have a handle and cannot spoof their
sender handle.

This is a net simplification, since it reduces our dependence on the
internal facet of agents and requires less machinery because it treats
messages as capabilities on the wire, freely exposing and carrying
identifiers. We no longer have separate internal and external
representations of messages and pet name “dubbing” is deferred to the
UI. This in turn enables us to defer to the UI the question of whether
to query the name for each identifier once or watch for changes.

Stacked on #2184
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.

2 participants