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

[BUG] Overriding a bot on a stage breaks DialogEngine and fails to update content-elements #1581

Closed
daukadolt opened this issue Dec 22, 2021 · 3 comments · Fixed by botpress/studio#229, botpress/botpress#11631 or botpress/botpress#11643
Labels
bug Something isn't working

Comments

@daukadolt
Copy link

daukadolt commented Dec 22, 2021

Describe the bug
In a workspace with 3 pipeline stages when a bot on some stage is overridden (using on_request_change pipeline hook in a comment below):

  1. Newly added contents are not visible in the flow editor and contents page of the bot

Screen Shot 2021-12-23 at 00 37 06

2. Chat stops working

Screen Shot 2021-12-23 at 00 35 48

May be related to this issue.

To Reproduce
Steps to reproduce the behavior:

  1. Set up a pipeline with 3 stages
  2. Create an empty bot

Screen Shot 2021-12-23 at 00 27 33

3. Add some initial content to it

Screen Shot 2021-12-23 at 00 29 48

4. Promote the bot to the next stage

Screen Shot 2021-12-23 at 00 30 13

5. Promoted bot should work for now

Screen Shot 2021-12-23 at 00 31 49

6. Add some new content to the original bot and promote it again

Screen Shot 2021-12-23 at 00 32 35

7. Open the studio for the promoted bot. You should see newly added content-elements rendered empty and webchat not working

Screen Shot 2021-12-23 at 00 46 07

Screen Shot 2021-12-23 at 00 35 48

Expected behavior
The promoted bot should have a working webchat and render newly added content-elements in the flow editor

Environment (please complete the following information):

  • OS: macOS
  • Browser Chrome
  • Browser Version Version 96.0.4664.110 (Official Build) (x86_64)
  • Botpress Version v12.26.7
  • NodeJS v12.18.1

Additional context
Add any other context about the problem here.

@daukadolt daukadolt added the bug Something isn't working label Dec 22, 2021
@daukadolt
Copy link
Author

on_stage_request hook:

const STAGE_SEPERATOR = '__'
const VERSION_SEPERATOR = ' :: v'
const STAGE_KEY = `${botId}-PipelineVersion`

const getPromoteVersionStage = () => {
  if (pipeline.length < 2) return 'NEVER'
  let stage2 = pipeline[1]
  return stage2.id
}

const getNextVersion = async () => {
  const promoteVersion = getPromoteVersionStage() === bot.pipeline_status.stage_request.id
  
  let globalKvs = bp.kvs.global()
  let storeExists = await globalKvs.exists(STAGE_KEY)
  let curVersion = storeExists ? await globalKvs.get(STAGE_KEY) : 0
  
  if (!promoteVersion) return curVersion // Updates the bot version only on the second stage and uses that version when promoted to the last stage
  
  let nextVersion = curVersion + 1
  
  await globalKvs.set(STAGE_KEY, nextVersion)
  
  return nextVersion
}

const getStageId = () => [botId, bot.pipeline_status.stage_request.id].join(STAGE_SEPERATOR)

const getStageName = async () => {
  let botName = bot.name.split(VERSION_SEPERATOR)[0]
  let nextVersion = await getNextVersion()

  return `${botName}${VERSION_SEPERATOR}${nextVersion}`
}

const handle = async () => {
  let stageId = getStageId()
  let stageName = await getStageName()

  let botConfig = await bp.bots.getBotById(stageId)

  if (botConfig) {
    await bp.bots.createBotRevision(stageId)
  }

  bot.id = stageId
  bot.name = stageName
}

handle()

@laurentlp laurentlp changed the title Overriding a bot on a stage breaks DialogEngine and fails to update content-elements [BUG] Overriding a bot on a stage breaks DialogEngine and fails to update content-elements Jan 26, 2022
@davidvitora
Copy link
Contributor

davidvitora commented Mar 10, 2022

Reopening the issue since the same issue can be reproduced at 12.26.10 with Postgress DB

here is a more complete on_stage_request hook


  const STAGE_SEPERATOR = '__'
  const VERSION_SEPERATOR = ' :: v'
  const botId = bot.id.split(STAGE_SEPERATOR)[0]
  const STAGE_KEY = `${botId}-PipelineVersion`
  const botLogger = bp.logger.forBot(bot.id)

  const getPromoteVersionStage = () => {
    if (pipeline.length < 2) return 'NEVER'
    let stage2 = pipeline[1]
    return stage2.id
  }

  const getNextVersion = async () => {
    const promoteVersion = getPromoteVersionStage() === bot.pipeline_status.stage_request.id

    let globalKvs = bp.kvs.global()
    let storeExists = await globalKvs.exists(STAGE_KEY)
    let curVersion = storeExists ? await globalKvs.get(STAGE_KEY) : 0

    if (!promoteVersion) return curVersion //We only promote the version on the second pipeline stage, then run with that version from there on

    let nextVersion = curVersion + 1

    await globalKvs.set(STAGE_KEY, nextVersion)

    return nextVersion
  }

  const getStageId = () => [botId, bot.pipeline_status.stage_request.id].join(STAGE_SEPERATOR)

  const getStageName = async () => {
    let botName = bot.name.split(VERSION_SEPERATOR)[0]
    let nextVersion = await getNextVersion()

    return `${botName}${VERSION_SEPERATOR}${nextVersion}`
  }

  const handler = async () => {
    /* Generate static Id based on stage */
    try {
      let stageId = getStageId()
      let stageName = await getStageName()

      /* Modify the bot definition */
      bot.id = stageId
      bot.name = stageName
    } catch (err) {
      botLogger.error(JSON.stringify(err, null, 2))
    }

    // bot.locked = true
  }

  return handler() 

@github-actions
Copy link

Available on v12.26.11

@michaelmass michaelmass transferred this issue from botpress/botpress Jun 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants