{"record":{"id":"44be9e60986db595","repo":"deepseek-ai/deepseek-harness","slug":"foreign-session","errorCode":"FOREIGN_SESSION","errorMessage":"PTY session ${id} belongs to another agent","messagePattern":"PTY session (.+?) belongs to another agent","errorType":"exception","errorClass":"TerminalError","httpStatus":null,"severity":"error","filePath":"packages/terminal/terminal/src/index.ts","lineNumber":390,"sourceCode":"  }\n\n  private async abortPendingSpawns(owner: Agent | undefined, reason: TerminalError): Promise<void> {\n    const pending = owner === undefined\n      ? [...this.pendingSpawns.values()].flatMap(owned => [...owned])\n      : [...(this.pendingSpawns.get(owner) ?? [])]\n    for (const spawn of pending) spawn.controller.abort(reason)\n    await Promise.all(pending.map(spawn => spawn.settled))\n    const failures = pending.flatMap(spawn => spawn.cleanupFailure === undefined ? [] : [spawn.cleanupFailure.error])\n    for (const spawn of pending) this.removePendingSpawn(spawn)\n    if (failures.length > 0) {\n      throw new AggregateError(failures, 'failed to roll back unpublished PTY setup')\n    }\n  }\n\n  private expectOwned(owner: Agent, id: TerminalSessionId): SessionRecord {\n    const record = this.sessions.get(id)\n    if (record === undefined) throw new TerminalError(`unknown PTY session ${id}`, 'NO_SESSION')\n    if (record.owner !== owner) throw new TerminalError(`PTY session ${id} belongs to another agent`, 'FOREIGN_SESSION')\n    return record\n  }\n\n  private snapshot(record: SessionRecord): TerminalSessionSnapshot\n  private snapshot(record: SessionRecord, motd: string): TerminalSpawnResult\n  private snapshot(record: SessionRecord, motd?: string): TerminalSpawnResult | TerminalSessionSnapshot {\n    return {\n      sessionId: record.id,\n      ...record.name !== undefined ? { name: record.name } : {},\n      type: record.type,\n      ...record.session.pid !== undefined ? { pid: record.session.pid } : {},\n      status: record.session.status(),\n      ...motd !== undefined ? { motd } : {},\n    }\n  }\n\n  private async abortAndClose(owner: Agent | undefined, abortReason: TerminalError, closeReason: string): Promise<void> {\n    const failures: unknown[] = []","sourceCodeStart":372,"sourceCodeEnd":408,"githubUrl":"https://github.com/deepseek-ai/deepseek-harness/blob/b150a551b8d465e31e418e1b2eaf5e79bbb7d28e/packages/terminal/terminal/src/index.ts#L372-L408","documentation":"Error \"PTY session ${id} belongs to another agent\" thrown in deepseek-ai/deepseek-harness.","triggerScenarios":"Thrown at packages/terminal/terminal/src/index.ts:390 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Operate only on PTY sessions owned by the calling agent."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"b150a551b8d465e31e418e1b2eaf5e79bbb7d28e","analyzedAt":"2026-08-24T18:12:29.105Z","schemaVersion":2},"datasetVersion":"2026-08-24T22:17:12.610Z"}