agent.spec.ts 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. import { describe, expect, it, vi } from 'vitest'
  2. import { Context } from 'cordis'
  3. import { AgentId } from '@deepseek-ai/dsh-agent'
  4. import LlmService from '@deepseek-ai/dsh-llm'
  5. import SessionStore, { SessionId } from '@deepseek-ai/dsh-session'
  6. import SystemPrompt from '@deepseek-ai/dsh-system-prompt'
  7. import ToolRegistry from '@deepseek-ai/dsh-tools'
  8. import AgentRegistry from '@deepseek-ai/dsh-agent'
  9. import AgentLoop, { DEFAULT_MAX_PARALLEL_TOOL_CALLS, ReactLoopAgent } from '@deepseek-ai/dsh-agent-loop'
  10. import { bindReactLoopAgentContext, prepareReactLoopAgent } from '../src/agent.ts'
  11. import { MockAdapter, textResponse } from './mock-adapter.ts'
  12. async function harness(adapter: MockAdapter) {
  13. const ctx = new Context()
  14. await ctx.plugin(LlmService)
  15. await ctx.plugin(SessionStore)
  16. await ctx.plugin(SystemPrompt)
  17. await ctx.plugin(ToolRegistry)
  18. await ctx.plugin(AgentRegistry)
  19. await ctx.plugin(AgentLoop, { agents: [] })
  20. ctx.llm.registerAdapter(['mock'], adapter)
  21. return ctx
  22. }
  23. function waitForIdle(ctx: Context, agent: ReactLoopAgent): Promise<void> {
  24. return new Promise((resolve) => {
  25. const dispose = ctx.on('agent/status', (subject, status) => {
  26. if (subject === agent && status === 'idle') {
  27. dispose()
  28. resolve()
  29. }
  30. })
  31. })
  32. }
  33. function waitForStatus(ctx: Context, agent: ReactLoopAgent, expected: ReactLoopAgent['status']): Promise<void> {
  34. return new Promise((resolve) => {
  35. const dispose = ctx.on('agent/status', (subject, status) => {
  36. if (subject === agent && status === expected) {
  37. dispose()
  38. resolve()
  39. }
  40. })
  41. })
  42. }
  43. function send(agent: ReactLoopAgent, text: string) {
  44. agent.send([{ type: 'text', text }])
  45. }
  46. describe('ReactLoopAgent', () => {
  47. it('rejects access before context binding and a second driver for one session', async () => {
  48. const ctx = new Context()
  49. await ctx.plugin(SessionStore)
  50. const session = ctx.sessions.create(SessionId('exclusive-driver'))
  51. const prepared = prepareReactLoopAgent(
  52. ctx, AgentId('first-driver'), { provider: 'mock', model: 'mock' }, session, DEFAULT_MAX_PARALLEL_TOOL_CALLS,
  53. )
  54. expect(() => prepared.agent.ctx).toThrow('context is not bound')
  55. expect(() => prepareReactLoopAgent(
  56. ctx, AgentId('second-driver'), { provider: 'mock', model: 'mock' }, session, DEFAULT_MAX_PARALLEL_TOOL_CALLS,
  57. ))
  58. .toThrow('already has a concrete agent driver')
  59. await prepared.dispose()
  60. await ctx.fiber.dispose()
  61. })
  62. it('borrows caller options and binds its scoped context exactly once', async () => {
  63. const ctx = await harness(new MockAdapter([textResponse('unused')]))
  64. const options = { provider: 'mock', model: 'mock' }
  65. const agent = ctx.agentLoop.create(AgentId('owned-bindings'), options)
  66. expect(agent.options).toBe(options)
  67. expect(agent.id).toBe('owned-bindings')
  68. expect(agent.session.id).toMatch(/^owned-bindings-session-/)
  69. expect(() => { bindReactLoopAgentContext(agent, new Context()) }).toThrow(/context is already bound/)
  70. await ctx.fiber.dispose()
  71. })
  72. it('send() throws after disposal', async () => {
  73. const adapter = new MockAdapter(['hang'])
  74. const ctx = await harness(adapter)
  75. let agent!: ReactLoopAgent
  76. const fiber = await ctx.plugin(Object.assign((inner: Context) => {
  77. agent = inner.agentLoop.create(AgentId('scoped'), { provider: 'mock', model: 'mock' })
  78. }, { inject: ['agentLoop'] }))
  79. send(agent, 'go')
  80. await new Promise(r => setTimeout(r, 30))
  81. await fiber.dispose()
  82. await agent.done
  83. expect(() => { agent.send([{ type: 'text', text: 'too late' }]) }).toThrow('disposed')
  84. })
  85. it('steer() throws after disposal', async () => {
  86. const adapter = new MockAdapter(['hang'])
  87. const ctx = await harness(adapter)
  88. let agent!: ReactLoopAgent
  89. const fiber = await ctx.plugin(Object.assign((inner: Context) => {
  90. agent = inner.agentLoop.create(AgentId('scoped'), { provider: 'mock', model: 'mock' })
  91. }, { inject: ['agentLoop'] }))
  92. send(agent, 'go')
  93. await new Promise(r => setTimeout(r, 30))
  94. await fiber.dispose()
  95. await agent.done
  96. expect(() => { agent.steer([{ type: 'text', text: 'too late' }]) }).toThrow('disposed')
  97. })
  98. it('inject() throws after disposal', async () => {
  99. const adapter = new MockAdapter(['hang'])
  100. const ctx = await harness(adapter)
  101. let agent!: ReactLoopAgent
  102. const fiber = await ctx.plugin(Object.assign((inner: Context) => {
  103. agent = inner.agentLoop.create(AgentId('scoped'), { provider: 'mock', model: 'mock' })
  104. }, { inject: ['agentLoop'] }))
  105. send(agent, 'go')
  106. await new Promise(r => setTimeout(r, 30))
  107. await fiber.dispose()
  108. await agent.done
  109. expect(() => { agent.inject([{ type: 'text', text: 'too late' }]) }).toThrow('disposed')
  110. })
  111. it('inject() decides enclosure from the LOG (open turn), not agent status', async () => {
  112. const adapter = new MockAdapter([textResponse('ok')])
  113. const ctx = await harness(adapter)
  114. const agent = ctx.agentLoop.create(AgentId('a1'), { provider: 'mock', model: 'mock' })
  115. // Simulate an OPEN turn in the log while the agent is idle (status is not a
  116. // reliable open-turn signal). inject must append into that open turn, NOT
  117. // wrap a new one.
  118. agent.session.append('turn/start', { turn: 1, trigger: { kind: 'message', source: { kind: 'user' } } })
  119. agent.inject([{ type: 'text', text: 'mid' }], { source: { kind: 'plugin', plugin: 'p' } })
  120. expect(agent.session.events.filter(e => e.type === 'turn/start')).toHaveLength(1)
  121. expect(agent.session.events.at(-1)!.type).toBe('context/message')
  122. // Close the turn; now inject must wrap its own one-shot injection turn.
  123. agent.session.append('turn/end', { turn: 1, reason: { kind: 'completed' } })
  124. agent.inject([{ type: 'text', text: 'after' }], { source: { kind: 'plugin', plugin: 'p' } })
  125. const starts = agent.session.events.filter(e => e.type === 'turn/start')
  126. expect(starts).toHaveLength(2)
  127. const last = starts[1]!
  128. expect(last.type === 'turn/start' && last.data.trigger.kind).toBe('injection')
  129. expect(agent.session.events.at(-1)!.type).toBe('turn/end') // turn-enclosed
  130. })
  131. it('idle inject() contains a failing flush (logs, does not throw into the caller)', async () => {
  132. const adapter = new MockAdapter([textResponse('ok')])
  133. const ctx = await harness(adapter)
  134. // A persistence-like listener whose flush rejects.
  135. ctx.on('session/flush', () => { throw new Error('disk gone') })
  136. const warn = vi.spyOn(ctx.logger, 'warn').mockImplementation(() => undefined)
  137. const agent = ctx.agentLoop.create(AgentId('a1'), { provider: 'mock', model: 'mock' })
  138. // inject() is synchronous and fires a fire-and-forget flush; a rejecting
  139. // flush must be contained (logged), never thrown into the caller.
  140. expect(() => { agent.inject([{ type: 'text', text: 'notice' }], { source: { kind: 'plugin', plugin: 'p' } }) }).not.toThrow()
  141. await new Promise(r => setTimeout(r, 20)) // let the contained flush settle
  142. expect(warn).toHaveBeenCalledWith(expect.stringContaining('flush after idle injection failed'))
  143. warn.mockRestore()
  144. })
  145. it('idle inject() closes its one-shot turn AND still checkpoints even if the append throws', async () => {
  146. const adapter = new MockAdapter([textResponse('ok')])
  147. const ctx = await harness(adapter)
  148. const agent = ctx.agentLoop.create(AgentId('a1'), { provider: 'mock', model: 'mock' })
  149. let flushes = 0
  150. ctx.on('session/flush', () => { flushes += 1 })
  151. // Invalid injected content throws after turn/start. `finally` must still append turn/end and
  152. // flush the balanced in-memory turn so a crash cannot lose it before the next checkpoint.
  153. expect(() => {
  154. agent.inject([{ type: 'text', text: 'x', bad: 1n } as never], { source: { kind: 'plugin', plugin: 'p' } })
  155. }).toThrow(/non-JSON-serializable/)
  156. const types = agent.session.events.map(e => e.type)
  157. expect(types).toEqual(['turn/start', 'turn/end']) // balanced, no open turn
  158. await new Promise(r => setTimeout(r, 10)) // let the fire-and-forget flush run
  159. expect(flushes).toBe(1) // checkpoint fired despite the throw
  160. })
  161. it('idle inject() still checkpoints when a listener throws on the synthetic turn/end', async () => {
  162. const adapter = new MockAdapter([textResponse('ok')])
  163. const ctx = await harness(adapter)
  164. const agent = ctx.agentLoop.create(AgentId('a1'), { provider: 'mock', model: 'mock' })
  165. let flushes = 0
  166. ctx.on('session/flush', () => { flushes += 1 })
  167. // Session contains a throwing post-commit turn/end observer. The accepted
  168. // boundary still triggers the idle injection's durability checkpoint.
  169. let threw = false
  170. ctx.on('session/event', (_s, event) => {
  171. if (!threw && event.type === 'turn/end') { threw = true; throw new Error('boom turn/end') }
  172. })
  173. expect(() => { agent.inject([{ type: 'text', text: 'notice' }], { source: { kind: 'plugin', plugin: 'p' } }) }).not.toThrow()
  174. const types = agent.session.events.map(e => e.type)
  175. expect(types).toEqual(['turn/start', 'context/message', 'turn/end']) // balanced
  176. await new Promise(r => setTimeout(r, 10))
  177. expect(flushes).toBe(1) // checkpoint fired despite the throwing turn/end listener
  178. })
  179. it('idle inject() reports a failing flush via agent/error (step 0) AND the logger', async () => {
  180. const adapter = new MockAdapter([textResponse('ok')])
  181. const ctx = await harness(adapter)
  182. // A non-Error rejection exercises the String() normalization branch.
  183. ctx.on('session/flush', () => { throw 'disk gone' })
  184. const warn = vi.spyOn(ctx.logger, 'warn').mockImplementation(() => undefined)
  185. const agent = ctx.agentLoop.create(AgentId('a1'), { provider: 'mock', model: 'mock' })
  186. const errors: { turn: number; step: number; message: string }[] = []
  187. ctx.on('agent/error', (_a, turn, step, error) => void errors.push({ turn, step, message: error.message }))
  188. agent.inject([{ type: 'text', text: 'notice' }], { source: { kind: 'plugin', plugin: 'p' } })
  189. await new Promise(r => setTimeout(r, 20)) // let the contained flush settle
  190. // Reported via agent/error (step 0 — the idle-injection convention) so
  191. // plugins monitoring agent/error see idle-injection persistence failures,
  192. // mirroring the loop's post-turn/end flush path. A non-Error throw is
  193. // normalized to an Error.
  194. expect(errors).toEqual([{ turn: 1, step: 0, message: 'disk gone' }])
  195. expect(warn).toHaveBeenCalledWith(expect.stringContaining('flush after idle injection failed'))
  196. warn.mockRestore()
  197. })
  198. it('idle inject() with a non-serializable source opens no turn (nothing to close)', async () => {
  199. const adapter = new MockAdapter([textResponse('ok')])
  200. const ctx = await harness(adapter)
  201. const agent = ctx.agentLoop.create(AgentId('a1'), { provider: 'mock', model: 'mock' })
  202. // A non-serializable source makes the turn/start append throw BEFORE the
  203. // event is pushed (Session.append validates before push), so NO turn opens.
  204. // The finally's isTurnOpen() guard sees no open turn and appends nothing —
  205. // the log stays empty, not left with a dangling turn/start.
  206. expect(() => {
  207. agent.inject([{ type: 'text', text: 'x' }], { source: { kind: 'plugin', plugin: 'p', bad: 1n } as never })
  208. }).toThrow(/non-JSON-serializable/)
  209. expect(agent.session.events).toHaveLength(0)
  210. })
  211. it('steer() when idle falls through to send() and starts a turn', async () => {
  212. const adapter = new MockAdapter([textResponse('ok')])
  213. const ctx = await harness(adapter)
  214. const agent = ctx.agentLoop.create(AgentId('a1'), { provider: 'mock', model: 'mock' })
  215. // steer while idle delegates to send
  216. agent.steer([{ type: 'text', text: 'steer idle' }], { source: { kind: 'plugin', plugin: 'test' } })
  217. await waitForIdle(ctx, agent)
  218. // The message was recorded as a user-level message (send path)
  219. expect(agent.session.events.some(e => e.type === 'user/message')).toBe(true)
  220. expect(adapter.requests).toHaveLength(1)
  221. })
  222. it('disposer is idempotent (double-stop)', async () => {
  223. // The internal start seam exposes one idle driver's disposer for repeated invocation.
  224. const ctx = new Context()
  225. await ctx.plugin(SessionStore)
  226. const session = ctx.sessions.create(SessionId('test'))
  227. const prepared = prepareReactLoopAgent(
  228. ctx, AgentId('bare'), { provider: 'mock', model: 'mock' }, session, DEFAULT_MAX_PARALLEL_TOOL_CALLS,
  229. )
  230. const { agent } = prepared
  231. prepared.markPublished()
  232. const dispose = prepared.startDriver()
  233. const firstDisposal = dispose()
  234. expect(agent.status).toBe('disposed')
  235. await firstDisposal
  236. await expect(dispose()).resolves.toBeUndefined()
  237. expect(agent.status).toBe('disposed')
  238. })
  239. it('a pre-start disposal makes a later driver-start attempt inert', async () => {
  240. const ctx = new Context()
  241. await ctx.plugin(SessionStore)
  242. const session = ctx.sessions.create(SessionId('pre-start-dispose'))
  243. const prepared = prepareReactLoopAgent(
  244. ctx, AgentId('pre-start-dispose'), { provider: 'mock', model: 'mock' }, session, DEFAULT_MAX_PARALLEL_TOOL_CALLS,
  245. )
  246. await prepared.dispose()
  247. expect(prepared.agent.status).toBe('disposed')
  248. const dispose = prepared.startDriver()
  249. await dispose()
  250. await expect(prepared.agent.done).resolves.toBeUndefined()
  251. expect(prepared.agent.session.events).toEqual([])
  252. await ctx.fiber.dispose()
  253. })
  254. it('setting the same status does not emit agent/status again', async () => {
  255. const adapter = new MockAdapter([textResponse('ok')])
  256. const ctx = await harness(adapter)
  257. const agent = ctx.agentLoop.create(AgentId('a1'), { provider: 'mock', model: 'mock' })
  258. const statuses: string[] = []
  259. ctx.on('agent/status', (subject, status) => {
  260. if (subject === agent) statuses.push(status)
  261. })
  262. send(agent, 'hi')
  263. await waitForIdle(ctx, agent)
  264. // After the turn, agent is idle. Send again to trigger another attempt
  265. // to go idle — but it's already idle, so no emission.
  266. const idleTransitionCount = statuses.filter(s => s === 'idle').length
  267. expect(idleTransitionCount).toBe(1) // only the final transition from running
  268. })
  269. it('whenIdle() resolves immediately when the agent is not running', async () => {
  270. const adapter = new MockAdapter([textResponse('ok')])
  271. const ctx = await harness(adapter)
  272. const agent = ctx.agentLoop.create(AgentId('a1'), { provider: 'mock', model: 'mock' })
  273. // Fresh agent is idle — whenIdle() takes the not-running fast path and
  274. // resolves without subscribing. await must not hang.
  275. await agent.whenIdle()
  276. expect(agent.status).not.toBe('running')
  277. })
  278. it('whenIdle() waits for queued work that has not flipped status yet', async () => {
  279. const adapter = new MockAdapter(['hang'])
  280. const ctx = await harness(adapter)
  281. const agent = ctx.agentLoop.create(AgentId('a1'), { provider: 'mock', model: 'mock' })
  282. send(agent, 'queued')
  283. let settled = false
  284. const idle = agent.whenIdle().then(() => { settled = true })
  285. await Promise.resolve()
  286. expect(settled).toBe(false)
  287. await waitForStatus(ctx, agent, 'running')
  288. agent.cancel('done')
  289. await idle
  290. expect(settled).toBe(true)
  291. expect(agent.status).toBe('idle')
  292. })
  293. it('whenIdle() awaits the running→idle transition, ignoring other subjects/running events', async () => {
  294. const adapter = new MockAdapter([textResponse('ok'), textResponse('ok')])
  295. const ctx = await harness(adapter)
  296. const agent = ctx.agentLoop.create(AgentId('a1'), { provider: 'mock', model: 'mock' })
  297. const other = ctx.agentLoop.create(AgentId('a2'), { provider: 'mock', model: 'mock' })
  298. // Drive `agent` into `running`, then await whenIdle() — it subscribes to
  299. // agent/status and resolves on the first transition out of running.
  300. const running = new Promise<void>((resolve) => {
  301. const dispose = ctx.on('agent/status', (subject, status) => {
  302. if (subject === agent && status === 'running') { dispose(); resolve() }
  303. })
  304. })
  305. send(agent, 'go')
  306. await running
  307. expect(agent.status).toBe('running')
  308. // While `agent`'s whenIdle is pending, churn `other` through running→idle:
  309. // every status event it emits hits whenIdle's guard with `subject !== this`,
  310. // so the wait must ignore them and only resolve on `agent`'s own idle.
  311. send(other, 'go')
  312. await agent.whenIdle()
  313. expect(agent.status).toBe('idle')
  314. })
  315. it('whenIdle() subscribed while running resolves via done when the agent is then disposed', async () => {
  316. // Queue the internal waiter while running, then dispose the bare driver. Its disposed branch
  317. // must chain the loop's `done` promise rather than resolve before exit.
  318. const ctx = new Context()
  319. await ctx.plugin(LlmService)
  320. await ctx.plugin(SessionStore)
  321. await ctx.plugin(SystemPrompt)
  322. await ctx.plugin(ToolRegistry)
  323. await ctx.plugin(AgentRegistry)
  324. const adapter = new MockAdapter(['hang'])
  325. ctx.llm.registerAdapter(['mock'], adapter)
  326. const session = ctx.sessions.create(SessionId('bare'))
  327. const prepared = prepareReactLoopAgent(
  328. ctx, AgentId('bare'), { provider: 'mock', model: 'mock' }, session, DEFAULT_MAX_PARALLEL_TOOL_CALLS,
  329. )
  330. const { agent } = prepared
  331. prepared.markPublished()
  332. const dispose = prepared.startDriver()
  333. agent.send([{ type: 'text', text: 'go' }])
  334. await new Promise(r => setTimeout(r, 30))
  335. expect(agent.status).toBe('running')
  336. const idle = agent.whenIdle() // queues an internal waiter (running)
  337. const disposal = dispose() // settles the waiter synchronously; whenIdle chains done
  338. await idle
  339. expect(agent.status).toBe('disposed')
  340. await disposal
  341. })
  342. it('whenIdle() subscribed while running survives a FIBER dispose (no hung promise)', async () => {
  343. // The waiter is agent-owned state, not an effect-scoped listener that owner disposal would
  344. // remove before the disposed transition. Fiber teardown must still settle it.
  345. const adapter = new MockAdapter(['hang'])
  346. const ctx = await harness(adapter)
  347. let agent!: ReactLoopAgent
  348. const fiber = await ctx.plugin(Object.assign((inner: Context) => {
  349. agent = inner.agentLoop.create(AgentId('scoped'), { provider: 'mock', model: 'mock' })
  350. }, { inject: ['agentLoop'] }))
  351. send(agent, 'go')
  352. await new Promise(r => setTimeout(r, 30))
  353. expect(agent.status).toBe('running')
  354. const idle = agent.whenIdle() // queued while running
  355. await fiber.dispose() // tears the fiber down (drops agent listeners)
  356. await idle // must resolve, not hang
  357. expect(agent.status).toBe('disposed')
  358. })
  359. it('whenIdle() on a disposed agent awaits the loop exit (done), not just the status flip', async () => {
  360. // Disposed status is emitted before the driver unwinds. `whenIdle()` must chain `done` so it
  361. // resolves only after true loop exit.
  362. const adapter = new MockAdapter(['hang'])
  363. const ctx = await harness(adapter)
  364. let agent!: ReactLoopAgent
  365. const fiber = await ctx.plugin(Object.assign((inner: Context) => {
  366. agent = inner.agentLoop.create(AgentId('scoped'), { provider: 'mock', model: 'mock' })
  367. }, { inject: ['agentLoop'] }))
  368. send(agent, 'go')
  369. await new Promise(r => setTimeout(r, 30))
  370. let doneResolved = false
  371. void agent.done.then(() => { doneResolved = true })
  372. await fiber.dispose() // sets status disposed, aborts, drains the loop
  373. expect(agent.status).toBe('disposed')
  374. // whenIdle() must not resolve before `done` has — chaining `done` is the
  375. // quiescence guarantee. By here dispose() awaited the loop, so done is
  376. // settled; whenIdle resolves and done is observed resolved.
  377. await agent.whenIdle()
  378. expect(doneResolved).toBe(true)
  379. })
  380. it('contains a throwing agent/status listener on the running transition', async () => {
  381. const adapter = new MockAdapter([textResponse('ok')])
  382. const ctx = await harness(adapter)
  383. const warn = vi.spyOn(ctx.logger, 'warn').mockImplementation(() => undefined)
  384. const agent = ctx.agentLoop.create(AgentId('a1'), { provider: 'mock', model: 'mock' })
  385. ctx.on('agent/status', (_subject, status) => {
  386. if (status === 'running') throw new Error('bad running listener')
  387. })
  388. send(agent, 'go')
  389. await agent.whenIdle()
  390. expect(adapter.requests).toHaveLength(1)
  391. expect(agent.status).toBe('idle')
  392. expect(warn).toHaveBeenCalledWith(expect.stringContaining('agent event "agent/status" listener threw'))
  393. warn.mockRestore()
  394. })
  395. it('contains a throwing agent/status listener on the idle transition', async () => {
  396. const adapter = new MockAdapter([textResponse('ok')])
  397. const ctx = await harness(adapter)
  398. const warn = vi.spyOn(ctx.logger, 'warn').mockImplementation(() => undefined)
  399. const agent = ctx.agentLoop.create(AgentId('a1'), { provider: 'mock', model: 'mock' })
  400. ctx.on('agent/status', (_subject, status) => {
  401. if (status === 'idle') throw new Error('bad idle listener')
  402. })
  403. send(agent, 'go')
  404. await agent.whenIdle()
  405. expect(adapter.requests).toHaveLength(1)
  406. expect(agent.status).toBe('idle')
  407. expect(warn).toHaveBeenCalledWith(expect.stringContaining('agent event "agent/status" listener threw'))
  408. warn.mockRestore()
  409. })
  410. })