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
Enforce task page limits on legacy responses and drop redundant singl…
…e-column indexes.

Refs #327
  • Loading branch information
euxaristia
euxaristia committed Sep 2, 2026
commit eccaf90bca4ddef988d757050f1282534195cace
20 changes: 20 additions & 0 deletions crates/gitlawb-node/src/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1150,6 +1150,12 @@ const MIGRATIONS: &[Migration] = &[
// the keyset order, so the LIMIT is an Index Cond stop. Column order
// and DESC are load-bearing and must match the query. The CASE in the
// assignee indexes must stay byte-identical to ASSIGNEE_DID_CASE_SQL.
//
// Drop the single-column idx_agent_tasks_assignee_key from v27 and
// idx_agent_tasks_status from v1 so the planner never picks a
// non-keyset index that requires an in-memory Sort before LIMIT.
"DROP INDEX IF EXISTS idx_agent_tasks_assignee_key",
"DROP INDEX IF EXISTS idx_agent_tasks_status",
"CREATE INDEX IF NOT EXISTS idx_agent_tasks_created_at_id ON agent_tasks (created_at DESC, id DESC)",
"CREATE INDEX IF NOT EXISTS idx_agent_tasks_status_created_at_id ON agent_tasks (status, created_at DESC, id DESC)",
"CREATE INDEX IF NOT EXISTS idx_agent_tasks_assignee_key_created_at_id ON agent_tasks ((CASE WHEN assignee_did LIKE 'did:key:%' AND position(':' in substr(assignee_did, 9)) = 0 THEN substr(assignee_did, 9) ELSE assignee_did END), created_at DESC, id DESC)",
Expand Down Expand Up @@ -5184,6 +5190,20 @@ mod migration_tests {
assert!(exists.0, "{name} must exist");
}

for old_name in ["idx_agent_tasks_assignee_key", "idx_agent_tasks_status"] {
let exists: (bool,) = sqlx::query_as(
"SELECT EXISTS(
SELECT 1 FROM pg_indexes
WHERE tablename = 'agent_tasks' AND indexname = $1
)",
)
.bind(old_name)
.fetch_one(&db.pool)
.await
.unwrap();
assert!(!exists.0, "{old_name} must be dropped by v28");
}

sqlx::query("DROP INDEX IF EXISTS idx_agent_tasks_created_at_id")
.execute(&db.pool)
.await
Expand Down
124 changes: 97 additions & 27 deletions crates/gl/src/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,12 @@ pub(crate) fn parse_task_page(val: Value) -> Result<TaskPage> {
}
};

if !has_more && next_cursor.is_some() {
anyhow::bail!(
"malformed task response: 'next_cursor' present when 'has_more' is false"
);
}

Ok(TaskPage::Paginated {
tasks: tasks_arr,
has_more,
Expand Down Expand Up @@ -406,40 +412,44 @@ pub(crate) async fn fetch_tasks(
pages += 1;

let page = parse_task_page(raw_val)?;
let page_tasks = match &page {
TaskPage::Paginated { tasks, .. } | TaskPage::Legacy { tasks } => tasks,
};

let mut has_duplicate_row = false;
for t in page_tasks {
if let Some(id) = t.get("id").and_then(|v| v.as_str()) {
if seen_task_ids.contains(id) {
has_duplicate_row = true;
break;
}
}
}
if has_duplicate_row {
incomplete = true;
safe_resume_cursor = None;
break TaskListStop::NoProgress;
}

// `want` is the remaining total, capped at the server page.
// A valid-shaped page larger than that can push the helper
// (and therefore both CLI and MCP) past `--limit`. Treat it
// as protocol-invalid rather than clipping, matching the
// hostile-node handling for duplicate rows and cursor cycles.
if page_tasks.len() as i64 > want {
anyhow::bail!(
"protocol-invalid task page: got {} tasks, asked for {want}",
page_tasks.len()
);
}

match page {
TaskPage::Paginated {
tasks: page_tasks,
has_more,
incomplete: page_incomplete,
next_cursor,
} => {
let mut has_duplicate_row = false;
for t in &page_tasks {
if let Some(id) = t.get("id").and_then(|v| v.as_str()) {
if seen_task_ids.contains(id) {
has_duplicate_row = true;
break;
}
}
}
if has_duplicate_row {
incomplete = true;
safe_resume_cursor = None;
break TaskListStop::NoProgress;
}

// `want` is the remaining total, capped at the server page.
// A valid-shaped page larger than that can push the helper
// (and therefore both CLI and MCP) past `--limit`. Treat it
// as protocol-invalid rather than clipping, matching the
// hostile-node handling for duplicate rows and cursor cycles.
if page_tasks.len() as i64 > want {
anyhow::bail!(
"protocol-invalid task page: got {} tasks, asked for {want}",
page_tasks.len()
);
}

for t in page_tasks {
if let Some(id) = t.get("id").and_then(|v| v.as_str()) {
seen_task_ids.insert(id.to_string());
Expand Down Expand Up @@ -1049,6 +1059,40 @@ mod tests {
);
}

/// A legacy node returning more rows than requested must also be rejected
/// as protocol-invalid before exposing any task rows to the caller.
#[tokio::test]
async fn list_rejects_oversized_legacy_page() {
let mut server = mockito::Server::new_async().await;
let oversized = server
.mock(
"GET",
mockito::Matcher::Regex(r"^/api/v1/tasks\?limit=1$".into()),
)
.with_status(200)
.with_header("content-type", "application/json")
.with_body(
r#"{"tasks":[{"id":"t1","kind":"test"},{"id":"t2","kind":"test"}],"count":2}"#,
)
.expect(1)
.create_async()
.await;

let err = fetch_tasks(&client_for(&server), None, None, 1, None)
.await
.expect_err("oversized legacy page must not succeed");
oversized.assert_async().await;
let msg = err.to_string();
assert!(
msg.contains("protocol-invalid") && msg.contains("asked for 1"),
"{msg}"
);
assert!(
!msg.contains("\"id\":\"t2\""),
"the extra rows must not appear in the error: {msg}"
);
}

/// Malformed responses (missing fields, wrong types) must fail with an error
/// rather than silently succeeding.
#[tokio::test]
Expand All @@ -1060,6 +1104,7 @@ mod tests {
r#"{"tasks":[],"has_more":"true"}"#,
r#"{"tasks":[],"has_more":true,"incomplete":"no"}"#,
r#"{"tasks":[],"has_more":true,"next_cursor":123}"#,
r#"{"tasks":[],"has_more":false,"next_cursor":"stray"}"#,
r#"{"tasks":[],"next_cursor":"c1"}"#,
r#"[]"#,
];
Expand All @@ -1085,6 +1130,31 @@ mod tests {
}
}

/// Contradictory pagination metadata (`has_more: false` alongside a non-empty `next_cursor`)
/// must be rejected as malformed rather than silently accepted or converting into complete: true.
#[tokio::test]
async fn list_rejects_contradictory_has_more_false_with_cursor() {
let mut server = mockito::Server::new_async().await;
let m = server
.mock("GET", mockito::Matcher::Any)
.with_status(200)
.with_header("content-type", "application/json")
.with_body(r#"{"tasks":[],"has_more":false,"next_cursor":"c1"}"#)
.expect(1)
.create_async()
.await;

let err = fetch_tasks(&client_for(&server), None, None, 50, None)
.await
.expect_err("has_more: false with next_cursor must be rejected as malformed");
m.assert_async().await;
assert!(
err.to_string()
.contains("next_cursor' present when 'has_more' is false"),
"{err}"
);
}

/// A node that loops cursors (c1 -> c2 -> c1) must be detected as a cycle,
/// terminating the loop without reaching the limit or page cap, and never
/// reporting duplicate rows as complete or recommending a stale cursor.
Expand Down
Loading