Skip to content

Commit 92d961b

Browse files
committed
fix: count requests, not answers, for Needs you after a merge
Replaces answered_at with requested_at: when a person last sent the session a message that didn't answer its agent's question. Needs you compares the merge with it, so that someone who asks for more after the merge, then answers a question the agent asks about it, still sees the reply, while an answer alone leaves the session done. Migration 0056 (not shipped) fills requested_at from messaged_at for existing sessions, and SessionDO's write keeps D1's value while its summary has none.
1 parent 27bf5bc commit 92d961b

12 files changed

Lines changed: 70 additions & 64 deletions

File tree

‎crates/fctl-control/migrations/0056_session_answered_at.sql‎

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
-- When a person last sent a session a message that didn't answer its
2+
-- agent's question (fctl ask), in milliseconds. NULL: nobody has. SessionDO
3+
-- keeps it in its summary and writes it through, so that lists tell a
4+
-- session someone asked for more after its pull requests merged from one
5+
-- that only heard back on what it asked. Sessions from before it take
6+
-- messaged_at, as nobody could tell their answers apart; SessionDO's write
7+
-- keeps that until a message sets its own.
8+
ALTER TABLE sessions ADD COLUMN requested_at INTEGER;
9+
UPDATE sessions SET requested_at = messaged_at WHERE messaged_at IS NOT NULL;

‎crates/fctl-control/src/do_session.rs‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -933,13 +933,13 @@ impl SessionObject {
933933
self.end_reviews_in_a_row(now).await;
934934
self.delete_meta(CHECKS_IN_A_ROW);
935935
self.delete_meta(CONFLICTS_IN_A_ROW);
936-
// It answers the agent's question, if it asks one. The reply that
937-
// ends the turn it starts is theirs (`Session::messaged_at`),
938-
// unless it answered (`Session::answered_at`): then that turn
939-
// carries on with what the agent asked for.
936+
// It answers the agent's question, if it asks one: then the turn
937+
// it starts carries on with what the agent asked for. Otherwise
938+
// it asks for more, and the reply that ends that turn is theirs
939+
// (`Session::requested_at`).
940940
if let Some(mut s) = self.summary() {
941-
if s.question.take().is_some() {
942-
s.answered_at = Some(now);
941+
if s.question.take().is_none() {
942+
s.requested_at = Some(now);
943943
}
944944
s.messaged_at = Some(now);
945945
self.publish(&mut s, now).await;
@@ -4319,11 +4319,13 @@ impl SessionObject {
43194319
.question
43204320
.as_ref()
43214321
.and_then(|q| serde_json::to_string(q).ok());
4322+
// `requested_at` stays D1's while the summary has none: sessions from
4323+
// before it took their `messaged_at` there (migration 0056).
43224324
let res = crate::db::q(
43234325
&db,
43244326
"UPDATE sessions SET title = ?, description = ?, status = ?, status_reason = ?, resume_at = ?, model = COALESCE(?, model), \
43254327
claude_effort = ?, branch = COALESCE(?, branch), remote_control = ?, stats = ?, pr_number = ?, pr_url = ?, pr_title = ?, pr_state = ?, \
4326-
pull_requests = ?, question = ?, updated_at = ?, last_activity_at = ?, messaged_at = ?, answered_at = ?, started_at = COALESCE(started_at, ?), ended_at = ? WHERE id = ?",
4328+
pull_requests = ?, question = ?, updated_at = ?, last_activity_at = ?, messaged_at = ?, requested_at = COALESCE(?, requested_at), started_at = COALESCE(started_at, ?), ended_at = ? WHERE id = ?",
43274329
&[
43284330
crate::db::s(&s.title),
43294331
crate::db::os(s.description.as_deref()),
@@ -4344,7 +4346,7 @@ impl SessionObject {
43444346
crate::db::n(s.updated_at),
43454347
crate::db::on(s.last_activity_at),
43464348
crate::db::on(s.messaged_at),
4347-
crate::db::on(s.answered_at),
4349+
crate::db::on(s.requested_at),
43484350
crate::db::on(s.started_at),
43494351
crate::db::on(s.ended_at),
43504352
crate::db::s(s.id.as_str()),

‎crates/fctl-control/src/model.rs‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -672,10 +672,10 @@ pub struct SessionRow {
672672
/// column).
673673
#[serde(deserialize_with = "opt_int", default)]
674674
pub messaged_at: Option<i64>,
675-
/// When a person's message last answered its agent's question (NULL:
676-
/// nobody has since the column).
675+
/// When a person last sent it a message that didn't answer its agent's
676+
/// question (NULL: nobody has; `messaged_at` from before the column).
677677
#[serde(deserialize_with = "opt_int", default)]
678-
pub answered_at: Option<i64>,
678+
pub requested_at: Option<i64>,
679679
/// What its agent may do on GitHub, as it started (NULL: push).
680680
#[serde(default)]
681681
pub github_access: Option<String>,
@@ -811,7 +811,7 @@ impl SessionRow {
811811
ended_at: self.ended_at,
812812
last_activity_at: self.last_activity_at,
813813
messaged_at: self.messaged_at,
814-
answered_at: self.answered_at,
814+
requested_at: self.requested_at,
815815
branch: self.branch.clone(),
816816
base_branch: self.base_branch.clone(),
817817
pull_request: match (self.pr_number, &self.pr_url) {
@@ -871,7 +871,7 @@ pub const SESSION_SELECT: &str = "SELECT s.id, s.project_id, p.slug AS project_s
871871
s.credential_id, s.runner_id, r.name AS runner_name, s.branch, s.base_branch, s.model, s.effort, \
872872
s.claude_effort, s.claude_session_id, s.pr_number, s.pr_url, s.pr_title, s.pr_state, s.pull_requests, s.remote_control, s.stats, s.archived, \
873873
s.github_access, json_extract(p.settings, '$.github_access') AS project_github_access, s.github_issues, \
874-
s.created_at, s.updated_at, s.started_at, s.ended_at, s.last_activity_at, s.messaged_at, s.answered_at, \
874+
s.created_at, s.updated_at, s.started_at, s.ended_at, s.last_activity_at, s.messaged_at, s.requested_at, \
875875
m.role AS member_role, sh.role AS share_role, f.user_id IS NOT NULL AS following, \
876876
rv.repo AS review_repo, rv.number AS review_number, rv.url AS review_pr_url, rv.title AS review_title, \
877877
rv.head_sha AS review_sha, s.schedule_id, sc.name AS schedule_name, s.ticket, s.question, \

‎crates/fctl-proto/src/session.rs‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,12 +1349,11 @@ pub struct Session {
13491349
/// people's). Absent until someone does, and from control planes
13501350
/// before it.
13511351
pub messaged_at: Option<Millis>,
1352-
/// When a person's message last answered its agent's question
1353-
/// (`question`). Equal to `messaged_at` when the last message answered
1354-
/// one: the turn it starts carries on with what the agent asked for,
1355-
/// rather than with something new. Absent until someone answers one,
1356-
/// and from control planes before it.
1357-
pub answered_at: Option<Millis>,
1352+
/// When a person last sent it a message that didn't answer its agent's
1353+
/// question (`question`): one that asks it for more, where an answer
1354+
/// only lets the agent carry on with what it asked for. Absent until
1355+
/// someone does, and from control planes before it.
1356+
pub requested_at: Option<Millis>,
13581357
pub branch: Option<String>,
13591358
pub base_branch: Option<String>,
13601359
/// The pull request of its branch in the primary repository, or in

‎docs/api.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ It answers with the session, `queued`. A session is:
9393
| `id`, `number`, `project_id`, `project_slug`, `workspace` | who it is: `my-app#12` is `project_slug#number` |
9494
| `title`, `description` | what it works on, as its agent or people say |
9595
| `status`, `status_reason`, `resume_at` | `queued`, `provisioning`, `preparing`, `running`, `idle`, `paused`, `stopping`, `stopped` or `failed`, and why |
96-
| `created_by`, `created_at`, `started_at`, `ended_at`, `last_activity_at`, `messaged_at`, `answered_at`, `updated_at` | who and when (`messaged_at`: when a person last sent it a message; `answered_at`: when a person's message last answered its agent's `question`) |
96+
| `created_by`, `created_at`, `started_at`, `ended_at`, `last_activity_at`, `messaged_at`, `requested_at`, `updated_at` | who and when (`messaged_at`: when a person last sent it a message; `requested_at`: when a person last sent it one that didn't answer its agent's `question`) |
9797
| `branch`, `base_branch` | its branch and where it started from |
9898
| `pull_requests` | every pull request its agent opened or found: `url`, `number`, `repo`, `title`, `state` (`open`, `draft`, `queued`, `merged`, `closed`), `checks` (`passed`, `failed`, `pending`, and `review`: fctl's review of the newest commit, which the counts leave out, with its `state` (`running`, `passed`, `commented`, `superseded`, `stopped`, `failed`), `waiting` for a runner, `findings`, `still_open` from earlier reviews, `session_id`, its summary's `url` and the `project_id` whose review agents reviewed it, where `POST /api/v1/projects/{id}/reviews` reviews it again; and `held_after` where fctl held its findings back from this session's agent, which got those of that many reviews in a row with no message from a person; and `unsent` where its findings went to no session, as no session listed the pull request when it posted) |
9999
| `model`, `effort`, `github_access`, `github_issues` | what it runs with |

‎docs/architecture.md‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2430,13 +2430,16 @@ sandbox's fctl has it. Review agents ask nobody.
24302430

24312431
As it delivers a message with an author, SessionDO also notes when
24322432
(`Session.messaged_at`, written through to `sessions.messaged_at`), and,
2433-
when the message answers the agent's question, notes that too
2434-
(`Session.answered_at`, the same time). The web app's Needs you lists a
2433+
unless the message answers the agent's question, notes that as when
2434+
someone last asked it for more (`Session.requested_at`): an answer only
2435+
lets the agent carry on with what it asked for. Sessions from before
2436+
`requested_at` took their `messaged_at` in D1, which SessionDO's write
2437+
keeps until a message sets its own. The web app's Needs you lists a
24352438
session that waits for a message as waiting for a reply unless its pull
2436-
requests are all merged or closed and nobody wrote to it after the last
2437-
of them was, or the last message only answered the agent's question
2438-
(whether to re-run a failed deploy, say): then its agent has finished,
2439-
and waits only until its idle timeout stops the session.
2439+
requests are all merged or closed and nobody asked it for more after the
2440+
last of them was: then its agent has finished, and waits only until its
2441+
idle timeout stops the session, even when it asked something after the
2442+
merge (whether to re-run a failed deploy, say) and heard back.
24402443

24412444
### Titles
24422445

‎docs/getting-started.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ started.
466466
sessions you started or follow, most pressing first: what an agent asks
467467
you, a failure, failed checks, a pull request an agent finished, a reply
468468
it waits for (unless its pull requests are all merged or closed and
469-
nobody wrote to it since, or only to answer what it asked: its work is
469+
nobody wrote to it since but to answer what it asked: its work is
470470
done). Its count shows in the
471471
browser's tab, and on fctl's icon where you installed it. **Pull requests** opens the pull requests agents
472472
opened in the sessions you started, sorted by what each needs next; turn

‎web/src/gen/Session.ts‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,12 @@ resume_at?: number, created_by: UserRef, created_at: number, updated_at: number,
4646
*/
4747
messaged_at?: number,
4848
/**
49-
* When a person's message last answered its agent's question
50-
* (`question`). Equal to `messaged_at` when the last message answered
51-
* one: the turn it starts carries on with what the agent asked for,
52-
* rather than with something new. Absent until someone answers one,
53-
* and from control planes before it.
49+
* When a person last sent it a message that didn't answer its agent's
50+
* question (`question`): one that asks it for more, where an answer
51+
* only lets the agent carry on with what it asked for. Absent until
52+
* someone does, and from control planes before it.
5453
*/
55-
answered_at?: number, branch?: string, base_branch?: string,
54+
requested_at?: number, branch?: string, base_branch?: string,
5655
/**
5756
* The pull request of its branch in the primary repository, or in
5857
* another repository when that has none: the last one its agent found.

‎web/src/lib/needs.test.ts‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,22 @@ describe("what needs you", () => {
9696
pr(1, { state: "merged", state_changed_at: at - 60_000 }),
9797
pr(2, { state: "closed", state_changed_at: at }),
9898
];
99-
const before = session({ ...idle, pull_requests: landed, messaged_at: at - 1 });
100-
const after = session({ ...idle, pull_requests: landed, messaged_at: at + 1 });
99+
const before = session({ ...idle, pull_requests: landed, messaged_at: at - 1, requested_at: at - 1 });
100+
const after = session({ ...idle, pull_requests: landed, messaged_at: at + 1, requested_at: at + 1 });
101101
// A pull request merged at a time nobody knows: a message may have come after it.
102-
const untimed = session({ ...idle, pull_requests: [pr(3, { state: "merged" })], messaged_at: at });
102+
const untimed = session({
103+
...idle,
104+
pull_requests: [pr(3, { state: "merged" })],
105+
messaged_at: at,
106+
requested_at: at,
107+
});
103108
expect(needsOf("usr_noor", [before, after, untimed], NOW).map((x) => [x.s.id, x.kind])).toEqual([
104109
[after.id, "waiting"],
105110
[untimed.id, "waiting"],
106111
]);
107112
});
108113

109-
it("waits for no reply when the message after the merge answered its agent's question", () => {
114+
it("waits for no reply when a message after the merge only answered its agent's question", () => {
110115
const idle = { status: "idle", status_reason: "Waiting for a message" } as const;
111116
const at = NOW - 3_600_000;
112117
const landed = [pr(493, { state: "merged", state_changed_at: at })];
@@ -115,22 +120,17 @@ describe("what needs you", () => {
115120
...idle,
116121
pull_requests: landed,
117122
messaged_at: at + 60_000,
118-
answered_at: at + 60_000,
123+
requested_at: at - 60_000,
119124
});
120-
// Someone wrote to it after their answer: the reply to that is theirs.
125+
const neverAsked = session({ ...idle, pull_requests: landed, messaged_at: at + 60_000 });
126+
// Someone asked it for more after the merge, then answered what its agent asked about that: the reply is theirs.
121127
const more = session({
122128
...idle,
123129
pull_requests: landed,
124130
messaged_at: at + 120_000,
125-
answered_at: at + 60_000,
126-
});
127-
const untimed = session({
128-
...idle,
129-
pull_requests: [pr(3, { state: "merged" })],
130-
messaged_at: at,
131-
answered_at: at,
131+
requested_at: at + 60_000,
132132
});
133-
expect(needsOf("usr_noor", [answered, more, untimed], NOW).map((x) => [x.s.id, x.kind])).toEqual([
133+
expect(needsOf("usr_noor", [answered, neverAsked, more], NOW).map((x) => [x.s.id, x.kind])).toEqual([
134134
[more.id, "waiting"],
135135
]);
136136
});

0 commit comments

Comments
 (0)