oficina / equipo Public

fix: bound turn prompts and journal their hashes

codex agent, operated by paul@keymail.dev pushed by claude agent, operated by paul@keymail.dev af30f982b01ae5ab49288dc446f6743527711013 parent a7050cc
6 files changed, +137 −7
  • internal/equipo/copy.go +2 −0
  • internal/runner/final_prompt_test.go +43 −0
  • internal/runner/supervisor.go +3 −0
  • internal/runner/turn_prompt.go +79 −0
  • internal/runner/workflow_integration_test.go +1 −1
  • internal/runner/workflow_turn.go +9 −6
diff --git a/internal/equipo/copy.go b/internal/equipo/copy.go
index 522ccdda..91ababd0 100644
--- a/internal/equipo/copy.go
+++ b/internal/equipo/copy.go
@@ -248,6 +248,8 @@ var runnerDraftCopy = map[string]string{
"task.group.queued": "Queued",
// COPY REVIEW REQUIRED: task.group.finished
"task.group.finished": "Finished this week",
+ // COPY REVIEW REQUIRED: runner.prompt_too_large
+ "runner.prompt_too_large": "The task instructions and reproduction are too large for one turn.",
// COPY REVIEW REQUIRED: runner.budget
"runner.budget": "The task has reached its budget.",
// COPY REVIEW REQUIRED: runner.quota
diff --git a/internal/runner/final_prompt_test.go b/internal/runner/final_prompt_test.go
new file mode 100644
index 00000000..d0060235
--- /dev/null
+++ b/internal/runner/final_prompt_test.go
@@ -0,0 +1,43 @@
+package runner
+
+import (
+ "amadan.net/oficina/equipo/internal/equipo/team"
+ "amadan.net/oficina/equipo/internal/runnerproto"
+ "encoding/json"
+ "fmt"
+ "strings"
+ "testing"
+)
+
+func TestTurnPromptOmitsThousandTestBaseline(t *testing.T) {
+ claim := RunClaim{}
+ claim.Assignment.StepKey = "review"
+ claim.Brief.Instructions = "fix the total"
+ claim.Brief.StandingInstructions = "preserve the contract"
+ var definition runnerproto.CheckDefinition
+ for i := 0; i < 1000; i++ {
+ definition.Baseline.Names = append(definition.Baseline.Names, team.TestIdentity{Package: "amadan.net/long/repository/package", Name: fmt.Sprintf("TestBaseline%04d", i)})
+ }
+ claim.Brief.CheckDefinition = marshal(definition)
+ repro := runnerproto.Reproduction{ExpectedSymptom: "wrong total", Files: []runnerproto.CheckFile{{Path: "total_test.go", Bytes: []byte("package total\nfunc TestRegression() {}")}}, TestNames: []team.TestIdentity{{Package: "total", Name: "TestRegression"}}}
+ arts := []team.Artifact{{Role: team.RoleReproduction, Payload: marshal(repro)}, {Role: team.RoleCandidate, Payload: marshal(team.GitCandidate{Commit: strings.Repeat("a", 40)})}}
+ prompt, err := buildTurnPrompt(claim, arts)
+ wfMust(t, err)
+ if strings.Contains(prompt, "TestBaseline") || strings.Contains(prompt, "CheckDefinition") || !strings.Contains(prompt, "package total") || !strings.Contains(prompt, "TestRegression") || !strings.Contains(prompt, strings.Repeat("a", 40)) {
+ t.Fatal("prompt omitted task inputs or embedded baseline", prompt)
+ }
+ raw, err := turnIntentPayload("claude", "sonnet", prompt)
+ wfMust(t, err)
+ var payload struct {
+ Hash string `json:"prompt_sha256"`
+ Bytes int `json:"prompt_bytes"`
+ }
+ wfMust(t, json.Unmarshal(raw, &payload))
+ if payload.Hash != team.ContentDigest([]byte(prompt)) || payload.Bytes != len(prompt) || len(raw) > 512 {
+ t.Fatal("intent embeds prompt or lost hash", string(raw))
+ }
+ _, err = turnIntentPayload("claude", "sonnet", strings.Repeat("x", 65536))
+ if err != ErrPromptTooLarge {
+ t.Fatal("oversized prompt reached intent", err)
+ }
+}
diff --git a/internal/runner/supervisor.go b/internal/runner/supervisor.go
index 692d00b7..b0e0917f 100644
--- a/internal/runner/supervisor.go
+++ b/internal/runner/supervisor.go
@@ -163,6 +163,9 @@ func (s *Supervisor) Run(ctx context.Context, claim RunClaim) error {
}
func (s *Supervisor) finishAttempt(cleanupCtx context.Context, r *attemptState, err error) error {
+ if errors.Is(err, ErrPromptTooLarge) {
+ r.FailureReason = "runner.prompt_too_large"
+ }
var refusal *RefusalError
if errors.As(err, &refusal) {
r.FailureReason = refusal.Reason
diff --git a/internal/runner/turn_prompt.go b/internal/runner/turn_prompt.go
new file mode 100644
index 00000000..38288480
--- /dev/null
+++ b/internal/runner/turn_prompt.go
@@ -0,0 +1,79 @@
+package runner
+
+import (
+ "amadan.net/oficina/equipo/internal/equipo/team"
+ "amadan.net/oficina/equipo/internal/runner/paseo"
+ "amadan.net/oficina/equipo/internal/runnerproto"
+ "encoding/json"
+ "errors"
+ "unicode/utf8"
+)
+
+var ErrPromptTooLarge = errors.New("runner.prompt_too_large")
+
+const maxTurnPromptBytes = 24 << 10
+
+type promptFile struct {
+ Path string `json:"path"`
+ Text string `json:"text"`
+}
+type turnPrompt struct {
+ Step string
+ Instructions string `json:"instructions"`
+ StandingInstructions string `json:"standing_instructions"`
+ Target team.TargetBinding `json:"target"`
+ ExpectedSymptom string `json:"expected_symptom,omitempty"`
+ Files []promptFile `json:"reproduction_files,omitempty"`
+ Tests []team.TestIdentity `json:"reproduction_tests,omitempty"`
+ CandidateCommit string `json:"candidate_commit,omitempty"`
+}
+
+func buildTurnPrompt(c RunClaim, artifacts []team.Artifact) (string, error) {
+ p := turnPrompt{Step: c.Assignment.StepKey, Instructions: c.Brief.Instructions, StandingInstructions: c.Brief.StandingInstructions, Target: c.Brief.Target}
+ for _, a := range artifacts {
+ switch a.Role {
+ case team.RoleReproduction:
+ var r runnerproto.Reproduction
+ if err := json.Unmarshal(a.Payload, &r); err != nil {
+ return "", err
+ }
+ p.ExpectedSymptom, p.Tests = r.ExpectedSymptom, r.TestNames
+ for _, f := range r.Files {
+ if !utf8.Valid(f.Bytes) {
+ return "", runnerproto.ErrInvalid
+ }
+ p.Files = append(p.Files, promptFile{f.Path, string(f.Bytes)})
+ }
+ case team.RoleCandidate:
+ var candidate team.GitCandidate
+ if err := json.Unmarshal(a.Payload, &candidate); err != nil {
+ return "", err
+ }
+ p.CandidateCommit = candidate.Commit
+ }
+ }
+ raw, err := json.Marshal(p)
+ if err != nil {
+ return "", err
+ }
+ if len(raw) > maxTurnPromptBytes {
+ return "", ErrPromptTooLarge
+ }
+ return string(raw), nil
+}
+func turnIntentPayload(provider, model, prompt string) ([]byte, error) {
+ quoted, err := json.Marshal(prompt)
+ if err != nil {
+ return nil, err
+ }
+ // Leave room for the agent identity, request ID and bridge frame envelope.
+ if len(prompt) > maxTurnPromptBytes || len(quoted)+8192 >= paseo.MaxFrameBytes {
+ return nil, ErrPromptTooLarge
+ }
+ return json.Marshal(struct {
+ Provider string `json:"provider"`
+ Model string `json:"model"`
+ Hash string `json:"prompt_sha256"`
+ Bytes int `json:"prompt_bytes"`
+ }{provider, model, team.ContentDigest([]byte(prompt)), len(prompt)})
+}
diff --git a/internal/runner/workflow_integration_test.go b/internal/runner/workflow_integration_test.go
index abaf7c6b..74b7bbe8 100644
--- a/internal/runner/workflow_integration_test.go
+++ b/internal/runner/workflow_integration_test.go
@@ -457,7 +457,7 @@ case 'subscribe':subs.set(p.agent.agent_id,p.subscription_id);event(p.agent,'tim
case 'send':{const a=p.agent,request=agents.get(a.agent_id).request,message=JSON.parse(p.message),step=message.Step;let name,args;++turn;
if(step==='reproduce'){name='submit_reproduction';args={expected_symptom:'wrong value',files:[{path:'bug_test.go',bytes:Buffer.from('package fixture\nimport "testing"\nfunc TestBug(t *testing.T){if Value()!=2 {t.Fatal("wrong value")}}\n').toString('base64')}],test_names:[{package:'fixture',name:'TestBug'}]};}
if(step==='implement'){fs.writeFileSync(request.workspace.path+'/value.go','package fixture\nfunc Value() int {return 2}\n');git(request.workspace.path,['add','.']);git(request.workspace.path,['commit','-m','fix']);name='submit_candidate';args={commit:git(request.workspace.path,['rev-parse','HEAD'])};}
-if(step==='review'){name='submit_review';args={candidate:JSON.parse(Buffer.from(message.Evidence.find(x=>x.Role==='candidate').Payload,'base64')).commit,decision:'approve',findings:[]};}
+if(step==='review'){name='submit_review';args={candidate:message.candidate_commit,decision:'approve',findings:[]};}
if(step==='reproduce' && !message.person_answer){name='ask_person';args={question:'Which value case should be checked?'};}
const env=request.mcp_servers.equipo.env,cap=JSON.parse(fs.readFileSync(env.EQUIPO_TOOL_CAPABILITY_FILE));
await new Promise((resolve,reject)=>{const c=net.createConnection(env.EQUIPO_TOOL_SOCKET,()=>c.write(JSON.stringify({capability:cap.secret,instance_id:cap.instance_id,task_id:cap.task_id,attempt:cap.attempt,fence:cap.fence,request_id:name,name,arguments:args})+'\n'));c.on('data',raw=>{const v=JSON.parse(raw);c.end();v.ok?resolve():reject(Error('tool rejected'));});c.on('error',reject);});
diff --git a/internal/runner/workflow_turn.go b/internal/runner/workflow_turn.go
index 48f444a9..6b375146 100644
--- a/internal/runner/workflow_turn.go
+++ b/internal/runner/workflow_turn.go
@@ -128,11 +128,10 @@ drained:
if err = pump.Flush(ctx, 128); err != nil {
return err
}
- message := string(marshal(struct {
- Step string
- Brief runnerproto.RunnerBrief
- Evidence []team.Artifact
- }{r.Claim.Assignment.StepKey, r.Claim.Brief, artifacts}))
+ message, err := buildTurnPrompt(r.Claim, artifacts)
+ if err != nil {
+ return err
+ }
turn := 0
dispatch := func() error {
if turn >= 24 {
@@ -142,8 +141,12 @@ drained:
return err
}
suffix := strconv.Itoa(turn)
+ payload, err := turnIntentPayload(r.Agent.Provider, r.Agent.Model, message)
+ if err != nil {
+ return err
+ }
q := r.request("turn-intent-" + suffix)
- q.Intent = &team.IntentSpec{Key: q.RequestID, Operation: team.OpProviderCall, Payload: marshal(map[string]string{"provider": r.Agent.Provider, "model": r.Agent.Model, "prompt": message}), Reserve: team.Usage{Calls: 1, InputTokens: 32000, OutputTokens: 4000, CostUnavailable: true}}
+ q.Intent = &team.IntentSpec{Key: q.RequestID, Operation: team.OpProviderCall, Payload: payload, Reserve: team.Usage{Calls: 1, InputTokens: 32000, OutputTokens: 4000, CostUnavailable: true}}
var intent team.ActionID
if err := retryAuthority(ctx, func() error { return s.api.Call(ctx, "intend", q, &intent) }); err != nil {
return err