refactor: remove agent entry mirror
This commit is contained in:
@@ -202,9 +202,6 @@ interface FactorySlot {
|
|||||||
*/
|
*/
|
||||||
export class AgentRegistry extends Service {
|
export class AgentRegistry extends Service {
|
||||||
private store = new Map<AgentId, AgentEntry>()
|
private store = new Map<AgentId, AgentEntry>()
|
||||||
// TODO(agent-entry-mirror): derive exact-object checks from store.get(agent.id)
|
|
||||||
// plus entry.agent identity; this WeakMap mirrors the authoritative id map.
|
|
||||||
private entries = new WeakMap<Agent, AgentEntry>()
|
|
||||||
private factory: FactorySlot | undefined
|
private factory: FactorySlot | undefined
|
||||||
|
|
||||||
constructor(ctx: Context) {
|
constructor(ctx: Context) {
|
||||||
@@ -334,7 +331,7 @@ export class AgentRegistry extends Service {
|
|||||||
const carrier = scopeTarget(agent, agent)
|
const carrier = scopeTarget(agent, agent)
|
||||||
// This is the authoritative collision boundary. Concurrent create/resume
|
// This is the authoritative collision boundary. Concurrent create/resume
|
||||||
// operations may both prepare, but only one exact entry can publish.
|
// operations may both prepare, but only one exact entry can publish.
|
||||||
if (this.entries.has(agent) || this.store.has(id)) throw new Error(`agent "${id}" is already registered`)
|
if (this.store.has(id)) throw new Error(`agent "${id}" is already registered`)
|
||||||
const entry: AgentEntry = {
|
const entry: AgentEntry = {
|
||||||
id,
|
id,
|
||||||
agent,
|
agent,
|
||||||
@@ -344,7 +341,6 @@ export class AgentRegistry extends Service {
|
|||||||
detachRequested: false,
|
detachRequested: false,
|
||||||
}
|
}
|
||||||
this.store.set(id, entry)
|
this.store.set(id, entry)
|
||||||
this.entries.set(agent, entry)
|
|
||||||
let entered = true
|
let entered = true
|
||||||
const detach = (): void => {
|
const detach = (): void => {
|
||||||
if (!entered) return
|
if (!entered) return
|
||||||
@@ -371,7 +367,6 @@ export class AgentRegistry extends Service {
|
|||||||
/* v8 ignore next -- enter() rejects replacement while this single-shot detach capability is live. */
|
/* v8 ignore next -- enter() rejects replacement while this single-shot detach capability is live. */
|
||||||
if (this.store.get(entry.id) !== entry) return
|
if (this.store.get(entry.id) !== entry) return
|
||||||
this.store.delete(entry.id)
|
this.store.delete(entry.id)
|
||||||
this.entries.delete(entry.agent)
|
|
||||||
// An insertion rolled back before announce was never externally created,
|
// An insertion rolled back before announce was never externally created,
|
||||||
// so emitting disposed would invent an impossible lifecycle edge. Marking
|
// so emitting disposed would invent an impossible lifecycle edge. Marking
|
||||||
// happens before the created emit: if a later created listener throws,
|
// happens before the created emit: if a later created listener throws,
|
||||||
@@ -403,8 +398,8 @@ export class AgentRegistry extends Service {
|
|||||||
* creation listener).
|
* creation listener).
|
||||||
*/
|
*/
|
||||||
announce(agent: Agent): void {
|
announce(agent: Agent): void {
|
||||||
const entry = this.entries.get(agent)
|
const entry = this.store.get(agent.id)
|
||||||
if (entry === undefined || this.store.get(entry.id) !== entry) {
|
if (entry === undefined || entry.agent !== agent) {
|
||||||
throw new Error(`agent "${agent.id}" is not live in this registry`)
|
throw new Error(`agent "${agent.id}" is not live in this registry`)
|
||||||
}
|
}
|
||||||
if (entry.announced || entry.announcing) {
|
if (entry.announced || entry.announcing) {
|
||||||
|
|||||||
Reference in New Issue
Block a user