Repository navigation
fix(chat): ask before a change in an agent run no session is behind - #1946
Merged
gkhngyk merged 2 commits intoNov 1, 2026
Merged
Conversation
An agent run that the minute tick or a signal started is driven in a
request with no signed-in person, but every WRITE tool calls a server
action that reads the person's session. So a change that the precedence
let run without a card (Full auto, an Admin's Always, a "Don't ask
again" tick) failed with Unauthorized. The run still ended done, the
fail count was reset, and the agent never paused. When someone's Run now
picked another person's queued run, the change ran with the clicker's
cookies while the activity log named the run's owner.
The agent run driver now passes the engine whose session the request
carries: the signed-in person of Run now and Run agent, only when the
run acts as them; null for the tick, a signal, or another person's
click. The engine turns every change the precedence would run in such a
run into a card, with no "Don't ask again" offer and a note saying why
("This agent ran on its own, so it asks before changing anything."). The
card waits in the owner's Inbox through the usual Needs you flow, and
their Approve runs it in their own request. A person's own Chat runs and
the run routes are unchanged (the session defaults to the actor's).
Help article updated (help/chat/agents.md: "When a run asks before a change").
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ss-writes-ask # Conflicts: # help/chat/agents.md
8 of 13 tasks
gkhngyk
pushed a commit
that referenced
this pull request
Nov 2, 2026
…ts person (#1972) * feat(chat): let a run with no session make a session-free change as its person An agent run that the minute tick or a signal started (or that another person's Run now picked up) has no session of its person behind it, so #1946 turned every change it would make by itself into a card. The draft rows already have their own writers for such a run (#1959: create_draft and update_draft runFor, checked as the run's person with the service role); this wires the engine to them. - engine.ts: askWithoutSession leaves a sessionFree row's decision as the precedence made it, read for the run's person like any call's (role, excludeRoles, plan, policy, mode, demo brand, brand scope): Full auto, an Admin's Always or the person's tick run it; Ask me first still shows the card. Every other row still asks first, with the no-session note. - write.ts: runLoggedWrite takes withoutSession and runs the row's runFor instead of run, with the same idempotency key, Activity log row and Undo window. A row without runFor refuses before anything runs. - The person is always the run's (the tool context the engine builds from the run's row), never the model's input. A card's Approve still runs in its person's own request, with their session. Tests: Full auto makes the draft with no card through createContentDraftFor, logged as the run's person's with Undo (and undone); Ask me first still asks and the owner's Approve uses their session; a row without runFor still asks; a Manager made an Analyst mid-run is refused update_draft (forbidden_role) and an Analyst's run never gets it; the owner's own Run now still uses their session; runLoggedWrite runs runFor for both draft rows, once per approval, and refuses a row without it. Help article updated (help/chat/agents.md: "When a run asks before a change"). Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(chat): decide an agent run's change in the mode it has now Review follow-ups (D-3, D-6) for the session-free engine: - An agent run's change is decided in the mode the run has now, read fresh at each change (agentModeNow): the mode it started in, or the agent's own mode when it was set lower since, and Ask me first once an Admin turned Full auto off for agents (chat_settings.agents_full_auto) under a run that started in it. What can't be read asks first. So a session-free row no longer runs by itself after the owner set the agent to Ask me first, or the Admin turned Full auto off, mid-run. A person's own chat keeps its mode; reads are not affected. - Engine tests for the session-free path with an Admin's Never (not offered, nothing made) and Ask (its card in Full auto), "Full auto for members" off (an Analyst's Full auto asks, an Admin's runs), and the agent run's mode now: still Full auto runs, Full auto off for agents or the agent set to Ask me first mid-run asks, an unreadable agent asks. Help article updated (help/chat/agents.md: "When a run asks before a change"). Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Cihan <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
gkhngyk
added a commit
that referenced
this pull request
Nov 2, 2026
…session is behind it (#1973) * feat(chat): let a run with no session make a session-free change as its person An agent run that the minute tick or a signal started (or that another person's Run now picked up) has no session of its person behind it, so #1946 turned every change it would make by itself into a card. The draft rows already have their own writers for such a run (#1959: create_draft and update_draft runFor, checked as the run's person with the service role); this wires the engine to them. - engine.ts: askWithoutSession leaves a sessionFree row's decision as the precedence made it, read for the run's person like any call's (role, excludeRoles, plan, policy, mode, demo brand, brand scope): Full auto, an Admin's Always or the person's tick run it; Ask me first still shows the card. Every other row still asks first, with the no-session note. - write.ts: runLoggedWrite takes withoutSession and runs the row's runFor instead of run, with the same idempotency key, Activity log row and Undo window. A row without runFor refuses before anything runs. - The person is always the run's (the tool context the engine builds from the run's row), never the model's input. A card's Approve still runs in its person's own request, with their session. Tests: Full auto makes the draft with no card through createContentDraftFor, logged as the run's person's with Undo (and undone); Ask me first still asks and the owner's Approve uses their session; a row without runFor still asks; a Manager made an Analyst mid-run is refused update_draft (forbidden_role) and an Analyst's run never gets it; the owner's own Run now still uses their session; runLoggedWrite runs runFor for both draft rows, once per approval, and refuses a row without it. Help article updated (help/chat/agents.md: "When a run asks before a change"). Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(chat): write through the API server as the run's person when no session is behind it A run an agent's trigger starts has no session of its person, so its writes through the API server (an opportunity's status, a dismissed prompt suggestion, Send to Action Center and its duplicate check, Site Audit) asked first on a card (#1946). The server takes such writes as a member since #1949 (CHAT_ACTING_SECRET + X-Acting-User, on seven routes); this is the web's side. - lib/chat/actor/api.ts: apiAs sends a request as the run's person: their own session's token in their own request, else the acting secret with X-Acting-User naming them, never another person's session. The person is the run's (the tool context the engine builds from the run's row), never the model's input. With CHAT_ACTING_SECRET unset or shorter than 32 characters the way is closed (actingOpen) and nothing is sent. A 401 or 403 chat_off on the acting way comes back as a value in the person's words (acting_refused, chat_off: chatEngine.acting in en.json), which the engine says on the step and to the model. - lib/chat/actor/api-writes.ts and action-center.ts: updateOpportunityStatusFor, dismissSuggestionFor, startSiteAuditsFor, createChatActionFor and checkChatActionCoverFor, with what the session's action checks first done as the person (isManagerFor, assertWritableFor, the chat being theirs for History's place). - Their requests and the reading of the answers move out of the 'use server' modules, unchanged, so both ways share them: lib/action-center/chat-send.ts (Send to Action Center) and lib/audit/start-answer.ts (Site Audit's start). - Registry: update_opportunity, dismiss_prompt_suggestion, create_action and run_site_audit are sessionFree with runFor and runForOpen: actingOpen; create_action has precheckFor, so its duplicate is checked as the run's person before any card. defineTool keeps runForOpen and precheckFor to session-free rows; runsWithoutSession says whether a row runs now. - Engine: askWithoutSession and runLoggedWrite use runsWithoutSession, so with the way closed these rows ask first as before; precheckOf uses precheckFor in a run with no session. Every change still goes through the precedence as the run's person (role, excludeRoles, plan, policy, mode); run_site_audit keeps its card in every mode, so its runFor isn't reached yet. - build_report stays as it is: its report reads fourteen sections with the person's session before the summary, so it still asks first. - web/.env.example and the self-host env docs say what the web sends and that, unset, those changes ask first. Help article updated (help/chat/agents.md: "When a run asks before a change"). Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(chat): decide an agent run's change in the mode it has now Review follow-ups (D-3, D-6) for the session-free engine: - An agent run's change is decided in the mode the run has now, read fresh at each change (agentModeNow): the mode it started in, or the agent's own mode when it was set lower since, and Ask me first once an Admin turned Full auto off for agents (chat_settings.agents_full_auto) under a run that started in it. What can't be read asks first. So a session-free row no longer runs by itself after the owner set the agent to Ask me first, or the Admin turned Full auto off, mid-run. A person's own chat keeps its mode; reads are not affected. - Engine tests for the session-free path with an Admin's Never (not offered, nothing made) and Ask (its card in Full auto), "Full auto for members" off (an Analyst's Full auto asks, an Admin's runs), and the agent run's mode now: still Full auto runs, Full auto off for agents or the agent set to Ask me first mid-run asks, an unreadable agent asks. Help article updated (help/chat/agents.md: "When a run asks before a change"). Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(chat): act as the run's person with the secret only, and ask when the server takes no one Review follow-ups (O-1, D-2, D-4, D-5, D-6) for the writes through the API server for a run with no session: - apiAs always sends CHAT_ACTING_SECRET with X-Acting-User naming the run's person, and never reads a session or a cookie: the engine calls runFor only when no session of the person is behind the run. A 401 is said once as a warning (a setup to fix), never with the secret. - precheckOf: in a run with no session only the row's precheckFor checks, and only while its way is open; with the way closed nothing is checked before the card (a request's session there isn't the person's), and the change checks again on approval. An acting refusal in Send to Action Center's duplicate check is no longer logged as an error. - When the server takes no one to act as (acting_refused: the web's and the server's secrets differ), the change is no longer a failed step: it waits on its card with the no-session note, its step no longer marked as made by itself, and the owner's Approve makes it with their session on the same approval (runLoggedWrite gives the idempotency key back for such a refusal). chat_off still ends the step with its words. - run_site_audit leaves the session-free rows: its card in every mode means its runFor is never reached. startSiteAuditsFor, the shared lib/audit/start-answer.ts and the audits.ts change are gone; audits.ts and audit-tools.ts are as on main. - web/.env.example and the self-host env docs say which writes use the secret and what a value that differs from the server's does. Tests: apiAs never reads a session and always names the run's person; the 401 warning; acting_refused turns into the card and the owner's Approve makes it once, logged as approved; Send to Action Center in the owner's own request uses precheck and createChatAction, never the run's-person ones; with the way closed nothing is checked before the card. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Cihan <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: Gökhan Geyik <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
An agent run that no session is behind now asks before it changes anything. Agent runs that start on their own have no cookie session: the minute tick, signals and the sweep. Their WRITE tools call session-based server actions, so a change could silently fail. A queued run could also be driven by another person's request and act under their cookies. Now such a run turns each WRITE into an approval card, and the run's owner approves it in their Inbox.
This is step 1 of the owner's two-step fix (2026-11-01: "İkisi de, sırayla"). Step 2 lets these runs write with no session through
*For(actor)functions, in separate PRs.What changes
agent-runs.ts:startQueuedAgentRunspasses the requesting person's id (sessionUserId) to the driver.null.agent-driver.ts: the driver hands that id to the engine only when it is the run's owner, the acting user. A run started by a tick, a signal or someone else's click gets none.engine.ts:driveRuntakes an optional fourth argument. It defaults to the run's owner, so normal Chat, the approval route andrun-api.tsdon't change.askWithoutSessionturns every WRITE that precedence would run into a card when the owner isn't the one asking. This covers Full auto, an Admin's "Always" policy and "Don't ask again".precedence.ts: only the type gains a reason,'no_session'inAskReason. The decision logic doesn't change.help/chat/agents.mdgets a "When a run asks before a change" section. The existing "Needs you / No answer in 7 days" sentences move there to keep "How a run works" under the 150-word limit.Known edges
approval_mismatch) doesn't carry the note. Adding it would mean storing the decision's reason; left out as a narrow case.engine.ts(driveRun,handleCall,openCard) andagent-driver.tstouch the same areas as the AGENT-OWN-KEY PRs. Whichever merges second needs a small merge.Related issue
None. Follow-up to the agent runs review (owner decision 2026-11-01).
Type of change
feat— New featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsHow to test
CHAT_AGENTIC=true, make an agent with Full auto and a schedule whose skill writes, for example one that adds a prompt.engine: a Full auto, Always or "Don't ask again" write with no session, or someone else's session, becomes a card. The owner's own session writes, and the owner's approval makes the change once.agent-driver: no id on a tick, an id on the owner's Run now, none for a run taken from the queue by someone else's request.agent-runs,agent-sweep,precedenceand help.Without the fix, the three new tests fail (1 engine, 2 driver).
Checklist
yarn lintpasses (0 errors; 7 old warnings in files this PR doesn't touch)yarn typecheckpassesyarn format:checkpasseshelp/(or no user-visible change)CI passed on this branch (50c5105), run on the fork (https://github.com/cihan-gyk/ansvisor/actions/runs/41332922620): schema is up to date; web
format:check, lint, typecheck, all tests andyarn buildpass; server lint,format:checkand all tests pass.🤖 Generated with Claude Code