Skip to content

Fix/nao admin bug 1145#1209

Open
ad4mou wants to merge 2 commits into
mainfrom
fix/nao-admin-bug-1145
Open

Fix/nao admin bug 1145#1209
ad4mou wants to merge 2 commits into
mainfrom
fix/nao-admin-bug-1145

Conversation

@ad4mou

@ad4mou ad4mou commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Summary

In admin mode, follow-up questions used to quietly switch back to the normal warehouse data after the first message. Now admin mode stays on for the whole chat (#1145).

  • Ask several questions in a row in admin mode -> they all stay in admin mode.
  • Turn admin mode off mid-chat and the next question uses normal data, as expected.
  • Reopening a chat picks up where you left off, in whichever mode the last question used.

Closes #1145

Review in cubic

@github-actions

Copy link
Copy Markdown
Contributor

🚀 Preview Deployment

URL https://pr-1209-ad1d992.preview.getnao.io
Commit ad1d992

⚠️ No LLM API keys configured - you'll see the API key setup flow when trying to chat.


Preview will be automatically removed when this PR is closed.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

1 issue found across 4 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="apps/backend/src/handlers/agent.ts">

<violation number="1" location="apps/backend/src/handlers/agent.ts:39">
P3: Follow-up admin messages with omitted `adminMode` now run against admin data but are recorded as `web` in `MessageSent`. Use resolved mode for telemetry so admin-mode usage and normal warehouse usage remain distinguishable.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic


let adminMode = opts.adminMode ?? false;
if (opts.adminMode === undefined && isProjectAdmin && opts.chatId) {
adminMode = await chatQueries.wasLastUserMessageAdmin(opts.chatId);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P3: Follow-up admin messages with omitted adminMode now run against admin data but are recorded as web in MessageSent. Use resolved mode for telemetry so admin-mode usage and normal warehouse usage remain distinguishable.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At apps/backend/src/handlers/agent.ts, line 39:

<comment>Follow-up admin messages with omitted `adminMode` now run against admin data but are recorded as `web` in `MessageSent`. Use resolved mode for telemetry so admin-mode usage and normal warehouse usage remain distinguishable.</comment>

<file context>
@@ -25,14 +26,19 @@ interface HandleAgentMessageResult {
 
+	let adminMode = opts.adminMode ?? false;
+	if (opts.adminMode === undefined && isProjectAdmin && opts.chatId) {
+		adminMode = await chatQueries.wasLastUserMessageAdmin(opts.chatId);
+	}
+
</file context>

@Bl3f Bl3f left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not sure i'd do it this way because here if you deactivate the mode on the frontend if the last message is admin then it will stay in admin, i'd stick to admin mode if first message source is admin, wdyt


await agentService.assertBudget(projectId, model);

let adminMode = opts.adminMode ?? false;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

unpack the adminMode if used twice


let adminMode = opts.adminMode ?? false;
if (opts.adminMode === undefined && isProjectAdmin && opts.chatId) {
adminMode = await chatQueries.wasLastUserMessageAdmin(opts.chatId);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

not sure if last user message or first user message should be considered, to me if the first message is source=admin then all the messages in the convo should be but the issue with this is that it forces it under the hood even if the user deactivate the admin mode in the frontend

@ad4mou ad4mou Jul 17, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes actually that's what caused the issue.
I think it makes more sense to just follow the most recent message but if the user changes manually the mode, then that takes priority and hence we change the mode.

Whether that should be the first message or the last, I think most recent makes more sense
But it's true in a practical scenario the user should stick to one mode in one chat. So perhaps we could lock the mode after the first prompt in a chat

@ad4mou

ad4mou commented Jul 17, 2026

Copy link
Copy Markdown
Contributor Author

Really? I think I made it so that if you deactivate the mode on the frontend it takes priority over the last message mode and hence deactivates the mode. I actually tested it

CleanShot.2026-07-17.at.15.51.42.mp4

This is the behavior I wanted. Do you prefer something else?

PS: sorry for the music, I forgot to mute

@ad4mou
ad4mou requested a review from Bl3f July 17, 2026 14:12
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.

[bug] nao admin mode switch back to non-admin mode in same conversation

2 participants