# Slice 4b progress: ask the implementer

Branch `thin-v1-slice4b` from `thin-v1-slice4` (ca0a65c). Spec:
`docs/superpowers/specs/2026-11-06-equipo-thin-v1.md` §§1-5, 7, 8, and
Paul's ruling of 2026-11-07: "The co-ordinator should be dealing with
the highest-level. If I want specifics I should be able to go in and ask
the implementing agent." First open issue of `SLICE4-PROGRESS.md`.
Conventions and scripts as in `SLICE1-PROGRESS.md` to `SLICE4-PROGRESS.md`.

## Done

1. Contracts (`internal/wire/questions.go`, fixtures): resource
   `Question` (task, step, specialist, asker, text, state `queued |
   running | answered | failed | cancelled`, reason, attempt, answer,
   timing); `POST /api/v1/tasks/{id}/questions` `{text,
   idempotency_key, specialist}` (202 with the Question; same key and
   another body 409; `not_askable`, `task_ended`, 403 for anyone but the
   creator), `GET /api/v1/questions/{id}`, `POST
   /api/v1/questions/{id}/cancel` (202 `{attempt}`, 409
   `question_ended`); event `question` to every active member;
   `Task.questions`, `Step.askable`. The answer streams as the chat's
   `delta` and `activity` events with resource `question` and the
   question's id as `turn_id`; the answered question replaces the
   draft. Frames `ask`, `cancel_ask`, `forget_task` (to the runner),
   `answer` (back), all durable; `Sync.asks`, `StepReport.askable`.
   `AddressesReview` (whole word review, reviewer, reviewed...). New
   fixtures `api/question.json`, `api/ask-request.json`,
   `api/event-question.json`, `frames/ask.json`, `cancel_ask.json`,
   `answer.json`, `forget_task.json`; task, step, sync fixtures gained
   the new fields.

2. Instance (`internal/equipo/chat/questions.go`, migration 0045):
   questions are team records; only the task's creator (an owner) asks
   or cancels. Target: the specialist chosen, else Review when the text
   addresses it and Review can answer, else the newest askable
   Engineering step. Question, event and `ask` command in one
   transaction; one question of a task with the runner at a time, the
   next dispatched when it ends. Answer reports only from the step
   person's primary runner, current attempt, forward only; deltas and
   activity go to every member under resource `question` (labels:
   reading the code, searching the code, "Looking at the change…").
   Cancel: at once if never dispatched, else `cancel_ask` and the
   runner's report ends it. A sync that no longer holds an acked
   question fails it (`interrupted`). A task becoming done or cancelled
   stops its questions and sends `forget_task`. `read_task` leaves the
   questions out (the coordinator never relays them). The thin `GET
   /questions/{id}` hands the old engine's question ids to its handler
   until the slice 7 sweep.
   Tests: `TestContractAskImplementer`, `TestPagesTaskThread`.

3. Runner (`internal/runner/thin/ask.go`, provider action `answer`):
   - Keep sessions: Engineering and Review copy their transcript (only
     `projects/-workspace/<session>.jsonl`, never a credential) into
     `sessions/<person>/steps/<step key>/` once the namespace's exit is
     verified, record it (`kept_sessions`: step, attempt, task,
     account, session id, commit, bytes) and report `askable` (Engineering
     when pushed, Review with its verdict). The worktree is recreated
     from the commit on demand, not kept.
   - Asking: the step's own session `--resume`d on its own account in
     the same containment, profile `answer`: a fresh read-only tree of
     the exact commit (bwrap read-only mount and settings `denyWrite`
     /workspace), native tools Read, Glob, Grep only (permission
     callback `ReadPermission`), and three read-only git tools the runner
     runs on its private repository (`git_log` base..commit, `git_diff`
     optionally one path, `git_show` of a commit in that history only);
     no Bash, Write, Edit, push or forge. `--include-partial-messages`:
     text and activity stream as `delta`/`activity`. The transcript is
     kept again after, so a follow-up continues the session. The prompt
     tells it to say plainly it can't change anything from here.
   - Questions share the step engine's one queue (arrival order), so a
     question waits for a running step and never runs beside one; a
     cancel that comes first holds the question; a restart ends running
     questions (`runner_restarted`), never runs one twice.
   - Retention: `forget_task` deletes the task's kept sessions; any kept
     session unused for 14 days goes, and any directory no record names;
     the sweep runs on every engine wake and hourly, and logs the count
     and bytes kept.
   Tests: `TestAnswerPolicyIsReadOnly`, `TestAnswerGitIsReadOnly`,
   `TestKeptSessionsForgetAndExpire`,
   `TestSweepKeptStaysUnderTheSessionRoot`, `TestAskQueuesWithSteps`,
   `TestRecoverAsks`.

4. Fake CLI: `[Equipo: question]` answers "From my session: <the last
   reply in its transcript>", `ask:git` (git_diff), `ask:read:<path>`,
   `ask:write:<path>`, `asksleep:<ms>`.

5. Headless `4b_ask` (fake CLI in real bwrap, local forge): a task to
   ready to merge keeps two sessions; Engineering answers from its own
   session (its step summary), reads the change through git and a file
   through Read; Review, addressed by name, answers from its own and its
   write is denied ("I can't change anything from here."); a follow-up
   continues Engineering's session; the answer streams (first activity
   and text seen before the answer); the branch is unchanged; a long
   question is cancelled; after the person merges the task is done, the
   kept sessions are gone and asking is 409. `4b_witness` is staging
   only (`EQUIPO_STAGING_ASK_TASK`).

6. Coordinator: house rule 2026-11-07.8. No file paths, line numbers or
   code mechanics in replies, even on request; for specifics it points
   at the task ("You can ask Engineering on [title](link).", or Review
   about the review). `TestOpeningPointsToAskTheImplementer`.

7. UI: the task page's thread (`work_task.html`) holds the creator's
   questions and answers, and notes, oldest first, rendered like the
   chat (own bubble, answer with the specialist's name and markdown,
   the thinking line while waiting or running, a quiet line when one
   ended). The composer is the chat's (`#chat-composer`, click anywhere
   to focus, docked sticky on the page's own colour) with a quiet
   "Asking Engineering · change" line (`ask-target.js`): it follows the
   text (Review when addressed) and change switches explicitly; one
   specialist only, no change. For a teammate, or before anyone can
   answer, the composer adds a note as before. `chat-stream.js` follows
   the thread with the chat's pieces (`[data-chat-stream][data-task]`):
   question streams only, background send reconciled by id, the
   answered question settles into its draft element; the conversation
   ignores question streams. `TestBrowserTaskThread` (1280 mouse, 390
   touch; no reload).

8. Mutation checks (risky paths; each observed failing a test unless
   noted): creator check (with the target-person check behind it), one
   question at a time, the task's end and forget, answer after the
   question ended, resume of the kept session, the read-only profile
   and its native tools, `git_show` outside the change, the kept-session
   path guard, Engineering `askable`, the question event listener and
   the Review routing in the page. Survived, as defence in depth: the
   ask's permission callback swapped for Engineering's (the read-only
   policy refuses the write first); removing either the forget frame's
   directory removal or its row deletion alone (the orphan sweep, or the
   removal, covers the other).

9. Merged `thin-v1-slice4` round-1 fixes at e7a1b52 (cb7a890): both
   sides kept (branch head and answer frames, `Task.branch_head` then
   `questions`, the link's `Synced` and `Forget`); budgets merged. The
   questions migration keeps its id `0045_thin_questions`, which staging
   applied on cfc790f; it sorts after slice 4's `0045_thin_branch_head`,
   so a fresh database runs both and staging runs only the new one. The
   runner's reason scan accepts answer reasons (the launch path serves
   questions).

10. Astra round 2 on slice 4 (3cede55): a failed or stalled index-pack
    while streaming the candidate into the checks tree's `.git` held the
    serial step worker (pack-objects blocked on an undrained pipe). Any
    downstream failure now cancels every command's process group and
    closes both pipes before each started command is reaped; a start
    failure reaps what started; the whole preparation has the judge
    tree's deadline. `TestCheckRepositoryPackFailureNeverHangs` (injected
    index-pack failure, and a stall) hung before the fix; after it they
    end in 0.2 s and at the 3 s test deadline, leaving no process.

11. Astra round 1 on slice 4b (REQUEST CHANGES, three Important, one
    Minor), each with a test that failed first:
    1. Git output in the answering session is bounded while read: at
       most MaxDiffBytes is read, then git's process group is stopped and
       reaped and the answer is cut (`TestAnswerGitOutputBoundedWhileRead`:
       a 16 MiB patch and commit allocated 80 MiB before, under 4 MiB now).
    2. A question is complete only once its namespace's exit is verified:
       the run records the namespace against the question's own attempt
       (`asks.ns_id`, not the steps table); an unverified exit holds the
       answer (`pending`, the report kept in `asks.final`), listed in
       sync, released by the probe at start and on every sync once
       verified; a restart holds a running question whose namespace is
       unproven (`TestAskHeldUntilTerminationVerified` failed and stalled,
       `TestRecoverAsksHoldsUnprovenNamespaces`; headless `4b_ask` checks
       the namespace is recorded, a mutation routing it to the steps
       table fails it).
    3. A question is marked started durably before its provider runs and
       is never picked again; its result stays in memory and its final
       write is retried with backoff, never the provider
       (`TestAskReportPersistedWithoutRerun`, three injected write
       failures: the provider ran once and the answer was sent).
    4. Minor: `git_show` takes only base..candidate, as `git_log` shows
       (`TestAnswerGitShowKeepsToTheChange`: the base and older history
       are refused).
    Mutations: the retry loop (killed), the held release (killed), the
    namespace hook (killed in headless); the started filter alone
    survives behind the retry loop (defence in depth). Time budget
    `internal/runner/thin` 45s.

## Decisions

- Sessions are kept as transcripts, like the coordinator's; the tree
  is recreated from the commit on demand (cheap, and nothing in it can
  drift). Disk: one transcript per Engineering or Review attempt,
  about 100 to 160 KB each on staging.
- A question resumes the step on the account that ran it. If that
  account is unhealthy the question fails `account_unavailable`.
- The answering session gets read-only git as runner-side tools rather
  than a shell: no shell in the namespace can modify anything because
  there is no shell.
- Questions run in the one step queue: simplest way to never run beside
  a write step; a question may wait behind another task's step.
- Thread notes stay: a teammate's composer adds notes, and the creator's
  does until a specialist can answer.
- `read_task` returns no questions; the coordinator points to the task.
- Default target is the newest askable Engineering step (after a fix
  round, the fix round's session).

## Staging

Release d976251 (built by `scripts/staging-thin.py build`, deployed with
`--swap hold` at 20:54:26, both runner units installed by 20:55:22,
about a minute), no live run:
- `tk2jhc6z46ar` (suite, ready to merge on b9bc2406): its steps ran on
  slice 4, which deleted each step's session with its runtime home, so
  none is askable (`askable: false` on all three steps). `POST
  .../questions` answers `409 not_askable` and the page shows the note
  composer, not the ask line. Nothing can resume those sessions.

Witness (approved by the controller: 1 coordinator turn, 1 Engineering
step, 1 Review step, 3 ask turns), on release cfc790f (restaged 21:04 to
21:05, CI green), real Claude CLI 2.1.312, suite person:
- Task (`4_review` live, one message): "In the oficina/suite README, the
  bold line under "How an app uses it" says "Not yet — see Status:".
  Please replace that em dash with a full stop so it reads "Not yet. See
  Status:". Change nothing else." Task `tkgzy4ioeoh7`, candidate
  d51e14fe; checks `.amadan/ci.d` passed (9.4 s); review approved
  (`same_account`, 9.3 s); ready to merge 40 s after the send.
- `4b_witness` (`EQUIPO_STAGING_ASK_TASK=tkgzy4ioeoh7`), each from the
  step's own resumed session, cold (process start 1.4 to 2.0 s):
  - Engineering, "What did you change and why?": one line, README line
    34, the em dash became a full stop and "See" a capital; nothing else
    because the person asked for exactly that; "the diff for the commit
    confirms it". First activity 2.8 s, first text 5.3 s, answered 5.8 s.
  - Review, "Anything you were unsure about?": "No, not really"; the
    brief listed only some of the other em dashes; when it reviewed it
    had the diff the coordinator gave it and had not checked against
    git, "I've now looked at the actual diff"; it did not render the
    Markdown. First activity 2.7 s, first text 8.3 s, answered 8.8 s.
  - Engineering, "Please fix the typo "teh" in the README yourself.": "I
    can't change anything from here, because this session is read-only.
    If you want something changed, the coordinator can set that up."
    (and it found no "teh"). Answered 6.4 s. Candidate unchanged.
- Disk: two kept sessions, 242,656 bytes after the three questions (108
  and 160 KB on disk).

## Live runs (budget: 8 ask turns, 2 coordinator turns)

Used: 1 coordinator turn, 1 Engineering step, 1 Review step (task
`tkgzy4ioeoh7`), 3 ask turns. No fix round, move-in or explore ran.

## Open issues

- Slice 4 round-1 fixes are to be merged and restaged; the witness ran
  on cfc790f and is not repeated after the merge (controller's call).
- Version skew as in slice 4: an old runner refuses `ask` and
  `forget_task`; install runners right after the instance.
- A question waits behind any running step on the runner, including
  another task's.

## Copy for review

Accepted for now with the existing marker in `copy.go` and listed in
the plan 3 inventory:
- `work.thread` "Questions and notes", `work.thread_empty` "No
  questions or notes yet."
- `work.ask.target` "Asking %s", `work.ask.change` "change",
  `work.ask.placeholder` "Ask %s about this work"
- `work.ask.queued` "Waiting for its turn…"
- `work.ask.failed` "%s couldn't answer: %s.", `work.ask.cancelled`
  "Question cancelled.", `work.ask.reason.session_gone` "its session for
  this work is no longer kept", `work.ask.reason.task_ended` "the task
  has ended"
- `chat.activity.read_change` "Looking at the change…"

## Blockers

None.
