Fix native approval controls and terminal Return handling
Co-Authored-By: Astra <noreply@openai.com>
6 files changed,
+329
−14
docs/superpowers/plans/CONTROLLER-REPORT-approval-controls.md+172 −0internal/directlive/approval_controls_test.go+87 −0internal/directlive/terminal.go+4 −4internal/release/manifest.json+9 −9internal/runner/provider/claude/certification_gaps_test.go+54 −0internal/runner/provider/claude/launcher.go+3 −1
CI passed — run details
diff --git a/docs/superpowers/plans/CONTROLLER-REPORT-approval-controls.md b/docs/superpowers/plans/CONTROLLER-REPORT-approval-controls.md| new file mode 100644 |
| index 00000000..ac8d477e |
| --- /dev/null |
| +++ b/docs/superpowers/plans/CONTROLLER-REPORT-approval-controls.md |
| @@ -0,0 +1,172 @@ |
| +# Approval controls, 2026-11-05 |
| + |
| +Claude Engineering and Codex Engineering completed the production controls |
| +phase with all six requested checks passing. Ordinary workspace file actions |
| +completed without a person. I played the person through the guide's actual |
| +terminal reader, as authorized. These were focused debugging runs, not |
| +certification. No full live gate or certification bundle was produced. |
| + |
| +## Causes and changes |
| + |
| +Claude Review's saved `turn-8.json` and `turn-9.json` in |
| +`~/.local/share/equipo/try/run-582068017/evidence/claude-Review/` contain |
| +successful Bash results for both control markers. Their permission metadata |
| +says `decision: accept`, `source: config`. The deny marker actually printed. |
| +`autoAllowBashIfSandboxed: true` admitted these commands before the permission |
| +callback. Neither the protected-path refusal nor workspace file auto-approval |
| +swallowed these requests: those paths only handle file tools. |
| + |
| +The Claude policy now has exact ask rules for `printf equipo-cert-allow` and |
| +`printf equipo-cert-deny`. Ordinary sandboxed commands retain automatic approval. |
| +The sandbox remains required and unsandboxed commands remain forbidden. |
| +Workspace file requests still pass through the protected-path check and are |
| +answered automatically inside the profile. Protected files and workspace |
| +symlinks retain their refusals. The nine changed Claude constructor hashes |
| +were updated in the release inventory; every entry remains uncertified. |
| + |
| +For every saved Codex specialist, the only answer artifact is from turn 7. |
| +There is no answer artifact for the turn 9 native control. The Engineering |
| +capture ends after request ID 1 asks for approval of the allow marker, followed |
| +by moderation and usage notifications. There is no completed command after it. |
| +`terminalAnswer` printed “Allow once is recorded as approved beyond profile.” |
| +before it read any input. That message was not evidence that Paul's answer |
| +had been read or delivered. The timeout occurred while collecting terminal |
| +input, before the adapter could send a response. |
| + |
| +The existing adapter response is accepted by Codex 0.165.0. A live run of the |
| +unchanged adapter completed the allow and deny controls. There was no reason |
| +to broaden its protocol or accept policy amendments. |
| + |
| +The terminal reader accepted only LF. A pseudo-terminal with canonical mode |
| +and CR-to-LF conversion disabled reproduced the timeout after `Allow once` |
| +and Return arrived as CR. The reader now accepts CR and LF, and ignores the |
| +empty LF left between successive CRLF answers. Tests exercise allow, deny and |
| +structured question answers consecutively with each line ending. The premature |
| +approval message was removed; no new app-owned text was added. |
| + |
| +The saved run does not contain terminal flags or input bytes. It establishes |
| +the failing stage, but cannot establish that Paul's terminal sent CR. That |
| +historical detail remains unproven. I asked which terminal he used and whether |
| +he pressed Enter. The CR defect is reproduced and fixed independently of that |
| +answer; a live Codex run with raw CR input now passes all controls. |
| + |
| +## Live proof and launch log |
| + |
| +Only `claude-a` (`account-1004981892`) and `codex` |
| +(`account-2598223264`), both bound to `paul@tito.io`, were launched. The harness |
| +read the permitted bindings and run configuration and used the pinned |
| +executables. It did not inspect credential contents, sign in, use another |
| +account, or modify state.json, bindings.json or runner.env. Only production |
| +account leases staged credentials. |
| + |
| +The temporary harness copied the production exercise setup through `open`, |
| +then called `exercise.turn` for ordinary workspace operations and the actual |
| +`exercise.controls`. It used production policies, launchers, journal, tool |
| +broker, namespace manager and `terminalAnswer`. It did not call the bundle or |
| +certificate writers. The disposable workspace was an initialized Git repository. |
| +A pseudo-terminal feeder typed exactly `Allow once`, `Deny`, and |
| +`{"answers":{"answer":"ordinary"}}` when the guide requested them. |
| + |
| +All times below are UTC on 2026-11-05. Launches were sequential. Model-turn |
| +admissions total **15 of 40**; preflights did not dispatch model turns. |
| + |
| +| Start–end | Tuple / debug directory | Turns | Outcome | |
| +| --- | --- | ---: | --- | |
| +| 14:01:53–14:01:53 | Codex Engineering / codex-before | 0 | Harness scratch mode was 0755; containment refused before account open. Corrected to 0700. | |
| +| 14:02:12–14:04:43 | Codex Engineering / codex-before | 4 | Existing wire response completed allow and deny. My delayed question response exceeded 60 seconds. Reusing the earlier evidence directory also caused exclusive capture creation to fail at cleanup. Later runs used fresh directories and immediate terminal feeding. | |
| +| 14:06:06–14:06:34 | Claude Engineering / claude-after | 4 | Workspace turn and all six controls passed. | |
| +| 14:06:59–14:07:39 | Codex Engineering / codex-after-raw | 3 | Raw CR allow succeeded. Terminal echo joined the next guidance line to the echoed answer, breaking the temporary feeder. It stopped the worker. Production ResumeInterrupted verified and retired the orphaned namespace before the next launch. | |
| +| 14:08:33–14:09:45 | Codex Engineering / codex-after-raw2 | 4 | Raw CR input with terminal echo disabled: workspace turn and all six controls passed. | |
| + |
| +An earlier harness invocation could not read its missing config |
| +because its generator used the wrong JSON field case. It launched no provider |
| +and admitted no model turn. |
| + |
| +| Check | Claude Engineering | Codex Engineering | |
| +| --- | --- | --- | |
| +| person-native-approval | pass | pass | |
| +| equipo-broker-approval | pass | pass | |
| +| real-question-answer | pass | pass | |
| +| stale-broker-denied | pass | pass | |
| +| invalid-broker-denied | pass | pass | |
| +| policy-escalation-denied | pass | pass | |
| + |
| +Both successful runs recorded one native allow, one native deny and one person |
| +answer. Claude recorded one broker validation; Codex recorded two, including |
| +its provider MCP elicitation. Stale and invalid broker submissions were refused. |
| +The attempt to respond `acceptForSession` was refused before the one-time |
| +answer was delivered. Both provider tool results contained the exact structured |
| +answer `{"answers":{"answer":"ordinary"}}`. |
| + |
| +Claude's preceding workspace turn successfully used Write, Read, Edit, Glob, |
| +Grep and Bash. Codex used apply_patch to create and edit the file and shell |
| +commands to read and search it. Neither turn produced an answer artifact or |
| +terminal question. Each file ended with `ordinary-updated`. |
| + |
| +The six control observations had identical payload digests within each run: |
| +Claude `5423dbd49284999b26028bd16bd3d7ba7ba9e873914c62a958059bafd39ce10b`; |
| +Codex `eba2d47fa9cdc375d7949d893fd4a42e5e7c7bd4cc34841ca7962210caba9f0f`. |
| +These identify the debug observations, not certified policies. |
| + |
| +## Verification |
| + |
| +Before implementation, these commands failed on the stated regressions: |
| + |
| +``` |
| +CGO_ENABLED=0 go test ./internal/directlive -run '^TestControlTerminalRawReturn$' -count=1 |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run '^TestNativeControlCommandsRequireApproval$' -count=1 |
| +``` |
| + |
| +The first failed with `context deadline exceeded` after raw Return. The second |
| +reported that both native controls could be auto-approved. After the fixes, |
| +the restored tests pass. Targeted tests also covered the existing canonical |
| +terminal reader, probe auto-denial, control guidance, protected native paths, |
| +all five ordinary workspace file callbacks, scoped Claude responses, Codex |
| +one-time approvals, persistent-approval refusal and release inventory authority. |
| + |
| +Six temporary source overlays deliberately broke the guards. Each command |
| +used `CGO_ENABLED=0 go test -overlay <overlay> <package> -run '^<test>$' -count=1` |
| +and returned exit 1 with a test assertion failure: |
| + |
| +| Deliberate break | Failing test | |
| +| --- | --- | |
| +| Accept only LF | TestControlTerminalRawReturn | |
| +| Treat the LF following CR as an empty answer | TestControlTerminalRawReturn | |
| +| Restore the premature approval message | TestControlTerminalRawReturn | |
| +| Remove the two exact Bash ask rules | TestNativeControlCommandsRequireApproval | |
| +| Disable workspace auto-approval | TestWorkspaceFileControlsStayAutomatic | |
| +| Skip the first protected-path refusal | TestProtectedPermissionNeverAsks | |
| + |
| +No mutation was retained. The release inventory test also failed on all nine |
| +old Claude hashes before their update, and passed afterward. |
| + |
| +The first `make -k ci` exited 2. Its full test step ran uncached in |
| +5m21.01s and failed only `TestReviewExpiredAccountSignsIn/claude` and |
| +`TestReviewUnconfirmedExpiredAccountSignsIn/claude` with |
| +`provider_account_busy`. These tests use disposable fake account homes. |
| +The two tests passed together on a focused rerun (0.676s), and the complete |
| +`internal/tryequipo` package then passed uncached (4.200s). No account code was |
| +changed to hide the failure. |
| + |
| +Every other lane passed, including migration and performance. Cold boot was |
| +94ms against 500ms; all screens stayed within 150ms. Timing warnings were |
| +provider 21.258s against 15s, Claude 47.807s against 45s and Codex 39.919s |
| +against 35s. Local timing warnings would fail with CI timing enforcement. |
| + |
| +The first permitted full rerun exited 0. All 28 packages ran uncached and |
| +passed in 5m7.397s. Build, vet, formatting, static analysis, vulnerability and |
| +secret scans, reference checks, size budgets, provider and namespace checks, |
| +migration and performance all passed. Cold boot was 91ms; all screens stayed |
| +within 150ms. Local timing warnings remained: provider 20.548s against 15s, |
| +Claude 46.426s against 45s and Codex 38.700s against 35s. No passing remote |
| +gate is claimed. There were exactly two full `make -k ci` invocations. |
| + |
| +## Delivery |
| + |
| +No README prose or copy.go entries were changed. No copy-review server, |
| +merge, default-branch push or deployment was performed. The delivery branch |
| +is `certification-gaps`. Task-created harnesses, overlays, captures, logs and |
| +scratch were removed after their results were recorded here. The interrupted |
| +worker's extra scratch was identified by its journal attempt key before |
| +removal; the recorded worker and namespace PIDs were absent. No task process |
| +or server remains. |
diff --git a/internal/directlive/approval_controls_test.go b/internal/directlive/approval_controls_test.go| new file mode 100644 |
| index 00000000..921c0744 |
| --- /dev/null |
| +++ b/internal/directlive/approval_controls_test.go |
| @@ -0,0 +1,87 @@ |
| +package directlive |
| + |
| +import ( |
| + "context" |
| + "os" |
| + "os/exec" |
| + "strings" |
| + "testing" |
| + "time" |
| + |
| + "amadan.net/oficina/equipo/internal/runnerproto" |
| +) |
| + |
| +func TestControlTerminalRawReturn(t *testing.T) { |
| + if os.Getenv("EQUIPO_TEST_RAW_RETURN") == "1" { |
| + ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second) |
| + defer cancel() |
| + q := runnerproto.Question{ID: "q", TaskID: "task", ServerID: "direct", AgentID: "agent", SessionID: "session", PermissionID: "p", Kind: "tool", RawRequest: []byte(`{"id":"p","kind":"tool","direct":true,"provider":"claude","name":"Bash","turn_id":"turn","input":{"command":"printf fixture"},"request":{"tool_name":"Bash","input":{"command":"printf fixture"}}}`)} |
| + if _, err := q.NativeApproval(); err != nil { |
| + t.Fatal(err) |
| + } |
| + for _, behavior := range []string{"allow", "deny", "question"} { |
| + if behavior == "question" { |
| + q.Kind = "person" |
| + q.RawRequest = []byte(`{"id":"p","kind":"person","question":"Which case?"}`) |
| + } |
| + a, err := terminalAnswer(withControlExpectation(ctx, behavior), q) |
| + want := behavior |
| + if want == "question" { |
| + want = "allow" |
| + } |
| + if err != nil || a.Behavior != want { |
| + t.Fatalf("raw Return lost: %+v %v", a, err) |
| + } |
| + } |
| + return |
| + } |
| + script := `import os,pty,select,signal,sys,termios,time |
| +pid,fd=pty.fork() |
| +if pid==0: |
| + attr=termios.tcgetattr(0) |
| + attr[0]&=~termios.ICRNL |
| + attr[3]&=~(termios.ICANON|termios.ECHO) |
| + termios.tcsetattr(0,termios.TCSANOW,attr) |
| + os.environ['EQUIPO_TEST_RAW_RETURN']='1' |
| + os.execv(sys.argv[1],[sys.argv[1],'-test.run=^TestControlTerminalRawReturn$']) |
| +output=b'';pending=b'';sent=0 |
| +answers=[b'Allow once',b'Deny',b'{"answers":{"answer":"ordinary"}}'] |
| +ending={'cr':b'\r','crlf':b'\r\n','lf':b'\n'}[sys.argv[2]] |
| +try: |
| + end=time.monotonic()+5 |
| + while time.monotonic()<end: |
| + if not select.select([fd],[],[],0.1)[0]:continue |
| + try:data=os.read(fd,65536) |
| + except OSError:break |
| + output+=data;pending+=data |
| + while b'\n' in pending: |
| + line,pending=pending.split(b'\n',1) |
| + if line.startswith(b'Type Allow once, Deny,'): |
| + os.write(fd,answers[sent]+ending);sent+=1 |
| + _,status=os.waitpid(pid,0) |
| + print(output.decode()) |
| + sys.exit(os.waitstatus_to_exitcode(status)) |
| +finally: |
| + try:os.kill(pid,signal.SIGKILL) |
| + except ProcessLookupError:pass |
| + os.close(fd) |
| +` |
| + for _, ending := range []string{"cr", "crlf", "lf"} { |
| + t.Run(ending, func(t *testing.T) { |
| + ctx, cancel := context.WithTimeout(context.Background(), 8*time.Second) |
| + defer cancel() |
| + self, _ := os.Executable() |
| + output, err := exec.CommandContext(ctx, "python3", "-c", script, self, ending).CombinedOutput() |
| + if err != nil { |
| + t.Fatalf("raw terminal: %v\n%s", err, output) |
| + } |
| + if strings.Contains(string(output), "Allow once is recorded") { |
| + t.Fatal("approval claimed before delivery") |
| + } |
| + if !strings.Contains(string(output), "PASS") { |
| + t.Fatal(string(output)) |
| + } |
| + |
| + }) |
| + } |
| +} |
diff --git a/internal/directlive/terminal.go b/internal/directlive/terminal.go| index 33ce8b00..03e15e44 100644 |
| --- a/internal/directlive/terminal.go |
| +++ b/internal/directlive/terminal.go |
| @@ -31,9 +31,6 @@ func terminalAnswer(ctx context.Context, q runnerproto.Question) (runnerproto.Qu |
| } |
| fmt.Fprintln(tty, equipo.RunnerText("live.answer")) |
| fmt.Fprintln(tty, string(q.RawRequest)) |
| - if _, err = q.NativeApproval(); err == nil { |
| - fmt.Fprintln(tty, equipo.RunnerText("live.beyond-profile")) |
| - } |
| ctx, cancel := context.WithTimeout(ctx, 60*time.Second) |
| defer cancel() |
| raw := []byte{} |
| @@ -56,8 +53,11 @@ func terminalAnswer(ctx context.Context, q runnerproto.Question) (runnerproto.Qu |
| if e != nil || n != 1 { |
| return answer, runnerproto.ErrInvalid |
| } |
| - if b[0] == '\n' { |
| + if b[0] == '\n' || b[0] == '\r' { |
| text := strings.TrimSpace(string(raw)) |
| + if text == "" { |
| + continue |
| + } |
| switch text { |
| case "Allow once": |
| answer.Behavior = "allow" |
diff --git a/internal/release/manifest.json b/internal/release/manifest.json| index 01b423ab..20bd020d 100644 |
| --- a/internal/release/manifest.json |
| +++ b/internal/release/manifest.json |
| @@ -18,49 +18,49 @@ |
| { |
| "provider": "claude", |
| "action": "reproduce", |
| - "inventory_hash": "6d89b04f2b78b27b4ca6bdae97192d5aa9c27236accfd97e16f995a55a50578a", |
| + "inventory_hash": "2d30111832a765985325c0c65ad47145f2fc20f91589f1d6a31f53cbe25064bc", |
| "status": "uncertified" |
| }, |
| { |
| "provider": "claude", |
| "action": "scope", |
| - "inventory_hash": "f763e7768c05c3edeb2ec12242817eb2325e711a3b11323c1f3b6f3a9aafaaa8", |
| + "inventory_hash": "542e489e809d8033a6695465083e8465c7d56653afd19a9ae4b57c7fd1902416", |
| "status": "uncertified" |
| }, |
| { |
| "provider": "claude", |
| "action": "recommend", |
| - "inventory_hash": "4e5667d02d30f7c83d06feff2e808422a855bdb3f21c15d3eaae38b5ba51ed74", |
| + "inventory_hash": "5793cd626d236cd3d88b5963c09902c14f1043a8933fa166398ce7f1c208e7fc", |
| "status": "uncertified" |
| }, |
| { |
| "provider": "claude", |
| "action": "investigate", |
| - "inventory_hash": "45a654d9c3319676d6a7f6f5168114581d63aa62409fb74f95b338335f0913a3", |
| + "inventory_hash": "32f8044b4fe444bebb181a1c0e08a3f9fcce322aec821e8fd03c0fdb0fea2ba7", |
| "status": "uncertified" |
| }, |
| { |
| "provider": "claude", |
| "action": "implement", |
| - "inventory_hash": "569d40e4b18a29f4ebcafddfee0b5ddb1e8743ed4ab33595cb8d74c34e3207bb", |
| + "inventory_hash": "72a972b9044c47ce5ac1a113300c106ce7ce6042b637f588d95fbc21992240bf", |
| "status": "uncertified" |
| }, |
| { |
| "provider": "claude", |
| "action": "copy", |
| - "inventory_hash": "70cbea437a37093e5058e4e70edbe62a00550c886d9a307edf936bc88b6fbc3b", |
| + "inventory_hash": "4089970bdc8d187421aa4a47d910e0ca557a2f53d1131f1f5ee2a9e2bc3dc891", |
| "status": "uncertified" |
| }, |
| { |
| "provider": "claude", |
| "action": "design", |
| - "inventory_hash": "7e11bd44eb4f6230cc206e6b5c28f12f0b8a70d6955510910ef6ca09e2269e7d", |
| + "inventory_hash": "0bb7c9b79bd32d907786dee975bd7d1af9ded0d643560cb65060d44f9f7514a6", |
| "status": "uncertified" |
| }, |
| { |
| "provider": "claude", |
| "action": "review", |
| - "inventory_hash": "36304992918ad43f9ef753744b9e1f40fd19ba0b5b3f8442c05868191d306c5d", |
| + "inventory_hash": "1575c1af43786b4051c966b76529a4e0c5da218d1628294c6248e652129dd320", |
| "status": "uncertified" |
| }, |
| { |
| @@ -114,7 +114,7 @@ |
| { |
| "provider": "claude", |
| "action": "coordinate", |
| - "inventory_hash": "252a113826bcbde5a1d28a45bbe0822ebbeda68068e904f6b09cad74de0aecdc", |
| + "inventory_hash": "dd19cd361277bd2cce8ca708c9b43ded23b71fb6d8bd3df4e244d0f1f4921a31", |
| "status": "uncertified" |
| }, |
| { |
diff --git a/internal/runner/provider/claude/certification_gaps_test.go b/internal/runner/provider/claude/certification_gaps_test.go| index 73dbb6ad..3505d13b 100644 |
| --- a/internal/runner/provider/claude/certification_gaps_test.go |
| +++ b/internal/runner/provider/claude/certification_gaps_test.go |
| @@ -2,9 +2,11 @@ package claude |
| import ( |
| "amadan.net/oficina/equipo/internal/runner/provider" |
| + "context" |
| "encoding/json" |
| "slices" |
| "testing" |
| + "time" |
| ) |
| func TestHookEventsAndNativeAskPolicy(t *testing.T) { |
| @@ -43,3 +45,55 @@ func TestHookEventFlagBoundToPolicy(t *testing.T) { |
| t.Fatal("missing hook-event flag accepted") |
| } |
| } |
| + |
| +func TestNativeControlCommandsRequireApproval(t *testing.T) { |
| + f := fixtureFor(t, "Engineering") |
| + var settings struct { |
| + Permissions struct{ Ask []string } |
| + Sandbox map[string]any |
| + } |
| + if err := json.Unmarshal(f.inputs.Settings, &settings); err != nil { |
| + t.Fatal(err) |
| + } |
| + for _, command := range []string{"printf equipo-cert-allow", "printf equipo-cert-deny"} { |
| + if !slices.Contains(settings.Permissions.Ask, "Bash("+command+")") { |
| + t.Errorf("native control auto-approved: %s", command) |
| + } |
| + } |
| + if settings.Sandbox["autoAllowBashIfSandboxed"] != true || settings.Sandbox["allowUnsandboxedCommands"] != false { |
| + t.Fatal("ordinary sandbox policy changed") |
| + } |
| +} |
| + |
| +func TestWorkspaceFileControlsStayAutomatic(t *testing.T) { |
| + f := fixtureFor(t, "Engineering") |
| + session, events := openFixture(t, f) |
| + f.l.mu.Lock() |
| + state, _ := f.l.state(session) |
| + state.active = true |
| + state.turn = provider.Turn{ID: "turn"} |
| + f.l.mu.Unlock() |
| + for tool, input := range map[string]string{ |
| + "Read": `{"file_path":"/workspace/ordinary.txt"}`, |
| + "Write": `{"file_path":"/workspace/ordinary.txt","content":"ordinary"}`, |
| + "Edit": `{"file_path":"/workspace/ordinary.txt","old_string":"ordinary","new_string":"updated"}`, |
| + "Glob": `{"path":"/workspace","pattern":"*.txt"}`, |
| + "Grep": `{"path":"/workspace","pattern":"ordinary"}`, |
| + } { |
| + t.Run(tool, func(t *testing.T) { |
| + ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond) |
| + defer cancel() |
| + raw, _ := json.Marshal(permissionRequest{Tool: tool, Input: json.RawMessage(input)}) |
| + reply, err := f.l.Permission(ctx, session, raw) |
| + var answer struct{ Behavior string } |
| + if err != nil || json.Unmarshal(reply, &answer) != nil || answer.Behavior != "allow" { |
| + t.Fatalf("workspace action reached person: %s %v", reply, err) |
| + } |
| + select { |
| + case ev := <-events: |
| + t.Fatalf("workspace approval published: %s", ev.Payload) |
| + default: |
| + } |
| + }) |
| + } |
| +} |
diff --git a/internal/runner/provider/claude/launcher.go b/internal/runner/provider/claude/launcher.go| index 0df35a72..712eb731 100644 |
| --- a/internal/runner/provider/claude/launcher.go |
| +++ b/internal/runner/provider/claude/launcher.go |
| @@ -151,7 +151,9 @@ func PolicyInputs(b provider.Binding, in provider.PolicyInputs, specialist, mode |
| } |
| } |
| allow := append([]string{}, in.Tools...) |
| - ask := []string{} |
| + // These harmless control commands must exercise the person approval path, |
| + // even though ordinary sandboxed Bash commands run without a prompt. |
| + ask := []string{"Bash(printf equipo-cert-allow)", "Bash(printf equipo-cert-deny)"} |
| for _, tool := range native { |
| if slices.Contains([]string{"Write", "Edit", "Read", "Glob", "Grep"}, tool) { |
| ask = append(ask, tool+"(//workspace/**)") |