Skip to content

fork: role-thread questions, part 2: the setting and the owner-question store (#808) - #1375

Merged
scuttletoby merged 3 commits into
mainfrom
fork/role-question-store
Nov 30, 2026
Merged

scuttletoby merged 3 commits into
mainfrom
fork/role-question-store

Conversation

@scuttletoby

Copy link
Copy Markdown
Owner

Part of #808: the role-thread question rule, part 2 (after #1355, "Left" item 1). This adds the fork setting and the durable store for owner-question records. No provider reads either yet, and this PR has no adapter seam lines.

What this adds

  • Setting server.roleQuestionsWait (default true, which is upstream's behaviour: a question from the assistant or an orchestrator thread waits for the owner). false turns the rule on once it is wired. Anything but false in the file reads as true, so a bad value never fails the rest of settings.json. A save is strict (true/false only). Only the person can change it (it is not in FORK_AGENT_WRITABLE_KEYS). It gets a forkDefaults.ts row, a docs row and section, a change file, and entries in the managed-settings whole-only list and the fork report's not-a-switch list.
  • apps/server/src/fork/ownerQuestionStore.ts: one file per record at <stateDir>/owner-questions/<digest>.json. Each write is atomic and runs under one lock. It offers insertNew, get, answer, withdraw and listOpen.
  • apps/server/src/fork/roleQuestionKeep.ts (keepRoleQuestion): the step a question call will take once it is wired. It reads roleQuestionsWait and threadRoles, runs planRoleQuestion, writes the record, and only then returns the reply.
  • Part-1 minor fixed (roleQuestion.ts): a non-string answer is turned into text the way upstream's claudeSdkUserInputAnswers does. A list keeps its text items, and any other value goes through String, so 42 reads as 42 instead of being dropped.

The code-lens points from #1355

  • Insert only new ids. insertNew writes only when no record has that id. Otherwise it returns the stored record unchanged and writes nothing. A replay of an answered call, which planRoleQuestion presents as a new open record with the same id, gets the answered record back. The question never reopens.
  • Write before the reply. keepRoleQuestion returns keep and its reply only after insertNew has stored the record. If the write fails, the call waits as upstream does. If the call is stopped half-way, no reply is given.

State question

  • Runs again (replay or restart of the same tool call): it gets the same id, so insertNew returns the stored record. For an open record the reply is "not answered yet" again. For an answered one the reply is the answer. For a withdrawn one the reply says so and adds "Do not ask it again". There is still one file per call.
  • Answered twice: the first answer is written and the second is refused with answered. A withdrawn record refuses answers with withdrawn. An unknown or malformed id is refused with unknown_record, and it never maps to a path outside the folder.
  • Stops half-way: the record is written atomically (temp file and rename) before the reply, so a stop leaves either no record and no reply (the call reruns), or the record (a replay finds it). One gap is left for part 3: between answer writing the answered record and the answer message being sent. Part 3 must deliver the message under an id derived from the record, and resend it at start for answered records whose message is missing.
  • Old, empty or bad state: no folder means no records. A record file that does not decode (not JSON, another version, or another record's id) is refused as unreadable and kept, never overwritten. listOpen skips it and still lists the rest. A settings file without the key waits (upstream).
  • The setting is off (true): no record is written and the call waits.

Left for later parts of #808

  1. Announce the adapter seam lines (Claude's AskUserQuestion branch of canUseTool, and Codex's request_user_input), then wire keepRoleQuestion in and provide OwnerQuestionStore.layer in a later PR. After that the setting does something, and the fork report should count it as a feature.
  2. The owner's card: the role thread and Waiting on you list listOpen, answer posts the message (see the gap above), and a deleted thread withdraws its records (thread_gone).

Tests

  • New ownerQuestionStore.test.ts (10 tests) and roleQuestionKeep.test.ts (8 tests), plus one new test each in roleQuestion.test.ts (non-string answer) and packages/contracts/src/forkSettings.test.ts (lenient read, strict save). All pass. The new files fail on main (the modules are missing there). The non-string-answer test and the lenient-read test were run before their fixes and failed.
  • vp run check:changed: format, lint, knip and typecheck pass. In its test step, one test fails here only: forkReport.test.ts > __fork-report --activity > exits 0 only when the running server says it is quiet. It serves on a local socket, and TCP to 127.0.0.1 is blocked on this machine. CI runs it.
  • packages/shared/src/forkDocs.test.ts, forkDefaults.test.ts, fork-changes-list.test.cjs, the policy tests and personOnlySettings.test.ts pass. The fork-checks scripts (schema, upstream files, seam) and their 201 tests pass.

🤖 Generated with Claude Code

…on store (#808)

The fork setting roleQuestionsWait (default true: a question from the
assistant or an orchestrator thread waits, as upstream's does) and the
durable store for kept owner questions, one file per record under
<stateDir>/owner-questions/. No provider reads either yet.

- The store inserts new ids only: a replay of the same call (same id)
  gets the stored record back, so an answered or withdrawn question
  never opens again. A record file that cannot be read is refused and
  kept, never overwritten.
- keepRoleQuestion writes the record before it returns the "not
  answered yet" reply; a failed write waits as upstream does, and a stop
  half-way gives no reply. A replay of an answered call gets the answer.
- answerText turns a non-string answer into text as upstream's
  claudeSdkUserInputAnswers does (part 1, code lens minor).
- The setting reads leniently (anything but false waits), so a bad
  value never fails the rest of the settings file; a save is strict.
- Docs row and section, change file, managed-settings and fork report
  lists.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@scuttletoby

Copy link
Copy Markdown
Owner Author

lens: state · reviewer: claude (state lens r1) · read at: d07abb8

blocker: none
major: none
minor: keepRoleQuestion looks up the stored record only after planRoleQuestion says keep. If the person flips roleQuestionsWait back to true, or the thread no longer holds its role, a replay of a call that was already answered or dismissed returns wait, and the owner is asked again the upstream way. The stored answer is ignored. I reproduced this with a scratch test (answer, then replay with true: wait). Nothing calls this yet, so it has no effect today. A fix for here or part 3: when the thread and tool call id are known, run store.get(ownerQuestionId(...)) first and return the stored answered or withdrawn reply whatever the setting says.
minor: an open record kept while the setting was false stays in listOpen after the setting goes back to true. The part-3 card should still show it and accept an answer, and it should not drop open records silently.

What I checked (reproduced where marked):

  • Insert-only: insertNew reads under the lock and returns the stored answered or withdrawn record unchanged. It writes nothing, and the tests cover this. planRoleQuestion only ever makes open records, so a replay cannot write over a closed one.
  • Unreadable record: bad JSON, another v, or another id gives unreadable. insertNew, answer and get refuse it and leave the file as it is. keepRoleQuestion turns the failure into upstream's wait, and listOpen skips that file and lists the rest.
  • Reply only after the store: the reply is built from what insertNew returns. A failed write gives wait. A stop is not caught, so no reply is given, and the tests cover both.
  • Non-text answers: same as claudeSdkUserInputAnswers (a list keeps its text items, anything else goes through String(x ?? "")). The only difference is that blank items are trimmed and dropped, which affects the message text only.
  • Setting writes: the patch schema is strictly a boolean. FORK_AGENT_WRITABLE_KEYS is empty, so FORK_PERSON_ONLY_KEYS includes the new key automatically, and the personOnlySettings test keeps it out of every T3 tool input. Through the file, an agent with shell access could edit settings.json. That is true of every fork setting and is not new here.
  • Lock (reproduced): I interrupted an insertNew mid-flight, and a second insertNew on the same store then succeeded within the timeout, so the semaphore is released on interruption. A crash takes the in-memory lock with it. The atomic write leaves at most a t3-write-* temp folder, which listOpen skips (it lists only .json files with a valid id). The layer comment says one store per server. Keep it to one layer value when wiring, because two values would mean two locks.
  • Default: if the key is missing or holds a bad value, it reads true. planRoleQuestion is then turned off and no store call is made, so behaviour is upstream's. Nothing in the server calls keepRoleQuestion yet.

State question:

  • Runs again: the same thread and tool call give the same digest, so a replay returns the one stored record. An open record gives "not answered yet", answered gives the answer, withdrawn gives "do not ask again", and there is still one file. The exception is the setting or role change in the first minor.
  • Stops half-way: write-then-rename means a stop leaves either no file (and no reply, so the call runs again) or a whole record. The known part-3 gap still stands: the answer is saved but the message may not be delivered before a stop.
  • Existing, old, empty or corrupt state: no folder means no records. An empty or corrupt file, or one from another version, is refused and kept, never written over. A settings file without the key, or with a bad value, waits (upstream). A record file a later version writes under v: 1 with extra fields would lose those fields if this version rewrites it on answer/withdraw. Bump v if part 3 adds fields.

🤖 Generated with Claude Code

@scuttletoby

Copy link
Copy Markdown
Owner Author

Merge conveyor: head d07abb8bee30 does not merge cleanly on main 40cd61834b57 (conflicts in apps/server/src/golive/forkReport.test.ts, docs/fork/README.md, packages/contracts/src/forkDefaults.test.ts, packages/contracts/src/forkDefaults.ts, packages/contracts/src/forkSettings.ts): fork:merge-ready swapped for fork:merge-blocked. Merge main into the branch (a writer may already be queued for it), then add fork:merge-ready again.

@scuttletoby scuttletoby added fork:merge-blocked Merge conveyor: did not merge, needs a look (PRs) and removed fork:merge-ready Merge conveyor: lenses done, merge when green (PRs) labels Nov 30, 2026
Conflicts were both sides adding a server setting next to each other
(main: accountThreadRules/hostTools; branch: roleQuestionsWait). Kept both.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@scuttletoby

Copy link
Copy Markdown
Owner Author

Rebase

Merged main (40cd618) into the branch as a merge commit, no force-push: new head d6ee2bf. The diff against main is still only this PR's 14 files.

What conflicted: all five files had the same kind of conflict. main added the accountThreadRules/hostTools server settings (#885) in the same spots where this branch adds roleQuestionsWait (#808). I kept both, with main's entries first:

  • packages/contracts/src/forkSettings.ts: the settings-file field (each with its own doc comment), the patch field and the patch rule ("replace").
  • packages/contracts/src/forkDefaults.ts: roleQuestionsWait is its own defaults entry, after hostTools.
  • packages/contracts/src/forkDefaults.test.ts: server.roleQuestionsWait comes after server.hostTools in the key list.
  • apps/server/src/golive/forkReport.test.ts: the roleQuestionsWait reason comes after accountThreadRules/hostTools.
  • docs/fork/README.md: both table rows, and the server.roleQuestionsWait section after server.hostTools.

Checks:

  • Contracts tests forkDefaults and forkSettings: 67/67 pass.
  • Server tests ownerQuestionStore, roleQuestion, roleQuestionKeep, forkReport and policy: 139/140 pass.
  • vp run check:changed: format, lint, knip, graphql and typecheck (40 packages) pass. Tests: 173/174 pass.
  • fork-checks scripts against main: schema check, upstream-files check and seam check all pass, and their self-tests pass (201/201).

The one failure in both runs is forkReport --activity "exits 0 only when the running server says it is quiet". It starts a probe server on a local port, and that can't run on the machine that did this merge (it gets unreachable). This PR doesn't touch that code, so CI should decide it.

@scuttletoby scuttletoby added fork:merge-ready Merge conveyor: lenses done, merge when green (PRs) and removed fork:merge-blocked Merge conveyor: did not merge, needs a look (PRs) labels Nov 30, 2026
scuttletoby added a commit that referenced this pull request Nov 30, 2026
… Codex adapters (#808) (#1465)

Step 1 of adding the seam lines for the role-thread question rule (part 3,
left by #1355): a question call from a thread that holds a role now (the
assistant or a project orchestrator) is kept as an open owner question and
answered at once with "not answered yet", so the thread does not wait for
the owner. List only; step 2 adds the lines with the fork seat
apps/server/src/fork/roleQuestionSeat.ts, after the store (#1375) merges.

- ClaudeAdapterV2.ts: an import, the seat made beside mcpProfiles, and two
  lines first in the AskUserQuestion branch of canUseTool.
- CodexAdapterV2.ts: an import, the seat made beside continuationRequests,
  and two lines in the item/tool/requestUserInput handler after its turn
  check.

Co-authored-by: Claude Opus 5.5 <[email protected]>
@scuttletoby

Copy link
Copy Markdown
Owner Author

Merge conveyor: head d6ee2bff4a86 does not merge cleanly on main 2da3e3f6b519 (conflicts in apps/server/src/golive/forkReport.test.ts, docs/fork/README.md, packages/contracts/src/forkDefaults.test.ts, packages/contracts/src/forkDefaults.ts, packages/contracts/src/forkSettings.ts): fork:merge-ready swapped for fork:merge-blocked. Merge main into the branch (a writer may already be queued for it), then add fork:merge-ready again.

@scuttletoby scuttletoby added fork:merge-blocked Merge conveyor: did not merge, needs a look (PRs) and removed fork:merge-ready Merge conveyor: lenses done, merge when green (PRs) labels Nov 30, 2026
main moved onto a new upstream tag. Resolved forkReport.test.ts, docs/fork/README.md,
forkDefaults.ts, forkDefaults.test.ts and forkSettings.ts by keeping both main's
hostToolsOutsideInput and this branch's roleQuestionsWait entries.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@scuttletoby

Copy link
Copy Markdown
Owner Author

Rebase

Merged main (2da3e3f) into this branch as a merge commit, e123b5a. No force-push. The tree is main plus only this PR's own changes (40cd618..d6ee2bf).

What conflicted and how I resolved it. Every conflict came from main's new server.hostToolsOutsideInput setting (#885) and this PR's server.roleQuestionsWait (#808) being added in the same place. Each one keeps both, with main's entry first:

  • packages/contracts/src/forkSettings.ts: both settings are kept in the settings fields (with their doc comments), the patch fields and FORK_PATCH_RULES.
  • packages/contracts/src/forkDefaults.ts: both default-off entries are kept.
  • packages/contracts/src/forkDefaults.test.ts: both keys are in the expected list.
  • apps/server/src/golive/forkReport.test.ts: both not-a-switch reasons are kept.
  • docs/fork/README.md: both table rows and both setting sections are kept.

Checks

  • fork-checks scripts: the script self-tests pass (201/201). The schema, upstream-files and seam checks against main all pass.
  • vp test run: contracts forkDefaults and forkSettings pass (68/68). Server fork/ownerQuestionStore, fork/roleQuestion, fork/roleQuestionKeep and policy/* pass.
  • vp run check:changed: format, lint, knip, graphql and typecheck pass.
  • The only red result is the __fork-report --activity "exits 0 only when the running server says it is quiet" test. It needs a random local port, which the machine that ran this does not allow, so it always times out there. It is not touched by this merge; CI runs it.

@scuttletoby scuttletoby added fork:merge-ready Merge conveyor: lenses done, merge when green (PRs) and removed fork:merge-blocked Merge conveyor: did not merge, needs a look (PRs) labels Nov 30, 2026
@scuttletoby
scuttletoby merged commit 9819f12 into main Nov 30, 2026
35 checks passed
@scuttletoby
scuttletoby deleted the fork/role-question-store branch November 30, 2026 06:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork:merge-ready Merge conveyor: lenses done, merge when green (PRs)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant