Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
8b91534
fix(node): gate agent-task reads behind the same visibility rules as …
Aug 12, 2026
e1d5149
fix(node): query the task limit-clamp test as the delegator
Aug 12, 2026
d3f0880
fix(node): scope task visibility lookups to the page's repos
Aug 12, 2026
c765498
Preserve authorized task reads across shipped clients.
Aug 13, 2026
b26db4b
Bound denied task history scans.
Aug 13, 2026
e3b1372
Signal incomplete task scans with recoverable cursors and map read er…
Aug 14, 2026
d43829b
Stop disclosing denied task rows in the scan-wall cursor and add Grap…
Aug 15, 2026
81a1776
Normalize task cursors and gate mutation endpoints behind visibility.
Aug 15, 2026
b1ddf9d
Update complete_task test in test_support to exercise both 404 on unr…
Aug 15, 2026
15d5748
Bind task to repo id in complete_task test in test_support.
Aug 15, 2026
70b2509
Preserve timestamp fractional width and anchor continuation tests on …
Aug 15, 2026
1029cdb
Match on Value::Object to extract task ID in GraphQL continuation test.
Aug 15, 2026
1ed73ae
Remove unused mut binding on visible_newer in GraphQL query test.
Aug 15, 2026
0ec4c71
Hide unauthorized claim and keep assigned tasks from being stolen
Aug 16, 2026
1b9820b
Keep task-list incomplete for the scan ceiling only.
Aug 16, 2026
ecf478e
fix(node): pin claim guards and map mutation errors through AppError
Aug 18, 2026
ecfbfe8
fix(node): match bare and did:key assignee forms in claim and list
Aug 18, 2026
5ac011f
fix(node): check task creation status and add assignee expression index
Aug 31, 2026
cb41fc3
fix(node)!: Replace task cursors with opaque continuation tokens
Aug 21, 2026
193a965
fix(node): End the candidate stream only after the batch is examined
Aug 21, 2026
a65d7c7
fix(gl): Reject a non-positive task-list limit and fault the write un…
Aug 21, 2026
62893e6
fix(node): Bind task cursors to the caller and brake the task read ro…
Aug 21, 2026
d0a34f1
fix(node): Brake anonymous GraphQL task reads on the same per-IP bucket
Aug 22, 2026
94605f8
fix(gl,node): parse typed task pages, track cursor cycles, and normal…
Aug 22, 2026
e6cf84e
fix(node): Cap aliased GraphQL task reads per request and derive has_…
Aug 23, 2026
e3f4031
fix(node): Check database continuation when scan budget ends on exact…
Aug 23, 2026
7d641a3
fix(node): Document and pin the bound on the task scan-ceiling probe
Aug 24, 2026
7da135c
Index task keyset pages so the scan ceiling bounds database work.
Aug 31, 2026
664fad4
Reject oversized task pages so list never returns more than the reque…
Aug 31, 2026
eccaf90
Enforce task page limits on legacy responses and drop redundant singl…
Sep 2, 2026
b079c11
Address review feedback on task-read authorization gating and client …
Sep 2, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Stop disclosing denied task rows in the scan-wall cursor and add Grap…
…hQL pagination state.

Refs #268
  • Loading branch information
euxaristia
euxaristia committed Aug 31, 2026
commit d43829b2350193ea06feb6d7fa992da4d3ebbe16
86 changes: 62 additions & 24 deletions crates/gitlawb-node/src/api/tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,15 @@ pub(crate) fn task_visible(
#[derive(Debug, Clone)]
pub(crate) struct VisibleTasks {
pub tasks: Vec<AgentTask>,
/// True when the candidate scan hit `MAX_TASK_SCAN_CANDIDATES` before
/// filling `limit`, so the caller cannot tell an empty/short page from an
/// exhaustive one. Deliberately carries no cursor: the scan position at
/// that point is the last *examined* candidate, which may be a task the
/// caller was denied, and handing that back would let a denied read leak
/// the id/created_at of a row `GET /tasks/{id}` otherwise 404s (the same
/// id `claim_task` accepts). A caller can still page with
/// `after_created_at`/`after_id` set to the last row *they* received.
pub incomplete: bool,
pub next_cursor: Option<(String, String)>,
}

/// Collect up to `limit` tasks visible to `caller`, applying the same gate the
Expand All @@ -203,14 +210,12 @@ pub(crate) async fn collect_visible_tasks(
return Ok(VisibleTasks {
tasks: Vec::new(),
incomplete: false,
next_cursor: None,
});
}
let mut visible = Vec::with_capacity(bounded_limit as usize);
let mut cursor: Option<(String, String)> =
after.map(|(ts, id)| (ts.to_string(), id.to_string()));
let mut scanned = 0;
let mut last_examined: Option<(String, String)> = None;

while scanned < MAX_TASK_SCAN_CANDIDATES {
let batch_limit = MAX_VISIBLE_TASKS.min(MAX_TASK_SCAN_CANDIDATES - scanned);
Expand All @@ -231,7 +236,6 @@ pub(crate) async fn collect_visible_tasks(
let next_cursor = tasks
.last()
.map(|task| (task.created_at.clone(), task.id.clone()));
last_examined = next_cursor.clone();

let referenced: Vec<String> = tasks
.iter()
Expand Down Expand Up @@ -264,12 +268,10 @@ pub(crate) async fn collect_visible_tasks(
}

let incomplete = visible.len() < bounded_limit as usize && scanned >= MAX_TASK_SCAN_CANDIDATES;
let next_cursor = if incomplete { last_examined } else { None };

Ok(VisibleTasks {
tasks: visible,
incomplete,
next_cursor,
})
}

Expand Down Expand Up @@ -354,11 +356,12 @@ pub async fn list_tasks(
auth: Option<Extension<AuthenticatedDid>>,
) -> crate::error::Result<Json<Value>> {
let caller = auth.as_ref().map(|e| e.0 .0.as_str());
let after = q
.after_created_at
.as_deref()
.or(q.cursor_created_at.as_deref())
.zip(q.after_id.as_deref().or(q.cursor_id.as_deref()));
let after = parse_after_cursor(
q.after_created_at
.as_deref()
.or(q.cursor_created_at.as_deref()),
q.after_id.as_deref().or(q.cursor_id.as_deref()),
)?;
let result = collect_visible_tasks(
&state.db,
q.status.as_deref(),
Expand All @@ -369,20 +372,29 @@ pub async fn list_tasks(
)
.await?;
let items: Vec<Value> = result.tasks.iter().map(task_to_read_json).collect();
let next_cursor = result.next_cursor.map(|(created_at, id)| {
json!({
"created_at": created_at,
"id": id,
})
});
Ok(Json(json!({
"tasks": items,
"count": items.len(),
"incomplete": result.incomplete,
"next_cursor": next_cursor,
})))
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

/// A cursor is two independently optional query fields (`created_at`, `id`);
/// treating a half-supplied pair as absent would silently restart the caller
/// at page one instead of surfacing the lost half. Require both together.
pub(crate) fn parse_after_cursor<'a>(
created_at: Option<&'a str>,
id: Option<&'a str>,
) -> crate::error::Result<Option<(&'a str, &'a str)>> {
match (created_at, id) {
(Some(ts), Some(id)) => Ok(Some((ts, id))),
(None, None) => Ok(None),
_ => Err(AppError::BadRequest(
"after_created_at and after_id must be supplied together".into(),
)),
}
}

/// GET /api/v1/tasks/{id}
///
/// Gated the same way as `list_tasks` (#268): a task the caller may not see
Expand Down Expand Up @@ -949,15 +961,23 @@ mod visible_tasks_tests {
assert_eq!(body["count"], 0);
assert_eq!(body["incomplete"], true);
assert!(!body.to_string().contains("past-ceiling"));
assert!(
body.get("next_cursor").is_none(),
"response must not disclose the last examined (denied) row's id/created_at: {body}"
);
assert!(
!body.to_string().contains("hidden-"),
"response must not leak any denied row's id: {body}"
);

let next_cursor = &body["next_cursor"];
let cursor_ts = next_cursor["created_at"].as_str().expect("cursor ts");
let cursor_id = next_cursor["id"].as_str().expect("cursor id");

// No cursor is disclosed above, so resuming past the scan wall in one
// more request requires `after_created_at`/`after_id` the caller
// already legitimately knows. This stands in for that out-of-band
// knowledge with the last seeded row's known position.
let resp = list_router(state)
.oneshot(anon_get(&format!(
"/api/v1/tasks?limit=1&after_created_at={}&after_id={}",
cursor_ts, cursor_id
"/api/v1/tasks?limit=1&after_created_at=2026-01-02T00:00:00Z&after_id=hidden-{:04}",
MAX_TASK_SCAN_CANDIDATES - 1
)))
.await
.unwrap();
Expand All @@ -967,6 +987,24 @@ mod visible_tasks_tests {
assert_eq!(body["tasks"][0]["id"], "past-ceiling");
}

#[sqlx::test]
async fn list_tasks_rejects_partial_cursor_pair(pool: PgPool) {
let state = test_state(pool).await;
let resp = list_router(state.clone())
.oneshot(anon_get(
"/api/v1/tasks?after_created_at=2026-01-01T00:00:00Z",
))
.await
.unwrap();
assert_eq!(resp.status(), StatusCode::BAD_REQUEST);

let resp = list_router(state)
.oneshot(anon_get("/api/v1/tasks?after_id=some-id"))
.await
.unwrap();
assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
}

#[sqlx::test]
async fn list_tasks_closed_pool_returns_503_db_unavailable(pool: PgPool) {
let state = test_state(pool.clone()).await;
Expand Down
87 changes: 70 additions & 17 deletions crates/gitlawb-node/src/graphql/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::sync::Arc;

use crate::db::Db;

use super::types::{AgentTaskReadType, RefUpdateType, RepoType};
use super::types::{AgentTaskReadType, RefUpdateType, RepoType, TaskPageType};

pub struct QueryRoot;

Expand Down Expand Up @@ -117,7 +117,7 @@ impl QueryRoot {
limit: i64,
after_created_at: Option<String>,
after_id: Option<String>,
) -> Result<Vec<AgentTaskReadType>> {
) -> Result<TaskPageType> {
let db = ctx.data_unchecked::<Arc<Db>>();
// #268: gate rows via the same collector the REST list route uses (like
// `ref_updates` shares `collect_visible_ref_updates` with its REST feed),
Expand All @@ -127,7 +127,9 @@ impl QueryRoot {
.data::<crate::auth::AuthenticatedDid>()
.ok()
.map(|d| d.0.as_str());
let after = after_created_at.as_deref().zip(after_id.as_deref());
let after =
crate::api::tasks::parse_after_cursor(after_created_at.as_deref(), after_id.as_deref())
.map_err(crate::graphql::graphql_app_err)?;
let result = crate::api::tasks::collect_visible_tasks(
db,
status.as_deref(),
Expand All @@ -138,11 +140,14 @@ impl QueryRoot {
)
.await
.map_err(crate::graphql::graphql_app_err)?;
Ok(result
.tasks
.into_iter()
.map(AgentTaskReadType::from)
.collect())
Ok(TaskPageType {
items: result
.tasks
.into_iter()
.map(AgentTaskReadType::from)
.collect(),
incomplete: result.incomplete,
})
}

async fn task(&self, ctx: &Context<'_>, id: String) -> Result<Option<AgentTaskReadType>> {
Expand Down Expand Up @@ -487,7 +492,7 @@ mod tests {
async fn tasks_negative_limit_clamped(pool: PgPool) {
let db = db(pool).await;
let schema = schema(db);
let resp = anon(&schema, "{ tasks(limit: -1) { id } }").await;
let resp = anon(&schema, "{ tasks(limit: -1) { items { id } } }").await;
assert!(
resp.errors.is_empty(),
"negative limit must clamp, not fail: {:?}",
Expand Down Expand Up @@ -525,7 +530,7 @@ mod tests {
// surface is visibility-gated, and an anonymous caller sees none of
// these repo-less tasks at all. The clamp is what this test pins, so it
// needs a caller who can legitimately see all 201 rows.
let resp = authed(&schema, "{ tasks(limit: 5000) { id } }", OWNER).await;
let resp = authed(&schema, "{ tasks(limit: 5000) { items { id } } }", OWNER).await;
assert_eq!(count_tasks(&resp), 200, "limit above 200 must clamp to 200");
}

Expand Down Expand Up @@ -562,7 +567,7 @@ mod tests {
let db = db(pool).await;
seed_task(&db, "t1", OWNER).await;
let schema = schema(db);
let resp = anon(&schema, "{ tasks { id } }").await;
let resp = anon(&schema, "{ tasks { items { id } } }").await;
assert_eq!(
count_tasks(&resp),
0,
Expand Down Expand Up @@ -641,11 +646,18 @@ mod tests {
}

let schema = schema(db);
let resp = anon(&schema, "{ tasks(limit: 1) { id } }").await;
let resp = anon(&schema, "{ tasks(limit: 1) { items { id } incomplete } }").await;
assert_eq!(count_tasks(&resp), 1);
assert!(!task_incomplete(&resp));
assert!(format!("{:?}", resp.data).contains("visible"));
}

/// The candidate scan wall reports `incomplete: true` with no cursor
/// (#268 follow-up review): the server never discloses the id/created_at
/// of a denied row it stopped scanning on. A caller that wants to push
/// past the wall in one more request must supply `after`/`id` it already
/// legitimately knows, which this test stands in for directly rather than
/// reading it from a prior response, since none is offered.
#[sqlx::test]
async fn tasks_continuation_past_candidate_ceiling(pool: PgPool) {
let db = db(pool).await;
Expand Down Expand Up @@ -678,26 +690,67 @@ mod tests {
}

let schema = schema(db);
let resp = anon(&schema, "{ tasks(limit: 1) { id } }").await;
let resp = anon(&schema, "{ tasks(limit: 1) { items { id } incomplete } }").await;
assert_eq!(count_tasks(&resp), 0);
assert!(task_incomplete(&resp));
assert!(!format!("{:?}", resp.data).contains("hidden-"));

let resp = anon(
&schema,
r#"{ tasks(limit: 1, afterCreatedAt: "2026-01-02T00:00:00Z", afterId: "hidden-0999") { id } }"#,
r#"{ tasks(limit: 1, afterCreatedAt: "2026-01-02T00:00:00Z", afterId: "hidden-0999") { items { id } incomplete } }"#,
)
.await;
assert_eq!(count_tasks(&resp), 1);
assert!(!task_incomplete(&resp));
assert!(format!("{:?}", resp.data).contains("past-ceiling"));
}

#[sqlx::test]
async fn tasks_rejects_partial_cursor_pair(pool: PgPool) {
let db = db(pool).await;
let schema = schema(db);
let resp = anon(
&schema,
r#"{ tasks(afterCreatedAt: "2026-01-01T00:00:00Z") { items { id } } }"#,
)
.await;
assert!(
!resp.errors.is_empty(),
"a half-supplied cursor must be rejected, not treated as page one"
);
}

fn task_items(resp: &async_graphql::Response) -> &Vec<async_graphql::Value> {
assert!(resp.errors.is_empty(), "graphql errors: {:?}", resp.errors);
let async_graphql::Value::Object(obj) = &resp.data else {
panic!("data not an object: {:?}", resp.data);
};
let async_graphql::Value::Object(page) = obj.get("tasks").expect("tasks key") else {
panic!("tasks not an object");
};
let async_graphql::Value::List(rows) = page.get("items").expect("items key") else {
panic!("items not a list");
};
rows
}

fn count_tasks(resp: &async_graphql::Response) -> usize {
task_items(resp).len()
}

fn task_incomplete(resp: &async_graphql::Response) -> bool {
assert!(resp.errors.is_empty(), "graphql errors: {:?}", resp.errors);
let async_graphql::Value::Object(obj) = &resp.data else {
panic!("data not an object: {:?}", resp.data);
};
let async_graphql::Value::List(rows) = obj.get("tasks").expect("tasks key") else {
panic!("tasks not a list");
let async_graphql::Value::Object(page) = obj.get("tasks").expect("tasks key") else {
panic!("tasks not an object");
};
rows.len()
let async_graphql::Value::Boolean(incomplete) =
page.get("incomplete").expect("incomplete key")
else {
panic!("incomplete not a bool");
};
*incomplete
}
}
12 changes: 12 additions & 0 deletions crates/gitlawb-node/src/graphql/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,18 @@ pub struct AgentTaskReadType {
pub deadline: Option<String>,
}

/// Wraps a `tasks` page with the same truncation signal the REST list route
/// exposes (`incomplete`), so a GraphQL caller behind a denied-row scan wall
/// can tell a short page from an exhaustive one instead of getting an
/// indistinguishable empty/short list. Carries no cursor, for the same reason
/// REST's `list_tasks` response does not: the scan wall lands on the last
/// *examined* candidate, not necessarily one the caller may see.
#[derive(SimpleObject, Clone)]
pub struct TaskPageType {
pub items: Vec<AgentTaskReadType>,
pub incomplete: bool,
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

impl From<AgentTask> for AgentTaskReadType {
fn from(t: AgentTask) -> Self {
Self {
Expand Down