From aeb3e9e6960cd8d7f076fb840cc87a2847157a64 Mon Sep 17 00:00:00 2001 From: Ara Ghukasyan <329227198+ZeroPoint95@users.noreply.github.com> Date: Tue, 24 Nov 2026 22:08:33 -0500 Subject: [PATCH 1/6] tasks: a task that only reads its ground says so when it starts, to its worker, and when it lands A proposal gave a repository as its ground and named no file by path, so the task was a reference: an empty folder of its own, the repository left alone. The receipt said "It works in ", the worker was told nothing, built the project in its own folder and reported it integrated, and the landing had no line. The conversation told the person to run it from the repository. All three now say the ground does not change and where the work is. A manager is also told a task is not a way round a member that did not start. Co-Authored-By: Claude Fable 5.2 --- internal/manual/chat/how-tasks-run.md | 16 +++++ internal/manual/chat/team-manager.md | 5 ++ internal/session/task.go | 16 +++++ internal/session/task_brief.go | 40 +++++++++---- internal/session/task_home_copy_test.go | 9 ++- internal/session/task_reference_test.go | 77 +++++++++++++++++++++++++ internal/session/task_run_belt.go | 27 +++++++++ internal/session/team.go | 3 +- internal/session/workspace_ownership.go | 7 ++- 9 files changed, 182 insertions(+), 18 deletions(-) create mode 100644 internal/session/task_reference_test.go diff --git a/internal/manual/chat/how-tasks-run.md b/internal/manual/chat/how-tasks-run.md index 68e56eb455..28f4f1fdf3 100644 --- a/internal/manual/chat/how-tasks-run.md +++ b/internal/manual/chat/how-tasks-run.md @@ -108,6 +108,22 @@ something the evidence did not — though nothing ever overrides a path you name The check runs where the work stood, cut from the same ground; the card and the `/history` row carry the ground and how the task stood on it. +## A task built my project somewhere else — it only read my repository, nothing changed in my folder, where is what the task made + +A task whose whole contract names no file to make or change is treated as reading its +repository: it gets an empty folder of its own and the repository is left alone. Naming a +project in words is not naming a file, so a brief such as "build the app in the MacStats +repo" reads this way. + +Such a task says so three times. Its receipt reads `It reads and writes only in a +folder of its own, so nothing in changes`, and says to stop it and propose it again +naming the files under that folder it makes or changes. Its worker is told the folder is to +read, not to change, and never to report the work as being there. Its landing ends `it +changed nothing in : what it made is in `. + +To have the work done in the repository, name a file under it in the brief, in what to +produce or in the done-when, as a path such as `Sources/App/main.swift`, or say "work here". + ## Does a task touch my working copy? — where does my task work, what the card calls the task's directory **A quick task is the exception, and not a small one.** It has no checkout and no branch diff --git a/internal/manual/chat/team-manager.md b/internal/manual/chat/team-manager.md index eb866f4282..637f7f11b2 100644 --- a/internal/manual/chat/team-manager.md +++ b/internal/manual/chat/team-manager.md @@ -417,6 +417,11 @@ on one waits for you. | `team_link` | records a file, pull request, issue or job the crew made as the crew's work, so the desktop app lists it with the crew (see **Link what the crew made**) | no | | `team_raise` | raises a conflict to the manager above every party (see **Conflicts between members and teams**); members have it too | no | +A manager hands work to members. It is told a task (`propose_task`) is not a member: a task +is for work no member is there for, or for when you ask for one, and never a way round a +member that did not start. When a member did not start, `team_send` says why, and the +manager is to tell you that. + ## Link what the crew made — team_link, add a file or pull request to the crew A manager records what its crew produced with `team_link`: `ref` is a file path (relative to diff --git a/internal/session/task.go b/internal/session/task.go index fe850994a5..731d1918db 100644 --- a/internal/session/task.go +++ b/internal/session/task.go @@ -1233,6 +1233,12 @@ func taskStandSentence(stand taskStand) string { switch { case stand.dir == "": return "" + case stand.mode == TaskModeReference && !HoldsHomeFolder(stand.dir): + // A REFERENCE IS SAID AS ONE, in the same breath as the start. "It + // works in " was true of where the task looks and false of + // where its work goes, and the proposer told the person the work was + // in the ground (task_brief.go's [copyOnto] has the run). + return taskReadsSentence(stand.dir) case stand.rung == taskGroundBrief: return "It works in " + stand.dir + ", the one folder its brief names the work in." case stand.rung == taskGroundSaid && !stand.kept: @@ -1241,6 +1247,16 @@ func taskStandSentence(stand taskStand) string { return "" } +// taskReadsSentence is what a proposer reads when its task only reads the +// ground: where the work will be, that the ground does not change, and what to +// do when that is not what was meant. The home folder has its own sentence +// ([homeTaskRedirect]). +func taskReadsSentence(dir string) string { + dir = cleanFolder(dir) + return "It reads " + dir + " and writes only in a folder of its own, so nothing in " + dir + " changes: this proposal named no file to make or change there. " + + "If the work is meant to change " + dir + ", stop this task and propose it again naming the files under " + dir + " it makes or changes." +} + // taskHandoffWakeSentence is what EVERY handoff receipt ends with, and it is one // sentence because it answers one question: what does the model do now? // diff --git a/internal/session/task_brief.go b/internal/session/task_brief.go index 310247e163..5ead88089b 100644 --- a/internal/session/task_brief.go +++ b/internal/session/task_brief.go @@ -376,9 +376,11 @@ type taskCopy struct { // the ground's to bind, and only what that rule leaves behind may be // considered as another task's tree. trees string - // readsHome is the home folder, or a folder holding it, when this task reads it - // from a folder of its own. It binds nothing: the folder is not a copy. - readsHome string + // reads is the ground this task only reads, from a folder of its own + // ([TaskModeReference]): the home folder or one holding it, or a repository + // its contract named no file to make or change in. It binds nothing: the + // folder is not a copy. + reads string } // newTaskCopy is the ONE PLACE A FOLDER IS SPELLED FOR THIS TYPE, and it exists @@ -651,11 +653,18 @@ func copyOnto(ground string, mode TaskMode, dir string, place Place) taskCopy { case TaskModeWorktree, TaskModeMirror: return newTaskCopyOf(ground, dir, place.Work(), place.Trees()) case TaskModeReference: - if HoldsHomeFolder(ground) { - own := standingOn(dir) - own.readsHome = cleanFolder(ground) - return own + // A REFERENCE WORKER IS TOLD ITS GROUND IS NOT ITS FOLDER, whatever the + // ground is. It used to be told only over the home folder. Measured + // 2026-11-23: a task whose proposal gave a repository as its ground, + // and whose brief named no file by path, was a reference; its worker + // woke in an empty folder, built the whole project there, and reported + // it "integrated", and the conversation told the person to run it from + // the repository, where nothing had changed. + own := standingOn(dir) + if canonicalPath(cleanFolder(ground)) != canonicalPath(cleanFolder(dir)) { + own.reads = cleanFolder(ground) } + return own } return standingOn(dir) } @@ -867,14 +876,21 @@ func (c taskCopy) note(sections ...string) string { return note } -// ownFolderNote tells a worker on the home folder where its output belongs, since -// the task was given no copy to work in and a person has to find what it made. +// ownFolderNote tells a worker that only reads its ground where its output +// belongs, since the task was given no copy to work in and a person has to find +// what it made. func (c taskCopy) ownFolderNote() string { - if c.readsHome == "" { + if c.reads == "" { return "" } - return c.readsHome + " is yours to read, not to change. Everything you make goes in " + c.dir + - ", your own folder. In your report, say where in that folder the results are." + return taskReadsNote(c.reads, c.dir) +} + +// taskReadsNote is the one sentence a worker that only reads its ground is +// given, for a node and for a run alike. +func taskReadsNote(ground, dir string) string { + return ground + " is yours to read, not to change. Everything you make goes in " + dir + + ", your own folder, and stays there: nothing you make reaches " + ground + ". In your report, say where in that folder the results are, and never say the work is in " + ground + "." } // names answers whether EITHER folder this map moves is spelled as a whole path diff --git a/internal/session/task_home_copy_test.go b/internal/session/task_home_copy_test.go index 3750f4fad6..68a35ff767 100644 --- a/internal/session/task_home_copy_test.go +++ b/internal/session/task_home_copy_test.go @@ -95,8 +95,13 @@ func TestWorkerOnHomeIsToldWhereOutputGoesAndToReportIt(t *testing.T) { project := filepath.Join(home, "project") plain := composeBrief(briefWhole, "read the docs", "summarise", "", "", "", AdmissionContext{}, taskOrigin{}, taskCopyFor(taskTree{dir: dir, ground: project, mode: TaskModeReference})) - if strings.Contains(plain, "yours to read") { - t.Fatalf("a reference on a project changed its brief:\n%s", plain) + // A reference on a project is told the same: its folder is not the project + // either, and a worker told nothing built there and reported the project + // changed (task_reference_test.go). + for _, want := range []string{project + " is yours to read", "Everything you make goes in " + dir, "never say the work is in " + project} { + if !strings.Contains(plain, want) { + t.Fatalf("a reference on a project lacks %q:\n%s", want, plain) + } } } diff --git a/internal/session/task_reference_test.go b/internal/session/task_reference_test.go new file mode 100644 index 0000000000..00990f301f --- /dev/null +++ b/internal/session/task_reference_test.go @@ -0,0 +1,77 @@ +package session + +import ( + "path/filepath" + "strings" + "testing" +) + +// A TASK THAT ONLY READS ITS GROUND SAYS SO AT ALL THREE ENDS: the proposer's +// receipt, the worker's own words, and the landing. The run this is from: a +// proposal gave a repository as its ground and named no file by path, the +// worker built the project in its own empty folder and reported it +// "integrated", and nothing told anybody the repository was untouched. +func TestAReferenceTaskSaysItsGroundDoesNotChange(t *testing.T) { + root := t.TempDir() + ground, own := filepath.Join(root, "MacStats"), filepath.Join(root, "trees", "1") + + said := taskStandSentence(taskStand{dir: ground, rung: taskGroundSaid, mode: TaskModeReference}) + for _, want := range []string{"It reads " + ground, "nothing in " + ground + " changes", "propose it again naming the files"} { + if !strings.Contains(said, want) { + t.Errorf("the receipt lacks %q:\n%s", want, said) + } + } + if strings.Contains(said, "It works in") { + t.Errorf("the receipt still says the task works in the ground it only reads:\n%s", said) + } + if got := taskStandSentence(taskStand{dir: ground, rung: taskGroundSaid, mode: TaskModeWorktree}); !strings.HasPrefix(got, "It works in "+ground) { + t.Errorf("a task that works in its ground is said as %q", got) + } + + note := copyOnto(ground, TaskModeReference, own, Place{}).ownFolderNote() + for _, want := range []string{ground + " is yours to read, not to change", "Everything you make goes in " + own, "never say the work is in " + ground} { + if !strings.Contains(note, want) { + t.Errorf("the worker's note lacks %q:\n%s", want, note) + } + } + if got := copyOnto(ground, TaskModeReference, ground, Place{}).ownFolderNote(); got != "" { + t.Errorf("a reference standing in its own ground was given a note: %q", got) + } + if got := copyOnto(ground, TaskModeWorktree, own, Place{}).ownFolderNote(); got != "" { + t.Errorf("a worktree was told its ground is read-only: %q", got) + } + + line := referenceLandingLine(taskTree{dir: own, ground: ground, mode: TaskModeReference}) + if line != "it changed nothing in "+ground+": what it made is in "+own { + t.Errorf("the landing line is %q", line) + } + if got := beltLandingLine(RunLanding{Line: line}); got != line { + t.Errorf("the landing's one line is %q", got) + } + for _, tree := range []taskTree{ + {dir: own, ground: ground, mode: TaskModeWorktree}, + {dir: ground, ground: ground, mode: TaskModeReference}, + {dir: own, mode: TaskModeReference}, + } { + if got := referenceLandingLine(tree); got != "" { + t.Errorf("%+v was given a reference landing: %q", tree, got) + } + } + + brief := withHomeReadingNote(Place{}, "Build it.", taskStand{dir: ground, mode: TaskModeReference}) + if !strings.Contains(brief, ground+" is yours to read, not to change") || !strings.Contains(brief, "your assigned working directory") { + t.Errorf("a run's workers are not told their ground is read-only:\n%s", brief) + } + if got := withHomeReadingNote(Place{}, "Build it.", taskStand{dir: ground, mode: TaskModeWorktree}); got != "Build it." { + t.Errorf("a run that works in its ground was told otherwise:\n%s", got) + } +} + +// A MANAGER IS TOLD A TASK IS NOT A WAY ROUND A MEMBER THAT DID NOT START. +func TestTheManagersLawsSayWhenATaskIsUsed(t *testing.T) { + for _, want := range []string{"A task (propose_task) is not a member", "never to get round a member that did not start"} { + if !strings.Contains(teamManagerLaws, want) { + t.Errorf("the manager's laws lack %q", want) + } + } +} diff --git a/internal/session/task_run_belt.go b/internal/session/task_run_belt.go index 09d2f61f6e..25515a4f35 100644 --- a/internal/session/task_run_belt.go +++ b/internal/session/task_run_belt.go @@ -2328,6 +2328,29 @@ func (a *Agent) releaseBeltRun(run *beltRun) { // branch the conversation's note names is the ground's, and a merge that would // not go in answers with the sentence that names the kept branch and the files. func (a *Agent) landBeltRun(ctx context.Context, engine RunEngine, run *beltRun) RunLanding { + landing := a.landBeltRunHome(ctx, engine, run) + // A RUN THAT ONLY READ ITS GROUND SAYS WHERE ITS WORK IS. It has no branch + // and nothing to merge, so its landing had no line at all, and the + // conversation was handed the worker's own account of the work with nothing + // saying the ground was untouched (task_brief.go's [copyOnto] has the run). + if line := referenceLandingLine(run.tree); line != "" { + landing.Line = line + } + return landing +} + +// referenceLandingLine is the landing of a tree that only read its ground: +// where what it made is, and that the ground did not change. Empty for every +// other tree. +func referenceLandingLine(tree taskTree) string { + if tree.mode != TaskModeReference || tree.workspaceSet != nil || tree.dir == "" || tree.ground == "" || + canonicalPath(cleanFolder(tree.dir)) == canonicalPath(cleanFolder(tree.ground)) { + return "" + } + return "it changed nothing in " + cleanFolder(tree.ground) + ": what it made is in " + cleanFolder(tree.dir) +} + +func (a *Agent) landBeltRunHome(ctx context.Context, engine RunEngine, run *beltRun) RunLanding { if run.tree.workspaceSet != nil { return a.landWorkspaceSet(ctx, engine, run) } @@ -2378,6 +2401,10 @@ func (a *Agent) bringBeltRunHome(run *beltRun, landing RunLanding) RunLanding { landing.Branch = branch } home := withReport("its work is in "+run.ground+" on "+landing.Branch, said) + if line := referenceLandingLine(run.tree); line != "" { + // A run that only read its ground left nothing in it to point at. + home = line + } if _, err := run.store.AddNote(run.root, run.root, home); err != nil { if g := a.graph(); g != nil { g.planNote("the run's homecoming note failed: " + err.Error()) diff --git a/internal/session/team.go b/internal/session/team.go index 2421b6f511..844816db16 100644 --- a/internal/session/team.go +++ b/internal/session/team.go @@ -1596,7 +1596,8 @@ const teamRoleWithdrawn = "You are no longer the manager or a member of any team // teamManagerLaws is how a manager works, stated once in the role. The verbs' // own descriptions carry how each is called. const teamManagerLaws = "Seven laws:\n" + - "1. Hand real work to members with team_send, or team_start for a new member, rather than doing it yourself, and keep track with team_status and team_read. Use team_add for an existing conversation and team_remove to release a membership without stopping work. Asked what is happening, answer from the team.\n" + + "1. Hand real work to members with team_send, or team_start for a new member, rather than doing it yourself, and keep track with team_status and team_read. Use team_add for an existing conversation and team_remove to release a membership without stopping work. Asked what is happening, answer from the team. " + + "A task (propose_task) is not a member: use one only for work no member is here for, or when the person asks for a task, and never to get round a member that did not start. When a member did not start, team_send's answer says why: tell the person that.\n" + "2. The person outranks you: what they say in a member's own conversation stands over your directive, and a conflict goes to them.\n" + "3. You cannot answer a member's permission prompt; tell the person it is waiting.\n" + "4. You direct only the members who report to you, one level down: a team under yours is its manager's to run, so you direct that manager, never its members. A member team_status marks `reports to` another team is shared: read it and send it notes, never a directive or a stop.\n" + diff --git a/internal/session/workspace_ownership.go b/internal/session/workspace_ownership.go index 24d29e62ab..fe8f9a985f 100644 --- a/internal/session/workspace_ownership.go +++ b/internal/session/workspace_ownership.go @@ -101,11 +101,12 @@ func homeTaskRedirect(dir string) string { } // withHomeReadingNote is [taskCopy.ownFolderNote] for a run, whose workers learn -// their folder as the assigned working directory and read the run's words. +// their folder as the assigned working directory and read the run's words. It +// is said over every ground a run only reads, the home folder or not. func withHomeReadingNote(place Place, brief string, stand taskStand) string { ground := canonicalPath(strings.TrimSpace(stand.dir)) - if stand.workspaceSet != nil || preparedTaskMode(place, ground, stand.mode) != TaskModeReference || !HoldsHomeFolder(ground) { + if stand.workspaceSet != nil || ground == "" || preparedTaskMode(place, ground, stand.mode) != TaskModeReference { return brief } - return brief + "\n\n" + cleanFolder(stand.dir) + " is yours to read, not to change. Everything you make goes in your assigned working directory. In your report, say where in that folder the results are." + return brief + "\n\n" + taskReadsNote(cleanFolder(stand.dir), "your assigned working directory") } From 025de95cceb4fd5bc25691a21923dd25647323bc Mon Sep 17 00:00:00 2001 From: Ara Ghukasyan <329227198+ZeroPoint95@users.noreply.github.com> Date: Tue, 24 Nov 2026 22:09:11 -0500 Subject: [PATCH 2/6] docs: change entry for a reference task saying so (#2909) Co-Authored-By: Claude Fable 5.2 --- .../unreleased/2909-reference-task-says-so.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 docs/changes/unreleased/2909-reference-task-says-so.md diff --git a/docs/changes/unreleased/2909-reference-task-says-so.md b/docs/changes/unreleased/2909-reference-task-says-so.md new file mode 100644 index 0000000000..89d630dca3 --- /dev/null +++ b/docs/changes/unreleased/2909-reference-task-says-so.md @@ -0,0 +1,16 @@ +--- +kind: changed +title: A task that only reads its folder says so when it starts, to its worker, and when it lands +pr: 2909 +surface: [engine, chat] +invalidates: + - "A task whose stand is a reference (TaskModeReference, a ground it only reads) got the same receipt as any task: \"It works in , the folder this proposal gave as its ground.\" or \"It works in , the one folder its brief names the work in.\" Outside the home folder its receipt now reads \"It reads and writes only in a folder of its own, so nothing in changes: this proposal named no file to make or change there. If the work is meant to change , stop this task and propose it again naming the files under it makes or changes.\" The home folder's sentence is as it was." + - "A reference worker was told \" is yours to read, not to change. Everything you make goes in , your own folder. In your report, say where in that folder the results are.\" only when its ground held the home folder (taskCopy.readsHome, withHomeReadingNote); over any other ground it was told nothing. Every reference worker whose folder is not its ground is now told \" is yours to read, not to change. Everything you make goes in , your own folder, and stays there: nothing you make reaches . In your report, say where in that folder the results are, and never say the work is in .\" (taskReadsNote; the field is taskCopy.reads)." + - "A run that only read its ground landed with no line of its own (RunLanding.Line empty, no branch), and its page's homecoming note read \"its work is in on \". Its landing line and that note now read \"it changed nothing in : what it made is in \" (referenceLandingLine)." + - "The manager's first law ended \"Asked what is happening, answer from the team.\" It now adds \"A task (propose_task) is not a member: use one only for work no member is here for, or when the person asks for a task, and never to get round a member that did not start. When a member did not start, team_send's answer says why: tell the person that.\" The law's earlier sentences are as they were." +--- + +A proposal that named a repository as its ground and no file by path was read as +work that only reads it. The worker built the project in its own folder, reported +it integrated, and the conversation told the person to run it from a repository +nothing had been written to. From 648ea9d7611c546c3a4079c7615a8d487c444e89 Mon Sep 17 00:00:00 2001 From: Ara Ghukasyan <329227198+ZeroPoint95@users.noreply.github.com> Date: Tue, 24 Nov 2026 23:16:37 -0500 Subject: [PATCH 3/6] tasks: final review round 1 repairs for a reference saying so A reference that joined a writing run was told it only reads; a joined task is now told what is true of the run it joined. The receipt's remedy asked for file names that do not work unless given by full path. A reference no longer prints the in-place redirect, and a home-folder ground given as the proposal's ground gets the home sentence. A reference run now lands without calling the engine's landing, which failed on a folder that is not a repository and filed a failure note. Co-Authored-By: Claude Fable 5.2 --- .../unreleased/2909-reference-task-says-so.md | 8 +- internal/manual/chat/how-tasks-run.md | 17 +- internal/session/task.go | 57 +++++-- internal/session/task_reference_test.go | 152 +++++++++++++++++- internal/session/task_run_belt.go | 116 +++++++------ internal/session/taskrouting.go | 2 +- internal/session/workspace_ownership.go | 4 +- 7 files changed, 279 insertions(+), 77 deletions(-) diff --git a/docs/changes/unreleased/2909-reference-task-says-so.md b/docs/changes/unreleased/2909-reference-task-says-so.md index 89d630dca3..1173a7bbca 100644 --- a/docs/changes/unreleased/2909-reference-task-says-so.md +++ b/docs/changes/unreleased/2909-reference-task-says-so.md @@ -4,9 +4,11 @@ title: A task that only reads its folder says so when it starts, to its worker, pr: 2909 surface: [engine, chat] invalidates: - - "A task whose stand is a reference (TaskModeReference, a ground it only reads) got the same receipt as any task: \"It works in , the folder this proposal gave as its ground.\" or \"It works in , the one folder its brief names the work in.\" Outside the home folder its receipt now reads \"It reads and writes only in a folder of its own, so nothing in changes: this proposal named no file to make or change there. If the work is meant to change , stop this task and propose it again naming the files under it makes or changes.\" The home folder's sentence is as it was." - - "A reference worker was told \" is yours to read, not to change. Everything you make goes in , your own folder. In your report, say where in that folder the results are.\" only when its ground held the home folder (taskCopy.readsHome, withHomeReadingNote); over any other ground it was told nothing. Every reference worker whose folder is not its ground is now told \" is yours to read, not to change. Everything you make goes in , your own folder, and stays there: nothing you make reaches . In your report, say where in that folder the results are, and never say the work is in .\" (taskReadsNote; the field is taskCopy.reads)." - - "A run that only read its ground landed with no line of its own (RunLanding.Line empty, no branch), and its page's homecoming note read \"its work is in on \". Its landing line and that note now read \"it changed nothing in : what it made is in \" (referenceLandingLine)." + - "A task whose stand is a reference (TaskModeReference, a ground it only reads) was told so on its receipt only when `where` named a folder holding the home folder (homeTaskRedirect). Where the proposal's `ground` or its brief had chosen the folder, the receipt read \"It works in , the folder this proposal gave as its ground.\" or \"It works in , the one folder its brief names the work in.\", the home folder included; on the other rungs it had no sentence about the folder. On every rung its receipt now reads \"It reads and writes only in a folder of its own, so nothing in changes: this proposal named no file there by full path. If the work is meant to change , stop this task and propose it again naming the files it makes or changes by their full path under .\" (taskReadsSentence), or over the home folder \"The task reads and keeps what it makes in its own folder; nothing in changes.\" whichever door named the folder." + - "A reference worker was told \" is yours to read, not to change. Everything you make goes in , your own folder. In your report, say where in that folder the results are.\" only when its ground held the home folder (taskCopy.readsHome, withHomeReadingNote); over any other ground it was told nothing. Every reference worker whose folder is not its ground is now told \" is yours to read, not to change. Everything you make goes in , your own folder, and stays there: nothing you make reaches . In your report, say where in that folder the results are, and never say the work is in .\" (taskReadsNote; the field is taskCopy.reads, and the run's helper is withTaskReadsNote)." + - "A run that only read its ground was handed to the engine's landing, which failed in its folder with \"fatal: not a git repository\": a plan note \"the run's landing failed\" was filed, the landing had no line (RunLanding.Line empty, no branch) and the run's page got no homecoming note. Such a run is no longer handed to the engine's landing (landReferenceRun): its landing line and its page's homecoming note both read \"it changed nothing in : what it made is in \" (referenceLandingLine)." + - "A reference whose proposal asked for `where: \"in place\"` inside a repository had the redirect \"in place was asked for, and is a repository — the work goes on a branch cut from it instead\" printed on its receipt. The stand still carries that redirect, and the receipt of a reference no longer prints it (taskStandRedirect)." + - "A hand-off that joined a live run was told about its own stand: a reference that joined a run working in a copy of the same ground got the read-only receipt and its worker the read-only note. The receipt sentence and the worker's note of a joined hand-off are now decided by the mode of the run it joined (startOrJoinTaskRunVia answers that mode)." - "The manager's first law ended \"Asked what is happening, answer from the team.\" It now adds \"A task (propose_task) is not a member: use one only for work no member is here for, or when the person asks for a task, and never to get round a member that did not start. When a member did not start, team_send's answer says why: tell the person that.\" The law's earlier sentences are as they were." --- diff --git a/internal/manual/chat/how-tasks-run.md b/internal/manual/chat/how-tasks-run.md index 28f4f1fdf3..c086c5338a 100644 --- a/internal/manual/chat/how-tasks-run.md +++ b/internal/manual/chat/how-tasks-run.md @@ -113,16 +113,19 @@ row carry the ground and how the task stood on it. A task whose whole contract names no file to make or change is treated as reading its repository: it gets an empty folder of its own and the repository is left alone. Naming a project in words is not naming a file, so a brief such as "build the app in the MacStats -repo" reads this way. +repo" reads this way. So does a relative path such as `Sources/App/main.swift` when +neither the file nor the folder that would hold it is there yet. Such a task says so three times. Its receipt reads `It reads and writes only in a folder of its own, so nothing in changes`, and says to stop it and propose it again -naming the files under that folder it makes or changes. Its worker is told the folder is to -read, not to change, and never to report the work as being there. Its landing ends `it -changed nothing in : what it made is in `. - -To have the work done in the repository, name a file under it in the brief, in what to -produce or in the done-when, as a path such as `Sources/App/main.swift`, or say "work here". +naming the files it makes or changes by their full path under that folder. Its worker is +told the folder is to read, not to change, and never to report the work as being there. A +task run as a run ends its landing `it changed nothing in : what it made is in `; the older single-task road lands without that line. A task that joins a run +already underway is told what is true of that run instead, since it shares the run's copy. + +To have the work done in the repository, name a file under it by full path in the brief, in +what to produce or in the done-when, such as `~/MacStats/Sources/App/main.swift`. ## Does a task touch my working copy? — where does my task work, what the card calls the task's directory diff --git a/internal/session/task.go b/internal/session/task.go index 731d1918db..bc63405b48 100644 --- a/internal/session/task.go +++ b/internal/session/task.go @@ -1091,14 +1091,18 @@ func (a *Agent) startApprovedHandoff(ctx context.Context, p *stagedProposal, spe ctx = withProgramWish(ctx, programWish{thinking: spec.thinking, carry: a.programCarryOf(prior, via.Name)}) } a.expectRunSource(p.id, spec.source) - joined, err := a.startOrJoinTaskRunVia(context.WithoutCancel(ctx), p.id, spec.title, proposalRunDescription(spec, via, placement), spec.dependsOn, stand, question, via, asked...) + mode, joined, err := a.startOrJoinTaskRunVia(context.WithoutCancel(ctx), p.id, spec.title, proposalRunDescription(spec, via, placement), spec.dependsOn, stand, question, via, asked...) a.rollbackFailedProgramStart(via, p.id, prior, err) + if joined { + stand.mode = mode + } return handoffStart{joined: joined, stand: stand, asked: asked, placed: placement.sentence}, err } // handoffStart is what starting an approved hand-off settled: whether it -// joined a run already underway, the stand it runs on, the programs asked -// for, and the sentence that says which computer it was placed on. +// joined a run already underway, the stand it runs on (in the joined run's +// mode when it joined one), the programs asked for, and the sentence that says +// which computer it was placed on. type handoffStart struct { joined bool stand taskStand @@ -1143,7 +1147,14 @@ func (a *Agent) handoffAnswer(p *stagedProposal, spec taskSpec, elsewhere string return refusal.Error(), true, true } if err == nil { - receipt := taskReceipt(p.id, spec, TaskRunning, p.stand, elsewhere) + said := p.stand + if joined { + // A TASK THAT JOINED A RUN IS SAID AS THAT RUN STANDS. It shares the + // run's copy, so a receipt read off its own stand told a reference + // that joined a worktree that nothing in the ground would change. + said.mode = stand.mode + } + receipt := taskReceipt(p.id, spec, TaskRunning, said, elsewhere) switch { case via != nil: receipt = delegateStartedReceipt(p.id, spec.title, strings.Join(asked, ", "), delegateReceipt(canonicalPath(stand.dir), *via, a.runRowCopy(p.id)), elsewhere) @@ -1211,10 +1222,10 @@ func taskReceipt(id uint64, spec taskSpec, state TaskState, stand taskStand, els } if state == TaskQueued { result := fmt.Sprintf("task %d queued%s: %s\nIt starts when the work it waits on has finished and a slot is free. %s", id, on, spec.title, taskHandoffWakeSentence) - return withElsewhere(withReport(withReport(result, taskStandSentence(stand)), stand.redirect), elsewhere) + return withElsewhere(withReport(withReport(result, taskStandSentence(stand)), taskStandRedirect(stand)), elsewhere) } result := fmt.Sprintf("task %d started%s: %s\nIt works from the brief alone, in a copy of its own. %s", id, on, spec.title, taskHandoffWakeSentence) - return withElsewhere(withReport(withReport(result, taskStandSentence(stand)), stand.redirect), elsewhere) + return withElsewhere(withReport(withReport(result, taskStandSentence(stand)), taskStandRedirect(stand)), elsewhere) } // taskStandSentence says WHERE the task works whenever that was read from the @@ -1227,13 +1238,19 @@ func taskReceipt(id uint64, spec taskSpec, state TaskState, stand taskStand, els // offered is accepted (it is somebody saying where the work is), and this line // is what makes a wrong one visible in the same breath rather than when the // work lands somewhere nobody looked. The rungs that read the conversation -// instead are silent here, as they always were: the work went where the -// conversation already is. +// instead are silent here when the task works in its ground: the work went +// where the conversation already is. A task that only reads its ground speaks +// on every rung, because its work goes somewhere else. func taskStandSentence(stand taskStand) string { switch { case stand.dir == "": return "" - case stand.mode == TaskModeReference && !HoldsHomeFolder(stand.dir): + case stand.mode == TaskModeReference && HoldsHomeFolder(stand.dir): + // The home folder has its own sentence, said here whichever door named + // it: only the `where` doors leave it on the stand as a redirect, and a + // home folder given as `ground` read "It works in ". + return homeTaskRedirect(stand.dir) + case stand.mode == TaskModeReference: // A REFERENCE IS SAID AS ONE, in the same breath as the start. "It // works in " was true of where the task looks and false of // where its work goes, and the proposer told the person the work was @@ -1247,14 +1264,32 @@ func taskStandSentence(stand taskStand) string { return "" } +// taskStandRedirect is the stand's redirect as a receipt prints it. A reference +// has said where its work goes ([taskStandSentence]) and cuts no branch, so the +// redirect a declined `in place` leaves on its stand +// ([groundModeAfterPlacement]) would contradict the sentence before it, and the +// home folder's redirect would say that sentence twice. +func taskStandRedirect(stand taskStand) string { + if stand.mode == TaskModeReference { + return "" + } + return stand.redirect +} + // taskReadsSentence is what a proposer reads when its task only reads the // ground: where the work will be, that the ground does not change, and what to // do when that is not what was meant. The home folder has its own sentence // ([homeTaskRedirect]). +// +// THE REMEDY IS A FULL PATH, because that is the one spelling that always +// counts: a relative path is read as work under the ground only when the file +// or its folder is already there ([groundHolds]), so "create +// Sources/App/main.swift" in a repository with no Sources folder was proposed +// again and was a reference again. func taskReadsSentence(dir string) string { dir = cleanFolder(dir) - return "It reads " + dir + " and writes only in a folder of its own, so nothing in " + dir + " changes: this proposal named no file to make or change there. " + - "If the work is meant to change " + dir + ", stop this task and propose it again naming the files under " + dir + " it makes or changes." + return "It reads " + dir + " and writes only in a folder of its own, so nothing in " + dir + " changes: this proposal named no file there by full path. " + + "If the work is meant to change " + dir + ", stop this task and propose it again naming the files it makes or changes by their full path under " + dir + "." } // taskHandoffWakeSentence is what EVERY handoff receipt ends with, and it is one diff --git a/internal/session/task_reference_test.go b/internal/session/task_reference_test.go index 00990f301f..54ea18e53d 100644 --- a/internal/session/task_reference_test.go +++ b/internal/session/task_reference_test.go @@ -1,7 +1,11 @@ package session import ( + "context" + "encoding/json" + "os" "path/filepath" + "strconv" "strings" "testing" ) @@ -16,7 +20,7 @@ func TestAReferenceTaskSaysItsGroundDoesNotChange(t *testing.T) { ground, own := filepath.Join(root, "MacStats"), filepath.Join(root, "trees", "1") said := taskStandSentence(taskStand{dir: ground, rung: taskGroundSaid, mode: TaskModeReference}) - for _, want := range []string{"It reads " + ground, "nothing in " + ground + " changes", "propose it again naming the files"} { + for _, want := range []string{"It reads " + ground, "nothing in " + ground + " changes", "propose it again naming the files it makes or changes by their full path under " + ground} { if !strings.Contains(said, want) { t.Errorf("the receipt lacks %q:\n%s", want, said) } @@ -45,9 +49,6 @@ func TestAReferenceTaskSaysItsGroundDoesNotChange(t *testing.T) { if line != "it changed nothing in "+ground+": what it made is in "+own { t.Errorf("the landing line is %q", line) } - if got := beltLandingLine(RunLanding{Line: line}); got != line { - t.Errorf("the landing's one line is %q", got) - } for _, tree := range []taskTree{ {dir: own, ground: ground, mode: TaskModeWorktree}, {dir: ground, ground: ground, mode: TaskModeReference}, @@ -58,11 +59,11 @@ func TestAReferenceTaskSaysItsGroundDoesNotChange(t *testing.T) { } } - brief := withHomeReadingNote(Place{}, "Build it.", taskStand{dir: ground, mode: TaskModeReference}) + brief := withTaskReadsNote(Place{}, "Build it.", taskStand{dir: ground, mode: TaskModeReference}) if !strings.Contains(brief, ground+" is yours to read, not to change") || !strings.Contains(brief, "your assigned working directory") { t.Errorf("a run's workers are not told their ground is read-only:\n%s", brief) } - if got := withHomeReadingNote(Place{}, "Build it.", taskStand{dir: ground, mode: TaskModeWorktree}); got != "Build it." { + if got := withTaskReadsNote(Place{}, "Build it.", taskStand{dir: ground, mode: TaskModeWorktree}); got != "Build it." { t.Errorf("a run that works in its ground was told otherwise:\n%s", got) } } @@ -75,3 +76,142 @@ func TestTheManagersLawsSayWhenATaskIsUsed(t *testing.T) { } } } + +// THE RECEIPT OF A REFERENCE SAYS ONE TRUE THING ABOUT WHERE ITS WORK GOES. A +// declined `in place` leaves a redirect naming a branch on the stand, and a +// reference cuts none; the home folder is said in its own sentence whether a +// `where` door or the proposal's `ground` named it. +func TestAReferenceReceiptSaysNoBranchAndTheHomeFolderOnce(t *testing.T) { + home := t.TempDir() + t.Setenv("HOME", home) + ground := filepath.Join(t.TempDir(), "MacStats") + spec := taskSpec{title: "the question"} + branch := whereRedirectSentence("in place", ground) + + reads := taskReceipt(7, spec, TaskRunning, taskStand{dir: ground, mode: TaskModeReference, rung: taskGroundSaid, redirect: branch}, "") + if !strings.Contains(reads, "It reads "+ground) || strings.Contains(reads, "branch cut from it") { + t.Errorf("a reference asked for in place is told about a branch:\n%s", reads) + } + if works := taskReceipt(7, spec, TaskRunning, taskStand{dir: ground, mode: TaskModeWorktree, rung: taskGroundSaid, redirect: branch}, ""); !strings.Contains(works, branch) { + t.Errorf("a task on a branch lost its redirect:\n%s", works) + } + + for _, stand := range []taskStand{ + {dir: home, mode: TaskModeReference, rung: taskGroundSaid}, + {dir: home, mode: TaskModeReference, rung: taskGroundNamed, redirect: homeTaskRedirect(home)}, + } { + for _, state := range []TaskState{TaskRunning, TaskQueued} { + receipt := taskReceipt(7, spec, state, stand, "") + if strings.Count(receipt, homeTaskRedirect(home)) != 1 || strings.Contains(receipt, "It works in "+home) { + t.Errorf("rung %q: the home folder's receipt is\n%s", stand.rung, receipt) + } + } + } +} + +// A REFERENCE RUN LANDS WITHOUT THE ENGINE. Its folder is no repository, so the +// engine's landing failed and filed a failure note for every such run; the +// landing is the one line, in the row's report and on the run's page. +// +// AND A TASK THAT JOINS IT IS TOLD THE RUN ONLY READS, whatever its own stand +// asked for: it works in the run's folder, which nothing lands from. +func TestAReferenceRunLandsWithItsLineAndNoEngineLanding(t *testing.T) { + t.Setenv("CODEAF_TASK_BELT", "bash") + double := newBeltRunDouble("the parser reads tokens") + // The engine's real landing, so that calling it would fail the way it did. + double.real = true + registerBeltRunEngine(t, double) + ground := newTestRepo(t) + sessionDir := t.TempDir() + agent, _ := newTestAgent(t, beltRunCompleter{text: "the parser reads tokens"}, func(config *Config) { + config.Workspace = ground + config.Place = Place{Dir: sessionDir} + config.SessionFile = filepath.Join(sessionDir, placeTranscript) + config.AskConsent = false + }) + if err := agent.startKnownTaskRun(context.Background(), 41, "explain the parser", "brief", nil, taskStand{dir: ground, mode: TaskModeReference, rung: taskGroundSaid}, ""); err != nil { + t.Fatalf("start the reference run: %v", err) + } + <-double.entered + double.mu.Lock() + workspace := double.spec.Workspace + double.mu.Unlock() + if err := agent.startKnownTaskRun(context.Background(), 42, "change the parser", "brief", nil, taskStand{dir: ground, mode: TaskModeWorktree, rung: taskGroundSaid}, ""); err != nil { + t.Fatalf("join the reference run: %v", err) + } + if task := beltRunTaskAt(t, sessionDir, "42"); task == nil || task.ParentID != "41" || !strings.Contains(task.Description, "is yours to read, not to change") { + t.Fatalf("a task that joined a run that only reads was not told so: %+v", task) + } + endBeltRun(t, agent, double) + + line := referenceLandingLine(taskTree{dir: workspace, ground: canonicalPath(ground), mode: TaskModeReference}) + if line == "" || !strings.Contains(line, "it changed nothing in "+canonicalPath(ground)) { + t.Fatalf("the run's folder %q and ground %q make no reference landing: %q", workspace, ground, line) + } + if double.lands() != 0 { + t.Errorf("the engine was asked to land a folder that is no repository %d times", double.lands()) + } + rows := agent.graph().runRows(41) + if len(rows) != 1 || !strings.Contains(rows[0].Report, line) { + t.Errorf("the settled row does not carry the landing line %q: %+v", line, rows) + } + if notes := strings.Join(beltRunNotes(t, sessionDir, "41"), "\n"); !strings.Contains(notes, line) || strings.Contains(notes, "its work is in") { + t.Errorf("the run's page does not say the landing line alone:\n%s", notes) + } + if logDir := agent.logDirectory(); logDir == "" { + t.Error("the conversation has no log directory to read plan notes from") + } else if log, _ := os.ReadFile(filepath.Join(logDir, "plandb.log")); strings.Contains(string(log), "landing failed") { + t.Errorf("a landing failure was filed for a run that had nothing to land:\n%s", log) + } +} + +// A REFERENCE THAT JOINS A RUN WORKING IN ITS GROUND IS TOLD WHAT IS TRUE OF +// THAT RUN. It shares the run's copy, which lands into the ground, so neither +// its receipt nor its worker may be told that nothing it makes reaches there. +func TestAReferenceThatJoinsAWritingRunIsNotToldItOnlyReads(t *testing.T) { + t.Setenv("CODEAF_TASK_BELT", "bash") + double := newBeltRunDouble("the run did the work") + registerBeltRunEngine(t, double) + sessionDir := t.TempDir() + ground := newTestRepo(t) + agent, _ := newTestAgent(t, beltRunCompleter{text: "the run did the work"}, func(config *Config) { + config.Workspace = ground + config.Place = Place{Dir: sessionDir} + config.AskConsent = false + config.TaskAutoApproveSeconds = 0 + }) + root, _, _, err := agent.StartTask(context.Background(), "open the run", false) + if err != nil { + t.Fatal(err) + } + <-double.entered + args, _ := json.Marshal(taskArguments{ + Title: "Explain the parser", Summary: "the proposed work", Brief: "say how the parser reads its input", + Deliverable: "a concise answer", Acceptance: "the question is answered", Ground: ground, + }) + proposal, ok := agent.stageTask(context.Background(), args).(*stagedProposal) + if !ok || proposal.stand.mode != TaskModeReference { + t.Fatalf("the proposal did not stage as a reference: %+v", proposal) + } + agent.ResolveTask(proposal.id, TaskAnswer{Approved: true}) + answer, failed, err := proposal.Commit(context.Background()) + if err != nil || failed { + t.Fatalf("propose_task: failed=%v err=%v answer=%q", failed, err, answer) + } + if !strings.Contains(answer, "It joined the work already underway and shares its copy.") { + t.Fatalf("the proposal did not join the live run:\n%s", answer) + } + for _, untrue := range []string{"It reads ", "nothing in " + canonicalPath(ground) + " changes"} { + if strings.Contains(answer, untrue) { + t.Errorf("the receipt of a task that joined a writing run says %q:\n%s", untrue, answer) + } + } + task := beltRunTaskAt(t, sessionDir, strconv.FormatUint(proposal.id, 10)) + if task == nil || task.ParentID != strconv.FormatUint(root, 10) { + t.Fatalf("the proposal is not a child of the live run: %+v", task) + } + if strings.Contains(task.Description, "yours to read") { + t.Errorf("the worker of a task that joined a writing run is told it only reads:\n%s", task.Description) + } + endBeltRun(t, agent, double) +} diff --git a/internal/session/task_run_belt.go b/internal/session/task_run_belt.go index 25515a4f35..a309d07c80 100644 --- a/internal/session/task_run_belt.go +++ b/internal/session/task_run_belt.go @@ -347,9 +347,10 @@ type RunLanding struct { // brought back to its ground ([Agent.landBeltRun]). Empty is an engine's own // landing, which commits on the copy's branch and merges nothing. Home string - // Line is a landing that says itself: a program's run, whose folder's - // ending ([ProgramFolderEnd.Sentence]) is the whole account of where its - // work is ([beltLandingLine]). Empty for every other run. + // Line is a landing that says itself ([beltLandingLine]): a program's run, + // whose folder's ending ([ProgramFolderEnd.Sentence]) is the whole account + // of where its work is, and a run that only read its ground + // ([referenceLandingLine]). Empty for every other run. Line string } @@ -590,7 +591,7 @@ func (e standsElsewhereError) Error() string { // An approved hand-off under the bash belt belongs to the run store and never to the session tree. func (a *Agent) startKnownTaskRun(ctx context.Context, id uint64, title, brief string, dependsOn []uint64, stand taskStand, question string) error { - _, err := a.startOrJoinTaskRunVia(ctx, id, title, brief, dependsOn, stand, question, nil) + _, _, err := a.startOrJoinTaskRunVia(ctx, id, title, brief, dependsOn, stand, question, nil) return err } @@ -606,7 +607,7 @@ func (a *Agent) startKnownTaskRun(ctx context.Context, id uint64, title, brief s // asked is the models the person asked the program to work with, resolved; // none means the conversation's crew ([Agent.delegateCrew]). func (a *Agent) startKnownTaskRunVia(ctx context.Context, id uint64, title, brief string, dependsOn []uint64, stand taskStand, question string, via *delegate.Delegate, asked ...string) error { - _, err := a.startOrJoinTaskRunVia(ctx, id, title, brief, dependsOn, stand, question, via, asked...) + _, _, err := a.startOrJoinTaskRunVia(ctx, id, title, brief, dependsOn, stand, question, via, asked...) return err } @@ -615,34 +616,36 @@ func (a *Agent) startKnownTaskRunVia(ctx context.Context, id uint64, title, brie // this door can know: a batch of hand-offs is one run, and which of them opened // it is decided here, under the start lock, and nowhere before. func (a *Agent) startOrJoinTaskRun(ctx context.Context, id uint64, title, brief string, dependsOn []uint64, stand taskStand, question string) (bool, error) { - return a.startOrJoinTaskRunVia(ctx, id, title, brief, dependsOn, stand, question, nil) + _, joined, err := a.startOrJoinTaskRunVia(ctx, id, title, brief, dependsOn, stand, question, nil) + return joined, err } // startOrJoinTaskRunVia is the one body behind every door above: the start -// lock, the join, the folder or the copy, the store and the first row. -func (a *Agent) startOrJoinTaskRunVia(ctx context.Context, id uint64, title, brief string, dependsOn []uint64, stand taskStand, question string, via *delegate.Delegate, asked ...string) (bool, error) { +// lock, the join, the folder or the copy, the store and the first row. A +// hand-off that joined answers the mode the run it joined stands in, which is +// the mode its own work now has whatever its stand asked for. +func (a *Agent) startOrJoinTaskRunVia(ctx context.Context, id uint64, title, brief string, dependsOn []uint64, stand taskStand, question string, via *delegate.Delegate, asked ...string) (TaskMode, bool, error) { a.taskStarting.Add(1) defer a.taskStarting.Add(-1) epoch, err := a.beltAdmissionEpoch() if err != nil { - return false, err + return "", false, err } engine := chatRunEngine g := a.graph() if engine == nil || g == nil || g.planPath() == "" { - return false, errRunRoadUnavailable + return "", false, errRunRoadUnavailable } if via == nil { stand, err = a.ownedRunPlacement(ctx, stand) if err != nil { - return false, err + return "", false, err } } - brief = withHomeReadingNote(a.config.Place, brief, stand) ctx, engine, err = a.placeTaskRunEngine(ctx, engine, stand, via != nil) if err != nil { - return false, err + return "", false, err } path := g.planPath() storeID := strconv.FormatUint(id, 10) @@ -686,11 +689,11 @@ func (a *Agent) startOrJoinTaskRunVia(ctx context.Context, id uint64, title, bri a.lockBeltStart() defer a.beltStartMu.Unlock() if err := a.checkBeltAdmission(epoch); err != nil { - return false, err + return "", false, err } live, err := a.joinOrWait(ctx, stand, id, title, brief, dependencies, via) if err != nil { - return false, err + return "", false, err } if live != nil { a.publishRunRow(g, TaskNotice{ @@ -708,8 +711,12 @@ func (a *Agent) startOrJoinTaskRunVia(ctx context.Context, id uint64, title, bri PlanTask: planStoreID(storeID), }) a.publishJoinedRunRows(g, live) - return true, nil + return preparedTaskMode(a.config.Place, live.ground, live.stand.mode), true, nil } + // THE READ-ONLY NOTE IS A RUN'S OWN, added once no live run took the work: + // a hand-off that joined was told what is true of the run it joined + // ([Agent.joinOrWait]). + brief = withTaskReadsNote(a.config.Place, brief, stand) // ADMISSION IS CHECKED BEFORE A FOLDER OR COPY IS TOUCHED. A held run seeds // only its plan store so stopping it cannot leave a repository claim behind; @@ -717,10 +724,12 @@ func (a *Agent) startOrJoinTaskRunVia(ctx context.Context, id uint64, title, bri admission := newRunAdmission(a.config.TaskMaxLoad, a.config.TaskMinFreeMB, a.config.ProfileDir, a.graph().lanes) held := admission != nil && !admission.MayStart() if held || taskPlacementOf(ctx).computer != nil { - return a.startDeferredBeltRun(ctx, engine, g, path, storeID, id, title, brief, stand, question, via, asked, admission, held) + joined, err := a.startDeferredBeltRun(ctx, engine, g, path, storeID, id, title, brief, stand, question, via, asked, admission, held) + return "", joined, err } - return a.startAdmittedBeltRun(ctx, engine, g, path, storeID, id, title, brief, stand, question, via, asked, admission) + joined, err := a.startAdmittedBeltRun(ctx, engine, g, path, storeID, id, title, brief, stand, question, via, asked, admission) + return "", joined, err } // startAdmittedBeltRun is the original synchronous road after admission: route @@ -990,8 +999,12 @@ func (a *Agent) joinOrWait(ctx context.Context, stand taskStand, id uint64, titl a.beltMu.Unlock() return nil, refusal } + // THE JOINED WORKER IS TOLD WHAT IS TRUE OF THE RUN IT JOINED. It works + // in that run's copy, so whether the ground is only read is the run's + // stand to say and never the hand-off's own: a reference that joined a + // worktree was told nothing it made reached a ground its work landed in. _, err := addJoinedTasks(ctx, live.store, []plandb.TaskSpec{{ - ID: storeID, ParentID: live.root, Title: title, Description: brief, Dependencies: dependencies, Model: crewWishOf(ctx).worker, + ID: storeID, ParentID: live.root, Title: title, Description: withTaskReadsNote(a.config.Place, brief, live.stand), Dependencies: dependencies, Model: crewWishOf(ctx).worker, }}) if err == nil { live.joined = append(live.joined, id) @@ -2328,32 +2341,12 @@ func (a *Agent) releaseBeltRun(run *beltRun) { // branch the conversation's note names is the ground's, and a merge that would // not go in answers with the sentence that names the kept branch and the files. func (a *Agent) landBeltRun(ctx context.Context, engine RunEngine, run *beltRun) RunLanding { - landing := a.landBeltRunHome(ctx, engine, run) - // A RUN THAT ONLY READ ITS GROUND SAYS WHERE ITS WORK IS. It has no branch - // and nothing to merge, so its landing had no line at all, and the - // conversation was handed the worker's own account of the work with nothing - // saying the ground was untouched (task_brief.go's [copyOnto] has the run). - if line := referenceLandingLine(run.tree); line != "" { - landing.Line = line - } - return landing -} - -// referenceLandingLine is the landing of a tree that only read its ground: -// where what it made is, and that the ground did not change. Empty for every -// other tree. -func referenceLandingLine(tree taskTree) string { - if tree.mode != TaskModeReference || tree.workspaceSet != nil || tree.dir == "" || tree.ground == "" || - canonicalPath(cleanFolder(tree.dir)) == canonicalPath(cleanFolder(tree.ground)) { - return "" - } - return "it changed nothing in " + cleanFolder(tree.ground) + ": what it made is in " + cleanFolder(tree.dir) -} - -func (a *Agent) landBeltRunHome(ctx context.Context, engine RunEngine, run *beltRun) RunLanding { if run.tree.workspaceSet != nil { return a.landWorkspaceSet(ctx, engine, run) } + if line := referenceLandingLine(run.tree); line != "" { + return a.landReferenceRun(run, line) + } landing, err := engine.Land(ctx, run.store, run.workspace, run.tree.checkBase, run.root) if err != nil { if stopped, _ := a.beltRunStopped(run); stopped { @@ -2367,6 +2360,37 @@ func (a *Agent) landBeltRunHome(ctx context.Context, engine RunEngine, run *belt return a.bringBeltRunHome(run, landing) } +// landReferenceRun is the landing of a run that only read its ground, and it +// asks the engine for nothing. Its folder is no repository, so the engine's +// landing failed with git's `fatal: not a git repository`, a failure note was +// filed for every such run, and the conversation was handed the worker's own +// account of the work with nothing saying the ground was untouched +// (task_brief.go's [copyOnto] has the run). There is no branch to merge and no +// copy to give back: the homecoming is the one line, on the run's page and in +// the landing alike. +func (a *Agent) landReferenceRun(run *beltRun, line string) RunLanding { + if !a.beginBeltHomecoming(run) { + return RunLanding{} + } + if _, err := run.store.AddNote(run.root, run.root, line); err != nil { + if g := a.graph(); g != nil { + g.planNote("the run's homecoming note failed: " + err.Error()) + } + } + return RunLanding{Line: line} +} + +// referenceLandingLine is the landing of a tree that only read its ground: +// where what it made is, and that the ground did not change. Empty for every +// other tree. +func referenceLandingLine(tree taskTree) string { + if tree.mode != TaskModeReference || tree.workspaceSet != nil || tree.dir == "" || tree.ground == "" || + canonicalPath(cleanFolder(tree.dir)) == canonicalPath(cleanFolder(tree.ground)) { + return "" + } + return "it changed nothing in " + cleanFolder(tree.ground) + ": what it made is in " + cleanFolder(tree.dir) +} + // bringBeltRunHome is the second half of a run's landing: the copy's branch // merged into the ground it was cut from, the person's unfinished work carried // across or the branch kept and the files named, the copy given back, and the @@ -2401,10 +2425,6 @@ func (a *Agent) bringBeltRunHome(run *beltRun, landing RunLanding) RunLanding { landing.Branch = branch } home := withReport("its work is in "+run.ground+" on "+landing.Branch, said) - if line := referenceLandingLine(run.tree); line != "" { - // A run that only read its ground left nothing in it to point at. - home = line - } if _, err := run.store.AddNote(run.root, run.root, home); err != nil { if g := a.graph(); g != nil { g.planNote("the run's homecoming note failed: " + err.Error()) @@ -2856,7 +2876,9 @@ func beltRunOutcomeNote(store *plandb.Store, rootID string, summary RunSummary, // go back to their own branch and bring the work in. This line is the one // account of a landing the conversation's model is given, and a model told // only `landed on task/x: 2 files` would tell the person a thing about their -// folder that nobody checked. +// folder that nobody checked. A run that only read its ground says itself the +// same way ([referenceLandingLine]): it has no branch, and its ground did not +// change. func beltLandingLine(landing RunLanding) string { if landing.Line != "" { return landing.Line diff --git a/internal/session/taskrouting.go b/internal/session/taskrouting.go index fa43dd32fe..618bb10ac0 100644 --- a/internal/session/taskrouting.go +++ b/internal/session/taskrouting.go @@ -1606,7 +1606,7 @@ func (a *Agent) retryRestoredPark(n uint64, parked *parkedHandoff) error { question := questionAtTaskHandoff(a.owedAsks) a.mu.Unlock() ctx := withCrewWish(context.Background(), a.proposalCrewWish(n, crewWish{effort: rec.Effort, worker: rec.Worker})) - _, err := a.startOrJoinTaskRunVia(ctx, n, parked.title, rec.Brief, rec.DependsOn, taskStand{dir: rec.Dir, mode: rec.StandMode}, question, nil, rec.Asked...) + _, _, err := a.startOrJoinTaskRunVia(ctx, n, parked.title, rec.Brief, rec.DependsOn, taskStand{dir: rec.Dir, mode: rec.StandMode}, question, nil, rec.Asked...) var none *crewroute.NoEligibleError switch { case err == nil: diff --git a/internal/session/workspace_ownership.go b/internal/session/workspace_ownership.go index fe8f9a985f..538e9e729a 100644 --- a/internal/session/workspace_ownership.go +++ b/internal/session/workspace_ownership.go @@ -100,10 +100,10 @@ func homeTaskRedirect(dir string) string { return "The task reads " + dir + " and keeps what it makes in its own folder; nothing in " + dir + " changes." } -// withHomeReadingNote is [taskCopy.ownFolderNote] for a run, whose workers learn +// withTaskReadsNote is [taskCopy.ownFolderNote] for a run, whose workers learn // their folder as the assigned working directory and read the run's words. It // is said over every ground a run only reads, the home folder or not. -func withHomeReadingNote(place Place, brief string, stand taskStand) string { +func withTaskReadsNote(place Place, brief string, stand taskStand) string { ground := canonicalPath(strings.TrimSpace(stand.dir)) if stand.workspaceSet != nil || ground == "" || preparedTaskMode(place, ground, stand.mode) != TaskModeReference { return brief From 82a0c3b6bf9f36320a50a0786550cd61dd995c74 Mon Sep 17 00:00:00 2001 From: Ara Ghukasyan <329227198+ZeroPoint95@users.noreply.github.com> Date: Tue, 24 Nov 2026 23:40:50 -0500 Subject: [PATCH 4/6] tasks: final review round 2 repairs for a reference saying so A writing task that joined a run which only reads its ground was told it had named no file and to propose again; it now has its own sentence. The read-only note was kept in the brief a rerun re-reads, and the ground's path inside it made the rerun a writing task; the note now goes only to the workers. The manual no longer promises a receipt to a typed /task, and the landing line appears once on the run's page. Co-Authored-By: Claude Fable 5.2 --- .../unreleased/2909-reference-task-says-so.md | 7 +- internal/manual/chat/how-tasks-run.md | 20 ++- internal/session/task.go | 27 +++- internal/session/task_reference_test.go | 121 +++++++++++++++++- internal/session/task_run_belt.go | 39 +++--- 5 files changed, 184 insertions(+), 30 deletions(-) diff --git a/docs/changes/unreleased/2909-reference-task-says-so.md b/docs/changes/unreleased/2909-reference-task-says-so.md index 1173a7bbca..9855f1eee1 100644 --- a/docs/changes/unreleased/2909-reference-task-says-so.md +++ b/docs/changes/unreleased/2909-reference-task-says-so.md @@ -4,11 +4,12 @@ title: A task that only reads its folder says so when it starts, to its worker, pr: 2909 surface: [engine, chat] invalidates: - - "A task whose stand is a reference (TaskModeReference, a ground it only reads) was told so on its receipt only when `where` named a folder holding the home folder (homeTaskRedirect). Where the proposal's `ground` or its brief had chosen the folder, the receipt read \"It works in , the folder this proposal gave as its ground.\" or \"It works in , the one folder its brief names the work in.\", the home folder included; on the other rungs it had no sentence about the folder. On every rung its receipt now reads \"It reads and writes only in a folder of its own, so nothing in changes: this proposal named no file there by full path. If the work is meant to change , stop this task and propose it again naming the files it makes or changes by their full path under .\" (taskReadsSentence), or over the home folder \"The task reads and keeps what it makes in its own folder; nothing in changes.\" whichever door named the folder." + - "A task whose stand is a reference (TaskModeReference, a ground it only reads) was told so on its receipt only when `where` named a folder holding the home folder (homeTaskRedirect). Where the proposal's `ground` or its brief had chosen the folder, the receipt read \"It works in , the folder this proposal gave as its ground.\" or \"It works in , the one folder its brief names the work in.\", the home folder included; on the other rungs it had no sentence about the folder. On every rung the receipt of a task the conversation's model proposes now reads \"It reads and writes only in a folder of its own, so nothing in changes: this proposal named no file there by full path. If the work is meant to change , stop this task and propose it again naming the files it makes or changes by their full path under .\" (taskReadsSentence), or over the home folder \"The task reads and keeps what it makes in its own folder; nothing in changes.\" whichever door named the folder. A task a person types with `/task` is handed no receipt sentence about its folder on the run road, and on the older single-task road only the stand's redirect, as before." - "A reference worker was told \" is yours to read, not to change. Everything you make goes in , your own folder. In your report, say where in that folder the results are.\" only when its ground held the home folder (taskCopy.readsHome, withHomeReadingNote); over any other ground it was told nothing. Every reference worker whose folder is not its ground is now told \" is yours to read, not to change. Everything you make goes in , your own folder, and stays there: nothing you make reaches . In your report, say where in that folder the results are, and never say the work is in .\" (taskReadsNote; the field is taskCopy.reads, and the run's helper is withTaskReadsNote)." - - "A run that only read its ground was handed to the engine's landing, which failed in its folder with \"fatal: not a git repository\": a plan note \"the run's landing failed\" was filed, the landing had no line (RunLanding.Line empty, no branch) and the run's page got no homecoming note. Such a run is no longer handed to the engine's landing (landReferenceRun): its landing line and its page's homecoming note both read \"it changed nothing in : what it made is in \" (referenceLandingLine)." + - "A run that only read its ground was handed to the engine's landing, which failed in its folder with \"fatal: not a git repository\": a plan note \"the run's landing failed\" was filed, the landing had no line (RunLanding.Line empty, no branch) and the run's page got no homecoming note. Such a run is no longer handed to the engine's landing (landReferenceRun): its landing line reads \"it changed nothing in : what it made is in \" (referenceLandingLine), and its page carries that line once, in the run's outcome note, with no separate homecoming note. A reference run that failed is given the same line; one that was stopped is given none." - "A reference whose proposal asked for `where: \"in place\"` inside a repository had the redirect \"in place was asked for, and is a repository — the work goes on a branch cut from it instead\" printed on its receipt. The stand still carries that redirect, and the receipt of a reference no longer prints it (taskStandRedirect)." - - "A hand-off that joined a live run was told about its own stand: a reference that joined a run working in a copy of the same ground got the read-only receipt and its worker the read-only note. The receipt sentence and the worker's note of a joined hand-off are now decided by the mode of the run it joined (startOrJoinTaskRunVia answers that mode)." + - "A hand-off that joined a live run was told about its own stand: a reference that joined a run working in a copy of the same ground got the read-only receipt and its worker the read-only note. The receipt sentence and the worker's note of a joined hand-off are now decided by the mode of the run it joined (startOrJoinTaskRunVia answers that mode). A hand-off that joined a run which only reads its ground, the home folder apart, is not given the starting task's sentence or \"It joined the work already underway and shares its copy.\": its receipt reads \"It joined the work already underway, which only reads and writes in a folder of its own, so nothing in changes while it is part of that run. To change , propose the work once that run has ended.\" (taskJoinedReadsSentence), whatever files its own proposal named." + - "Over the home folder, the read-only note of a run was appended to the run's brief before its crew was routed (withHomeReadingNote in startOrJoinTaskRunVia), so the brief a crew kept (taskCrew.brief, TaskCrewRecord.Brief) and the text it was routed on carried the note. Over every ground a run only reads, the note is now added only to what the workers are given: the store's root description, RunSpec.Brief, and the brief a deferred run keeps (beltRun.brief, PendingRunRecord.Brief). The crew's kept brief, which `/redo stronger` and a rerun with routing read again as a contract, is the brief as it was handed in." - "The manager's first law ended \"Asked what is happening, answer from the team.\" It now adds \"A task (propose_task) is not a member: use one only for work no member is here for, or when the person asks for a task, and never to get round a member that did not start. When a member did not start, team_send's answer says why: tell the person that.\" The law's earlier sentences are as they were." --- diff --git a/internal/manual/chat/how-tasks-run.md b/internal/manual/chat/how-tasks-run.md index c086c5338a..223751c352 100644 --- a/internal/manual/chat/how-tasks-run.md +++ b/internal/manual/chat/how-tasks-run.md @@ -116,13 +116,19 @@ project in words is not naming a file, so a brief such as "build the app in the repo" reads this way. So does a relative path such as `Sources/App/main.swift` when neither the file nor the folder that would hold it is there yet. -Such a task says so three times. Its receipt reads `It reads and writes only in a -folder of its own, so nothing in changes`, and says to stop it and propose it again -naming the files it makes or changes by their full path under that folder. Its worker is -told the folder is to read, not to change, and never to report the work as being there. A -task run as a run ends its landing `it changed nothing in : what it made is in `; the older single-task road lands without that line. A task that joins a run -already underway is told what is true of that run instead, since it shares the run's copy. +Such a task says so wherever there is somebody to tell. One the conversation's model +proposes says it in its receipt: `It reads and writes only in a folder of its own, +so nothing in changes`, and to stop it and propose it again naming the files it +makes or changes by their full path under that folder. A task you type with `/task` has no +such receipt. Every such task tells its worker the folder is to read, not to change, and +never to report the work as being there. A task run as a run ends its landing `it changed +nothing in : what it made is in `; the older single-task road lands +without that line. + +A proposed task that joins a run already underway shares that run's copy, so it is told +what is true of that run instead. Joining one that only reads the folder, its receipt says +`nothing in changes while it is part of that run`, whatever files it named, and to +propose the work once that run has ended. To have the work done in the repository, name a file under it by full path in the brief, in what to produce or in the done-when, such as `~/MacStats/Sources/App/main.swift`. diff --git a/internal/session/task.go b/internal/session/task.go index bc63405b48..27e7f1ef1b 100644 --- a/internal/session/task.go +++ b/internal/session/task.go @@ -1147,19 +1147,26 @@ func (a *Agent) handoffAnswer(p *stagedProposal, spec taskSpec, elsewhere string return refusal.Error(), true, true } if err == nil { - said := p.stand + said, shares := p.stand, "It joined the work already underway and shares its copy." if joined { // A TASK THAT JOINED A RUN IS SAID AS THAT RUN STANDS. It shares the // run's copy, so a receipt read off its own stand told a reference // that joined a worktree that nothing in the ground would change. said.mode = stand.mode + // AND A RUN THAT ONLY READS IS SAID AS THE RUN'S DOING, never the + // proposal's: the starting task's sentence told a proposal that had + // named its files by full path that it named none, and to propose + // again, which joins the same run. + if reads := taskJoinedReadsSentence(said); reads != "" { + said, shares = taskStand{}, reads + } } receipt := taskReceipt(p.id, spec, TaskRunning, said, elsewhere) switch { case via != nil: receipt = delegateStartedReceipt(p.id, spec.title, strings.Join(asked, ", "), delegateReceipt(canonicalPath(stand.dir), *via, a.runRowCopy(p.id)), elsewhere) case joined: - receipt = withReport(receipt, "It joined the work already underway and shares its copy.") + receipt = withReport(receipt, shares) } return receipt, false, true } @@ -1292,6 +1299,22 @@ func taskReadsSentence(dir string) string { "If the work is meant to change " + dir + ", stop this task and propose it again naming the files it makes or changes by their full path under " + dir + "." } +// taskJoinedReadsSentence is what a proposer reads when its task joined a run +// already underway that only reads the ground, and nothing for any other +// stand. What the proposal named does not decide it and proposing again +// changes nothing while that run lives, so it says neither +// ([taskReadsSentence]) and names the one thing that does: the run's ending. +// The home folder is only ever read and keeps its own sentence +// ([homeTaskRedirect]). +func taskJoinedReadsSentence(stand taskStand) string { + if stand.mode != TaskModeReference || stand.dir == "" || HoldsHomeFolder(stand.dir) { + return "" + } + dir := cleanFolder(stand.dir) + return "It joined the work already underway, which only reads " + dir + " and writes in a folder of its own, so nothing in " + dir + " changes while it is part of that run. " + + "To change " + dir + ", propose the work once that run has ended." +} + // taskHandoffWakeSentence is what EVERY handoff receipt ends with, and it is one // sentence because it answers one question: what does the model do now? // diff --git a/internal/session/task_reference_test.go b/internal/session/task_reference_test.go index 54ea18e53d..27b7536786 100644 --- a/internal/session/task_reference_test.go +++ b/internal/session/task_reference_test.go @@ -8,6 +8,10 @@ import ( "strconv" "strings" "testing" + "time" + + "github.com/Agent-Field/codeaf/internal/config" + "github.com/Agent-Field/codeaf/internal/crewroute" ) // A TASK THAT ONLY READS ITS GROUND SAYS SO AT ALL THREE ENDS: the proposer's @@ -155,8 +159,8 @@ func TestAReferenceRunLandsWithItsLineAndNoEngineLanding(t *testing.T) { if len(rows) != 1 || !strings.Contains(rows[0].Report, line) { t.Errorf("the settled row does not carry the landing line %q: %+v", line, rows) } - if notes := strings.Join(beltRunNotes(t, sessionDir, "41"), "\n"); !strings.Contains(notes, line) || strings.Contains(notes, "its work is in") { - t.Errorf("the run's page does not say the landing line alone:\n%s", notes) + if notes := strings.Join(beltRunNotes(t, sessionDir, "41"), "\n"); strings.Count(notes, line) != 1 || strings.Contains(notes, "its work is in") { + t.Errorf("the run's page does not say the landing line alone, once:\n%s", notes) } if logDir := agent.logDirectory(); logDir == "" { t.Error("the conversation has no log directory to read plan notes from") @@ -215,3 +219,116 @@ func TestAReferenceThatJoinsAWritingRunIsNotToldItOnlyReads(t *testing.T) { } endBeltRun(t, agent, double) } + +// A TASK THAT JOINS A RUN THAT ONLY READS IS TOLD SO AS THE RUN'S DOING. Its +// own proposal named a file by full path, so the starting task's reason ("named +// no file") is false of it, and its remedy ("propose it again") joins the same +// run: the receipt says what is true and the one thing that changes it. +func TestAWritingTaskThatJoinsAReferenceRunIsToldTheRunOnlyReads(t *testing.T) { + t.Setenv("CODEAF_TASK_BELT", "bash") + double := newBeltRunDouble("the parser reads tokens") + registerBeltRunEngine(t, double) + sessionDir := t.TempDir() + ground := newTestRepo(t) + agent, _ := newTestAgent(t, beltRunCompleter{text: "the parser reads tokens"}, func(config *Config) { + config.Workspace = ground + config.Place = Place{Dir: sessionDir} + config.AskConsent = false + config.TaskAutoApproveSeconds = 0 + }) + if err := agent.startKnownTaskRun(context.Background(), 41, "explain the parser", "brief", nil, taskStand{dir: ground, mode: TaskModeReference, rung: taskGroundSaid}, ""); err != nil { + t.Fatalf("start the reference run: %v", err) + } + <-double.entered + file := filepath.Join(canonicalPath(ground), "parser_notes.go") + args, _ := json.Marshal(taskArguments{ + Title: "Write the parser notes", Summary: "the proposed work", Brief: "write " + file, + Deliverable: "the file " + file, Acceptance: file + " is there", Ground: ground, + }) + proposal, ok := agent.stageTask(context.Background(), args).(*stagedProposal) + if !ok || proposal.stand.mode != TaskModeWorktree { + t.Fatalf("the proposal did not stage as work in its ground: %+v", proposal) + } + agent.ResolveTask(proposal.id, TaskAnswer{Approved: true}) + answer, failed, err := proposal.Commit(context.Background()) + if err != nil || failed { + t.Fatalf("propose_task: failed=%v err=%v answer=%q", failed, err, answer) + } + dir := canonicalPath(ground) + for _, want := range []string{ + "It joined the work already underway, which only reads " + dir, + "nothing in " + dir + " changes while it is part of that run", + "To change " + dir + ", propose the work once that run has ended.", + } { + if !strings.Contains(answer, want) { + t.Errorf("the receipt of a task that joined a run that only reads lacks %q:\n%s", want, answer) + } + } + for _, untrue := range []string{"named no file", "propose it again", "It works in", "shares its copy"} { + if strings.Contains(answer, untrue) { + t.Errorf("the receipt of a task that joined a run that only reads says %q:\n%s", untrue, answer) + } + } + endBeltRun(t, agent, double) +} + +// A RERUN OF A REFERENCE RUN IS STILL A REFERENCE. The read-only note names the +// ground by full path, and a rerun reads the crew's kept brief again as a +// contract: kept with the note, the rerun stood as a writing task on the +// repository, cut a branch and merged, under words calling it read-only. +func TestARerunOfAReferenceRunIsStillAReference(t *testing.T) { + t.Setenv("CODEAF_TASK_BELT", "bash") + first := newBeltRunDouble("the parser reads tokens") + registerBeltRunEngine(t, first) + ground := canonicalPath(newTestRepo(t)) + sessionDir := t.TempDir() + agent, _ := newTestAgent(t, beltRunCompleter{text: "the parser reads tokens"}, func(c *Config) { + // The conversation stands in a plain folder and is about the repository. + c.Workspace = t.TempDir() + c.Place = Place{Dir: sessionDir} + c.SessionFile = filepath.Join(sessionDir, placeTranscript) + c.AskConsent = false + c.ProfileDir = t.TempDir() + c.RouteCrew = func(config.CrewAsk) (crewroute.Decision, error) { return flashDecision(), nil } + }) + agent.refer(PlaceRef{Path: ground, Arrival: PlaceSaid, Referred: time.Now()}) + liveStand := func() taskStand { + agent.beltMu.Lock() + defer agent.beltMu.Unlock() + if agent.beltRun == nil { + return taskStand{} + } + return agent.beltRun.stand + } + + id, _, _, err := agent.StartTask(context.Background(), "say how the parser reads its input", false) + if err != nil { + t.Fatalf("start the reference run: %v", err) + } + <-first.entered + if stand := liveStand(); stand.dir != ground || stand.mode != TaskModeReference { + t.Fatalf("the run does not only read %s: %+v", ground, stand) + } + first.mu.Lock() + given := first.spec.Brief + first.mu.Unlock() + if !strings.Contains(given, ground+" is yours to read, not to change") { + t.Errorf("the run's workers are not told their ground is read-only:\n%s", given) + } + crew := agent.crews.get(id) + if crew == nil || strings.Contains(crew.brief, "yours to read") || strings.Contains(crew.brief, ground) { + t.Fatalf("the brief a rerun reads again carries the read-only note: %+v", crew) + } + endBeltRun(t, agent, first) + + second := newBeltRunDouble("the parser reads tokens") + registerBeltRunEngine(t, second) + if _, err := agent.rerunWithRouting(context.Background(), TaskNotice{ID: id, Title: crew.title, State: TaskDone}, crew, TaskRoutingAction{Kind: TaskRoutingBest}); err != nil { + t.Fatalf("rerun the reference run: %v", err) + } + <-second.entered + if stand := liveStand(); stand.dir != ground || stand.mode != TaskModeReference { + t.Errorf("the rerun of a run that only read %s stands as %+v", ground, stand) + } + endBeltRun(t, agent, second) +} diff --git a/internal/session/task_run_belt.go b/internal/session/task_run_belt.go index a309d07c80..ee19659570 100644 --- a/internal/session/task_run_belt.go +++ b/internal/session/task_run_belt.go @@ -713,10 +713,6 @@ func (a *Agent) startOrJoinTaskRunVia(ctx context.Context, id uint64, title, bri a.publishJoinedRunRows(g, live) return preparedTaskMode(a.config.Place, live.ground, live.stand.mode), true, nil } - // THE READ-ONLY NOTE IS A RUN'S OWN, added once no live run took the work: - // a hand-off that joined was told what is true of the run it joined - // ([Agent.joinOrWait]). - brief = withTaskReadsNote(a.config.Place, brief, stand) // ADMISSION IS CHECKED BEFORE A FOLDER OR COPY IS TOUCHED. A held run seeds // only its plan store so stopping it cannot leave a repository claim behind; @@ -740,7 +736,15 @@ func (a *Agent) startAdmittedBeltRun(ctx context.Context, engine RunEngine, g *T if err != nil { return false, err } - plan, store, err := a.openBeltRunStore(g, path, storeID, title, brief, false) + // THE READ-ONLY NOTE IS IN WHAT THE WORKERS ARE GIVEN AND NEVER IN THE + // CONTRACT. The crew above keeps the brief it was routed on, and a rerun + // reads that brief again as a contract (taskcrew.go, taskrouting.go): the + // note names the ground by full path, so a rerun that found it there stood + // as a writing task on the folder its own words called read-only. It is a + // run's own, added once no live run took the work: a hand-off that joined + // was told what is true of the run it joined ([Agent.joinOrWait]). + given := withTaskReadsNote(a.config.Place, brief, stand) + plan, store, err := a.openBeltRunStore(g, path, storeID, title, given, false) if err != nil { folder.abandon() return false, err @@ -807,7 +811,7 @@ func (a *Agent) startAdmittedBeltRun(ctx context.Context, engine RunEngine, g *T Crew: run.crewDecision(), CrewState: a.initialCrewRecord(run), Model: run.crewWorker(), }) - spec := a.beltRunSpec(run, brief) + spec := a.beltRunSpec(run, given) a.holdProgramCeilings(run, spec) go a.driveBeltRun(runCtx, engine, run, spec) return false, nil @@ -825,7 +829,10 @@ func (a *Agent) startDeferredBeltRun(ctx context.Context, engine RunEngine, g *T return false, err } } - plan, store, err := a.openBeltRunStore(g, path, storeID, title, brief, false) + // The workers' words, and never the crew's kept brief + // ([Agent.startAdmittedBeltRun] has why). + given := withTaskReadsNote(a.config.Place, brief, stand) + plan, store, err := a.openBeltRunStore(g, path, storeID, title, given, false) if err != nil { return false, err } @@ -848,7 +855,7 @@ func (a *Agent) startDeferredBeltRun(ctx context.Context, engine RunEngine, g *T machineHeld = map[string]bool{planStoreID(storeID): true} } run := &beltRun{ - plan: plan, store: store, root: store.RootID(), row: id, title: title, brief: brief, + plan: plan, store: store, root: store.RootID(), row: id, title: title, brief: given, stand: stand, ground: canonicalPath(stand.dir), pending: true, admission: admission, machineHeld: machineHeld, cut: cut, born: born, over: make(chan struct{}), @@ -864,7 +871,7 @@ func (a *Agent) startDeferredBeltRun(ctx context.Context, engine RunEngine, g *T ID: id, Title: title, State: TaskQueued, Program: programName(via), Remote: cloneTaskRemote(run.remote), Computer: run.taskComputerName(), PlanTask: planStoreID(storeID), Crew: run.crewDecision(), CrewState: a.initialCrewRecord(run), Model: run.crewWorker(), Waiting: waiting, - PendingRun: &PendingRunRecord{WorkspaceSet: stand.workspaceSet, Brief: brief, Ground: stand.dir, Mode: stand.mode, Asked: asked}, + PendingRun: &PendingRunRecord{WorkspaceSet: stand.workspaceSet, Brief: given, Ground: stand.dir, Mode: stand.mode, Asked: asked}, }) go a.driveBeltRun(runCtx, engine, run, RunSpec{}) return false, nil @@ -2366,17 +2373,17 @@ func (a *Agent) landBeltRun(ctx context.Context, engine RunEngine, run *beltRun) // filed for every such run, and the conversation was handed the worker's own // account of the work with nothing saying the ground was untouched // (task_brief.go's [copyOnto] has the run). There is no branch to merge and no -// copy to give back: the homecoming is the one line, on the run's page and in -// the landing alike. +// copy to give back: the homecoming is the one line. It is not written twice: +// the landing carries it and the run's one outcome note is where its page +// reads it ([beltRunOutcomeNote]), as a merge that did not go in is read +// ([Agent.bringBeltRunHome]). +// +// A RUN THAT FAILED IS GIVEN THE SAME LINE, and it is as true of it: the ground +// was not its to change, and whatever it made before it ended is in its folder. func (a *Agent) landReferenceRun(run *beltRun, line string) RunLanding { if !a.beginBeltHomecoming(run) { return RunLanding{} } - if _, err := run.store.AddNote(run.root, run.root, line); err != nil { - if g := a.graph(); g != nil { - g.planNote("the run's homecoming note failed: " + err.Error()) - } - } return RunLanding{Line: line} } From 3cd3c04350dc1675fc57c5281c0323f791ec2e26 Mon Sep 17 00:00:00 2001 From: Ara Ghukasyan <329227198+ZeroPoint95@users.noreply.github.com> Date: Wed, 25 Nov 2026 00:23:20 -0500 Subject: [PATCH 5/6] tasks: final review round 3 repairs for a reference saying so A reference run recovered after a crash before its landing no longer takes the git landing, which failed on a folder that is not a repository; it is accepted with the same line. The manual says when a task that names no file reads its repository and when it gets a branch. Tests cover a held run, a failed and a stopped run, a recovered run and a proposal's receipt through the real proposal road. Co-Authored-By: Claude Fable 5.2 --- .../unreleased/2909-reference-task-says-so.md | 4 +- internal/manual/chat/how-tasks-run.md | 25 +- internal/manual/chat/worker-harness.md | 5 +- internal/session/task.go | 8 +- internal/session/task_reference_test.go | 288 +++++++++++++++++- internal/session/task_run_belt.go | 4 +- internal/session/task_run_resolve.go | 13 + 7 files changed, 332 insertions(+), 15 deletions(-) diff --git a/docs/changes/unreleased/2909-reference-task-says-so.md b/docs/changes/unreleased/2909-reference-task-says-so.md index 9855f1eee1..05dbd6bd27 100644 --- a/docs/changes/unreleased/2909-reference-task-says-so.md +++ b/docs/changes/unreleased/2909-reference-task-says-so.md @@ -4,9 +4,9 @@ title: A task that only reads its folder says so when it starts, to its worker, pr: 2909 surface: [engine, chat] invalidates: - - "A task whose stand is a reference (TaskModeReference, a ground it only reads) was told so on its receipt only when `where` named a folder holding the home folder (homeTaskRedirect). Where the proposal's `ground` or its brief had chosen the folder, the receipt read \"It works in , the folder this proposal gave as its ground.\" or \"It works in , the one folder its brief names the work in.\", the home folder included; on the other rungs it had no sentence about the folder. On every rung the receipt of a task the conversation's model proposes now reads \"It reads and writes only in a folder of its own, so nothing in changes: this proposal named no file there by full path. If the work is meant to change , stop this task and propose it again naming the files it makes or changes by their full path under .\" (taskReadsSentence), or over the home folder \"The task reads and keeps what it makes in its own folder; nothing in changes.\" whichever door named the folder. A task a person types with `/task` is handed no receipt sentence about its folder on the run road, and on the older single-task road only the stand's redirect, as before." + - "A task whose stand is a reference (TaskModeReference, a ground it only reads) was told so on its receipt only when `where` named a folder holding the home folder (homeTaskRedirect). Where the proposal's `ground` or its brief had chosen the folder, the receipt read \"It works in , the folder this proposal gave as its ground.\" or \"It works in , the one folder its brief names the work in.\", the home folder included; on the other rungs it had no sentence about the folder. On every rung the receipt of a task the conversation's model proposes now reads \"It reads and writes only in a folder of its own, so nothing in changes: this proposal named no file there by full path. If the work is meant to change , stop this task and propose it again naming the files it makes or changes by their full path under .\" (taskReadsSentence), or over the home folder \"The task reads and keeps what it makes in its own folder; nothing in changes.\" whichever door named the folder. The started receipt of such a task now opens \"It works from the brief alone, in a folder of its own.\"; every other task's still opens \"It works from the brief alone, in a copy of its own.\" (taskReceipt). A task a person types with `/task` is handed no receipt sentence about its folder on the run road, and on the older single-task road only the stand's redirect, as before." - "A reference worker was told \" is yours to read, not to change. Everything you make goes in , your own folder. In your report, say where in that folder the results are.\" only when its ground held the home folder (taskCopy.readsHome, withHomeReadingNote); over any other ground it was told nothing. Every reference worker whose folder is not its ground is now told \" is yours to read, not to change. Everything you make goes in , your own folder, and stays there: nothing you make reaches . In your report, say where in that folder the results are, and never say the work is in .\" (taskReadsNote; the field is taskCopy.reads, and the run's helper is withTaskReadsNote)." - - "A run that only read its ground was handed to the engine's landing, which failed in its folder with \"fatal: not a git repository\": a plan note \"the run's landing failed\" was filed, the landing had no line (RunLanding.Line empty, no branch) and the run's page got no homecoming note. Such a run is no longer handed to the engine's landing (landReferenceRun): its landing line reads \"it changed nothing in : what it made is in \" (referenceLandingLine), and its page carries that line once, in the run's outcome note, with no separate homecoming note. A reference run that failed is given the same line; one that was stopped is given none." + - "A run that only read its ground was handed to the engine's landing, which failed in its folder with \"fatal: not a git repository\": a plan note \"the run's landing failed\" was filed, the landing had no line (RunLanding.Line empty, no branch) and the run's page got no homecoming note. Such a run is no longer handed to the engine's landing (landReferenceRun): its landing line reads \"it changed nothing in : what it made is in \" (referenceLandingLine), and its page carries that line once, in the run's outcome note, with no separate homecoming note. A reference run that failed is given the same line; one that was stopped is given none. A reference run recovered after the process ended between its plan finishing and its landing still waits for the person to accept it (completedRunReview); accepting it took the git landing in its folder and failed with the same error, and it now takes this landing and line instead (acceptCompletedRun). A recovered run whose plan had already failed is settled with its failure alone, without the line." - "A reference whose proposal asked for `where: \"in place\"` inside a repository had the redirect \"in place was asked for, and is a repository — the work goes on a branch cut from it instead\" printed on its receipt. The stand still carries that redirect, and the receipt of a reference no longer prints it (taskStandRedirect)." - "A hand-off that joined a live run was told about its own stand: a reference that joined a run working in a copy of the same ground got the read-only receipt and its worker the read-only note. The receipt sentence and the worker's note of a joined hand-off are now decided by the mode of the run it joined (startOrJoinTaskRunVia answers that mode). A hand-off that joined a run which only reads its ground, the home folder apart, is not given the starting task's sentence or \"It joined the work already underway and shares its copy.\": its receipt reads \"It joined the work already underway, which only reads and writes in a folder of its own, so nothing in changes while it is part of that run. To change , propose the work once that run has ended.\" (taskJoinedReadsSentence), whatever files its own proposal named." - "Over the home folder, the read-only note of a run was appended to the run's brief before its crew was routed (withHomeReadingNote in startOrJoinTaskRunVia), so the brief a crew kept (taskCrew.brief, TaskCrewRecord.Brief) and the text it was routed on carried the note. Over every ground a run only reads, the note is now added only to what the workers are given: the store's root description, RunSpec.Brief, and the brief a deferred run keeps (beltRun.brief, PendingRunRecord.Brief). The crew's kept brief, which `/redo stronger` and a rerun with routing read again as a contract, is the brief as it was handed in." diff --git a/internal/manual/chat/how-tasks-run.md b/internal/manual/chat/how-tasks-run.md index 223751c352..7757c22902 100644 --- a/internal/manual/chat/how-tasks-run.md +++ b/internal/manual/chat/how-tasks-run.md @@ -82,7 +82,9 @@ rung asks, in the two names you already know. An explicit existing `ground` stil every other rung, even when it is a third folder not offered by that question; the receipt says where in words, `It works in , the folder this proposal gave as its ground.`, so a wrong choice is visible immediately. A stand read from the brief is said the same way: -`It works in , the one folder its brief names the work in.` +`It works in , the one folder its brief names the work in.` A task that only reads +its ground is the exception: its receipt says `It reads and writes only in a folder +of its own` instead (see **A task built my project somewhere else**). **How it stands on that ground is not asked either — it follows from the work.** A repository the task writes in gets a working copy of its own, on a branch cut **from that @@ -111,10 +113,15 @@ row carry the ground and how the task stood on it. ## A task built my project somewhere else — it only read my repository, nothing changed in my folder, where is what the task made A task whose whole contract names no file to make or change is treated as reading its -repository: it gets an empty folder of its own and the repository is left alone. Naming a -project in words is not naming a file, so a brief such as "build the app in the MacStats -repo" reads this way. So does a relative path such as `Sources/App/main.swift` when -neither the file nor the folder that would hold it is there yet. +repository when something chose that repository for it: the proposal's `ground`, its brief, +a place the conversation remembered, or the files the conversation has been working with. +It gets an empty folder of its own and the repository is left alone, even when the +conversation was opened there. A task nothing placed, which simply takes the repository +the conversation stands in, gets a working copy on a branch instead. + +Naming a project in words is not naming a file, so "build the app in the MacStats repo" +with `~/MacStats` as its `ground` reads this way. So does a relative path such as +`Sources/App/main.swift` when neither the file nor its folder is there yet. Such a task says so wherever there is somebody to tell. One the conversation's model proposes says it in its receipt: `It reads and writes only in a folder of its own, @@ -125,10 +132,10 @@ never to report the work as being there. A task run as a run ends its landing `i nothing in : what it made is in `; the older single-task road lands without that line. -A proposed task that joins a run already underway shares that run's copy, so it is told -what is true of that run instead. Joining one that only reads the folder, its receipt says -`nothing in changes while it is part of that run`, whatever files it named, and to -propose the work once that run has ended. +A proposed task that joins a run already underway is told what is true of that run +instead. Joining one that only reads the folder, its receipt says `nothing in +changes while it is part of that run`, whatever files it named, and to propose the work +once that run has ended. To have the work done in the repository, name a file under it by full path in the brief, in what to produce or in the done-when, such as `~/MacStats/Sources/App/main.swift`. diff --git a/internal/manual/chat/worker-harness.md b/internal/manual/chat/worker-harness.md index 2c0ca5fc4c..0f6ac0551e 100644 --- a/internal/manual/chat/worker-harness.md +++ b/internal/manual/chat/worker-harness.md @@ -76,7 +76,10 @@ works in that one copy. **A second `/task` joins the run already underway** when it is about the same folder: the new work becomes a child of the run's root, shares the run's copy, and its answer -says `It joined the work already underway and shares its copy.` A proposed task about +says `It joined the work already underway and shares its copy.` The exception is a run that +only reads its folder, the home folder apart: there is no copy to share, and a proposed +task that joins it is told `It joined the work already underway, which only reads +and writes in a folder of its own` instead. A proposed task about ANOTHER folder is refused while that run is underway, with both folders named and `tasks that run together share one copy of one folder. Propose it again when that work has ended`. A task handed off after the run has ended starts a run of its own, in a new diff --git a/internal/session/task.go b/internal/session/task.go index 27e7f1ef1b..2af3c05d68 100644 --- a/internal/session/task.go +++ b/internal/session/task.go @@ -1231,7 +1231,13 @@ func taskReceipt(id uint64, spec taskSpec, state TaskState, stand taskStand, els result := fmt.Sprintf("task %d queued%s: %s\nIt starts when the work it waits on has finished and a slot is free. %s", id, on, spec.title, taskHandoffWakeSentence) return withElsewhere(withReport(withReport(result, taskStandSentence(stand)), taskStandRedirect(stand)), elsewhere) } - result := fmt.Sprintf("task %d started%s: %s\nIt works from the brief alone, in a copy of its own. %s", id, on, spec.title, taskHandoffWakeSentence) + // A reference has no copy: the sentence after this one says it writes only + // in a folder of its own, and the opener may not say otherwise first. + own := "copy" + if stand.mode == TaskModeReference { + own = "folder" + } + result := fmt.Sprintf("task %d started%s: %s\nIt works from the brief alone, in a %s of its own. %s", id, on, spec.title, own, taskHandoffWakeSentence) return withElsewhere(withReport(withReport(result, taskStandSentence(stand)), taskStandRedirect(stand)), elsewhere) } diff --git a/internal/session/task_reference_test.go b/internal/session/task_reference_test.go index 27b7536786..bebd6d252c 100644 --- a/internal/session/task_reference_test.go +++ b/internal/session/task_reference_test.go @@ -12,6 +12,7 @@ import ( "github.com/Agent-Field/codeaf/internal/config" "github.com/Agent-Field/codeaf/internal/crewroute" + "github.com/Agent-Field/codeaf/internal/plandb" ) // A TASK THAT ONLY READS ITS GROUND SAYS SO AT ALL THREE ENDS: the proposer's @@ -96,9 +97,16 @@ func TestAReferenceReceiptSaysNoBranchAndTheHomeFolderOnce(t *testing.T) { if !strings.Contains(reads, "It reads "+ground) || strings.Contains(reads, "branch cut from it") { t.Errorf("a reference asked for in place is told about a branch:\n%s", reads) } - if works := taskReceipt(7, spec, TaskRunning, taskStand{dir: ground, mode: TaskModeWorktree, rung: taskGroundSaid, redirect: branch}, ""); !strings.Contains(works, branch) { + if !strings.Contains(reads, "It works from the brief alone, in a folder of its own. ") || strings.Contains(reads, "in a copy of its own") { + t.Errorf("a reference's receipt opens on a copy it does not have:\n%s", reads) + } + works := taskReceipt(7, spec, TaskRunning, taskStand{dir: ground, mode: TaskModeWorktree, rung: taskGroundSaid, redirect: branch}, "") + if !strings.Contains(works, branch) { t.Errorf("a task on a branch lost its redirect:\n%s", works) } + if !strings.Contains(works, "It works from the brief alone, in a copy of its own. ") { + t.Errorf("a task on a branch lost its opener:\n%s", works) + } for _, stand := range []taskStand{ {dir: home, mode: TaskModeReference, rung: taskGroundSaid}, @@ -332,3 +340,281 @@ func TestARerunOfAReferenceRunIsStillAReference(t *testing.T) { } endBeltRun(t, agent, second) } + +// A PLAIN REFERENCE PROPOSAL IS TOLD SO THROUGH THE PROPOSAL'S OWN ROAD. The +// sentence is tested above as a function; this is the receipt the model that +// proposed the task is handed, with no run underway to join. +func TestAProposedReferenceTaskIsToldItOnlyReads(t *testing.T) { + t.Setenv("CODEAF_TASK_BELT", "bash") + double := newBeltRunDouble("the parser reads tokens") + registerBeltRunEngine(t, double) + sessionDir := t.TempDir() + ground := newTestRepo(t) + agent, _ := newTestAgent(t, beltRunCompleter{text: "the parser reads tokens"}, func(config *Config) { + config.Workspace = ground + config.Place = Place{Dir: sessionDir} + config.AskConsent = false + config.TaskAutoApproveSeconds = 0 + }) + args, _ := json.Marshal(taskArguments{ + Title: "Explain the parser", Summary: "the proposed work", Brief: "say how the parser reads its input", + Deliverable: "a concise answer", Acceptance: "the question is answered", Ground: ground, + }) + proposal, ok := agent.stageTask(context.Background(), args).(*stagedProposal) + if !ok || proposal.stand.mode != TaskModeReference { + t.Fatalf("the proposal did not stage as a reference: %+v", proposal) + } + agent.ResolveTask(proposal.id, TaskAnswer{Approved: true}) + answer, failed, err := proposal.Commit(context.Background()) + if err != nil || failed { + t.Fatalf("propose_task: failed=%v err=%v answer=%q", failed, err, answer) + } + <-double.entered + dir := canonicalPath(ground) + for _, want := range []string{ + "It works from the brief alone, in a folder of its own. ", + "It reads " + dir + " and writes only in a folder of its own, so nothing in " + dir + " changes: this proposal named no file there by full path.", + "stop this task and propose it again naming the files it makes or changes by their full path under " + dir + ".", + } { + if !strings.Contains(answer, want) { + t.Errorf("the receipt of a proposed reference lacks %q:\n%s", want, answer) + } + } + for _, untrue := range []string{"It works in", "in a copy of its own", "It joined the work already underway"} { + if strings.Contains(answer, untrue) { + t.Errorf("the receipt of a proposed reference says %q:\n%s", untrue, answer) + } + } + endBeltRun(t, agent, double) +} + +// A REFERENCE RUN THAT FAILED IS GIVEN THE LANDING LINE AND ONE THAT WAS +// STOPPED IS GIVEN NONE. What a failed run made is still in its folder and its +// ground is still untouched; a stopped run has its own ending and no landing. +func TestAFailedReferenceRunHasItsLandingLineAndAStoppedOneHasNone(t *testing.T) { + for _, tc := range []struct { + name string + stop bool + }{{name: "failed"}, {name: "stopped", stop: true}} { + t.Run(tc.name, func(t *testing.T) { + t.Setenv("CODEAF_TASK_BELT", "bash") + double := newBeltRunDouble("the parser was not read") + // The engine's own ending of a run that did not finish: its word for + // it, and the store's root left for the door to end. + double.summary.Outcome, double.leaveOpen = "ran and did not finish", true + double.real, double.honoursStop = true, tc.stop + registerBeltRunEngine(t, double) + ground := newTestRepo(t) + sessionDir := t.TempDir() + agent, _ := newTestAgent(t, beltRunCompleter{text: "the parser was not read"}, func(config *Config) { + config.Workspace = ground + config.Place = Place{Dir: sessionDir} + config.SessionFile = filepath.Join(sessionDir, placeTranscript) + config.AskConsent = false + }) + if err := agent.startKnownTaskRun(context.Background(), 41, "explain the parser", "brief", nil, taskStand{dir: ground, mode: TaskModeReference, rung: taskGroundSaid}, ""); err != nil { + t.Fatalf("start the reference run: %v", err) + } + <-double.entered + if tc.stop { + if _, err := agent.Cancel(CancelTask + ":41"); err != nil { + t.Fatalf("stop the run: %v", err) + } + beltRunWaitFor(t, "the stopped run to end", func() bool { + agent.beltMu.Lock() + defer agent.beltMu.Unlock() + return agent.beltRun == nil + }) + } else { + endBeltRun(t, agent, double) + } + rows := agent.graph().runRows(41) + if len(rows) != 1 || rows[0].State != TaskFailed || rows[0].Stopped != tc.stop { + t.Fatalf("the run did not end %s: %+v", tc.name, rows) + } + said := rows[0].Report + "\n" + strings.Join(beltRunNotes(t, sessionDir, "41"), "\n") + line := "it changed nothing in " + canonicalPath(ground) + ": what it made is in " + if got := strings.Contains(rows[0].Report, line); got == tc.stop { + t.Errorf("a %s reference run's row carries the landing line: %v\n%s", tc.name, got, rows[0].Report) + } + if tc.stop && strings.Contains(said, "it changed nothing in") { + t.Errorf("a stopped reference run was given a landing:\n%s", said) + } + if double.lands() != 0 { + t.Errorf("the engine was asked to land a folder that is no repository %d times", double.lands()) + } + }) + } +} + +// A REFERENCE RUN THAT IS HELD AND ADMITTED LATER STILL TELLS ITS WORKERS. The +// held road keeps the workers' words itself (the store's root, the run's own +// brief and the record a reopened conversation reads the run back from), and +// the crew's kept brief stays the brief as it was handed in. +func TestAHeldReferenceRunStillTellsItsWorkersTheGroundIsReadOnly(t *testing.T) { + littleMemoryHost(t) + t.Setenv("CODEAF_TASK_BELT", "bash") + engine := newBeltRunDouble("the parser reads tokens") + registerBeltRunEngine(t, engine) + ground := canonicalPath(newTestRepo(t)) + // The conversation stands in a plain folder and is about the repository. + sessionDir, workspace, profile := t.TempDir(), t.TempDir(), t.TempDir() + open := func() *Agent { + agent, _ := newTestAgent(t, beltRunCompleter{text: "the parser reads tokens"}, func(c *Config) { + c.Workspace = workspace + c.Place = Place{Dir: sessionDir} + c.SessionFile = filepath.Join(sessionDir, placeTranscript) + c.ProfileDir = profile + c.AskConsent, c.TaskMaxLoad, c.TaskMinFreeMB = false, 0, 1<<40 + c.RouteCrew = func(config.CrewAsk) (crewroute.Decision, error) { return flashDecision(), nil } + }) + return agent + } + note := ground + " is yours to read, not to change" + keptBrief := func(agent *Agent, id uint64) { + t.Helper() + crew := agent.crews.get(id) + if crew == nil || strings.Contains(crew.brief, "yours to read") || strings.Contains(crew.brief, ground) { + t.Fatalf("the brief a rerun reads again carries the read-only note: %+v", crew) + } + } + + first := open() + first.refer(PlaceRef{Path: ground, Arrival: PlaceSaid, Referred: time.Now()}) + id, _, _, err := first.StartTask(context.Background(), "say how the parser reads its input", false) + if err != nil { + t.Fatalf("start the held reference run: %v", err) + } + beltRunWaitFor(t, "the held row", func() bool { + rows := first.graph().runRows(id) + return len(rows) == 1 && rows[0].State == TaskQueued && rows[0].Waiting == waitingMachineBusy + }) + first.beltMu.Lock() + held := first.beltRun + stand, brief := taskStand{}, "" + if held != nil { + stand, brief = held.stand, held.brief + } + first.beltMu.Unlock() + if held == nil || stand.dir != ground || stand.mode != TaskModeReference { + t.Fatalf("the held run does not only read %s: %+v", ground, stand) + } + if !strings.Contains(brief, note) { + t.Errorf("the brief a held run keeps for its workers lacks the read-only note:\n%s", brief) + } + storeID := strconv.FormatUint(id, 10) + if root := beltRunTaskAt(t, sessionDir, storeID); root == nil || !strings.Contains(root.Description, note) { + t.Errorf("the held run's root does not tell its workers the ground is read-only: %+v", root) + } + if row, found := runRowOf(first.graph(), id); !found || row.PendingRun == nil || !strings.Contains(row.PendingRun.Brief, note) { + t.Errorf("the record a reopened conversation reads the run from lacks the read-only note: %+v", row.PendingRun) + } + keptBrief(first, id) + if engine.didRun() { + t.Fatal("a held run reached the engine") + } + if err := first.Close(); err != nil { + t.Fatal(err) + } + select { + case <-held.over: + case <-time.After(5 * time.Second): + t.Fatal("the held driver did not leave") + } + + // The machine has room now, and the reopened conversation admits the run + // it kept: a host that says nothing holds nothing. + little := readHost + readHost = func() (machineReading, bool) { return machineReading{}, false } + t.Cleanup(func() { readHost = little }) + second := open() + select { + case <-engine.entered: + case <-time.After(10 * time.Second): + t.Fatal("the admitted run did not reach its engine") + } + engine.mu.Lock() + given, own := engine.spec.Brief, engine.spec.Workspace + engine.mu.Unlock() + if !strings.Contains(given, note) || !strings.Contains(given, "your assigned working directory") { + t.Errorf("the workers of a run admitted later are not told their ground is read-only:\n%s", given) + } + if own == "" || canonicalPath(own) == ground { + t.Errorf("the admitted run works in %q, not a folder of its own", own) + } + keptBrief(second, id) + endBeltRun(t, second, engine) + if rows := second.graph().runRows(id); len(rows) != 1 || !strings.Contains(rows[0].Report, "it changed nothing in "+ground) { + t.Errorf("the run admitted later did not land as a reference: %+v", rows) + } +} + +// A REFERENCE RUN RECOVERED AFTER ITS PLAN FINISHED IS ACCEPTED WITH THE SAME +// LANDING. The process ended between the root's `done` and the landing, so the +// row waits for the person; accepting it took the git landing in a folder that +// is no repository and failed, and the run never got its line. +func TestARecoveredReferenceRunIsAcceptedWithItsLandingLine(t *testing.T) { + t.Setenv("CODEAF_TASK_BELT", "bash") + engine := newBeltRunDouble("must not run") + registerBeltRunEngine(t, engine) + place, repo := t.TempDir(), newTestRepo(t) + open := func() *Agent { + agent, _ := newTestAgent(t, &scriptedCompleter{}, func(c *Config) { + c.Place, c.Workspace, c.SessionFile = Place{Dir: place}, repo, filepath.Join(place, placeTranscript) + c.AskConsent = false + }) + return agent + } + first := open() + g := first.graph() + id := g.reserve() + tree, err := prepareTaskTreeOn(context.Background(), first.config.Place, repo, "1111dddd1111dddd", id, "explain the parser", + taskStand{dir: repo, mode: TaskModeReference, rung: taskGroundSaid}) + if err != nil { + t.Fatal(err) + } + line := referenceLandingLine(tree) + if line == "" { + t.Fatalf("the prepared tree is no reference: %+v", tree) + } + made := filepath.Join(tree.dir, "parser.md") + if err := os.WriteFile(made, []byte("the parser reads tokens\n"), 0o600); err != nil { + t.Fatal(err) + } + storeID := strconv.FormatUint(id, 10) + store, err := plandb.Open(g.planPath(), "mock", storeID, "explain the parser", "say how the parser reads its input", g.planChat()) + if err != nil { + t.Fatal(err) + } + if err := store.CompleteRoot("the parser reads tokens; see parser.md"); err != nil { + t.Fatal(err) + } + _ = store.Close() + first.publishRunRow(g, TaskNotice{ID: id, Title: "explain the parser", State: TaskRunning, Copy: runCopyOf(tree), CrewState: first.unroutedCrewRecord(), StartedAt: time.Now().Add(-time.Minute), PlanTask: planStoreID(storeID)}) + if err := first.Close(); err != nil { + t.Fatal(err) + } + + second := open() + if kept, found := runRowOf(second.graph(), id); !found || kept.State != TaskUnverified || !kept.RecoveredCompletion { + t.Fatalf("the recovered reference run does not wait for the person: %+v", kept) + } + before := runTreeHead(repo) + if err := second.ResolveUnverified(id, TaskAccept, "read parser.md"); err != nil { + t.Fatalf("accepting a recovered reference run: %v", err) + } + landed, _ := runRowOf(second.graph(), id) + if landed.State != TaskDone || !strings.Contains(landed.Report, line) || !strings.Contains(landed.Report, "the parser reads tokens; see parser.md") { + t.Errorf("the accepted run did not land with its line %q: %+v", line, landed) + } + if landed.Branch != "" || landed.Merge != "" || runTreeHead(repo) != before { + t.Errorf("accepting a run that only read %s touched it: %+v", repo, landed) + } + if _, err := os.Stat(made); err != nil { + t.Errorf("what the run made is gone from its folder: %v", err) + } + if notes := strings.Join(beltRunNotes(t, place, storeID), "\n"); strings.Count(notes, line) != 1 { + t.Errorf("the run's page does not say the landing line once:\n%s", notes) + } + nothingStarted(t, second, engine) +} diff --git a/internal/session/task_run_belt.go b/internal/session/task_run_belt.go index ee19659570..5854b1d062 100644 --- a/internal/session/task_run_belt.go +++ b/internal/session/task_run_belt.go @@ -711,7 +711,9 @@ func (a *Agent) startOrJoinTaskRunVia(ctx context.Context, id uint64, title, bri PlanTask: planStoreID(storeID), }) a.publishJoinedRunRows(g, live) - return preparedTaskMode(a.config.Place, live.ground, live.stand.mode), true, nil + // The stand is fixed when the run is made; the run's ground is written + // again under beltMu once a held run's copy is ready. + return preparedTaskMode(a.config.Place, canonicalPath(strings.TrimSpace(live.stand.dir)), live.stand.mode), true, nil } // ADMISSION IS CHECKED BEFORE A FOLDER OR COPY IS TOUCHED. A held run seeds diff --git a/internal/session/task_run_resolve.go b/internal/session/task_run_resolve.go index eeb2df3ead..6a8ccaf93d 100644 --- a/internal/session/task_run_resolve.go +++ b/internal/session/task_run_resolve.go @@ -99,6 +99,19 @@ func (a *Agent) acceptCompletedRun(ctx context.Context, g *TaskGraph, kept TaskN if err != nil { return "", true, err } + // A RUN THAT ONLY READ ITS GROUND IS ACCEPTED WITH THE LANDING IT WOULD HAVE + // HAD ([Agent.landReferenceRun]). Its folder is no repository, so the git + // landing below failed in it with `fatal: not a git repository` and the + // run could never be accepted; there is no branch to restore, commit or + // merge, and the homecoming is the one line. + if line := referenceLandingLine(tree); line != "" && kept.WorkspaceSet == nil { + if err := a.admitCompletedRunHomecoming(ctx, epoch); err != nil { + return "", true, err + } + kept.State = TaskDone + kept.Report = withReport(acceptedLine(strings.TrimSpace(why), by), withReport(root.Result, line)) + return a.saveCompletedRunOutcome(g, kept, path, root.ID) + } // A refused landing releases Git's registration while retaining its files. // Restore that registration before checking or committing the saved branch. if reopened, back, problem := tree.reopenReleased(); problem != "" { From 51b72c1ef1651209e0cccaaa77e9a62228ba2b9d Mon Sep 17 00:00:00 2001 From: Ara Ghukasyan <329227198+ZeroPoint95@users.noreply.github.com> Date: Wed, 25 Nov 2026 00:40:35 -0500 Subject: [PATCH 6/6] tasks: keep the recovered-run accept under the complexity ceiling The reference branch added to acceptCompletedRun put it one decision over the task engine's ceiling of 15. The copy is read and the reference case decided in a small wrapper; the git landing is its own function. Co-Authored-By: Claude Fable 5.2 --- internal/session/task_run_resolve.go | 31 ++++++++++++++++++---------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/internal/session/task_run_resolve.go b/internal/session/task_run_resolve.go index 6a8ccaf93d..dc72d43195 100644 --- a/internal/session/task_run_resolve.go +++ b/internal/session/task_run_resolve.go @@ -94,24 +94,33 @@ func (a *Agent) completedRunPlan(id uint64) (string, *plandb.Task, error) { return "", nil, fmt.Errorf("task %d has no completed plan in this conversation; its saved work has not been changed", id) } +// acceptReferenceRun accepts a recovered run that only read its ground, with +// the landing it would have had ([Agent.landReferenceRun]). Its folder is no +// repository, so the git landing failed in it with `fatal: not a git +// repository` and the run could never be accepted; there is no branch to +// restore, commit or merge, and the homecoming is the one line. +func (a *Agent) acceptReferenceRun(ctx context.Context, g *TaskGraph, kept TaskNotice, path string, root *plandb.Task, epoch uint64, why string, by TaskAskOwner, line string) (string, bool, error) { + if err := a.admitCompletedRunHomecoming(ctx, epoch); err != nil { + return "", true, err + } + kept.State = TaskDone + kept.Report = withReport(acceptedLine(strings.TrimSpace(why), by), withReport(root.Result, line)) + return a.saveCompletedRunOutcome(g, kept, path, root.ID) +} + func (a *Agent) acceptCompletedRun(ctx context.Context, g *TaskGraph, kept TaskNotice, path string, root *plandb.Task, epoch uint64, why string, by TaskAskOwner) (string, bool, error) { tree, err := runCopyTree(kept.Copy, a.config.Place) if err != nil { return "", true, err } - // A RUN THAT ONLY READ ITS GROUND IS ACCEPTED WITH THE LANDING IT WOULD HAVE - // HAD ([Agent.landReferenceRun]). Its folder is no repository, so the git - // landing below failed in it with `fatal: not a git repository` and the - // run could never be accepted; there is no branch to restore, commit or - // merge, and the homecoming is the one line. if line := referenceLandingLine(tree); line != "" && kept.WorkspaceSet == nil { - if err := a.admitCompletedRunHomecoming(ctx, epoch); err != nil { - return "", true, err - } - kept.State = TaskDone - kept.Report = withReport(acceptedLine(strings.TrimSpace(why), by), withReport(root.Result, line)) - return a.saveCompletedRunOutcome(g, kept, path, root.ID) + return a.acceptReferenceRun(ctx, g, kept, path, root, epoch, why, by, line) } + return a.acceptCompletedRunTree(ctx, g, kept, path, root, epoch, why, by, tree) +} + +// acceptCompletedRunTree is the git landing of a recovered run's saved copy. +func (a *Agent) acceptCompletedRunTree(ctx context.Context, g *TaskGraph, kept TaskNotice, path string, root *plandb.Task, epoch uint64, why string, by TaskAskOwner, tree taskTree) (string, bool, error) { // A refused landing releases Git's registration while retaining its files. // Restore that registration before checking or committing the saved branch. if reopened, back, problem := tree.reopenReleased(); problem != "" {